use of org.apache.jackrabbit.oak.plugins.index.TrackingCorruptIndexHandler.CorruptIndexInfo in project jackrabbit-oak by apache.
the class AsyncIndexUpdate method markFailingIndexesAsCorrupt.
private void markFailingIndexesAsCorrupt(NodeBuilder builder) {
for (Map.Entry<String, CorruptIndexInfo> index : corruptIndexHandler.getCorruptIndexData(name).entrySet()) {
NodeBuilder indexBuilder = childBuilder(builder, index.getKey());
CorruptIndexInfo info = index.getValue();
if (!indexBuilder.hasProperty(IndexConstants.CORRUPT_PROPERTY_NAME)) {
String corruptSince = ISO8601.format(info.getCorruptSinceAsCal());
indexBuilder.setProperty(PropertyStates.createProperty(IndexConstants.CORRUPT_PROPERTY_NAME, corruptSince, Type.DATE));
log.info("Marking [{}] as corrupt. The index is failing {}", info.getPath(), info.getStats());
} else {
log.debug("Failing index at [{}] is already marked as corrupt. The index is failing {}", info.getPath(), info.getStats());
}
}
}
use of org.apache.jackrabbit.oak.plugins.index.TrackingCorruptIndexHandler.CorruptIndexInfo 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"));
}
Aggregations