Skip to content

Commit

Permalink
Update cluster id (#5514)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aiee authored and Sophie-Xie committed Apr 19, 2023
1 parent a3d1bea commit abc9f35
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/meta/KVBasedClusterIdMan.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,17 @@ class ClusterIdMan {
* @return
*/
static ClusterID create(const std::string& metaAddrs) {
// Generate random salt
std::random_device rd;
std::mt19937 gen(rd());
std::string randomBytes(16, ' ');
std::generate_n(randomBytes.begin(), 16, std::ref(gen));

// Concatenate salt with input string
std::string saltedInput = metaAddrs + randomBytes;

std::hash<std::string> hash_fn;
auto clusterId = hash_fn(metaAddrs);
auto clusterId = hash_fn(saltedInput);
uint64_t mask = 0x7FFFFFFFFFFFFFFF;
clusterId &= mask;
LOG(INFO) << "Create ClusterId " << clusterId;
Expand Down

0 comments on commit abc9f35

Please sign in to comment.