acid

Definition

Logging (ACID)

When starting, a transaction registers itself in the log: .

When modifying data item by write in transaction :

  1. Add log entry with:
  • transaction’s ID (i.e., )
  • data item name (i.e., )
  • old value of the item
  • new value of the item
  1. Write new value of the item

When committing transaction :

When aborting a transaction :

Example:

Recovery

Available operations:

  • Redo: perform the changes to the database again
  • Undo: restore database to state prior to execution

Example:

Given a database:

ResourceValue
A100
B300
C5
D60
E80

and log records:

  1. [ T1, start ]
  2. [ T1, B, 300, 400]
  3. [ T1, C, 5, 10 ]
  4. [ T2, start ]
  5. [ T2, E, 80, 480 ]
  6. [ T1, A, 100, 560 ]
  7. [ T1, commit ]
  8. [ T2, A, 560, 570 ]
  9. [ T2, D, 60, 530 ]

Phases 1 - REDO:

Start with an empty undo list: :

  1. started. Accept into undo list: .

  2. updated . Update database:

ResourceValue
A100
B
C5
D60
E80
  1. updated . Update database:
ResourceValue
A100
B400
C
D60
E80
  1. started. Accept into undo list: .

  2. updated . Update database:

ResourceValue
A100
B400
C10
D60
E
  1. updated . Update database:
ResourceValue
A
B400
C10
D60
E480
  1. committed. Remove from undo list: .

  2. updated . Update database:

ResourceValue
A
B400
C10
D60
E480
  1. updated . Update database:
ResourceValue
A570
B400
C10
D
E480

Phases 2 - UNDO:

ResourceValue
A570
B400
C10
D530
E480

. Undoing changes caused by in reverse order.

  • Reversing and add to end of log entries:
ResourceValue
A570
B400
C10
D
E480
  1. [ T1, start ]
  2. [ T1, B, 300, 400 ]
  3. [ T1, C, 5, 10]
  4. [ T2, start ]
  5. [ T2, E, 80, 480 ]
  6. [ T1, A, 100, 560 ]
  7. [ T1, commit ]
  8. [ T2, A, 560, 570 ]
  9. [ T2, D, 60, 530 ]
  10. [ T2, D, 60 ]
  • Reversing and add to end of log entries:
ResourceValue
A
B400
C10
D60
E480
  1. [ T1, start ]
  2. [ T1, B, 300, 400 ]
  3. [ T1, C, 5, 10]
  4. [ T2, start ]
  5. [ T2, E, 80, 480 ]
  6. [ T1, A, 100, 560 ]
  7. [ T1, commit ]
  8. [ T2, A, 560, 570 ]
  9. [ T2, D, 60, 530 ]
  10. [ T2, D, 60 ]
  11. [ T2, A, 560 ]
  • Reversing and add to end of log entries:
ResourceValue
A560
B400
C10
D60
E480
  1. [ T1, start ]
  2. [ T1, B, 300, 400 ]
  3. [ T1, C, 5, 10]
  4. [ T2, start ]
  5. [ T2, E, 80, 480 ]
  6. [ T1, A, 100, 560 ]
  7. [ T1, commit ]
  8. [ T2, A, 560, 570 ]
  9. [ T2, D, 60, 530 ]
  10. [ T2, D, 60 ]
  11. [ T2, A, 560 ]
  12. [ T2, E, 80 ]
  • Found . Remove from undo list, i.e. , and add to end of log entries:
  1. [ T1, start ]
  2. [ T1, B, 300, 400 ]
  3. [ T1, C, 5, 10 ]
  4. [ T2, start ]
  5. [ T2, E, 80, 480 ]
  6. [ T1, A, 100, 560 ]
  7. [ T1, commit ]
  8. [ T2, A, 560, 570 ]
  9. [ T2, D, 60, 530 ]
  10. [ T2, D, 60 ]
  11. [ T2, A, 560 ]
  12. [ T2, E, 80 ]
  13. [ T2, abort ]