Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add salt when generating cluster id to reduce duplication #5514

Merged
merged 1 commit into from
Apr 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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