/** * 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; }