From 1355e61f99605030745af3c70f396b4ea336be49 Mon Sep 17 00:00:00 2001 From: Dmitry Kropachev Date: Mon, 17 Mar 2025 23:06:02 -0400 Subject: [PATCH] Fix multi DC token calculation Provision multi DC cluster and list `initial_token`: ``` rm -rf ~/.ccm/test ccm create test -i 127.0.0. -n 4:0 -v release:6.2 --scylla cat ~/.ccm/test/*/node.conf | grep init initial_token: -9223372036854775808 initial_token: -9223372036854775708 ``` As you can see only two nodes got `initial_token` To fix that we need to pass `node_locations` to `balanced_tokens_across_dcs` And have ti fixed a bit. --- ccmlib/cluster.py | 12 ++++++------ ccmlib/node.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ccmlib/cluster.py b/ccmlib/cluster.py index 4c897f0e..78c4ee58 100644 --- a/ccmlib/cluster.py +++ b/ccmlib/cluster.py @@ -319,7 +319,7 @@ def populate(self, nodes, debug=False, tokens=None, use_vnodes=False, ipprefix=N if dcs is None or len(dcs) <= 1: tokens = self.balanced_tokens(node_count) else: - tokens = self.balanced_tokens_across_dcs(dcs) + tokens = self.balanced_tokens_across_dcs(node_locations) assert node_count == len(node_locations) for i in range(1, node_count + 1): @@ -379,18 +379,18 @@ def balanced_tokens(self, node_count): return [int(t - 2 ** 63) for t in ptokens] return [int(i * (2 ** 127 // node_count)) for i in range(0, node_count)] - def balanced_tokens_across_dcs(self, dcs): + def balanced_tokens_across_dcs(self, node_locations): tokens = [] - current_dc = dcs[0] + current_dc = node_locations[0][0] count = 0 dc_count = 0 - for dc in dcs: - if dc == current_dc: + for dc in node_locations: + if dc[0] == current_dc: count += 1 else: new_tokens = [tk + (dc_count * 100) for tk in self.balanced_tokens(count)] tokens.extend(new_tokens) - current_dc = dc + current_dc = dc[0] count = 1 dc_count += 1 new_tokens = [tk + (dc_count * 100) for tk in self.balanced_tokens(count)] diff --git a/ccmlib/node.py b/ccmlib/node.py index 4e53311a..cabec0e3 100644 --- a/ccmlib/node.py +++ b/ccmlib/node.py @@ -1577,7 +1577,7 @@ def _update_config(self): } if self.pid: values['pid'] = self.pid - if self.initial_token: + if self.initial_token is not None: values['initial_token'] = self.initial_token if self.__install_dir is not None: values['install_dir'] = self.__install_dir