@Override public long getLong(String name) { return delegate.getLong(name); }
@Override public long getLong(String name) { return delegate.getLong(name); }
@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 @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 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; }
public int clean(NodeBuilder builder, long lastIndexedTo) { int removalCount = 0; NodeState baseState = builder.getBaseState(); for (ChildNodeEntry e : baseState.getChildNodeEntries()) { long entryCreationTime = e.getNodeState().getLong(PROP_CREATED); if (entryCovered(entryCreationTime, lastIndexedTo)) { builder.child(e.getName()).remove(); removalCount++; } } return removalCount; }
public int clean(NodeBuilder builder, long lastIndexedTo) { int removalCount = 0; NodeState baseState = builder.getBaseState(); for (ChildNodeEntry e : baseState.getChildNodeEntries()) { long entryCreationTime = e.getNodeState().getLong(PROP_CREATED); if (entryCovered(entryCreationTime, lastIndexedTo)) { builder.child(e.getName()).remove(); removalCount++; } } return removalCount; }
private long getLeaseValue() { return store.getRoot().getChildNode(":async").getLong( AsyncIndexUpdate.leasify(name)); }
protected void initLease() throws CommitFailedException { if (hasLease) { return; } NodeState root = store.getRoot(); NodeState async = root.getChildNode(ASYNC); if(isLeaseCheckEnabled(leaseTimeOut)) { long now = getTime(); this.lease = now + 2 * leaseTimeOut; long beforeLease = async.getLong(leaseName); if (beforeLease > now) { throw newConcurrentUpdateException(); } NodeBuilder builder = root.builder(); builder.child(ASYNC).setProperty(leaseName, lease); mergeWithConcurrencyCheck(store, validatorProviders, builder, checkpoint, beforeLease, name); } else { lease = null; // remove stale lease info if needed if (async.hasProperty(leaseName)) { NodeBuilder builder = root.builder(); builder.child(ASYNC).removeProperty(leaseName); mergeWithConcurrencyCheck(store, validatorProviders, builder, checkpoint, null, name); } } hasLease = true; }
protected void initLease() throws CommitFailedException { if (hasLease) { return; } NodeState root = store.getRoot(); NodeState async = root.getChildNode(ASYNC); if(isLeaseCheckEnabled(leaseTimeOut)) { long now = getTime(); this.lease = now + 2 * leaseTimeOut; long beforeLease = async.getLong(leaseName); if (beforeLease > now) { throw newConcurrentUpdateException(); } NodeBuilder builder = root.builder(); builder.child(ASYNC).setProperty(leaseName, lease); mergeWithConcurrencyCheck(store, validatorProviders, builder, checkpoint, beforeLease, name); } else { lease = null; // remove stale lease info if needed if (async.hasProperty(leaseName)) { NodeBuilder builder = root.builder(); builder.child(ASYNC).removeProperty(leaseName); mergeWithConcurrencyCheck(store, validatorProviders, builder, checkpoint, null, name); } } hasLease = true; }
@Test public void defaultSetup() throws Exception{ NodeState state = builder.build(); assertEquals(2, state.getLong("compatVersion")); assertEquals("async", state.getString("async")); assertEquals("lucene", state.getString("type")); }
@Test public void testReindexAuto_ImportCase() throws Exception{ NodeState before = builder.getNodeState(); NodeBuilder idx = createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", false, false, ImmutableSet.of("foo"), null); idx.child(":index"); NodeState after = builder.getNodeState(); NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY); NodeState ns = checkPathExists(indexed, INDEX_DEFINITIONS_NAME, "rootIndex"); assertEquals(0, ns.getLong("reindexCount")); PropertyState ps = ns.getProperty(REINDEX_PROPERTY_NAME); assertNotNull(ps); assertFalse(ps.getValue(Type.BOOLEAN)); }
/** * Test that an index is still reindexed if it has hidden nodes but with all such * hidden nodes having IndexConstants.REINDEX_RETAIN set to true i.e. this index * does not yet have any hidden nodes corresponding to persisted index like lucene */ @Test public void reindexSkipRemovalOfRetainedNodes_FreshIndex() throws Exception{ builder.child("testRoot").setProperty("foo", "abc"); NodeState before = builder.getNodeState(); NodeBuilder nb = createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", false, false, ImmutableSet.of("foo"), null); nb.child(":hidden-node-2").setProperty(IndexConstants.REINDEX_RETAIN, true); nb.child("visible-node"); NodeState after = builder.getNodeState(); NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY); // first check that the index content nodes exist NodeState ns = checkPathExists(indexed, INDEX_DEFINITIONS_NAME, "rootIndex"); checkPathExists(ns, "visible-node"); checkPathExists(ns, ":hidden-node-2"); assertEquals(1, ns.getLong(REINDEX_COUNT)); }
/** * Tests that with explicit reindex i.e. reindex=true those hidden nodes * which have IndexConstants.REINDEX_RETAIN set to true are not removed */ @Test public void reindexSkipRemovalOfRetainedNodes() throws Exception{ builder.child("testRoot").setProperty("foo", "abc"); NodeState before = builder.getNodeState(); NodeBuilder nb = createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null); nb.child(":hidden-node-1").setProperty("foo", "bar"); nb.child(":hidden-node-2").setProperty(IndexConstants.REINDEX_RETAIN, true); nb.child("visible-node"); NodeState after = builder.getNodeState(); NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY); // first check that the index content nodes exist NodeState ns = checkPathExists(indexed, INDEX_DEFINITIONS_NAME, "rootIndex"); checkPathExists(ns, "visible-node"); checkPathExists(ns, ":hidden-node-2"); assertFalse(ns.getChildNode(":hidden-node-1").exists()); assertEquals(1, ns.getLong(REINDEX_COUNT)); }
@Test public void getPropertyReportsProperty() { final NodeBuilder builder = EmptyNodeState.EMPTY_NODE.builder(); final String name = "meaningOfLife"; builder.setProperty(name, "42"); final AssertingPeriodicReporter reporter = new AssertingPeriodicReporter(1, 1); final NodeState nodeState = ReportingNodeState.wrap(builder.getNodeState(), reporter); reporter.reset(); // 7 accesses via 7 methods nodeState.getProperty(name); nodeState.getBoolean(name); nodeState.getLong(name); nodeState.getString(name); nodeState.getStrings(name); nodeState.getName(name); nodeState.getNames(name); assertThat(reporter, not(hasReportedProperty(0, "/meaningOfLife"))); assertThat(reporter, hasReportedProperty(1, "/meaningOfLife")); assertThat(reporter, hasReportedProperty(2, "/meaningOfLife")); assertThat(reporter, hasReportedProperty(3, "/meaningOfLife")); assertThat(reporter, hasReportedProperty(4, "/meaningOfLife")); assertThat(reporter, hasReportedProperty(5, "/meaningOfLife")); assertThat(reporter, hasReportedProperty(6, "/meaningOfLife")); assertThat(reporter, hasReportedProperty(7, "/meaningOfLife")); assertThat(reporter, not(hasReportedProperty(8, "/meaningOfLife"))); }