Skip to content

Commit

Permalink
PR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cezarmoise authored and fruch committed Sep 18, 2024
1 parent ee7ebef commit 4b1ac16
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
13 changes: 7 additions & 6 deletions ccmlib/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ def __decode(self, value):

# Groups: 0 = ks, 1 = cf, 2 = tmp or none, 3 = version, 4 = identifier (generation), 4 = "big-" or none, 5 = suffix (Compacted or Data.db)
_sstable_regexp = re.compile(r'((?P<keyspace>[^\s-]+)-(?P<cf>[^\s-]+)-)?(?P<tmp>tmp(link)?-)?(?P<version>[^\s-]+)-(?P<identifier>[^-]+)-(?P<big>big-)?(?P<suffix>[a-zA-Z]+)\.[a-zA-Z0-9]+$')
# Regexes for parsing nodetool compactionstats
_pending_tasks_pattern = re.compile(r'- (?P<ks>\w+)\.(?P<cf>\w+): (?P<tasks>\d+)')
_active_tasks_pattern = re.compile(r'\s*([\w-]+)\s+\w+\s+(?P<ks>\w+)\s+(?P<cf>\w+)\s+\d+\s+\d+\s+\w+\s+\d+\.\d+%')


class Node(object):
Expand Down Expand Up @@ -763,14 +766,12 @@ def _parse_tasks(output: str, keyspace: str, column_family: str):
"""
lines = output.strip().splitlines()
tasks = defaultdict(int)
pending_tasks_pattern = re.compile(r'- (?P<ks>\w+)\.(?P<cf>\w+): (?P<tasks>\d+)')
active_tasks_pattern = re.compile(r'\s*([\w-]+)\s+\w+\s+(?P<ks>\w+)\s+(?P<cf>\w+)\s+\d+\s+\d+\s+\w+\s+\d+\.\d+%')

for line in lines:
line = line.strip()
if match := pending_tasks_pattern.match(line):
if match := _pending_tasks_pattern.match(line):
tasks[(match.group("ks"), match.group("cf"))] += int(match.group("tasks"))
elif match := active_tasks_pattern.match(line):
elif match := _active_tasks_pattern.match(line):
tasks[(match.group("ks"), match.group("cf"))] += 1

if keyspace is None and column_family is None:
Expand All @@ -786,8 +787,8 @@ def wait_for_compactions(self, keyspace: str=None, column_family: str=None, idle
:param keyspace: only wait for the compactions performed for specified keyspace.
If not specified, all keyspaces are waited.
Must be provided if collumn_family is provided.
:param column_family: only wait for the compactions performed for specified column_family.
If not specified, all keyspaces are waited.
:param column_family: only wait for the compactions performed for specified column family.
If not specified, all column families are waited.
:param idle_timeout: the time in seconds to wait for progress.
Total time to wait is undeteremined, as long as we observe forward progress.
"""
Expand Down
7 changes: 2 additions & 5 deletions tests/test_internal_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,8 @@
}
]

@pytest.mark.parametrize("test_case", test_cases, ids=[tc["id"] for tc in test_cases])
def test_parse_tasks(test_case):
output = test_case["output"]
expected_tasks = test_case["expected_tasks"]

@pytest.mark.parametrize("output, expected_tasks", [pytest.param(t["output"], t["expected_tasks"], id=t["id"]) for t in test_cases])
def test_parse_tasks(output, expected_tasks):
for ks, cf, expected in expected_tasks:
n = Node._parse_tasks(output, ks, cf)
assert n == expected, f"Expected {expected} tasks for {ks}.{cf}, but got {n}"

0 comments on commit 4b1ac16

Please sign in to comment.