reset password
Author Message
se1k1h1mawar1
Posts: 121
Posted 15:48 Nov 20, 2015 |

Since I was certain that I am still confused about this topic, I tried a couple of different scenarios of crash and failure recoveries (Undo-only and Redo-only logging and recovery).  Could anyone please point out any mistakes I made? I think I need a few other sets of eyes or a very skilled set of eyes to do this.
Just to be clear, scenarios are made randomly, and what I attempted was to try to judge if the scenarios would have been problematic or not.

 

Case 1-a (with Undo Only Logging and Recovery) :
 
 Start Transaction T:
 <START, T>
 Flush(log)
 Write(T, X, Vx')
 <UPDATE, T, X, Vx> 
 Flush(log)
 Flush(X)
 Write(T, Y, Vy')
 <UPDATE, T, Y, Vy>
 Commit:
 <COMMIT, T>
 Flush(log)

-- crash -->

 Flush(Y)

 
 
The log would look like this after the crash:
 <START, T>
 <UPDATE, T, X, Vx> 
 <UPDATE, T, Y, Vy>
 
The disk would have these values in the appropriate location (in the appropriate block) after the crash:
 X - Vx',    Y - Vy

The disk would have these values in the appropriate location after Undo-Only Recovery:
 X - Vx,    Y - Vy
 
* This would have been okay. But ideally,  <COMMIT, T>, Flush(log) sequence should have come after Flush(Y).
==============
Case 1-b (with Undo Only Logging and Recovery) :
 
 Start Transaction T:
 <START, T>
 Flush(log)
 Write(T, X, Vx)
 Write(T, Y, Vy)
 <UPDATE, T, Y, Vy>
 <UPDATE, T, X, Vx>
 Flush(log) 
 Flush(X) 
 Flush(Y)
 Commit:
 <Commit, T> 
 
-- crash -->

 Flush(log) 
 
The log would look like this after the crash:
 <START, T>
 <UPDATE, T, X, Vx> 
 <UPDATE, T, Y, Vy>

The disk would have these values in the appropriate location after the crash:
 X - Vx',    Y - Vy'

The disk would have these values in the appropriate location after Undo-Only Recovery:
 X - Vx,    Y - Vy
 
* This would have been okay.

==============
Case 2-a (with Redo Only Logging and Recovery) :
 
 Start Transaction T:
 <START, T>
 Flush(log)
 Write(T, X, Vx')
 Write(T, Y, Vy')
 <UPDATE, T, Y, Vy'>
 <UPDATE, T, X, Vx'> 
 Flush(log)
 Write(T, Z, Vz')
 <UPDATE, T, Z, Vz'> 
 Commit:
 <Commit, T> 
 Flush(log)
 Flush(X)
 
-- crash --> 

 Flush(Y)
 Flush(Z) 

 
The log would look like this after the crash:
 <START, T>
 <UPDATE, T, Y, Vy'>
 <UPDATE, T, X, Vx'> 
 <UPDATE, T, Z, Vz'> 
 <Commit, T> 
 
The disk would have these values after the crash:
 X - Vx',    Y - Vy,    Z - Vz

The disk would have these values after Redo Only Recovery:
 X - Vx',    Y - Vy',    Z - Vz'
 
* This would have been okay.

==============
Case 2-b (with Redo Only Logging and Recovery) :
 
 Start Transaction T:
 <START, T>
 Flush(log)
 Write(T, X, Vx')
 Write(T, Y, Vy')
 <UPDATE, T, Y, Vy'>
 <UPDATE, T, X, Vx'> 
 Flush(log)
 Flush(X)
 Flush(Y)
 Write(T, Z, Vz')
 Commit:
 <Commit, T>
 Flush(log)
 
-- crash -->
 
 Flush(Z)
 <UPDATE, T, Z, Vz'> 
 Flush(log)

 
The log would look like this after the crash:
 <START, T>
 <UPDATE, T, Y, Vy'>
 <UPDATE, T, X, Vx'> 
 <Commit, T>
 
The disk would have these values after the crash:
 X - Vx',    Y - Vy',    Z - Vz

The disk would have these values after Redo Only Recovery:
 X - Vx',    Y - Vy',    Z - Vz
 
* This would not have been okay because the Z will have the old value since the log does not have the new value of Vz,
 
 
============== 
Case 3-a (with Undo Only Logging and Recovery) :
 
 Start Transaction T1:
 <START, T1>
 Start Transaction T2:
 <START, T2>
 Flush(log)
 Write(T1, X, Vx')
 Write(T1, Y, Vy')
 <UPDATE, T1, Y, Vy>
 <UPDATE, T1, X, Vx> 
 flush(log)
 Write(T2, Z, Vz')
 Commit T1:
 Flush(X)
 <UPDATE, T2, Z, Vz> 
 <Commit, T1> 
 Flush(log) 
 Flush(Y)
 flush(Z)
 Commit T2:
 
-- crash --> 

 <COMMIT, T2>
 Flush(log)

 

The log would look like this after the crash:
 <START, T1>
 <START, T2>
 <UPDATE, T1, Y, Vy>
 <UPDATE, T1, X, Vx> 
 <UPDATE, T2, Z, Vz> 
 <Commit, T1> 
 
The disk would have these values after the crash:
 X - Vx',    Y - Vy',    Z - Vz'

The disk would have these values after Undo Only Recovery:
 X - Vx',    Y - Vy',    Z - Vz
 
 
This would have been okay provided the commit was never returned, because T2 commit was never returned, but it has a new value on the disk.
It would not have been okay if commit was returned before the crash (we should not return commit before writing <COMMIT,T> to disk)

==============
Case 3-b (with Undo Only Logging and Recovery) :
 
 Start Transaction T1:
 <START, T1>
 Start Transaction T2:
 <START, T2>
 Flush(log)
 Write(T1, X, Vx')
 Write(T1, Y, Vy')
 <UPDATE, T1, Y, Vy>
 <UPDATE, T1, X, Vx> 
 flush(log)
 Write(T2, Z, Vz')
 <UPDATE, T2, X, Vx> 
 Flush(X)
 Flush(Y) 
 <Commit, T1> 
 flush(log)
 <UPDATE, T2, Z, Vz> 
 flush(Z)
 
 -- crash -->
 


 <COMMIT, T2>
 Commit T2

The log would look like this after the crash:
 <START, T1>
 <START, T2>
 <UPDATE, T1, Y, Vy>
 <UPDATE, T1, X, Vx> 
 <UPDATE, T2, Z, Vz> 
 <Commit, T1> 
 
The disk would have these values after the crash:
 X - Vx',    Y - Vy',    Z - Vz'

The disk would have these values after Undo Only Recovery:
 X - Vx',    Y - Vy',    Z - Vz
 
This would have been okay, because it appears to the user that  Write(T1, Y, Vy) has been performed, and the log also shows that <UPDATE, T1, Y, Vy> has been done, indicating Y currently contains vy', but Y in the block (in the disk) still contains the old value, Vy.

Last edited by se1k1h1mawar1 at 22:27 Nov 20, 2015.
vsluong4
Posts: 87
Posted 21:33 Nov 20, 2015 |

For 2-b(redo), I think you're saving to disk before it is committed and "Prerequisite: none of the changes made by uncommitted transactions have been saved to disk"

 

And you're also trying to change the value of Z after a commit.  Someone correct me if I'm wrong, but I don't think you're supposed to do that

se1k1h1mawar1
Posts: 121
Posted 22:26 Nov 20, 2015 |
vsluong4 wrote:

For 2-b(redo), I think you're saving to disk before it is committed and "Prerequisite: none of the changes made by uncommitted transactions have been saved to disk"

 

And you're also trying to change the value of Z after a commit.  Someone correct me if I'm wrong, but I don't think you're supposed to do that

I completely agree. Thank you for your reply.

 

cysun
Posts: 2935
Posted 10:45 Nov 21, 2015 |

Case 1a: cannot be recovered with Undo-only. Because crash happens after <COMMIT,T> and Flush(log), <COMMIT,T> is in the log. The recovery process will think T is already committed so it won't undo T, but in fact Y is not written to disk.

Case 1b: can be recovered with Undo-only. The difference between this and 1a is that <COMMIT,T> is not in the log, so the transaction will be undone.

Case 2a: can be recovered with Redo-only.

Case 2b: this is an invalid sequence: because Write(T,Z,Vz') is before Commit, <UPDATE,T,Z,Vz'> must be before <Commit,T>.

Case 3a: can be recovered with Undo-only given the time of the crash, but not Undo-only recoverable in general because <COMMIT,T1> is flushed to the log before all the changes made by T1 are flushed to disk.

Case 3b: cannot be recovered with Undo-only because <UPDATE,T2,Z,Vz> is not flushed to disk so change to Z cannot be undone.

se1k1h1mawar1
Posts: 121
Posted 11:23 Nov 21, 2015 |
cysun wrote:

Case 1a: cannot be recovered with Undo-only. Because crash happens after <COMMIT,T> and Flush(log), <COMMIT,T> is in the log. The recovery process will think T is already committed so it won't undo T, but in fact Y is not written to disk.

Case 1b: can be recovered with Undo-only. The difference between this and 1a is that <COMMIT,T> is not in the log, so the transaction will be undone.

Case 2a: can be recovered with Redo-only.

Case 2b: this is an invalid sequence: because Write(T,Z,Vz') is before Commit, <UPDATE,T,Z,Vz'> must be before <Commit,T>.

Case 3a: can be recovered with Undo-only given the time of the crash, but not Undo-only recoverable in general because <COMMIT,T1> is flushed to the log before all the changes made by T1 are flushed to disk.

Case 3b: cannot be recovered with Undo-only because <UPDATE,T2,Z,Vz> is not flushed to disk so change to Z cannot be undone.

Thank you for taking the time to look through and reply. I have a lot clearer understanding now.
I did not mean to annoy people with wall of logs and actions ...

jpascua
Posts: 197
Posted 15:15 Nov 27, 2015 |
cysun wrote:

Case 1a: cannot be recovered with Undo-only. Because crash happens after <COMMIT,T> and Flush(log), <COMMIT,T> is in the log. The recovery process will think T is already committed so it won't undo T, but in fact Y is not written to disk.

Case 1b: can be recovered with Undo-only. The difference between this and 1a is that <COMMIT,T> is not in the log, so the transaction will be undone.

Case 2a: can be recovered with Redo-only.

Case 2b: this is an invalid sequence: because Write(T,Z,Vz') is before Commit, <UPDATE,T,Z,Vz'> must be before <Commit,T>.

Case 3a: can be recovered with Undo-only given the time of the crash, but not Undo-only recoverable in general because <COMMIT,T1> is flushed to the log before all the changes made by T1 are flushed to disk.

Case 3b: cannot be recovered with Undo-only because <UPDATE,T2,Z,Vz> is not flushed to disk so change to Z cannot be undone.

Case 2b: What's wrong with Write(T,Z,Vz') being before Commit? Perhaps I overlooked something in the examples / lecture notes.

Last edited by jpascua at 15:16 Nov 27, 2015.
cysun
Posts: 2935
Posted 21:21 Nov 27, 2015 |
jpascua wrote:
cysun wrote:

Case 1a: cannot be recovered with Undo-only. Because crash happens after <COMMIT,T> and Flush(log), <COMMIT,T> is in the log. The recovery process will think T is already committed so it won't undo T, but in fact Y is not written to disk.

Case 1b: can be recovered with Undo-only. The difference between this and 1a is that <COMMIT,T> is not in the log, so the transaction will be undone.

Case 2a: can be recovered with Redo-only.

Case 2b: this is an invalid sequence: because Write(T,Z,Vz') is before Commit, <UPDATE,T,Z,Vz'> must be before <Commit,T>.

Case 3a: can be recovered with Undo-only given the time of the crash, but not Undo-only recoverable in general because <COMMIT,T1> is flushed to the log before all the changes made by T1 are flushed to disk.

Case 3b: cannot be recovered with Undo-only because <UPDATE,T2,Z,Vz> is not flushed to disk so change to Z cannot be undone.

Case 2b: What's wrong with Write(T,Z,Vz') being before Commit? Perhaps I overlooked something in the examples / lecture notes.

Each log record is generated by an operation in a transaction, e.g. a Write(T,X) operation generates an <Update,T,X> log record and a Commit T operation generates a <COMMIT,T> record. Because of this, the order of the log records must match the order of the operations in the transaction.

jpascua
Posts: 197
Posted 22:41 Nov 27, 2015 |
cysun wrote:
jpascua wrote:
cysun wrote:

Case 1a: cannot be recovered with Undo-only. Because crash happens after <COMMIT,T> and Flush(log), <COMMIT,T> is in the log. The recovery process will think T is already committed so it won't undo T, but in fact Y is not written to disk.

Case 1b: can be recovered with Undo-only. The difference between this and 1a is that <COMMIT,T> is not in the log, so the transaction will be undone.

Case 2a: can be recovered with Redo-only.

Case 2b: this is an invalid sequence: because Write(T,Z,Vz') is before Commit, <UPDATE,T,Z,Vz'> must be before <Commit,T>.

Case 3a: can be recovered with Undo-only given the time of the crash, but not Undo-only recoverable in general because <COMMIT,T1> is flushed to the log before all the changes made by T1 are flushed to disk.

Case 3b: cannot be recovered with Undo-only because <UPDATE,T2,Z,Vz> is not flushed to disk so change to Z cannot be undone.

Case 2b: What's wrong with Write(T,Z,Vz') being before Commit? Perhaps I overlooked something in the examples / lecture notes.

Each log record is generated by an operation in a transaction, e.g. a Write(T,X) operation generates an <Update,T,X> log record and a Commit T operation generates a <COMMIT,T> record. Because of this, the order of the log records must match the order of the operations in the transaction.

Makes sense. Thanks for the reply.