Skip to content

Fix CCM not cleaning up all nodes if one fails to start #792

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

Merged
merged 1 commit into from
May 28, 2025
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions ccmlib/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ def start(self, no_wait=False, verbose=False, wait_for_binary_proto=True,
if not node._wait_for_running(p, timeout_s=7):
raise NodeError("Node {} should be running before waiting for <started listening> log message, "
"but C* process is terminated.".format(node.name))
for node, p, mark in started:
try:
timeout=kwargs.get('timeout', DEFAULT_CLUSTER_WAIT_TIMEOUT_IN_SECS)
timeout=int(os.environ.get('CCM_CLUSTER_START_TIMEOUT_OVERRIDE', timeout))
Expand Down
28 changes: 27 additions & 1 deletion ccmlib/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,9 @@ def get_launch_bin(self):
def add_custom_launch_arguments(self, args):
pass

def __log_dir(self):
return '-Dcassandra.logdir=%s' % os.path.join(self.get_path(), 'logs')

def start(self,
join_ring=True,
no_wait=False,
Expand Down Expand Up @@ -876,7 +879,7 @@ def start(self,

args = args + ['-p', pidfile, '-Dcassandra.join_ring=%s' % str(join_ring)]

args.append('-Dcassandra.logdir=%s' % os.path.join(self.get_path(), 'logs'))
args.append(self.__log_dir())
if replace_token is not None:
args.append('-Dcassandra.replace_token=%s' % str(replace_token))
if replace_address is not None:
Expand Down Expand Up @@ -982,6 +985,25 @@ def _wait_for_running(self, process, timeout_s):
self._update_pid(process)
return self.is_running()

def __unix_kill_process_matching(self, pattern, sig=signal.SIGTERM):
matcher = re.compile(pattern)
for proc in psutil.process_iter(['pid', 'cmdline']):
try:
pid = proc.info['pid']
cmdline = " ".join(proc.info['cmdline']) if proc.info['cmdline'] else ""
if matcher.search(cmdline):
try:
os.kill(int(pid), sig)
except ProcessLookupError:
logger.info(f"Process {pid} not found")
except PermissionError:
logger.info(f"Did not have permissions to kill {pid}")
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
pass

def __unix_kill(self, sig):
self.__unix_kill_process_matching(".*{}.*{}.*".format(self.__log_dir(), "org.apache.cassandra.service.CassandraDaemon"), sig)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using log_dir wfm


def stop(self, wait=True, wait_other_notice=False, signal_event=signal.SIGTERM, **kwargs):
"""
Stop the node.
Expand Down Expand Up @@ -1046,6 +1068,10 @@ def stop(self, wait=True, wait_other_notice=False, signal_event=signal.SIGTERM,
else:
return True
else:
# Make sure it is actually stopped even if the PID wasn't found for some reason
# Always kill because it should already be stopped and we aren't waiting for it to stop
if not common.is_win():
self.__unix_kill(signal.SIGKILL)
return False

def wait_for_compactions(self, timeout=120):
Expand Down