|
|
@@ -112,6 +112,24 @@ class SegmentingJsonlWriter:
|
|
|
if name.startswith("frames-") and name.endswith(".jsonl")
|
|
|
)
|
|
|
|
|
|
+ def segment_files(self) -> List[str]:
|
|
|
+ """按**写入顺序**返回全部分段文件(含当前正在写的 ``frames.jsonl``)。
|
|
|
+
|
|
|
+ 归档段命名为 ``frames-<时间戳>-<序号>.jsonl``,字符 ``'-'``(0x2D) 小于
|
|
|
+ ``'.'``(0x2E),所以按文件名排序正好是「旧归档段 → 当前段」。外部读取证据
|
|
|
+ (现场复盘、脚本抽样)必须走这个函数:``os.listdir`` 的顺序在 ext4 上是
|
|
|
+ 目录哈希序,跨机器/跨文件系统都不稳定,直接拼接会把记录读乱。
|
|
|
+ """
|
|
|
+
|
|
|
+ current = os.path.basename(self.path)
|
|
|
+ names = [
|
|
|
+ name
|
|
|
+ for name in os.listdir(self.directory)
|
|
|
+ if name.endswith(".jsonl")
|
|
|
+ and (name == current or name.startswith("frames-"))
|
|
|
+ ]
|
|
|
+ return [os.path.join(self.directory, name) for name in sorted(names)]
|
|
|
+
|
|
|
def _repair_tail(self) -> None:
|
|
|
"""断电时最后一行可能只写了一半;补换行,保留原始字节供排查。"""
|
|
|
|