Search in sources :

Example 36 with PropertyIndexEditorProvider

use of org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider in project jackrabbit-oak by apache.

the class AsyncIndexUpdateTest method taskSplitNoMatch.

@Test
public void taskSplitNoMatch() 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");
    createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "ignored", true, false, ImmutableSet.of("baz"), null).setProperty(ASYNC_PROPERTY_NAME, "async-ignored");
    builder.child("testRoot").setProperty("foo", "abc");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    assertTrue("Expecting no checkpoints", store.listCheckpoints().size() == 0);
    AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider);
    async.run();
    assertTrue("Expecting one checkpoint", store.listCheckpoints().size() == 1);
    String firstCp = store.listCheckpoints().iterator().next();
    builder = store.getRoot().builder();
    builder.child("testRoot").setProperty("foo", "def");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    IndexTaskSpliter splitter = async.getTaskSplitter();
    // no match on the provided path
    splitter.registerSplit(newHashSet("/oak:index/ignored"), "async-slow");
    async.run();
    Set<String> checkpoints = newHashSet(store.listCheckpoints());
    assertTrue("Expecting a single checkpoint", checkpoints.size() == 1);
    String secondCp = checkpoints.iterator().next();
    NodeState asyncNode = store.getRoot().getChildNode(ASYNC);
    assertEquals(secondCp, asyncNode.getString("async"));
    assertNull(firstCp, asyncNode.getString("async-slow"));
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) 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) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) IndexTaskSpliter(org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate.IndexTaskSpliter) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 37 with PropertyIndexEditorProvider

use of org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider 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 38 with PropertyIndexEditorProvider

use of org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider 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 39 with PropertyIndexEditorProvider

use of org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider 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 40 with PropertyIndexEditorProvider

use of org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider 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

PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)48 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)35 Test (org.junit.Test)34 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)29 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)17 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)14 ProxyNodeStore (org.apache.jackrabbit.oak.spi.state.ProxyNodeStore)14 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)11 InitialContent (org.apache.jackrabbit.oak.InitialContent)9 Oak (org.apache.jackrabbit.oak.Oak)9 OpenSecurityProvider (org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 AsyncIndexStats (org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate.AsyncIndexStats)6 PropertyIndexLookup (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexLookup)6 Semaphore (java.util.concurrent.Semaphore)5 ReferenceEditorProvider (org.apache.jackrabbit.oak.plugins.index.reference.ReferenceEditorProvider)5 Before (org.junit.Before)5 LogCustomizer (org.apache.jackrabbit.oak.commons.junit.LogCustomizer)4 PropertyIndexProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexProvider)4 TypeEditorProvider (org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider)4