@Override public String toString() { return String.format("%s(%s, xlock=%s sharedLock=%s size=%s)", getClass().getSimpleName(), key, lockStatus.hasExclusiveLock() ? "true (" + lockStatus.getExclusiveLockProcIdOwner() + ")" : "false", lockStatus.getSharedLockCount(), size()); } }
/** * Return the id of the procedure which holds the exclusive lock, if exists. Or a negative value * which means no one holds the exclusive lock. * <p/> * Notice that, in HBase, we assume that the procedure id is positive, or at least non-negative. */ default long getExclusiveLockProcIdOwner() { Procedure<?> proc = getExclusiveLockOwnerProcedure(); return proc != null ? proc.getProcId() : -1L; }
private <T extends Comparable<T>> boolean isLockReady(Procedure<?> proc, Queue<T> rq) { LockStatus s = rq.getLockStatus(); // if we have the lock access, we are ready if (s.hasLockAccess(proc)) { return true; } boolean xlockReq = rq.requireExclusiveLock(proc); // if we need to hold the xlock, then we need to make sure that no one holds any lock, including // the shared lock, otherwise, we just need to make sure that no one holds the xlock return xlockReq ? !s.isLocked() : !s.hasExclusiveLock(); }
/** * Return whether this lock has already been held, * <p/> * Notice that, holding the exclusive lock or shared lock are both considered as locked, i.e, this * method usually equals to {@code hasExclusiveLock() || getSharedLockCount() > 0}. */ default boolean isLocked() { return hasExclusiveLock() || getSharedLockCount() > 0; }
private <T extends Comparable<T>> void doAdd(FairQueue<T> fairq, Queue<T> queue, Procedure<?> proc, boolean addFront) { queue.add(proc, addFront); // For the following conditions, we will put the queue back into execution // 1. The procedure has already held the lock, or the lock has been restored when restarting, // which means it can be executed immediately. // 2. The exclusive lock for this queue has not been held. // 3. The given procedure has the exclusive lock permission for this queue. Supplier<String> reason = null; if (proc.hasLock()) { reason = () -> proc + " has lock"; } else if (proc.isLockedWhenLoading()) { reason = () -> proc + " restores lock when restarting"; } else if (!queue.getLockStatus().hasExclusiveLock()) { reason = () -> "the exclusive lock is not held by anyone when adding " + proc; } else if (queue.getLockStatus().hasLockAccess(proc)) { reason = () -> proc + " has the excusive lock access"; } if (reason != null) { addToRunQueue(fairq, queue, reason); } }
@Override public boolean isAvailable() { return !isEmpty() && !namespaceLockStatus.hasExclusiveLock(); }
/** * Return whether this lock has already been held, * <p/> * Notice that, holding the exclusive lock or shared lock are both considered as locked, i.e, this * method usually equals to {@code hasExclusiveLock() || getSharedLockCount() > 0}. */ default boolean isLocked() { return hasExclusiveLock() || getSharedLockCount() > 0; }
/** * Return the id of the procedure which holds the exclusive lock, if exists. Or a negative value * which means no one holds the exclusive lock. * <p/> * Notice that, in HBase, we assume that the procedure id is positive, or at least non-negative. */ default long getExclusiveLockProcIdOwner() { Procedure<?> proc = getExclusiveLockOwnerProcedure(); return proc != null ? proc.getProcId() : -1L; }