Search in sources :

Example 1 with CorruptIndexInfo

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());
        }
    }
}
Also used : Throwables.getStackTraceAsString(com.google.common.base.Throwables.getStackTraceAsString) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) CorruptIndexInfo(org.apache.jackrabbit.oak.plugins.index.TrackingCorruptIndexHandler.CorruptIndexInfo)

Example 2 with CorruptIndexInfo

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"));
}
Also used : MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) PropertyIndexLookup(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexLookup) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Clock(org.apache.jackrabbit.oak.stats.Clock) CorruptIndexInfo(org.apache.jackrabbit.oak.plugins.index.TrackingCorruptIndexHandler.CorruptIndexInfo) Test(org.junit.Test)

Aggregations

CorruptIndexInfo (org.apache.jackrabbit.oak.plugins.index.TrackingCorruptIndexHandler.CorruptIndexInfo)2 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)2 Throwables.getStackTraceAsString (com.google.common.base.Throwables.getStackTraceAsString)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Map (java.util.Map)1 PropertyIndexLookup (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexLookup)1 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)1 Clock (org.apache.jackrabbit.oak.stats.Clock)1 Test (org.junit.Test)1