-
Notifications
You must be signed in to change notification settings - Fork 272
Open
Description
LockTable的add方法:
/**
* 向依赖等待图中添加一条边xid->uid
*
* 不需要等待则返回null,否则返回锁对象
* 会造成死锁则抛出异常
*/
public Lock add(long xid, long uid) throws Exception {
lock.lock();
try {
// ...
// uid被持有,且不会造成死锁,则返回当前xid的锁
Lock l = new ReentrantLock();
l.lock();
waitLock.put(xid, l);
return l;
} finally {
lock.unlock();
}
}LockTable.add()是在VersionManagerImpl.delete()中被调用的:
if(!Visibility.isVisible(tm, t, entry)) {
return false;
}
Lock l = null;
try {
l = lt.add(xid, uid);
} catch (Exception e) {
t.err = Error.ConcurrentUpdateException;
internAbort(xid, true);
t.autoAborted = true;
throw t.err;
}
// TODO 这在干嘛,由于使用的是ReentrantLock,这里并不会阻塞,没啥用
if(l != null) {
l.lock();
l.unlock();
}整个过程都是在同一个线程中完成的,原本我们期望会在delete的l.lock()处阻塞,直至通过selectNewXID释放对应xid的锁,但实际不会这样,同线程ReentrantLock多次加锁不会阻塞
Metadata
Metadata
Assignees
Labels
No labels