test/cluster/dtest: add ScyllaCluster.compact() method

Add compact() method to ScyllaCluster, delegating to
ScyllaNode.compact() on each running node. Accepts optional
keyspace and tables parameters to allow scoping compaction to
specific keyspaces/tables.

Also fix ScyllaNode.compact() to use list[str] for tables
parameter and extend() instead of +=, so that passing a single
table name as a string does not iterate over its characters.
This commit is contained in:
Benny Halevy
2026-04-28 00:03:58 +03:00
parent 9a24be2fe9
commit 1d6403ddad
2 changed files with 8 additions and 2 deletions

View File

@@ -227,6 +227,11 @@ class ScyllaCluster:
def flush(self) -> None:
self.nodetool("flush")
def compact(self, keyspace: str = "", tables: list[str] | None = None) -> None:
for node in self.nodelist():
if node.is_running():
node.compact(keyspace=keyspace, tables=tables)
@staticmethod
def debug(message: str) -> None:
logger.debug(message)

View File

@@ -647,11 +647,12 @@ class ScyllaNode:
cmd.append(table)
self.nodetool(" ".join(cmd), **kwargs)
def compact(self, keyspace: str = "", tables: str | None = ()) -> None:
def compact(self, keyspace: str = "", tables: list[str] | None = None) -> None:
compact_cmd = ["compact"]
if keyspace:
compact_cmd.append(keyspace)
compact_cmd += tables
if tables:
compact_cmd.extend(tables)
self.nodetool(" ".join(compact_cmd))
def drain(self, block_on_log: bool = False) -> None: