ARIES: recover from a crash during undo.
Optional advanced lab A1. Recovery can fail after reversing a loser transaction's change but before finishing its rollback. Record the rollback itself so another restart can continue without reversing the same original update again.
You will: reconstruct transaction and dirty-page tables, repeat history, generate redo-only compensation log records, and follow undoNextLSN across repeated failures. Prerequisites: Build log recovery, Crash during recovery, pageLSN/recLSN and per-transaction prevLSN chains. Runtime: an executable ARIES recovery core with controlled failures and an implementation bench.
ARIES stands for Algorithm for Recovery and Isolation Exploiting Semantics. A loser is an unfinished transaction that recovery must roll back. A compensation log record (CLR) records an undo action that redo can repeat safely. Its prevLSN follows transaction history; undoNextLSN identifies remaining rollback work.
ARIES logs the rollback so rollback can restart
Predict
Compare three interruptions: the CLR is still buffered; the CLR is durable but its page action is missing; both CLR and page are durable. For each, predict whether restart must redo compensation, generate it again, or skip it, and identify the next original UPDATE to undo. Distinguish record durability from page durability.
From the foundation to ARIES
The core recovery lab uses one writer and before-image undo. This optional lab adds interleaved transaction chains, multiple losers, compensation records and failures during rollback. Its recovery sequence is analysis, repeat-history redo, then undo of unfinished work.
The model's pages A, B and C are independent counters starting at 100. T1 changes A by +10 and commits. T2 changes B by +20 and +5 but never commits. T3 changes C by +7 and never commits. Successful recovery must retain A = 110 and restore B = C = 100. Changes are interleaved in the log even though the transactions own different pages.
| LSN | Record | Transaction chain / meaning |
|---|---|---|
| 1–3 | BEGIN T1, T2, T3 | Open independent transaction chains |
| 4 | UPDATE T1, A += 10 | prevLSN = 1 |
| 5 | UPDATE T2, B += 20 | prevLSN = 2 |
| 6 | UPDATE T3, C += 7 | prevLSN = 3 |
| 7 | CHECKPOINT | Transaction and dirty-page metadata; data pages remain dirty |
| 8 | UPDATE T2, B += 5 | prevLSN = 5 |
| 9 | COMMIT T1 | Durable winner; no END record yet |
The base scenario steals B's uncommitted page to disk after its log is durable. A's committed page can remain unwritten. Restart therefore has both redo and undo work.
Three passes, with explicit state
Analysis starts at the durable checkpoint metadata and scans later records. It reconstructs the transaction table (status and lastLSN) and dirty-page table (recLSN). A durable COMMIT without END is finished with END. Running losers enter aborting state; their last log positions seed ToUndo.
Redo repeats history, including loser UPDATEs and existing CLRs. It is not “redo only the winners.” For a page record, use the dirty-page table, its recLSN and pageLSN to decide whether the action is missing. Reconstructing the logged history makes later undo operate on the state its records describe.
Undo selects the highest outstanding LSN across all losers. An original UPDATE is compensated by a new CLR. A CLR is redo-only: undo follows its undoNextLSN without compensating that CLR. Other chain records follow prevLSN. Completing a loser writes END and removes its undo frontier. Undo does not skip an original UPDATE merely because its pageLSN is already high: that can mean the update was installed and still needs rollback. The CLR skip pointer records completed compensation.
Control the experiment
The page loads Baseline with three interleaved transactions and one repeated crash. Select Run to end. Find the final disk values and the compensation for UPDATE 8 in UPDATEs and redo-only CLRs. Why does the faulty prevLSN rule revisit UPDATE 8?
Optional advanced ARIES core with interleaved winner/loser transactions, TT/DPT analysis, repeat-history redo, redo-only CLRs and highest-LSN undo. Transactions modify disjoint fixed pages with full-transaction rollback only. Checkpoint metadata is captured atomically in one record; no full fuzzy-checkpoint merge, logical index undo, nested top actions, media recovery or production-engine claim. CLR flushes are deliberately conservative.
Edit the experiment
Change the JSON settings and select Step or Run to end. Restore scenario reloads the selected preset.
Select Step to inspect the initial state.
Model checks at this step
Inspect JSON or download run evidence
No execution yet.
The drawing follows the recovery phase and the newest CLR. Its two arrows point to the actual prevLSN and undoNextLSN records; the faulty policy highlights the transaction-order path, while the repaired policy highlights the rollback skip path. The caption says whether that CLR is durable or still buffered.
Choose Repair and select Run to end. In the log table, compare prevLSN, undoNextLSN and Compensates for the first CLR. Read the final disk value of B. Which pointer preserves undo progress across the crash? The log view follows the latest records; scroll up for earlier history and horizontally for additional columns on a narrow screen. The check counts durable CLRs, since a buffered record can be lost without having published its recovery action.
A CLR is a new forward log action
For the first compensation in this history:
CLR 13:
tx = T2
prevLSN = 11 # T2's ABORT record: previous T2 record in log order
compensates = 8 # the original UPDATE being reversed
page = B, delta = -5 # redo description of the compensation
undoNextLSN = 5 # UPDATE 8's predecessor: remaining original work
prevLSN preserves transaction log order. undoNextLSN preserves rollback progress. They answer different questions. Redo may apply CLR 13 to a page whose LSN is still 8; a page already at LSN 13 skips that application. Undo then follows 5, so it does not generate another durable compensation for UPDATE 8.
WAL applies to compensation too: the CLR must be durable before its changed page reaches disk. This lab conservatively forces each CLR before applying its buffered action so the failure points are easy to inspect. A production engine may batch log flushes while still enforcing WAL before the data-page flush.
Read the engine code executed by this lab
These functions come directly from the running engine. Shared helpers and every mechanism are in the complete downloadable module.
function ariesUndoNext(record) {
return record.type==='CLR' ? record.undoNextLSN : record.prevLSN;
}
function ariesExpected(s) {
const durable=s.log.filter(r=>r.lsn<=s.flushedLSN);
const winners=new Set(durable.filter(r=>r.type==='COMMIT').map(r=>r.tx));
const expected={A:100,B:100,C:100};
for(const r of durable)if(r.type==='UPDATE'&&winners.has(r.tx))expected[r.page]+=r.delta;
return expected;
}
function ariesChecks(s) {
const durable=s.log.filter(r=>r.lsn<=s.flushedLSN),counts={};
for(const r of durable)if(r.type==='CLR')counts[r.compensates]=(counts[r.compensates]||0)+1;
const winners=new Set(durable.filter(r=>r.type==='COMMIT').map(r=>r.tx));
return [
check('completed recovery preserves committed updates and removes loser updates',s.complete?Object.entries(ariesExpected(s)).every(([p,v])=>s.disk[p].value===v):null),
check('no original UPDATE has more than one durable compensation record',Object.values(counts).every(n=>n===1)),
check('every persisted page is covered by the durable log',Object.values(s.disk).every(p=>p.pageLSN<=s.flushedLSN)),
check('completed loser rollback has exactly one durable CLR per original UPDATE',s.complete?durable.filter(r=>r.type==='UPDATE').every(r=>winners.has(r.tx)?!counts[r.lsn]:counts[r.lsn]===1):null),
];
}
function ariesAppend(s,record) {
const lsn=(s.log.at(-1)?.lsn||0)+1;
const r={lsn,...(record.tx?{prevLSN:s.transactionTable[record.tx]?.lastLSN||0}:{}),...copy(record)};
s.log.push(r);
if(r.tx){const status=r.type==='COMMIT'?'committing':['ABORT','CLR'].includes(r.type)?'aborting':s.transactionTable[r.tx]?.status||'running';s.transactionTable[r.tx]={status,lastLSN:lsn};}
return r;
}
function ariesApply(s,record) {
const frame=s.buffer[record.page];
if(frame.pageLSN>=record.lsn)return false;
frame.value+=record.delta;frame.pageLSN=record.lsn;
return true;
}
function ariesFlush(s,page) {
if(s.buffer[page].pageLSN>s.flushedLSN)throw Error('WAL violation: flush the page’s log dependency first.');
s.disk[page]=copy(s.buffer[page]);
}
function ariesPass(s,emit=()=>{},failure='none') {
s.pass++;s.phase='analysis';s.complete=false;
const discarded=s.log.filter(r=>r.lsn>s.flushedLSN).map(r=>r.lsn);
s.log=s.log.filter(r=>r.lsn<=s.flushedLSN);s.buffer=copy(s.disk);
s.transactionTable={};s.dirtyPageTable={};s.toUndo={};
const cp=s.log.find(r=>r.lsn===s.masterCheckpointLSN&&r.type==='CHECKPOINT');
if(cp){s.transactionTable=copy(cp.transactions);s.dirtyPageTable=copy(cp.dirtyPages);}
const scanned=s.log.filter(r=>r.lsn>(cp?.lsn||0));
for(const r of scanned) {
if(r.type==='END'){delete s.transactionTable[r.tx];continue;}
if(r.tx){const status=r.type==='COMMIT'?'committing':['ABORT','CLR'].includes(r.type)?'aborting':s.transactionTable[r.tx]?.status||'running';s.transactionTable[r.tx]={status,lastLSN:r.lsn};}
if(['UPDATE','CLR'].includes(r.type))s.dirtyPageTable[r.page]??=r.lsn;
}
s.analysis={checkpointLSN:cp?.lsn||0,scannedLSNs:scanned.map(r=>r.lsn),discardedLogLSNs:discarded};
emit(`Restart ${s.pass}: rebuild transaction/dirty-page tables from durable records`);
for(const [tx,entry] of Object.entries(s.transactionTable)) {
if(entry.status==='committing'){
ariesAppend(s,{type:'END',tx});s.flushedLSN=s.log.at(-1).lsn;delete s.transactionTable[tx];emit(`Analysis finishes durable winner ${tx} with END`);
}else if(entry.status==='running'){
ariesAppend(s,{type:'ABORT',tx});s.flushedLSN=s.log.at(-1).lsn;emit(`Analysis records ${tx} as aborting`);
}
}
s.phase='redo';s.redoStartLSN=Object.values(s.dirtyPageTable).length?Math.min(...Object.values(s.dirtyPageTable)):null;
emit('Redo repeats history, including loser UPDATEs and existing CLRs');
for(const r of s.log.filter(r=>r.lsn<=s.flushedLSN))if(['UPDATE','CLR'].includes(r.type)) {
const eligible=s.dirtyPageTable[r.page]!==undefined&&r.lsn>=s.dirtyPageTable[r.page];
const applied=eligible&&ariesApply(s,r);
s.redoDecisions.push({pass:s.pass,lsn:r.lsn,type:r.type,tx:r.tx,page:r.page,applied});
emit(`Redo ${r.type} ${r.lsn} on ${r.page}: ${applied?'apply':'skip by DPT/pageLSN'}`);
}
s.phase='undo';
s.toUndo=Object.fromEntries(Object.entries(s.transactionTable).filter(([,t])=>t.status==='aborting').map(([tx,t])=>[tx,t.lastLSN]));
emit('Undo starts from each loser’s lastLSN; choose the highest remaining LSN');
while(Object.keys(s.toUndo).length) {
const [tx,cursor]=Object.entries(s.toUndo).sort((a,b)=>b[1]-a[1])[0];
const r=s.log.find(record=>record.lsn===cursor);
if(cursor===0||r?.type==='BEGIN') {
ariesAppend(s,{type:'END',tx});s.flushedLSN=s.log.at(-1).lsn;delete s.transactionTable[tx];delete s.toUndo[tx];emit(`Undo finishes ${tx}; append END`);continue;
}
if(!r)throw Error(`Missing undo dependency at LSN ${cursor}.`);
if(r.type==='CLR') {
s.toUndo[tx]=s.undoLink==='undoNextLSN'?ariesUndoNext(r):r.prevLSN;
emit(`CLR ${r.lsn} is redo-only: follow ${s.undoLink} to ${s.toUndo[tx]}`);continue;
}
if(r.type!=='UPDATE'){s.toUndo[tx]=r.prevLSN;emit(`Follow ${r.type} ${r.lsn} to prevLSN ${r.prevLSN}`);continue;}
const clr=ariesAppend(s,{type:'CLR',tx,page:r.page,delta:-r.delta,compensates:r.lsn,undoNextLSN:r.prevLSN});
emit(`Append CLR ${clr.lsn}: compensate UPDATE ${r.lsn}; undoNextLSN = ${r.prevLSN}`);
if(failure==='before-clr-flush'){s.crashes.push({pass:s.pass,at:failure,clr:clr.lsn});emit('Crash before flushing the new CLR; its volatile suffix will be lost');return;}
s.flushedLSN=clr.lsn;emit(`Flush CLR ${clr.lsn} before any compensated data page can reach disk`);
if(failure==='after-clr-flush'){s.crashes.push({pass:s.pass,at:failure,clr:clr.lsn});emit('Crash with a durable CLR whose page action has not been installed');return;}
ariesApply(s,clr);s.undoActions.push({pass:s.pass,tx,update:r.lsn,clr:clr.lsn,page:r.page,delta:clr.delta});
emit(`Apply CLR ${clr.lsn} to the buffered page; never compensate the CLR itself`);
if(failure==='after-undo-flush'){ariesFlush(s,r.page);s.crashes.push({pass:s.pass,at:failure,clr:clr.lsn});emit('Flush the undo page, then crash before finishing rollback');return;}
s.toUndo[tx]=r.prevLSN;
}
s.flushedLSN=s.log.at(-1)?.lsn||0;
for(const page of Object.keys(s.disk))ariesFlush(s,page);
s.phase='complete';s.complete=true;emit('Recovery complete: persist final pages for independent verification');
}
function ariesRecovery(config) {
choose(config,'undoLink',['prevLSN','undoNextLSN']);
choose(config,'failure',['none','before-clr-flush','after-clr-flush','after-undo-flush']);
choose(config,'pageFlush',['none','B','B-and-C']);
if(!Number.isSafeInteger(config.attempts)||config.attempts<1||config.attempts>6)throw Error('attempts must be an integer from 1 to 6.');
const disk={A:{value:100,pageLSN:0},B:{value:100,pageLSN:0},C:{value:100,pageLSN:0}};
const s={disk,buffer:copy(disk),log:[],flushedLSN:0,masterCheckpointLSN:0,transactionTable:{},dirtyPageTable:{},toUndo:{},phase:'normal',pass:0,complete:false,undoLink:config.undoLink,redoDecisions:[],undoActions:[],crashes:[]};
const t=recorder(s,ariesChecks);
for(const tx of ['T1','T2','T3']){ariesAppend(s,{type:'BEGIN',tx});t.emit(`Begin ${tx}`);}
for(const [tx,page,delta] of [['T1','A',10],['T2','B',20],['T3','C',7]]){
const r=ariesAppend(s,{type:'UPDATE',tx,page,delta});ariesApply(s,r);s.dirtyPageTable[page]??=r.lsn;t.emit(`Append UPDATE ${r.lsn}: ${tx} changes ${page} by ${delta}`);
}
const cp=ariesAppend(s,{type:'CHECKPOINT',transactions:copy(s.transactionTable),dirtyPages:copy(s.dirtyPageTable)});
s.flushedLSN=cp.lsn;s.masterCheckpointLSN=cp.lsn;t.emit('Persist checkpoint metadata without forcing its dirty pages');
const extra=ariesAppend(s,{type:'UPDATE',tx:'T2',page:'B',delta:5});ariesApply(s,extra);t.emit(`T2 appends another UPDATE at LSN ${extra.lsn}`);
const commit=ariesAppend(s,{type:'COMMIT',tx:'T1'});s.flushedLSN=commit.lsn;t.emit('T1 flushes COMMIT; T2 and T3 remain losers');
if(config.pageFlush!=='none'){ariesFlush(s,'B');if(config.pageFlush==='B-and-C')ariesFlush(s,'C');t.emit(`Steal uncommitted ${config.pageFlush} pages after their WAL is durable`);}
for(let attempt=0;attempt<config.attempts;attempt++)ariesPass(s,t.emit,attempt<config.attempts-1?config.failure:'none');
return t.finish();
}
function recoverAries(original) {
const s=copy(original);ariesPass(s);
return {state:s,checks:ariesChecks(s),label:'ARIES restart: repeat durable history, then resume losers through CLR undoNextLSN links'};
}Implement the undo-chain rule
Select Test implementation and inspect the failing CLR case. In Your JavaScript implementation, choose undoNextLSN for a CLR and prevLSN for the other records. Test again. Explain why undoNextLSN || prevLSN would follow the wrong link when undoNextLSN is zero.
Implement the ARIES undo-chain pointer
solve(record) returns undoNextLSN for a CLR and prevLSN for an ordinary record. CLRs are redo-only. A zero undoNextLSN means stop; do not fall back to prevLSN.
The trace above uses the published algorithm. Test your own function here against the named cases.
Test the starter to find the cases it misses.
Compare the reference implementation
Attempt the named cases before comparing your solution.
function solve(record) {
return record.type==='CLR' ? record.undoNextLSN : record.prevLSN;
}Download your code
Change the failure boundary
Choose each scenario below and select Run to end. Revisit the second restart’s redo and undo steps in the trace.
- clr-durable-page-missing. Find the redo action for the durable CLR and its next undo position.
- clr-not-durable. Find why the first compensation can be generated again when the unfinished log record is lost.
- Repair. Find the redo skip when the undo page is already durable.
- repeated-crashes. Compare ToUndo between the restarts and count the durable CLRs for each compensated UPDATE.
To test a different boundary, select a revealed trace entry and then Crash & recover here. The model restarts from that entry’s durable log and disk pages.
Hint 1 · Draw both chains
From CLR 13, prevLSN leads to ABORT 11 and then UPDATE 8. undoNextLSN leads to UPDATE 5. Only the second path represents work still needing rollback after UPDATE 8's compensation.
Hint 2 · Redo the compensation, never undo the CLR
If the CLR reached storage but its page did not, repeat its delta during redo using the pageLSN guard. The undo phase uses its pointer; it does not create a CLR to reverse that CLR.
Why this result occurs
Analysis finishes T1 and identifies T2/T3 as losers. Redo restores missing committed and uncommitted history. Undo compensates original updates in highest-LSN order, recording each action and its next remaining predecessor. Across a failure, durable CLRs let redo reconstruct compensation already decided and let undo bypass the corresponding original update. The correct final values are A 110, B 100, C 100; the faulty prevLSN rule can instead double-undo B's final +5.
What this core simplifies
The checkpoint is one atomic metadata snapshot between model operations. Full ARIES fuzzy checkpoints use checkpoint records and merge transaction/dirty-page information while work continues. Pages here are fixed and owned by different transactions; there is no index structure, logical undo, nested top action, lock reacquisition, media recovery or log truncation. LSNs are logical record numbers. Whole record/page writes and stable log-prefix storage are assumed. The lab does implement CLRs and repeated restart; it is not a complete production ARIES engine or a claim that PostgreSQL implements this same recovery design.
Transfer the idea
- Propose how to merge a transaction-table snapshot from an END_CHECKPOINT without resurrecting a transaction whose END was seen during analysis. State how an older recLSN must be preserved.
- Add a savepoint. Show which original updates partial rollback compensates, how later work links past that rollback, and what another crash must redo and skip.
- Explain when earlier log records remain necessary for dirty-page redo or loser undo. A checkpoint by itself is not permission to truncate them.
Success criteria: explain one actual redo/skip decision, identify both CLR links, recover from each supplied interruption boundary, and support the bounded-compensation claim with the log records and independent final counter values.
Primary sources: Mohan et al., ARIES (1992), especially rollback and restart processing and Apache Derby's logging/recovery explanation and implementation differences.
Your design record
Explain what happened and cite the run or SQL result that supports it.
Write your design notes
Download notes and evidence
Downloads include current editor text. Run evidence stays on this page until you leave.