修复:独立回收中断备份并限制 AI 日志增长
This commit is contained in:
@@ -85,6 +85,8 @@ PYTHONDONTWRITEBYTECODE=1 .runtime/retention-env/bin/python3 -m unittest discove
|
||||
|
||||
注册过的测试数据库在正常退出时回收;异常遗留超过 24 小时,确认所有者和子进程退出、标记一致且无连接后才删除。未登记数据库继续保留。日志按 7 天、每类 100MiB 限制;Java 原生日志滚动配置在 `logback-quality.xml`,MySQL 通过重新打开错误日志完成滚动,不重启数据库,不截断活动文件。
|
||||
|
||||
未完成备份候选使用独立回收步骤:超过 24 小时且进程身份确认退出后才清理,不等待下一次备份成功;当前备份、有效候选、身份不完整和仍运行的记录保留。AI 用户及会话日志也纳入后台检查;新启动的原生服务通过 `nao_log_stream.py` 捕获输出,单段 10MiB、每服务约 90MiB、归档最长 7 天。捕获进程与原生子进程共享进程组,沿用原有会话身份与停止保护;日志写入异常不会为清理中断 AI 请求。已有实例不因升级被终止,下次正常启动时加载新方式。
|
||||
|
||||
```sh
|
||||
.runtime/retention-env/bin/python3 deploy/macos/operations.py install --root "$PWD"
|
||||
.runtime/retention-env/bin/python3 deploy/macos/operations.py status --root "$PWD"
|
||||
|
||||
@@ -47,6 +47,7 @@ def snapshot(root, support=SUPPORT, now=None):
|
||||
output_logs = sum(p.stat().st_blocks * 512 for p in logs if p.is_relative_to(root / 'output'))
|
||||
runtime_logs = sum(p.stat().st_blocks * 512 for p in logs if p.is_relative_to(root / '.runtime'))
|
||||
native = allocated(root / '.runtime/nao-users')
|
||||
native_logs = sum(p.stat().st_blocks * 512 for p in logs if p.is_relative_to(root / '.runtime/nao-users'))
|
||||
registered = 0; overdue = 0
|
||||
for p in resources.registry(root).glob('*.json'):
|
||||
value = resources.load(root, p.stem)
|
||||
@@ -61,10 +62,11 @@ def snapshot(root, support=SUPPORT, now=None):
|
||||
if owner.get('kind') == 'private-quality-restore' and owner.get('directory') == str(p): private += allocated(p)
|
||||
# Core service data is the same scope as the earlier 11.86GiB measurement.
|
||||
# Software/build/delivery artifacts are visible separately and included in growth checks.
|
||||
core = max(0, mysql - registered) + archives + backups + log_bytes + native
|
||||
artifacts = max(0, runtime - mysql - private - native - runtime_logs) + max(0, outputs - backups - output_logs)
|
||||
native_data = max(0, native - native_logs)
|
||||
core = max(0, mysql - registered) + archives + backups + log_bytes + native_data
|
||||
artifacts = max(0, runtime - mysql - private - native - (runtime_logs - native_logs)) + max(0, outputs - backups - output_logs)
|
||||
return {'at': now, 'mysqlBytes': mysql, 'archiveBytes': archives, 'backupBytes': backups,
|
||||
'logBytes': log_bytes, 'nativeDataBytes': native, 'registeredTestBytes': registered,
|
||||
'logBytes': log_bytes, 'nativeDataBytes': native_data, 'registeredTestBytes': registered,
|
||||
'privateVerifierBytes': private, 'temporaryBytes': registered + private,
|
||||
'coreBytes': core, 'artifactBytes': artifacts, 'permanentBytes': core + artifacts,
|
||||
'freeBytes': shutil.disk_usage(root).free, 'overdueTestResources': overdue}
|
||||
@@ -143,17 +145,18 @@ def janitor(root, support, policy):
|
||||
if (root / '.runtime/retention/paused').exists(): return {'deferred': 'Maintenance is paused'}
|
||||
try:
|
||||
with br.lock(root, timeout=0):
|
||||
result = br.clean_incomplete(root)
|
||||
db = Database(root)
|
||||
try:
|
||||
config = json.loads((root / '.runtime/retention/config.json').read_text())
|
||||
accepted = br.accepted_backend(root)
|
||||
if config['schemaSignature'] != db.schema_signature or not accepted or config['acceptedJarSha256'] != accepted[1]:
|
||||
return {'deferred': 'Application version changed'}
|
||||
return {**result, 'deferred': 'Application version changed'}
|
||||
db.current()
|
||||
if db.busy(): return {'deferred': 'Application jobs are active'}
|
||||
if db.busy(): return {**result, 'deferred': 'Application jobs are active'}
|
||||
# Use a short-lived CLI connection so no observer holds a test schema open.
|
||||
import backup
|
||||
result = resources.cleanup(root, backup.client)
|
||||
result.update(resources.cleanup(root, backup.client))
|
||||
result['abandonedVerifiersRemoved'] = backup_verifier.clean_abandoned(root)
|
||||
result['mysqlLogsRotated'] = log_retention.rotate_mysql(root, backup.client, br)
|
||||
result.update(log_retention.retain(root, support,
|
||||
|
||||
@@ -372,6 +372,7 @@ def run(root, max_batches=30, grace=1800):
|
||||
state=json.loads(state_path.read_text()) if state_path.exists() else {}
|
||||
result={'checkedAt':time.time(),'releasesRemoved':0,'buildsRemoved':0,'rowsRemoved':0,'draftsRemoved':0,'bytesRemoved':0}
|
||||
with br.lock(root,timeout=0):
|
||||
result.update(br.clean_incomplete(root))
|
||||
result['retiredBackupFoldersRemoved']=br.clean_retired(root)
|
||||
result['privateVerifiersRemoved']=backup_verifier.clean_abandoned(root)
|
||||
db=Database(root)
|
||||
|
||||
@@ -21,6 +21,16 @@ ops = importlib.util.module_from_spec(spec); spec.loader.exec_module(ops)
|
||||
|
||||
|
||||
class OperationsTests(unittest.TestCase):
|
||||
def test_native_logs_are_counted_once_and_do_not_hide_other_runtime_artifacts(self):
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
root=Path(d).resolve();native=root/'.runtime/nao-users/actor'
|
||||
for relative in ['logs/server.log','private/nao.sqlite']:
|
||||
path=native/relative;path.parent.mkdir(parents=True,exist_ok=True);path.write_bytes(b'x'*8192)
|
||||
(root/'.runtime/tool.bin').write_bytes(b'x'*16384)
|
||||
sample=ops.snapshot(root,root/'support')
|
||||
self.assertEqual(sample['coreBytes'],sum(sample[k] for k in ['mysqlBytes','archiveBytes','backupBytes','logBytes','nativeDataBytes']))
|
||||
self.assertEqual(sample['artifactBytes'],ops.allocated(root/'.runtime')-ops.allocated(root/'.runtime/nao-users'))
|
||||
|
||||
def sample(self, **extra):
|
||||
return {'at': 200000., 'coreBytes': 12*ops.GIB, 'permanentBytes': 40*ops.GIB,
|
||||
'freeBytes': 500*ops.GIB, 'overdueTestResources': 0, **extra}
|
||||
|
||||
Reference in New Issue
Block a user