Skip to content

VM关于锁的实现有问题 #31

@qk-antares

Description

@qk-antares

LockTableadd方法:

/**
 * 向依赖等待图中添加一条边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();
}

整个过程都是在同一个线程中完成的,原本我们期望会在deletel.lock()处阻塞,直至通过selectNewXID释放对应xid的锁,但实际不会这样,同线程ReentrantLock多次加锁不会阻塞

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions