sync.setBroken(true);
/** {@inheritDoc} */ @Override public void onNodeRemoved(UUID nodeId) { try { initializeSemaphore(); } catch (IgniteCheckedException e) { U.error(log, "Failed to recover from failover because distributed semaphore cannot be initialized " + "(Ignore if this node is failing also)." ); // Degrade gracefully, no exception is thrown // because other semaphores might also attempt to recover from failover. return; } int numPermits = sync.getPermitsForNode(nodeId); if (numPermits > 0) { // Semaphore is broken if reaches this point in non-failover safe mode. boolean broken = !sync.failoverSafe; // Release permits acquired by threads on failing node. sync.releaseFailedNode(nodeId, broken); if (broken) { // Interrupt every waiting thread if this semaphore is not failover safe. sync.setBroken(true); for (Thread t : sync.getSharedQueuedThreads()) t.interrupt(); // Try to notify any waiting threads. sync.releaseShared(0); } } }
sync.setBroken(true);
/** {@inheritDoc} */ @Override public void onNodeRemoved(UUID nodeId) { try { initializeSemaphore(); } catch (IgniteCheckedException e) { U.error(log, "Failed to recover from failover because distributed semaphore cannot be initialized " + "(Ignore if this node is failing also)." ); // Degrade gracefully, no exception is thrown // because other semaphores might also attempt to recover from failover. return; } int numPermits = sync.getPermitsForNode(nodeId); if (numPermits > 0) { // Semaphore is broken if reaches this point in non-failover safe mode. boolean broken = !sync.failoverSafe; // Release permits acquired by threads on failing node. sync.releaseFailedNode(nodeId, broken); if (broken) { // Interrupt every waiting thread if this semaphore is not failover safe. sync.setBroken(true); for (Thread t : sync.getSharedQueuedThreads()) t.interrupt(); // Try to notify any waiting threads. sync.releaseShared(0); } } }
@Override public Sync call() throws Exception { try (GridNearTxLocal tx = CU.txStartInternal(ctx, cacheView, PESSIMISTIC, REPEATABLE_READ)) { GridCacheSemaphoreState val = cacheView.get(key); if (val == null) { if (log.isDebugEnabled()) log.debug("Failed to find semaphore with given name: " + name); return null; } final int cnt = val.getCount(); Map<UUID, Integer> waiters = val.getWaiters(); final boolean failoverSafe = val.isFailoverSafe(); tx.commit(); Sync sync = new Sync(cnt, waiters, failoverSafe); sync.setBroken(val.isBroken()); return sync; } } });
/** {@inheritDoc} */ @Override public void onUpdate(GridCacheSemaphoreState val) { if (sync == null) return; // Update broken flag. sync.setBroken(val.isBroken()); // Update permission count. sync.setPermits(val.getCount()); // Update waiters' counts. sync.setWaiters(val.getWaiters()); // Try to notify any waiting threads. sync.releaseShared(0); }
@Override public Sync call() throws Exception { try (GridNearTxLocal tx = CU.txStartInternal(ctx, cacheView, PESSIMISTIC, REPEATABLE_READ)) { GridCacheSemaphoreState val = cacheView.get(key); if (val == null) { if (log.isDebugEnabled()) log.debug("Failed to find semaphore with given name: " + name); return null; } final int cnt = val.getCount(); Map<UUID, Integer> waiters = val.getWaiters(); final boolean failoverSafe = val.isFailoverSafe(); tx.commit(); Sync sync = new Sync(cnt, waiters, failoverSafe); sync.setBroken(val.isBroken()); return sync; } } });
/** {@inheritDoc} */ @Override public void onUpdate(GridCacheSemaphoreState val) { if (sync == null) return; // Update broken flag. sync.setBroken(val.isBroken()); // Update permission count. sync.setPermits(val.getCount()); // Update waiters' counts. sync.setWaiters(val.getWaiters()); // Try to notify any waiting threads. sync.releaseShared(0); }