public AsyncUpdateCallback(NodeStore store, String name, long leaseTimeOut, String checkpoint, AsyncIndexStats indexStats, AtomicBoolean forcedStop) { this.store = store; this.name = name; this.forcedStop = forcedStop; this.leaseTimeOut = leaseTimeOut; this.checkpoint = checkpoint; this.tempCpName = getTempCpName(name); this.indexStats = indexStats; this.leaseName = leasify(name); }
public AsyncUpdateCallback(NodeStore store, String name, long leaseTimeOut, String checkpoint, AsyncIndexStats indexStats, AtomicBoolean forcedStop) { this.store = store; this.name = name; this.forcedStop = forcedStop; this.leaseTimeOut = leaseTimeOut; this.checkpoint = checkpoint; this.tempCpName = getTempCpName(name); this.indexStats = indexStats; this.leaseName = leasify(name); }
public AsyncUpdateCallback(NodeStore store, String name, long leaseTimeOut, String checkpoint, AsyncIndexStats indexStats, AtomicBoolean forcedStop) { this.store = store; this.name = name; this.forcedStop = forcedStop; this.leaseTimeOut = leaseTimeOut; this.checkpoint = checkpoint; this.tempCpName = getTempCpName(name); this.indexStats = indexStats; this.leaseName = leasify(name); }
@Override @NotNull public NodeState processCommit( NodeState before, NodeState after, CommitInfo info) throws CommitFailedException { // check for concurrent updates by this async task NodeState async = before.getChildNode(ASYNC); if ((checkpoint == null || Objects.equal(checkpoint, async.getString(name))) && (lease == null || lease == async.getLong(leasify(name)))) { return after; } else { throw newConcurrentUpdateException(); } } };
@Override @NotNull public NodeState processCommit( NodeState before, NodeState after, CommitInfo info) throws CommitFailedException { // check for concurrent updates by this async task NodeState async = before.getChildNode(ASYNC); if ((checkpoint == null || Objects.equal(checkpoint, async.getString(name))) && (lease == null || lease == async.getLong(leasify(name)))) { return after; } else { throw newConcurrentUpdateException(); } } };
@Override @Nonnull public NodeState processCommit( NodeState before, NodeState after, CommitInfo info) throws CommitFailedException { // check for concurrent updates by this async task NodeState async = before.getChildNode(ASYNC); if ((checkpoint == null || Objects.equal(checkpoint, async.getString(name))) && (lease == null || lease == async.getLong(leasify(name)))) { return after; } else { throw newConcurrentUpdateException(); } } };
@Override public AsyncIndexInfo getInfo(String name, NodeState root) { NodeState async = getAsyncState(root); if (async.hasProperty(name)) { long lastIndexedTo = getLastIndexedTo(name, async); long leaseEnd = -1; boolean running = false; if (async.hasProperty(AsyncIndexUpdate.leasify(name))) { running = true; leaseEnd = async.getLong(AsyncIndexUpdate.leasify(name)); } IndexStatsMBean mbean = statsMBeans.get(name); return new AsyncIndexInfo(name, lastIndexedTo, leaseEnd, running, mbean); } return null; }
@Override public AsyncIndexInfo getInfo(String name, NodeState root) { NodeState async = getAsyncState(root); if (async.hasProperty(name)) { long lastIndexedTo = getLastIndexedTo(name, async); long leaseEnd = -1; boolean running = false; if (async.hasProperty(AsyncIndexUpdate.leasify(name))) { running = true; leaseEnd = async.getLong(AsyncIndexUpdate.leasify(name)); } IndexStatsMBean mbean = statsMBeans.get(name); return new AsyncIndexInfo(name, lastIndexedTo, leaseEnd, running, mbean); } return null; }
@Override public AsyncIndexInfo getInfo(String name, NodeState root) { NodeState async = getAsyncState(root); if (async.hasProperty(name)) { long lastIndexedTo = getLastIndexedTo(name, async); long leaseEnd = -1; boolean running = false; if (async.hasProperty(AsyncIndexUpdate.leasify(name))) { running = true; leaseEnd = async.getLong(AsyncIndexUpdate.leasify(name)); } IndexStatsMBean mbean = statsMBeans.get(name); return new AsyncIndexInfo(name, lastIndexedTo, leaseEnd, running, mbean); } return null; }
@Override public void unlock(ClusteredLockToken token) throws CommitFailedException { String leaseName = AsyncIndexUpdate.leasify(token.laneName); NodeBuilder builder = nodeStore.getRoot().builder(); NodeBuilder async = builder.child(":async"); async.removeProperty(leaseName); async.removeProperty(lockName(token.laneName)); NodeStoreUtils.mergeWithConcurrentCheck(nodeStore, builder); log.info("Remove the lock for async indexer lane [{}]", token.laneName); }
@Override public void unlock(ClusteredLockToken token) throws CommitFailedException { String leaseName = AsyncIndexUpdate.leasify(token.laneName); NodeBuilder builder = nodeStore.getRoot().builder(); NodeBuilder async = builder.child(":async"); async.removeProperty(leaseName); async.removeProperty(lockName(token.laneName)); NodeStoreUtils.mergeWithConcurrentCheck(nodeStore, builder); log.info("Remove the lock for async indexer lane [{}]", token.laneName); }
@Override public void unlock(ClusteredLockToken token) throws CommitFailedException { String leaseName = AsyncIndexUpdate.leasify(token.laneName); NodeBuilder builder = nodeStore.getRoot().builder(); NodeBuilder async = builder.child(":async"); async.removeProperty(leaseName); async.removeProperty(lockName(token.laneName)); NodeStoreUtils.mergeWithConcurrentCheck(nodeStore, builder); log.info("Remove the lock for async indexer lane [{}]", token.laneName); }
@Override public ClusteredLockToken lock(String asyncIndexerLane) throws CommitFailedException { NodeBuilder builder = nodeStore.getRoot().builder(); NodeBuilder async = builder.child(":async"); String leaseName = AsyncIndexUpdate.leasify(asyncIndexerLane); long leaseEndTime = clock.getTime() + LOCK_TIMEOUT; if (async.hasProperty(leaseName)){ log.info("AsyncIndexer found to be running currently. Lease update would cause its" + "commit to fail. Such a failure should be ignored"); } //TODO Attempt few times if merge failure due to current running indexer cycle async.setProperty(leaseName, leaseEndTime); async.setProperty(lockName(asyncIndexerLane), true); NodeStoreUtils.mergeWithConcurrentCheck(nodeStore, builder); log.info("Acquired the lock for async indexer lane [{}]", asyncIndexerLane); return new ClusteredLockToken(asyncIndexerLane, leaseEndTime); }
@Override public ClusteredLockToken lock(String asyncIndexerLane) throws CommitFailedException { NodeBuilder builder = nodeStore.getRoot().builder(); NodeBuilder async = builder.child(":async"); String leaseName = AsyncIndexUpdate.leasify(asyncIndexerLane); long leaseEndTime = clock.getTime() + LOCK_TIMEOUT; if (async.hasProperty(leaseName)){ log.info("AsyncIndexer found to be running currently. Lease update would cause its" + "commit to fail. Such a failure should be ignored"); } //TODO Attempt few times if merge failure due to current running indexer cycle async.setProperty(leaseName, leaseEndTime); async.setProperty(lockName(asyncIndexerLane), true); NodeStoreUtils.mergeWithConcurrentCheck(nodeStore, builder); log.info("Acquired the lock for async indexer lane [{}]", asyncIndexerLane); return new ClusteredLockToken(asyncIndexerLane, leaseEndTime); }
@Override public ClusteredLockToken lock(String asyncIndexerLane) throws CommitFailedException { NodeBuilder builder = nodeStore.getRoot().builder(); NodeBuilder async = builder.child(":async"); String leaseName = AsyncIndexUpdate.leasify(asyncIndexerLane); long leaseEndTime = clock.getTime() + LOCK_TIMEOUT; if (async.hasProperty(leaseName)){ log.info("AsyncIndexer found to be running currently. Lease update would cause its" + "commit to fail. Such a failure should be ignored"); } //TODO Attempt few times if merge failure due to current running indexer cycle async.setProperty(leaseName, leaseEndTime); async.setProperty(lockName(asyncIndexerLane), true); NodeStoreUtils.mergeWithConcurrentCheck(nodeStore, builder); log.info("Acquired the lock for async indexer lane [{}]", asyncIndexerLane); return new ClusteredLockToken(asyncIndexerLane, leaseEndTime); }
private long getLeaseValue() { return store.getRoot().getChildNode(":async").getLong( AsyncIndexUpdate.leasify(name)); }
long leaseEndTime = async.getLong(leasify(name)); long currentTime = System.currentTimeMillis(); if (leaseEndTime > currentTime) {
@Test public void locking() throws Exception{ new AsyncIndexUpdate(name, store, provider).run(); assertFalse(getAsync().hasProperty(AsyncIndexUpdate.leasify(name))); ClusterNodeStoreLock lock = new ClusterNodeStoreLock(store); ClusteredLockToken token = lock.lock("async"); assertTrue(getAsync().hasProperty(AsyncIndexUpdate.leasify(name))); assertTrue(lock.isLocked(name)); lock.unlock(token); assertFalse(getAsync().hasProperty(AsyncIndexUpdate.leasify(name))); assertFalse(lock.isLocked(name)); }
@Test public void testLeaseExpiredToDisabled() throws Exception { // take care of initial reindex before new AsyncIndexUpdate(name, store, provider).run(); // add extra indexed content testContent(store); // make it look like lease got stuck due to force shutdown NodeBuilder builder = store.getRoot().builder(); builder.getChildNode(AsyncIndexUpdate.ASYNC).setProperty( AsyncIndexUpdate.leasify(name), System.currentTimeMillis() + 500000); store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); final IndexStatusListener l1 = new IndexStatusListener() { @Override protected void postIndexUpdate() { executed.set(true); } }; assertRunOk(new SpecialAsyncIndexUpdate(name, store, provider, l1) .setLeaseTimeOut(0)); assertFalse("Stale lease info must be cleaned", store.getRoot().getChildNode(AsyncIndexUpdate.ASYNC) .hasProperty(AsyncIndexUpdate.leasify(name))); }
String checkpointName = async.getString("async"); if (store.retrieve(checkpointName) == null && async.getProperty(AsyncIndexUpdate.leasify("async")) == null){ oldRootState.set(ns); break;