Skip to content

Commit

Permalink
Add salt when generating cluster id to reduce duplication (#2545)
Browse files Browse the repository at this point in the history
Co-authored-by: Yichen Wang <18348405+Aiee@users.noreply.github.com>
  • Loading branch information
nebula-bots and Aiee authored Mar 31, 2023
1 parent ea5b969 commit 6deb7b8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/clients/meta/MetaClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ class MetaClient : public BaseMetaClient {
ListenersMap doGetListenersMap(const HostAddr& host, const LocalCache& localCache);

// Checks if the client version is compatible with the server version by checking the
// whilelist in meta.
// whitelist in meta.
Status verifyVersion();

// Save the version of the graph service into meta so that it could be looked up.
Expand Down
11 changes: 10 additions & 1 deletion src/common/meta/ClusterIdManBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,17 @@ class ClusterIdManBase {
ClusterIdManBase() = delete;

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 6deb7b8

Please sign in to comment.