|
|
@ -69,20 +69,20 @@ func GenKey(ip, port string) (kyber.Scalar, kyber.Point) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// AllocateShard uses the number of current nodes and number of shards
|
|
|
|
// AllocateShard uses the number of current nodes and number of shards
|
|
|
|
// to return the shardnum a new node belongs to, it also tells whether the node is a leader
|
|
|
|
// to return the shardNum a new node belongs to, it also tells whether the node is a leader
|
|
|
|
func AllocateShard(numnode, numshards int) (int, bool) { |
|
|
|
func AllocateShard(numOfAddedNodes, numOfShards int) (int, bool) { |
|
|
|
if numshards == 1 { |
|
|
|
if numOfShards == 1 { |
|
|
|
if numnode == 1 { |
|
|
|
if numOfAddedNodes == 1 { |
|
|
|
return 1, true |
|
|
|
return 1, true |
|
|
|
} |
|
|
|
} |
|
|
|
return 1, false |
|
|
|
return 1, false |
|
|
|
} |
|
|
|
} |
|
|
|
if numnode > numshards { |
|
|
|
if numOfAddedNodes > numOfShards { |
|
|
|
shardnum := numnode % numshards |
|
|
|
shardNum := numOfAddedNodes % numOfShards |
|
|
|
if shardnum == 0 { |
|
|
|
if shardNum == 0 { |
|
|
|
return numshards, false |
|
|
|
return numOfShards, false |
|
|
|
} |
|
|
|
} |
|
|
|
return shardnum, false |
|
|
|
return shardNum, false |
|
|
|
} |
|
|
|
} |
|
|
|
return numnode, true |
|
|
|
return numOfAddedNodes, true |
|
|
|
} |
|
|
|
} |
|
|
|