Skip to content

Partition ID

When inserting into Nebula Graph, vertices and edges are distributed across different partitions. And the partitions are located on different machines. If you want certain vertices to locate on the same partition (i.e., on the same machine), you can control the generation of the VIDs by using the following formula / code.

    // If the length of the id is 8, we will treat it as int64_t to be compatible
    // with the version 1.0
    uint64_t vid = 0;
    if (id.size() == 8) {
        memcpy(static_cast<void*>(&vid),, 8);
    } else {
        MurmurHash2 hash;
        vid = hash(;
    PartitionID pId = vid % numParts + 1;

Roughly say, after hashing a fixed string to int64, (the hashing of int64 is the number itself), do modulo and then plus one.

pId = vid % numParts + 1;

In the preceding formula,

  • % is the modulo operation.
  • numParts is the number of partition for the graph space where the VID is located, namely the value of partition_num in the CREATE SPACE statement.
  • pId is the ID for the partition where the VID is located.

For example, if there are 100 partitions, the vertices with VID 1, 101, 1001 will be stored on the same partition.

But, the mapping between the partition ID and the machine address is random. Therefore, you can't assume that any two partitions are located on the same machine.

Last update: May 20, 2021
Back to top