Skip to content

Commit 04dfa0d

Browse files
committed
scylla-node: start: do not preserve smp and memory passed via env or cmd_line
If a test wants to preserve memory and/or smp across node restarts, it should use the methods that were intended for this: set_smp and set_mem_mb_per_cpu. Preserving those implicitly when passed to start was not intended. Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
1 parent 1e9a0cc commit 04dfa0d

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

ccmlib/scylla_node.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,15 @@ def __init__(self, name, cluster: 'ScyllaCluster', auto_bootstrap,
161161
self._process_scylla_waiter = None
162162
self._process_agent = None
163163
self._process_agent_waiter = None
164-
self._smp = 2
164+
# _conf_smp and _conf_mem_mb_per_cpu reflect the default values to be used when starting the node
165+
# and they may be overridden by ad-hoc jvm_args.
166+
# The default values hard-coded here may may be overridden by options in the SCYLLA_EXT_OPTS environment variable.
167+
self._conf_smp = 2
165168
self._smp_set_during_test = False
166-
self._mem_mb_per_cpu = 512
169+
self._conf_mem_mb_per_cpu = 512
167170
self._mem_mb_set_during_test = False
171+
# _smp and _memory reflect the current value when the node is running
172+
self._smp = None
168173
self._memory = None
169174
self.__conf_updated = False
170175
self.scylla_manager = scylla_manager
@@ -224,14 +229,14 @@ def is_scylla_reloc(self):
224229
return self.cluster.is_scylla_reloc()
225230

226231
def set_smp(self, smp):
227-
self._smp = smp
232+
self._conf_smp = smp
228233
self._smp_set_during_test = True
229234

230235
def smp(self):
231236
return self._smp
232237

233238
def set_mem_mb_per_cpu(self, mem):
234-
self._mem_mb_per_cpu = mem
239+
self._conf_mem_mb_per_cpu = mem
235240
self._mem_mb_set_during_test = True
236241

237242
def get_install_cassandra_root(self):
@@ -688,22 +693,27 @@ def start(self, join_ring=True, no_wait=False, verbose=False,
688693
# Lets search for default overrides in SCYLLA_EXT_OPTS
689694
env_args = process_opts(os.getenv('SCYLLA_EXT_OPTS', "").split())
690695

691-
# precalculate self._mem_mb_per_cpu if --memory is given in SCYLLA_EXT_OPTS
696+
smp = self._conf_smp
697+
memory_in_mb = None
698+
699+
if not self._smp_set_during_test and '--smp' in env_args:
700+
smp = int(env_args['--smp'][0])
701+
702+
# precalculate self._conf_mem_mb_per_cpu if --memory is given in SCYLLA_EXT_OPTS
692703
# and it wasn't set explicitly by the test
693704
if not self._mem_mb_set_during_test and '--memory' in env_args:
694-
memory = self.parse_size(env_args['--memory'][0])
695-
smp = int(env_args['--smp'][0]) if '--smp' in env_args else self._smp
696-
self._mem_mb_per_cpu = int((memory / smp) // MB)
705+
memory_in_mb = self.parse_size(env_args['--memory'][0]) // MB
706+
self._conf_mem_mb_per_cpu = int(memory_in_mb / smp)
697707

698708
cmd_args = process_opts(jvm_args)
699709

700710
# use '--memory' in jmv_args if mem_mb_per_cpu was not set by the test
701711
if not self._mem_mb_set_during_test and '--memory' in cmd_args:
702-
self._memory = self.parse_size(cmd_args['--memory'][0])
712+
memory_in_mb = self.parse_size(cmd_args['--memory'][0]) // MB
703713

704714
# use '--smp' in jvm_args if was not set by the test
705715
if not self._smp_set_during_test and '--smp' in cmd_args:
706-
self._smp = int(cmd_args['--smp'][0])
716+
smp = int(cmd_args['--smp'][0])
707717

708718
ext_args = env_args
709719
ext_args.update(cmd_args)
@@ -721,12 +731,16 @@ def start(self, join_ring=True, no_wait=False, verbose=False,
721731

722732
# calculate memory from smp * mem_mb_per_cpu
723733
# if not given in jvm_args
724-
if not self._memory:
725-
self._memory = int(self._smp * self._mem_mb_per_cpu * MB)
734+
if not memory_in_mb:
735+
memory_in_mb = smp * self._conf_mem_mb_per_cpu
736+
737+
# Update the _smp and _memory members that are returned by the respective methods.
738+
self._smp = smp
739+
self._memory = memory_in_mb * MB
726740

727741
assert '--smp' not in args and '--memory' not in args, args
728-
args += ['--smp', str(self._smp)]
729-
args += ['--memory', f"{int(self._memory // MB)}M"]
742+
args += ['--smp', str(smp)]
743+
args += ['--memory', f"{memory_in_mb}M"]
730744

731745
if '--developer-mode' not in args:
732746
args += ['--developer-mode', 'true']

0 commit comments

Comments
 (0)