wip(k1): checkpoint connection recovery rewrite

Capture the current unreleased K1 connection, recovery, lifecycle, viewer, and test work as a single known-bad baseline for subsequent fixes.
This commit is contained in:
DCCONSTRUCTIONS
2026-08-14 14:57:50 +03:00
parent aff331082f
commit 0ca7316a24
157 changed files with 152962 additions and 4036 deletions
+20 -6
View File
@@ -30,6 +30,7 @@ class ActiveSessionLease:
_descriptor: int
_marker_identity: tuple[int, int]
_released: bool = False
_marker_removed: bool = False
@classmethod
def acquire(cls, sessions_root: Path, session_root: Path) -> ActiveSessionLease:
@@ -72,18 +73,21 @@ class ActiveSessionLease:
if self._released:
return
marker = self.sessions_root / ACTIVE_SESSION_MARKER
try:
if not self._marker_removed:
try:
metadata = marker.lstat()
except FileNotFoundError:
metadata = None
if metadata is not None and (metadata.st_dev, metadata.st_ino) == self._marker_identity:
marker.unlink()
_fsync_directory(self.sessions_root)
finally:
_unlock_descriptor(self._descriptor)
os.close(self._descriptor)
self._released = True
self._marker_removed = True
# Keep the descriptor/lock owned until marker retirement is durably
# synchronized. If unlink or fsync fails, a later cleanup-only retry
# resumes this staged release without reopening command authority.
_fsync_directory_strict(self.sessions_root)
_unlock_descriptor(self._descriptor)
os.close(self._descriptor)
self._released = True
def __enter__(self) -> ActiveSessionLease:
return self
@@ -170,3 +174,13 @@ def _fsync_directory(path: Path) -> None:
os.fsync(descriptor)
finally:
os.close(descriptor)
def _fsync_directory_strict(path: Path) -> None:
"""Synchronize a lease transition or fail while retaining its lock."""
descriptor = os.open(path, os.O_RDONLY | getattr(os, "O_DIRECTORY", 0))
try:
os.fsync(descriptor)
finally:
os.close(descriptor)