Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 42

ARIES Analysis for Crash Recovery

Recommended resources

Hello! Let's continue our journey into the world of database recovery.

In our last lesson, we examined the key bookkeeping data structures ARIES uses during normal operation: the Active Transaction Table (ATT) and the Dirty Page Table (DPT), all orchestrated by Log Sequence Numbers (LSNs).

But what happens when the system crashes? All that carefully maintained in-memory information vanishes. The only source of truth is the log stored on disk. Today, we tackle the first and most critical step of recovery: the Analysis phase. Your goal for this lesson is to perform the Analysis phase of ARIES to reconstruct the system's state at the time of a crash. We will act like the recovery manager, scanning the log to figure out precisely which transactions were "winners" and "losers," and which data pages were left in a dubious state.

The ARIES Recovery Roadmap

ARIES recovery is a methodical, three-phase process designed to be restartable even if a crash occurs during recovery itself.

Three Phases of ARIES
This diagram shows the three phases of ARIES recovery relative to the log. The Analysis phase scans forward from the last checkpoint to the end of the log (the crash point). The Redo phase also scans forward, starting from the oldest change that might be missing from disk. The Undo phase works backward from the crash point to reverse the changes of incomplete transactions.
  1. Phase 1: Analysis (Our focus today)

    • Goal: Scan the log forward from the last checkpoint to the crash point.
    • Output: Reconstruct the Active Transaction Table (ATT) and Dirty Page Table (DPT) as they were at the moment of the crash. This tells us which transactions need to be undone and which pages might need their changes reapplied.
  2. Phase 2: Redo

    • Goal: "Repeat history." Reapply all updates from the log for all transactions (even losers) to ensure the database reflects the state at the crash, including the effects of uncommitted changes that might have been written to disk.
  3. Phase 3: Undo

    • Goal: "Clean up the mess." Roll back all "loser" transactions (those that did not commit) in reverse order, writing Compensation Log Records (CLRs) for each change that is undone.

Without a successful Analysis phase, the system has no map to guide the Redo and Undo operations. Let's learn how to draw that map.


The Analysis Algorithm

After a crash, the recovery manager starts the Analysis phase. The process is algorithmic and, given your background, you can think of it as a single forward pass over a file (the log) to build two in-memory hash tables (the ATT and DPT).

Here are the rules:

  1. Start: The system finds the LSN of the last successful CHECKPOINT-BEGIN record via a pointer called the MasterRecord. It initializes an empty ATT and an empty DPT.

  2. Scan Forward: It scans the log from that checkpoint record to the end (the crash point). For each log record it encounters, it applies the following logic:

    • For any record from a transaction T: If T is not in the ATT, add it with status = U (Undo-candidate). This is the default assumption; a transaction is considered a loser until we see proof otherwise. Update T's lastLSN in the ATT to the LSN of the current record.
    • For an UPDATE record: If the modified page P is not in the DPT, add it. Set P's recLSN to the LSN of this update record, because this is the first change that has made this page dirty since the checkpoint began.
    • For a COMMIT record: Change the status of the corresponding transaction in the ATT to C (Committed).
    • For a TXN-END record: This signifies that a transaction is well and truly finished, and any cleanup is done. We can remove its entry from the ATT.
    • For a CHECKPOINT-END record: This record contains the ATT and DPT as they existed when the checkpoint began. The recovery manager merges this information with the ATT and DPT it is currently building. This is crucial for finding transactions and dirty pages that existed before the checkpoint but were still active.

At the end of this pass, we have a complete picture of the database state at the moment of the crash.


Walkthrough: Analysis in Action

Let's see this algorithm in practice. The following video from CMU's database course provides an excellent, detailed walkthrough of the Analysis phase on a sample log.

20 - Database Recovery with ARIES (CMU Intro to Database Systems / Fall 2022)

Watch this segment to see Professor Andy Pavlo apply the Analysis phase rules to a log after a crash. Pay close attention to how the ATT and DPT are built step-by-step as he scans the log.

Watch from 56:04 to 1:06:20. Focus on: The initial state of the ATT and DPT. How an UPDATE record for T96 adds entries to both tables. What happens when the CHECKPOINT-END record is processed—notice how it adds information about T97 and P20, which occurred before the checkpoint. How the status of T96 changes upon seeing the COMMIT record. The final state of both tables after the TXN-END record is processed and the system crashes.

To solidify what you just saw, let's trace the example from the video textually.

The Log:

