public boolean lockAndRecord(Fqn fqn, LockType lockType, InvocationContext ctx) throws InterruptedException { if (lockType == READ) return true; // we don't support read locks. if (trace) log.trace("Attempting to lock " + fqn); if (lockContainer.acquireLock(fqn, ctx.getLockAcquisitionTimeout(lockAcquisitionTimeout), MILLISECONDS)) { ctx.addLock(fqn); return true; } // couldn't acquire lock! return false; }
public boolean lockAllAndRecord(Fqn fqn, LockType lockType, InvocationContext ctx) throws InterruptedException { return lockRecursively(dataContainer.peekInternalNode(fqn, false), ctx.getLockAcquisitionTimeout(lockAcquisitionTimeout), false, ctx); }
public boolean lockAllAndRecord(NodeSPI node, LockType lockType, InvocationContext ctx) throws InterruptedException { if (lockType == READ) return true; // we don't support read locks. return lockRecursively(node.getDelegationTarget(), ctx.getLockAcquisitionTimeout(lockAcquisitionTimeout), false, ctx); }
public boolean lockAllAndRecord(NodeSPI node, LockType lockType, InvocationContext ctx) { List<NodeLock> locks = lockAllNodes(node, lockType, getLockOwner(ctx), ctx.getLockAcquisitionTimeout(lockAcquisitionTimeout), false); if (locks == null) return false; if (locks.size() > 0) { ctx.addAllLocks(locks); } return true; }
public boolean lockAndRecord(NodeSPI node, LockType lockType, InvocationContext ctx) { NodeLock lock = acquireLock(node, lockType, getLockOwner(ctx), ctx.getLockAcquisitionTimeout(lockAcquisitionTimeout)); if (lock != null) { ctx.addLock(lock); return true; } else { return false; } }
long timeout = zeroLockTimeout ? 0 : ctx.getLockAcquisitionTimeout(lockAcquisitionTimeout);
/** * Attempts to lock a node if the lock isn't already held in the current scope, and records the lock in the context. * * @param ctx context * @param fqn Fqn to lock * @return true if a lock was needed and acquired, false if it didn't need to acquire the lock (i.e., lock was * already held) * @throws InterruptedException if interrupted * @throws TimeoutException if we are unable to acquire the lock after a specified timeout. */ private boolean acquireLock(InvocationContext ctx, Fqn fqn) throws InterruptedException, TimeoutException { // don't EVER use lockManager.isLocked() since with lock striping it may be the case that we hold the relevant // lock which may be shared with another Fqn that we have a lock for already. // nothing wrong, just means that we fail to record the lock. And that is a problem. // Better to check our records and lock again if necessary. if (!ctx.hasLock(fqn)) { if (!lockManager.lockAndRecord(fqn, WRITE, ctx)) { Object owner = lockManager.getWriteOwner(fqn); throw new TimeoutException("Unable to acquire lock on Fqn [" + fqn + "] after [" + ctx.getLockAcquisitionTimeout(defaultLockAcquisitionTimeout) + "] milliseconds for requestor [" + lockManager.getLockOwner(ctx) + "]! Lock held by [" + owner + "]"); } return true; } return false; }