use of org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore in project jackrabbit-oak by apache.
the class AsyncIndexUpdateTest method recoverFromMissingCpRef.
/**
* OAK-1959, stale ref to checkpoint thorws the indexer into a reindexing
* loop
*/
@Test
public void recoverFromMissingCpRef() throws Exception {
MemoryNodeStore store = new MemoryNodeStore();
IndexEditorProvider provider = new PropertyIndexEditorProvider();
NodeBuilder builder = store.getRoot().builder();
createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null).setProperty(ASYNC_PROPERTY_NAME, "async");
builder.child("testRoot").setProperty("foo", "abc");
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
new AsyncIndexUpdate("async", store, provider).run();
checkPathExists(store.getRoot(), INDEX_DEFINITIONS_NAME, "rootIndex", INDEX_CONTENT_NODE_NAME, "abc", "testRoot");
builder = store.getRoot().builder();
// change cp ref to point to a non-existing one
builder.child(ASYNC).setProperty("async", "faulty");
builder.child("testAnother").setProperty("foo", "def");
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
new AsyncIndexUpdate("async", store, provider).run();
checkPathExists(store.getRoot(), INDEX_DEFINITIONS_NAME, "rootIndex", INDEX_CONTENT_NODE_NAME, "def", "testAnother");
}
use of org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore in project jackrabbit-oak by apache.
the class AsyncIndexUpdateTest method greedyLeaseReindex.
@Test
public void greedyLeaseReindex() throws Exception {
MemoryNodeStore store = new MemoryNodeStore();
IndexEditorProvider provider = new PropertyIndexEditorProvider();
NodeBuilder builder = store.getRoot().builder();
createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null).setProperty(ASYNC_PROPERTY_NAME, "async");
builder.child("testRoot").setProperty("foo", "abc");
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
AsyncIndexUpdate pre = new AsyncIndexUpdate("async", store, provider);
pre.run();
pre.close();
// rm all cps to simulate 'missing cp scenario'
for (String cp : store.listCheckpoints()) {
store.release(cp);
}
final AtomicBoolean greedyLease = new AtomicBoolean(false);
final AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider) {
@Override
protected AsyncUpdateCallback newAsyncUpdateCallback(NodeStore store, String name, long leaseTimeOut, String beforeCheckpoint, AsyncIndexStats indexStats, AtomicBoolean stopFlag) {
return new AsyncUpdateCallback(store, name, leaseTimeOut, beforeCheckpoint, indexStats, stopFlag) {
@Override
protected void initLease() throws CommitFailedException {
greedyLease.set(true);
super.initLease();
}
@Override
protected void prepare(String afterCheckpoint) throws CommitFailedException {
assertTrue(greedyLease.get());
super.prepare(afterCheckpoint);
}
};
}
};
async.run();
async.close();
assertTrue(greedyLease.get());
}
use of org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore in project jackrabbit-oak by apache.
the class AsyncIndexUpdateTest method longTimeFailingIndexMarkedAsCorrupt.
@Test
public void longTimeFailingIndexMarkedAsCorrupt() throws Exception {
MemoryNodeStore store = new MemoryNodeStore();
NodeBuilder builder = store.getRoot().builder();
createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "fooIndex", true, false, ImmutableSet.of("foo"), null).setProperty(ASYNC_PROPERTY_NAME, "async");
createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "barIndex", true, false, ImmutableSet.of("bar"), null).setProperty(ASYNC_PROPERTY_NAME, "async");
builder.child("testRoot1").setProperty("foo", "abc");
builder.child("testRoot2").setProperty("bar", "abc");
// merge it back in
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
TestIndexEditorProvider provider = new TestIndexEditorProvider();
Clock clock = new Clock.Virtual();
AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider);
async.getCorruptIndexHandler().setClock(clock);
async.run();
//1. Basic sanity check. Indexing works
PropertyIndexLookup lookup = new PropertyIndexLookup(store.getRoot());
assertEquals(ImmutableSet.of("testRoot1"), find(lookup, "foo", "abc"));
assertEquals(ImmutableSet.of("testRoot2"), find(lookup, "bar", "abc"));
//2. Add some new content
builder = store.getRoot().builder();
builder.child("testRoot3").setProperty("foo", "xyz");
builder.child("testRoot4").setProperty("bar", "xyz");
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
//3. Now fail the indexing for 'bar'
provider.enableFailureMode("/oak:index/barIndex");
async.run();
assertTrue(async.getIndexStats().isFailing());
//barIndex is failing but not yet considered corrupted
assertTrue(async.getCorruptIndexHandler().getFailingIndexData("async").containsKey("/oak:index/barIndex"));
assertFalse(async.getCorruptIndexHandler().getCorruptIndexData("async").containsKey("/oak:index/barIndex"));
CorruptIndexInfo barIndexInfo = async.getCorruptIndexHandler().getFailingIndexData("async").get("/oak:index/barIndex");
//fooIndex is fine
assertFalse(async.getCorruptIndexHandler().getFailingIndexData("async").containsKey("/oak:index/fooIndex"));
//lookup should also fail as indexing failed
lookup = new PropertyIndexLookup(store.getRoot());
assertTrue(find(lookup, "foo", "xyz").isEmpty());
assertTrue(find(lookup, "bar", "xyz").isEmpty());
//4.Now move the clock forward and let the failing index marked as corrupt
clock.waitUntil(clock.getTime() + async.getCorruptIndexHandler().getCorruptIntervalMillis() + 1);
//5. Let async run again
async.run();
//Indexing would be considered as failing
assertTrue(async.getIndexStats().isFailing());
assertEquals(IndexStatsMBean.STATUS_FAILING, async.getIndexStats().getStatus());
//barIndex should be considered corrupt now
assertTrue(async.getCorruptIndexHandler().getCorruptIndexData("async").containsKey("/oak:index/barIndex"));
lookup = new PropertyIndexLookup(store.getRoot());
//fooIndex should now report updated result. barIndex would fail
assertEquals(ImmutableSet.of("testRoot3"), find(lookup, "foo", "xyz"));
assertTrue(find(lookup, "bar", "xyz").isEmpty());
assertEquals(1, barIndexInfo.getSkippedCount());
//6. Index some stuff
builder = store.getRoot().builder();
builder.child("testRoot5").setProperty("foo", "pqr");
builder.child("testRoot6").setProperty("bar", "pqr");
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
async.run();
assertTrue(async.getIndexStats().isFailing());
//barIndex should be skipped
assertEquals(2, barIndexInfo.getSkippedCount());
//7. Lets reindex barIndex and ensure index is not misbehaving
provider.disableFailureMode();
builder = store.getRoot().builder();
builder.child("oak:index").child("barIndex").setProperty("reindex", true);
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
async.run();
//now barIndex should not be part of failing index
assertFalse(async.getCorruptIndexHandler().getFailingIndexData("async").containsKey("/oak:index/barIndex"));
}
use of org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore in project jackrabbit-oak by apache.
the class AsyncIndexUpdateTest method noRunWhenClosed.
@Test
public void noRunWhenClosed() throws Exception {
NodeStore store = new MemoryNodeStore();
IndexEditorProvider provider = new PropertyIndexEditorProvider();
AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider);
async.run();
async.close();
LogCustomizer lc = createLogCustomizer(Level.WARN);
async.run();
assertEquals(1, lc.getLogs().size());
assertThat(lc.getLogs().get(0), containsString("Could not acquire run permit"));
lc.finished();
async.close();
}
use of org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore in project jackrabbit-oak by apache.
the class AsyncIndexUpdateTest method testReindexMissingProvider.
/**
* OAK-2203 Test reindex behavior on an async index when the index provider is missing
* for a given type
*/
@Test
public void testReindexMissingProvider() throws Exception {
MemoryNodeStore store = new MemoryNodeStore();
IndexEditorProvider provider = new PropertyIndexEditorProvider();
NodeBuilder builder = store.getRoot().builder();
String missingAsync = "missing-async";
createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null).setProperty(ASYNC_PROPERTY_NAME, missingAsync);
builder.child("testRoot").setProperty("foo", "abc");
// merge it back in
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
AsyncIndexUpdate async = new AsyncIndexUpdate(missingAsync, store, provider);
//first run, creates a checkpoint and a ref to it as the last indexed state
async.run();
assertFalse(async.isFailing());
assertTrue("Expecting one checkpoint", store.listCheckpoints().size() == 1);
String firstCp = store.listCheckpoints().iterator().next();
assertEquals(firstCp, store.getRoot().getChildNode(ASYNC).getString(missingAsync));
// second run, simulate an index going away
provider = CompositeIndexEditorProvider.compose(new ArrayList<IndexEditorProvider>());
async = new AsyncIndexUpdate(missingAsync, store, provider);
async.run();
assertTrue(async.isFailing());
// don't set reindex=true but skip the update
PropertyState reindex = store.getRoot().getChildNode(INDEX_DEFINITIONS_NAME).getChildNode("rootIndex").getProperty(REINDEX_PROPERTY_NAME);
assertTrue(reindex == null || !reindex.getValue(Type.BOOLEAN));
assertTrue("Expecting one checkpoint", store.listCheckpoints().size() == 1);
String secondCp = store.listCheckpoints().iterator().next();
assertTrue("Store should not create a new checkpoint", secondCp.equals(firstCp));
assertEquals(firstCp, store.getRoot().getChildNode(ASYNC).getString(missingAsync));
}
Aggregations