From f0ea1fd7cd39150deb0428feb4614dc5aaf7d8d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Untersch=C3=BCtz?= Date: Thu, 3 Dec 2026 21:50:35 +0100 Subject: [PATCH] test(dev): add second snapshot, timings and cleanup to million test - create the application snapshot "changed" after the mutation - record durations of every step and prefix engine log lines with UTC time and phase time - verify only snapshots that were not removed, then run cleanup and check that only application snapshots remain - accept any RUN_LABEL and pass FILES and RUN_LABEL through Compose Co-Authored-By: Claude Opus 5.5 --- dev/compose.million.yaml | 3 ++ dev/million-start.sh | 2 +- dev/million.py | 59 +++++++++++++++++++++++++++++++++------- 3 files changed, 53 insertions(+), 11 deletions(-) diff --git a/dev/compose.million.yaml b/dev/compose.million.yaml index 5628a50..1d06533 100644 --- a/dev/compose.million.yaml +++ b/dev/compose.million.yaml @@ -16,6 +16,9 @@ services: image: cephmig-native:dev init: true entrypoint: [python3, -u, /lab/million.py] + environment: + FILES: ${FILES:-1000000} + RUN_LABEL: ${RUN_LABEL:-main} networks: [lab] depends_on: source: {condition: service_healthy} diff --git a/dev/million-start.sh b/dev/million-start.sh index b25d238..0de56a9 100644 --- a/dev/million-start.sh +++ b/dev/million-start.sh @@ -18,5 +18,5 @@ mkdir -p .dev/million "${compose[@]}" up -d --wait --wait-timeout 600 source target "${compose[@]}" up -d benchmark docker inspect cephmig-million-benchmark-1 --format '{{.Image}}' > .dev/million/native-image.txt -echo 'Persistent test started. Status: .dev/million/main/status.json' +echo "Persistent test started. Status: .dev/million/${RUN_LABEL:-main}/status.json" echo 'Logs: docker compose -p cephmig-million -f dev/compose.yaml -f dev/compose.million.yaml logs -f benchmark' diff --git a/dev/million.py b/dev/million.py index bcd611e..30a85ec 100644 --- a/dev/million.py +++ b/dev/million.py @@ -23,8 +23,8 @@ import cephfs from smallfiles import ceph, volume, snap, payload, posix_acl RUN_LABEL = os.environ.get('RUN_LABEL', 'main') -if RUN_LABEL not in ('main', 'pilot'): - raise ValueError('RUN_LABEL must be main or pilot') +if not RUN_LABEL or not all(c.isascii() and (c.isalnum() or c == '-') for c in RUN_LABEL): + raise ValueError('RUN_LABEL must consist of letters, digits and hyphens') REPORT = Path('/report') / RUN_LABEL WORK = Path('/state') / ('million-' + RUN_LABEL) COUNT = int(os.environ.get('FILES', '1000000')) @@ -58,6 +58,16 @@ def progress(**changes): print(json.dumps(changes), flush=True) +def timed(step, function, *args): + """Run function and record its duration under timings[step].""" + started = time.monotonic() + result = function(*args) + timings = dict(state.get('timings', {})) + timings[step] = round(time.monotonic() - started, 3) + progress(timings=timings) + return result + + def guard(): if STOP.is_set(): raise RuntimeError('test stopped') @@ -262,6 +272,11 @@ def mutate(): create_file(fs, root, i, 2) reset_dir_times(fs, root, end) fs.sync_fs() + # A second application snapshot holds the changed state. + name = state['name'] + if 'changed' not in {x['name'] for x in json.loads(snap('source', 'ls', 'cephfs', name))}: + snap('source', 'create', 'cephfs', name, 'changed') + snap('source', 'metadata', 'set', 'cephfs', name, 'changed', 'fixture', 'million-v1') progress(mutated=True) @@ -278,13 +293,24 @@ def run_phase(phase): progress(phase=phase, phase_started=datetime.datetime.now(datetime.timezone.utc).isoformat(), phase_attempts=attempts) before = {c: counters(c) for c in ('source', 'target')} - args = ['/usr/local/bin/cephmig-native', 'finalize' if phase == 'final' else 'sync', + command = {'final': 'finalize', 'cleanup': 'cleanup'}.get(phase, 'sync') + args = ['/usr/local/bin/cephmig-native', command, '--config', str(WORK / 'config.json'), '--state', str(WORK / 'job.json')] if phase == 'final': args.append('--writers-stopped') started, wall_started, last = time.monotonic(), time.time(), 0 peak = 0 with (REPORT / f'{phase}.stdout.json').open('w') as out, (REPORT / f'{phase}.log').open('w') as log: - p = subprocess.Popen(args, stdout=out, stderr=log) + p = subprocess.Popen(args, stdout=out, stderr=subprocess.PIPE) + + def stamp_lines(): + # Prefix every engine log line with the UTC time and the phase time. + for raw in p.stderr: + now = datetime.datetime.now(datetime.timezone.utc).isoformat(timespec='milliseconds') + log.write(f'{now} +{time.monotonic() - started:9.3f}s {raw.decode(errors="replace")}') + log.flush() + + logger = threading.Thread(target=stamp_lines, daemon=True) + logger.start() try: while p.poll() is None: now = time.monotonic() @@ -311,6 +337,8 @@ def run_phase(phase): except subprocess.TimeoutExpired: p.kill(); p.wait() raise + finally: + logger.join(timeout=30) if p.returncode: raise RuntimeError(f'{phase} failed ({p.returncode}); see {phase}.log') result = json.loads((WORK / 'job.json').read_text()) @@ -325,6 +353,9 @@ def run_phase(phase): if phase == 'final': if result['phase'] != 'ready-for-cutover' or result['snapshots'][-1]['transfer']['bytes_copied']: raise RuntimeError('unchanged final round must be ready and write zero payload bytes') + timings = dict(state.get('timings', {})) + timings[phase] = round(metrics['seconds'], 3) + state['timings'] = timings completed = {phase + '_complete': True} if phase == 'initial': completed['initial_snapshots'] = [record['name'] for record in result['snapshots']] @@ -470,12 +501,12 @@ def main(): started_at=datetime.datetime.now(datetime.timezone.utc).isoformat()) for sig in (signal.SIGTERM, signal.SIGINT): signal.signal(sig, lambda *_: STOP.set()) try: - if not state.get('prepared'): prepare() + if not state.get('prepared'): timed('prepare', prepare) thread = threading.Thread(target=other_writer, daemon=True) thread.start() try: if not state.get('initial_complete'): run_phase('initial') - if not state.get('mutated'): mutate() + if not state.get('mutated'): timed('mutate', mutate) if not state.get('catchup_complete'): run_phase('catchup') before = state.get('other_subvolume_writes', 0) if not state.get('final_complete'): @@ -485,18 +516,26 @@ def main(): job = json.loads((WORK / 'job.json').read_text()) if len(job['snapshots']) < 4: raise RuntimeError('expected at least four snapshot stands') initial = set(state.get('initial_snapshots', [x['name'] for x in job['snapshots'][:2]])) - verify_view('live', state['roots']['target'], True) - for record in job['snapshots']: + timed('verify live', verify_view, 'live', state['roots']['target'], True) + # Round snapshots that sync already removed are not verifiable. + present = [record for record in job['snapshots'] if not record.get('removed')] + for record in present: path = ceph('target', 'fs', 'subvolume', 'snapshot', 'getpath', 'cephfs', state['name'], record['name'], 'migration') - verify_view(record['name'], path, record['name'] not in initial) + timed('verify ' + record['name'], verify_view, record['name'], path, record['name'] not in initial) if snap('source', 'metadata', 'ls', 'cephfs', state['name'], record['name']) != snap( 'target', 'metadata', 'ls', 'cephfs', state['name'], record['name']): raise RuntimeError('snapshot custom metadata mismatch') + if not state.get('cleanup_complete'): run_phase('cleanup') + application = {'baseline', 'changed'} + for cluster in ('source', 'target'): + left = {x['name'] for x in json.loads(snap(cluster, 'ls', 'cephfs', state['name']))} + if left != application: + raise RuntimeError(f'{cluster} snapshots after cleanup: {sorted(left)}') if state.get('other_writer_error'): raise RuntimeError(state['other_writer_error']) progress(phase='complete', result='PASS', snapshot_count=len(job['snapshots']), - total_regular_paths_verified=(COUNT + 100) * (len(job['snapshots']) + 1)) + total_regular_paths_verified=(COUNT + 100) * (len(present) + 1)) finally: STOP.set() thread.join(timeout=30)