@Override public void processResult(final int rc, final String path, Object ctx) { lockStateExecutor.executeOrdered(lockPath, new SafeRunnable() { @Override public void safeRun() { if (KeeperException.Code.OK.intValue() == rc) { LOG.info("Deleted lock node {} for {} successfully.", path, lockId); } else if (KeeperException.Code.NONODE.intValue() == rc || KeeperException.Code.SESSIONEXPIRED.intValue() == rc) { LOG.info("Delete node failed. Node already gone for node {} id {}, rc = {}", new Object[] { path, lockId, KeeperException.Code.get(rc) }); } else { LOG.error("Failed on deleting lock node {} for {} : {}", new Object[] { path, lockId, KeeperException.Code.get(rc) }); } FailpointUtils.checkFailPointNoThrow(FailpointUtils.FailPointName.FP_LockUnlockCleanup); promise.complete(null); } }); } }, null);
private void orderedSubmit(SafeRunnable runnable) { synchronized (this) { if (null != closePromise) { return; } } try { scheduler.executeOrdered(streamName, runnable); } catch (RejectedExecutionException ree) { logger.debug("Failed to submit and execute an operation for readhead entry reader of {}", streamName, ree); } }
lockStateExecutor.executeOrdered(lockPath, new SafeRunnable() { @Override public void safeRun() {
CompletableFuture<Void> asyncUnlock(final Throwable cause) { final CompletableFuture<Void> promise = new CompletableFuture<Void>(); // Use lock executor here rather than lock action, because we want this opertaion to be applied // whether the epoch has changed or not. The member node is EPHEMERAL_SEQUENTIAL so there's no // risk of an ABA problem where we delete and recreate a node and then delete it again here. lockStateExecutor.executeOrdered(lockPath, new SafeRunnable() { @Override public void safeRun() { acquireFuture.completeExceptionally(cause); unlockInternal(promise); promise.whenComplete(new OpStatsListener<Void>(unlockStats)); } }); return promise; }
@Override public void processResult(final int rc, String path, Object ctx, final List<String> children, Stat stat) { lockStateExecutor.executeOrdered(lockPath, new SafeRunnable() { @Override public void safeRun() {
lockStateExecutor.executeOrdered(lockPath, new SafeRunnable() { @Override public void safeRun() {
protected void submitTask(Object key, SafeRunnable r) { closeLock.readLock().lock(); try { if (closed) { return; } scheduler.executeOrdered(key, r); } finally { closeLock.readLock().unlock(); } }
void internalReacquireLock(final AtomicInteger numRetries, final long lockTimeout, final CompletableFuture<ZKDistributedLock> reacquirePromise) { lockStateExecutor.executeOrdered( lockPath, () -> doInternalReacquireLock(numRetries, lockTimeout, reacquirePromise)); }
public synchronized void scheduleBackgroundRead() { // if the reader is already closed, we don't need to schedule background read again. if (null != closeFuture) { return; } long prevCount = scheduleCountUpdater.getAndIncrement(this); if (0 == prevCount) { scheduleDelayStopwatch.reset().start(); scheduler.executeOrdered(streamName, this); } }
@Override public CompletableFuture<Void> asyncClose() { final CompletableFuture<Void> closeFuture; synchronized (this) { if (null != closePromise) { return closePromise; } closePromise = closeFuture = new CompletableFuture<Void>(); } // cancel the idle reader task cancelIdleReaderTask(); // use runnable here instead of CloseableRunnable, // because we need this to be executed try { scheduler.executeOrdered(streamName, () -> unsafeAsyncClose(closeFuture)); } catch (RejectedExecutionException ree) { logger.warn("Scheduler has been shutdown before closing the readahead entry reader for stream {}", streamName, ree); unsafeAsyncClose(closeFuture); } return closeFuture; }
@Override public CompletableFuture<Void> asyncClose() { final CompletableFuture<Void> closePromise; synchronized (this) { if (closed) { return closeFuture; } closed = true; closeFuture = closePromise = new CompletableFuture<Void>(); } final CompletableFuture<Void> closeWaiterFuture = new CompletableFuture<Void>(); closeWaiterFuture.whenCompleteAsync(new FutureEventListener<Void>() { @Override public void onSuccess(Void value) { complete(); } @Override public void onFailure(Throwable cause) { complete(); } private void complete() { FutureUtils.complete(closePromise, null); } }, lockStateExecutor.chooseThread(lockPath)); lockStateExecutor.executeOrdered( lockPath, () -> closeWaiter(lockWaiter, closeWaiterFuture)); return closePromise; }
return; lockStateExecutor.executeOrdered(lockPath, () -> asyncClose()); }); final Stopwatch stopwatch = Stopwatch.createStarted(); lockStateExecutor.executeOrdered( lockPath, () -> doAsyncAcquireWithSemaphore(promise, lockTimeout)); return promise;
private void processReadRequests() { if (isClosed()) { // the reader is already closed. return; } long prevCount = scheduleCountUpdater.getAndIncrement(this); if (0 == prevCount) { scheduler.executeOrdered(getSegment().getLogSegmentId(), this); } }
null); } else { scheduler.executeOrdered(key, () -> { execute( future,
private boolean checkOrClaimLockOwner(final Pair<String, Long> currentOwner, final CompletableFuture<String> result) { if (lockId.compareTo(currentOwner) != 0 && !lockContext.hasLockId(currentOwner)) { lockStateExecutor.executeOrdered(lockPath, new SafeRunnable() { @Override public void safeRun() { result.complete(currentOwner.getLeft()); } }); return false; } // current owner is itself final int curEpoch = epochUpdater.incrementAndGet(this); executeLockAction(curEpoch, new LockAction() { @Override public void execute() { if (!lockState.inState(State.INIT)) { result.completeExceptionally( new LockStateChangedException(lockPath, lockId, State.INIT, lockState.getState())); return; } asyncTryLock(false, result); } @Override public String getActionName() { return "claimOwnership(owner=" + currentOwner + ")"; } }, result); return true; }