fix: complete CLI admission and retire finished catalog journals
This commit is contained in:
1 parent
8e0f78979a
commit
f4f5e939eb
6 files changed
+271
-188
No files matched your search
@@ -254,10 +254,27 @@ def main(argv: Sequence[str] | None = None) -> int:
|
||||
lease.drive or '-', lease.remote_root or '-', lease.display_path,
|
||||
mentor_path, reason)
|
||||
try:
|
||||
from threading import Event
|
||||
stop = Event()
|
||||
with batch_stop_signals(stop):
|
||||
results = run_batch(requests, stop=stop)
|
||||
from .operation_queue import BatchTaskContext, NativeQueue, request_library_keys
|
||||
from .session_record import discover_sessions, handoff_session
|
||||
|
||||
aliases = tuple(request_library_keys(requests[0]))
|
||||
task = BatchTaskContext(str(mentor_path), aliases=aliases,
|
||||
targets=tuple(names), native_policy='external')
|
||||
queue = NativeQueue()
|
||||
with batch_stop_signals(task.stop):
|
||||
for old_session in discover_sessions(context.root):
|
||||
if old_session.get('status') != 'ACTIVE':
|
||||
continue
|
||||
old_request = VerifyRequest(Path(old_session['library']), names[0], context.root)
|
||||
if request_library_keys(old_request).intersection(aliases):
|
||||
handoff_session(old_session['path'], evidence_root=context.root, observe_only=True)
|
||||
|
||||
def admit(_request, action):
|
||||
return queue.run(action, stop=task.stop, context=task,
|
||||
wait_for_release_seconds=120,
|
||||
waiting=lambda: logger.info('batch_waiting_for_session_release library=%s', mentor_path))
|
||||
|
||||
results = run_batch(requests, stop=task.stop, context=task, item_executor=admit)
|
||||
except Exception:
|
||||
retain_mapping('batch_exception')
|
||||
raise
|
||||
|
||||
@@ -513,6 +513,26 @@ def handoff_session(path, *, evidence_root, process=None, progress=None, stop=No
|
||||
thread.start()
|
||||
|
||||
|
||||
def _completed_read_only_catalog(path, session, observed):
|
||||
if (session.get('operation') != 'catalog' or session.get('worker_role') != 'catalog_readonly'
|
||||
or observed.get('phase') != 'FINISHED' or observed.get('processes_exited') is not True):
|
||||
return False
|
||||
# A final worker receipt and fresh exit facts retire the read-only journal
|
||||
# from recovery discovery. The original files remain available as evidence.
|
||||
result_path = path.with_name('result.json')
|
||||
try:
|
||||
if result_path.lstat().st_file_attributes & stat.FILE_ATTRIBUTE_REPARSE_POINT:
|
||||
return False
|
||||
with result_path.open('rb') as stream:
|
||||
data = stream.read(MAX_BYTES + 1)
|
||||
if len(data) > MAX_BYTES:
|
||||
return False
|
||||
result = json.loads(data)
|
||||
return isinstance(result, dict) and result.get('safe_to_continue') is True
|
||||
except (OSError, ValueError):
|
||||
return False
|
||||
|
||||
|
||||
def discover_sessions(evidence_root, *, library=None):
|
||||
"""Only our bounded journals are inputs; never execute a stored command."""
|
||||
root = Path(evidence_root)
|
||||
@@ -553,6 +573,8 @@ def discover_sessions(evidence_root, *, library=None):
|
||||
if library is not None and _library_key(value.get('library', '')) != _library_key(library):
|
||||
continue
|
||||
observed = inspect_session_record(path, evidence_root=root)
|
||||
if _completed_read_only_catalog(path, value, observed):
|
||||
continue
|
||||
value = {**value, **observed, 'library': value.get('library'),
|
||||
'block': value.get('block'), 'operation_id': value['operation_id'], 'path': str(path)}
|
||||
except (OSError, ValueError):
|
||||
|
||||
@@ -618,8 +618,8 @@ class MainWindow(QWidget):
|
||||
unfinished = unfinished_operations(root/'management')
|
||||
sessions = discover_sessions(root)
|
||||
for session in sessions:
|
||||
recover_catalog = orphaned_catalog_session(session['path'])
|
||||
if recover_catalog or session['status'] == 'ACTIVE':
|
||||
if session['status'] == 'ACTIVE':
|
||||
recover_catalog = orphaned_catalog_session(session['path'])
|
||||
handoff_session(session['path'], evidence_root=root,
|
||||
observe_only=not recover_catalog,
|
||||
progress=lambda value: notify({'stage': 'session_observation', **value}))
|
||||
|
||||
Reference in new issue
Block a user