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:
+13
-1
@@ -14,7 +14,12 @@ def utc_now_iso() -> str:
|
||||
|
||||
|
||||
def write_json_atomic(path: Path, payload: Any) -> None:
|
||||
"""Write JSON without exposing a partially written artifact."""
|
||||
"""Write JSON without exposing or acknowledging a partial commit.
|
||||
|
||||
Flushing the temporary file protects its contents, but a crash can still
|
||||
lose the directory entry created by ``replace``. The parent directory is
|
||||
therefore flushed after the atomic rename as the second durability edge.
|
||||
"""
|
||||
path = path.expanduser()
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
serialized = json.dumps(payload, ensure_ascii=False, indent=2) + "\n"
|
||||
@@ -34,6 +39,13 @@ def write_json_atomic(path: Path, payload: Any) -> None:
|
||||
stream.flush()
|
||||
os.fsync(stream.fileno())
|
||||
Path(temp_name).replace(path)
|
||||
directory_flags = os.O_RDONLY | getattr(os, "O_CLOEXEC", 0)
|
||||
directory_flags |= getattr(os, "O_DIRECTORY", 0)
|
||||
directory_descriptor = os.open(path.parent, directory_flags)
|
||||
try:
|
||||
os.fsync(directory_descriptor)
|
||||
finally:
|
||||
os.close(directory_descriptor)
|
||||
finally:
|
||||
if temp_name is not None:
|
||||
Path(temp_name).unlink(missing_ok=True)
|
||||
|
||||
Reference in New Issue
Block a user