Search in sources :

Example 71 with MemoryNodeStore

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

Example 72 with MemoryNodeStore

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());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ProxyNodeStore(org.apache.jackrabbit.oak.spi.state.ProxyNodeStore) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) AsyncIndexStats(org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate.AsyncIndexStats) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 73 with MemoryNodeStore

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"));
}
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)

Example 74 with MemoryNodeStore

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();
}
Also used : ProxyNodeStore(org.apache.jackrabbit.oak.spi.state.ProxyNodeStore) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) LogCustomizer(org.apache.jackrabbit.oak.commons.junit.LogCustomizer) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) Test(org.junit.Test)

Example 75 with MemoryNodeStore

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));
}
Also used : MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) ArrayList(java.util.ArrayList) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Test(org.junit.Test)

Aggregations

MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)92 Test (org.junit.Test)66 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)58 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)37 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)35 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)33 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)19 ProxyNodeStore (org.apache.jackrabbit.oak.spi.state.ProxyNodeStore)14 MountInfoProvider (org.apache.jackrabbit.oak.spi.mount.MountInfoProvider)13 Oak (org.apache.jackrabbit.oak.Oak)9 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 AsyncIndexStats (org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate.AsyncIndexStats)7 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)7 OpenSecurityProvider (org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider)7 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)6 InitialContent (org.apache.jackrabbit.oak.InitialContent)6 PropertyIndexLookup (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexLookup)6 Validator (org.apache.jackrabbit.oak.spi.commit.Validator)6 ApplyDiff (org.apache.jackrabbit.oak.spi.state.ApplyDiff)6 Semaphore (java.util.concurrent.Semaphore)5