Author | Message |
---|---|
ptran6
Posts: 25
|
Posted 20:23 Nov 21, 2010 |
Dr. Sun, Suppose T1 requests an exclusive lock on Block 1, but T2 and T3 already have a shared lock on Block 1. If T1 is older than T2, but younger than T3, then what happens to T1? Does T1 wait or does it die? |
cysun
Posts: 2935
|
Posted 20:27 Nov 21, 2010 |
First of all, understand why the wait-die protocol is able to avoid deadlock. Then, ask yourself the question: if T1 waits, is a deadlock possible? |
victormejia
Posts: 40
|
Posted 23:57 Nov 23, 2010 |
just to clarify, the wait-die algorithm only applies to when transactions are trying to obtain an xLock an a block, right? since shared locks can automatically be granted? |
cysun
Posts: 2935
|
Posted 00:01 Nov 24, 2010 |
What if another transaction is holding an xlock? |
victormejia
Posts: 40
|
Posted 00:07 Nov 24, 2010 |
Ohh I see. Well the current implementation of sLock() checks for that, but I realized it is still implementing the time-limit strategy. So for xLock() we check for no locks at all, and for sLocks we check for xLocks(), implementing wait-die for both, right? Also, to rollback a transaction, is it enough to just throw the LockAbortException in the LockTable's xLock and sLock, or do have to catch it in the recovery manager, then throw it again so that the transaction get catch it and to a this.rollback()? I was a little confused about this. |
victormejia
Posts: 40
|
Posted 08:51 Nov 24, 2010 |
I have the following code:
public String getString(Block blk, int offset) { try{ concurMgr.sLock(blk,this.txnum); Buffer buff = myBuffers.getBuffer(blk); return buff.getString(offset);
} catch(LockAbortException e){ this.rollback(); }
}
I made it so that the sLock and xLock functions throw an exception if the requesting transaction is newer than the transactions that have a lock on the requested block. this would notify the transaction to rollback. However, I still have to return a string. If I have this situation and the transactions rollsback, what string do I return in order to safely call tx.getString(...) in my test code? And what int would I return for the getInt() function? Last edited by victormejia at
08:59 Nov 24, 2010.
|
cysun
Posts: 2935
|
Posted 14:28 Nov 24, 2010 |
Throw an exception is enough. |
cysun
Posts: 2935
|
Posted 14:31 Nov 24, 2010 |
First of all, please don't post complete code. Secondly, you don't need to catch the exception and rollback. There are various places in simpledb.remote (e.g. connection, resultset etc.) that catch exceptions and initiate rollback. |
cysun
Posts: 2935
|
Posted 14:34 Nov 24, 2010 |
First of all, please don't post complete code. Secondly, you don't need to catch the exception and rollback there. Under normal operations, there are various places in simpledb.remote (e.g. connection, resultset etc.) that catch exceptions and initiate rollback. For testing purpose, you can add catch and rollback to your test code. Last edited by cysun at
14:34 Nov 24, 2010.
|