bada-terminal / src /db /batch-loop-ghost-record.js
VanyaJ's picture
Release BADA Terminal v2.1.0 (Enterprise Ontology, NVIDIA auto-ontology, Release Preflight)
d739b1b verified
Raw History Blame Contribute Delete
1.48 kB
// 승인 grant에 원본이 보존된 마지막 유령 행 하나만 현재 writer transaction에서 제외할 수 있다.
// 설명 문서: docs/specs/batch-loop-ghost.md v1.1.0, docs/specs/batch-loop-first.md v1.0.0
const{hash}=require('../services/bong-browser-resolution'),{same}=require('./batch-recovery-record'),ghost=require('../services/batch-loop-ghost');
function verifyRemoval(db,runId,grantId,verify){
const c=db.getBatchCheckpoint(runId),g=Object.values(c?.recoveries||{}).at(-1),d=g?.loopState,row=db.getBatchRun(runId),{usage:_,...raw}=row||{};
const first=require('../services/batch-loop-first');
if(!c||c.revocations||!g||g.id!==grantId||c.revision!==g.checkpointRevision+1||!['unstarted_iteration','unstarted_first_iteration'].includes(d?.reconciliation?.kind)||!same(raw,{...g.originalRun,status:'paused',error_message:null,completed_at:null})||typeof verify!=='function')ghost.fail();
const actual={run:db.getLoopRun(d.originalRun.run_id),iterations:db.getLoopIterations(d.originalRun.run_id)},event=first.source(c,d);require('../services/batch-recovery-proof').prefixes({checkpoint:c,usage:db.getRuntimeUsage(runId)});if(first.isFirst(d))first.validate(c,g);else ghost.validate(d.reconciliation,event);
if(hash(actual)!==d.rowsHash||actual.iterations.at(-1)?.id!==d.reconciliation.ghostId||hash(actual.iterations.at(-1))!==d.reconciliation.ghostHash||verify(g)!==true)ghost.fail();
return d.reconciliation.ghostId;
}
module.exports={verifyRemoval};