...
010: <CHECKPOINT-BEGIN>
...
020: <T96, UPDATE P33, ...>
...
030: <CHECKPOINT-END ATT={T96,T97}, DPT={P20(recLSN=008)}>
...
040: <T96, COMMIT>
...
050: <T96, TXN-END>
...
CRASH!

The Analysis Trace:

LSN Processed Log Record Content State of ATT State of DPT
010 <CHECKPOINT-BEGIN> {} {}
020 <T96, UPDATE P33, ...> {(T96, U, lastLSN=020)} {(P33, recLSN=020)}
030 <CHECKPOINT-END ...> {(T96, U, ...), (T97, U, ...)} {(P33, 020), (P20, 008)}
040 <T96, COMMIT> {(T96, C, ...), (T97, U, ...)} {(P33, 020), (P20, 008)}
050 <T96, TXN-END> {(T97, U, ...)} {(P33, 020), (P20, 008)}
End of Log CRASH! Final ATT: {(T97, U, ...)} Final DPT: {(P33, 020), (P20, 008)}

Outcome of the Analysis:

  • Active Transaction Table (ATT): The only transaction left is T97, with status U (Undo-candidate). This is our "loser" transaction. Its changes must be rolled back in the Undo phase.
  • Dirty Page Table (DPT): Two pages, P33 and P20, were potentially dirty in memory. The Redo phase will need to ensure their changes are on disk. It will start its scan from the smallest recLSN in this table, which is 008.
Test your understanding!

Now it's your turn. Here is a log from a different system that crashed. Perform the Analysis phase and determine the final state of the ATT and DPT.

Log on Disk:

LSN  Log Record
---  ----------
1    <T1, UPDATE P1, ...>
2    <T2, UPDATE P1, ...>
3    <T2, UPDATE P2, ...>
4    <T1, UPDATE P2, ...>
5    <T1, COMMIT>
CRASH!

(Assume the analysis starts from LSN 1 for simplicity).

What is the content of the ATT and DPT at the end of the Analysis phase?

Show answer

Let's trace the analysis:

  1. LSN 1: <T1, UPDATE P1, ...>
    • ATT: {(T1, U, lastLSN=1)}
    • DPT: {(P1, recLSN=1)}
  2. LSN 2: <T2, UPDATE P1, ...>
    • ATT: {(T1, U, 1), (T2, U, 2)}
    • DPT: {(P1, 1)} (P1 is already in DPT, so recLSN doesn't change)
  3. LSN 3: <T2, UPDATE P2, ...>
    • ATT: {(T1, U, 1), (T2, U, 3)}
    • DPT: {(P1, 1), (P2, 3)}
  4. LSN 4: <T1, UPDATE P2, ...>
    • ATT: {(T1, U, 4), (T2, U, 3)}
    • DPT: {(P1, 1), (P2, 3)} (P2 is already in DPT)
  5. LSN 5: <T1, COMMIT>
    • ATT: {(T1, C, 4), (T2, U, 3)}
    • DPT: {(P1, 1), (P2, 3)}

Final State at Crash:

  • ATT: {(T1, C, lastLSN=4), (T2, U, lastLSN=3)}
  • DPT: {(P1, recLSN=1), (P2, recLSN=3)}

Conclusion: T1 is a "winner" (committed), and its TXN-END record will be written during the Redo phase. T2 is a "loser" (status U), and its changes will be rolled back during the Undo phase. The Redo phase will begin its scan from LSN 1, the smallest recLSN in the DPT.


Conclusion

In this lesson, you learned how to perform the first and most fundamental phase of ARIES recovery. By systematically scanning the log forward, the Analysis phase acts as a detective, piecing together the state of the database at the exact moment of a crash from the evidence left behind.

Key Takeaways:

  • The Analysis phase is a forward pass over the log, starting from the last checkpoint.
  • Its purpose is to reconstruct the Active Transaction Table (ATT) and Dirty Page Table (DPT).
  • The final ATT identifies which transactions are "losers" (status U) that must be undone.
  • The final DPT identifies pages that might not have their latest versions on disk. The smallest recLSN in the DPT determines the starting point for the Redo phase.

Preview of the Next Lesson

We have successfully analyzed the crash scene and have our map: the final ATT and DPT. In the next lesson, we will begin the actual restoration work by executing the Redo phase. You will learn how ARIES uses the DPT to "repeat history," ensuring that all changes up to the crash point—including those from both winner and loser transactions—are correctly applied to the database on disk.