@Test public void pushWriteLockedEdge() { mLockList.lockRootEdge(LockMode.WRITE); assertEquals(LockMode.WRITE, mLockList.getLockMode()); assertTrue(mLockList.getLockedInodes().isEmpty()); mLockList.pushWriteLockedEdge(mRootDir, mDirA.getName()); assertEquals(LockMode.WRITE, mLockList.getLockMode()); assertEquals(Arrays.asList(mRootDir), mLockList.getLockedInodes()); mLockList.pushWriteLockedEdge(mDirA, mDirB.getName()); assertEquals(LockMode.WRITE, mLockList.getLockMode()); assertEquals(Arrays.asList(mRootDir, mDirA), mLockList.getLockedInodes()); checkOnlyNodesReadLocked(mRootDir, mDirA); checkOnlyNodesWriteLocked(); checkOnlyIncomingEdgesReadLocked(mRootDir, mDirA); checkOnlyIncomingEdgesWriteLocked(mDirB); }
@Override public void pushWriteLockedEdge(Inode inode, String childName) { Edge edge = new Edge(inode.getId(), childName); Preconditions.checkState(!endsInInode(), "Cannot push edge write lock to edge %s; lock list %s ends in an inode", edge, this); Preconditions.checkState(endsInWriteLock(), "Cannot push write lock; lock list %s ends in a read lock"); if (endsInMultipleWriteLocks()) { lockInode(inode, LockMode.WRITE); lockEdge(inode, childName, LockMode.WRITE); } else { Edge lastEdge = lastEdge(); RWLockResource lastEdgeReadLock = mInodeLockManager.lockEdge(lastEdge, LockMode.READ, mUseTryLock); RWLockResource inodeLock = mInodeLockManager.lockInode(inode, LockMode.READ, mUseTryLock); RWLockResource nextEdgeLock = mInodeLockManager.lockEdge(edge, LockMode.WRITE, mUseTryLock); removeLastLock(); addEdgeLock(lastEdge, LockMode.READ, lastEdgeReadLock); addInodeLock(inode, LockMode.READ, inodeLock); addEdgeLock(edge, LockMode.WRITE, nextEdgeLock); } }
SimpleInodeLockList implements InodeLockList { @Override public void pushWriteLockedEdge(Inode inode, String childName) { Edge edge = new Edge(inode.getId(), childName); Preconditions.checkState(!endsInInode(), "Cannot push edge write lock to edge %s; lock list %s ends in an inode", edge, this); Preconditions.checkState(endsInWriteLock(), "Cannot push write lock; lock list %s ends in a read lock"); if (endsInMultipleWriteLocks()) { lockInode(inode, LockMode.WRITE); lockEdge(inode, childName, LockMode.WRITE); } else { Edge lastEdge = lastEdge(); RWLockResource lastEdgeReadLock = mInodeLockManager.lockEdge(lastEdge, LockMode.READ, mUseTryLock); RWLockResource inodeLock = mInodeLockManager.lockInode(inode, LockMode.READ, mUseTryLock); RWLockResource nextEdgeLock = mInodeLockManager.lockEdge(edge, LockMode.WRITE, mUseTryLock); removeLastLock(); addEdgeLock(lastEdge, LockMode.READ, lastEdgeReadLock); addInodeLock(inode, LockMode.READ, inodeLock); addEdgeLock(edge, LockMode.WRITE, nextEdgeLock); } } }
SimpleInodeLockList implements InodeLockList { @Override public void pushWriteLockedEdge(Inode inode, String childName) { Edge edge = new Edge(inode.getId(), childName); Preconditions.checkState(!endsInInode(), "Cannot push edge write lock to edge %s; lock list %s ends in an inode", edge, this); Preconditions.checkState(endsInWriteLock(), "Cannot push write lock; lock list %s ends in a read lock"); if (endsInMultipleWriteLocks()) { lockInode(inode, LockMode.WRITE); lockEdge(inode, childName, LockMode.WRITE); } else { Edge lastEdge = lastEdge(); RWLockResource lastEdgeReadLock = mInodeLockManager.lockEdge(lastEdge, LockMode.READ, mUseTryLock); RWLockResource inodeLock = mInodeLockManager.lockInode(inode, LockMode.READ, mUseTryLock); RWLockResource nextEdgeLock = mInodeLockManager.lockEdge(edge, LockMode.WRITE, mUseTryLock); removeLastLock(); addEdgeLock(lastEdge, LockMode.READ, lastEdgeReadLock); addInodeLock(inode, LockMode.READ, inodeLock); addEdgeLock(edge, LockMode.WRITE, nextEdgeLock); } } SimpleInodeLockList(InodeLockManager inodeLockManager, boolean useTryLock); }
SimpleInodeLockList implements InodeLockList { @Override public void pushWriteLockedEdge(Inode inode, String childName) { Edge edge = new Edge(inode.getId(), childName); Preconditions.checkState(!endsInInode(), "Cannot push edge write lock to edge %s; lock list %s ends in an inode", edge, this); Preconditions.checkState(endsInWriteLock(), "Cannot push write lock; lock list %s ends in a read lock"); if (endsInMultipleWriteLocks()) { lockInode(inode, LockMode.WRITE); lockEdge(inode, childName, LockMode.WRITE); } else { Edge lastEdge = lastEdge(); RWLockResource lastEdgeReadLock = mInodeLockManager.lockEdge(lastEdge, LockMode.READ, mUseTryLock); RWLockResource inodeLock = mInodeLockManager.lockInode(inode, LockMode.READ, mUseTryLock); RWLockResource nextEdgeLock = mInodeLockManager.lockEdge(edge, LockMode.WRITE, mUseTryLock); removeLastLock(); addEdgeLock(lastEdge, LockMode.READ, lastEdgeReadLock); addInodeLock(inode, LockMode.READ, inodeLock); addEdgeLock(edge, LockMode.WRITE, nextEdgeLock); } } SimpleInodeLockList(InodeLockManager inodeLockManager, boolean useTryLock); @Override void lockInode(Inode inode, LockMode mode); @Override void lockEdge(Inode lastInode, String childName, LockMode mode); @Override void lockRootEdge(LockMode mode); @Override void pushWriteLockedEdge(Inode inode, String childName); @Override void unlockLastInode(); @Override void unlockLastEdge(); @Override void downgradeToReadLocks(); @Override void downgradeLastEdge(); @Override LockMode getLockMode(); @Override List<Inode> getLockedInodes(); @Override Inode get(int index); @Override int numInodes(); @Override boolean isEmpty(); @Override InodeLockManager getInodeLockManager(); @Override boolean endsInInode(); @Override String toString(); @Override void close(); }
SimpleInodeLockList implements InodeLockList { @Override public void pushWriteLockedEdge(Inode inode, String childName) { Edge edge = new Edge(inode.getId(), childName); Preconditions.checkState(!endsInInode(), "Cannot push edge write lock to edge %s; lock list %s ends in an inode", edge, this); Preconditions.checkState(endsInWriteLock(), "Cannot push write lock; lock list %s ends in a read lock"); if (endsInMultipleWriteLocks()) { lockInode(inode, LockMode.WRITE); lockEdge(inode, childName, LockMode.WRITE); } else { Edge lastEdge = lastEdge(); RWLockResource lastEdgeReadLock = mInodeLockManager.lockEdge(lastEdge, LockMode.READ, mUseTryLock); RWLockResource inodeLock = mInodeLockManager.lockInode(inode, LockMode.READ, mUseTryLock); RWLockResource nextEdgeLock = mInodeLockManager.lockEdge(edge, LockMode.WRITE, mUseTryLock); removeLastLock(); addEdgeLock(lastEdge, LockMode.READ, lastEdgeReadLock); addInodeLock(inode, LockMode.READ, inodeLock); addEdgeLock(edge, LockMode.WRITE, nextEdgeLock); } } SimpleInodeLockList(InodeLockManager inodeLockManager, boolean useTryLock); @Override void lockInode(Inode inode, LockMode mode); @Override void lockEdge(Inode lastInode, String childName, LockMode mode); @Override void lockRootEdge(LockMode mode); @Override void pushWriteLockedEdge(Inode inode, String childName); @Override void unlockLastInode(); @Override void unlockLastEdge(); @Override void downgradeToReadLocks(); @Override void downgradeLastEdge(); @Override LockMode getLockMode(); @Override List<Inode> getLockedInodes(); @Override Inode get(int index); @Override int numInodes(); @Override boolean isEmpty(); @Override InodeLockManager getInodeLockManager(); @Override boolean endsInInode(); @Override String toString(); @Override void close();  }