Search in sources :

Example 11 with PropertyIndexLookup

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

the class IndexUpdateTest method reindexAndIndexDefnChildRemoval_OAK_2117.

@Test
public void reindexAndIndexDefnChildRemoval_OAK_2117() throws Exception {
    builder.child("testRoot").setProperty("foo", "abc");
    NodeState before = builder.getNodeState();
    NodeBuilder nb = createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", false, false, ImmutableSet.of("foo"), null);
    nb.child("prop1").setProperty("foo", "bar");
    NodeState after = builder.getNodeState();
    NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
    // first check that the index content nodes exist
    NodeState ns = checkPathExists(indexed, INDEX_DEFINITIONS_NAME, "rootIndex");
    //Check index defn child node exist
    checkPathExists(ns, "prop1");
    checkPathExists(ns, INDEX_CONTENT_NODE_NAME);
    // next, lookup
    PropertyIndexLookup lookup = new PropertyIndexLookup(indexed);
    assertEquals(ImmutableSet.of("testRoot"), find(lookup, "foo", "abc"));
}
Also used : EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) PropertyIndexLookup(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexLookup) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 12 with PropertyIndexLookup

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

the class IndexUpdateTest method test.

/**
     * Simple Test
     * <ul>
     * <li>Add an index definition</li>
     * <li>Add some content</li>
     * <li>Search & verify</li>
     * </ul>
     *
     */
@Test
public void test() throws Exception {
    createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null);
    createIndexDefinition(builder.child("newchild").child("other").child(INDEX_DEFINITIONS_NAME), "subIndex", true, false, ImmutableSet.of("foo"), null);
    NodeState before = builder.getNodeState();
    // Add nodes
    builder.child("testRoot").setProperty("foo", "abc");
    builder.child("newchild").child("other").child("testChild").setProperty("foo", "xyz");
    NodeState after = builder.getNodeState();
    NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
    // first check that the index content nodes exist
    checkPathExists(indexed, INDEX_DEFINITIONS_NAME, "rootIndex", INDEX_CONTENT_NODE_NAME);
    checkPathExists(indexed, "newchild", "other", INDEX_DEFINITIONS_NAME, "subIndex", INDEX_CONTENT_NODE_NAME);
    PropertyIndexLookup lookup = new PropertyIndexLookup(indexed);
    assertEquals(ImmutableSet.of("testRoot"), find(lookup, "foo", "abc"));
    PropertyIndexLookup lookupChild = new PropertyIndexLookup(indexed.getChildNode("newchild").getChildNode("other"));
    assertEquals(ImmutableSet.of("testChild"), find(lookupChild, "foo", "xyz"));
    assertEquals(ImmutableSet.of(), find(lookupChild, "foo", "abc"));
}
Also used : EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) PropertyIndexLookup(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexLookup) Test(org.junit.Test)

Example 13 with PropertyIndexLookup

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

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

the class IndexUpdateTest method testReindex2.

/**
     * Reindex Test
     * <ul>
     * <li>Add some content & an index definition</li>
     * <li>Update the index def by setting the reindex flag to true</li>
     * <li>Search & verify</li>
     * </ul>
     */
@Test
public void testReindex2() throws Exception {
    builder.child("testRoot").setProperty("foo", "abc");
    createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null).removeProperty("reindex");
    NodeState before = builder.getNodeState();
    builder.child(INDEX_DEFINITIONS_NAME).child("rootIndex").setProperty(REINDEX_PROPERTY_NAME, true);
    NodeState after = builder.getNodeState();
    NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
    // first check that the index content nodes exist
    NodeState ns = checkPathExists(indexed, INDEX_DEFINITIONS_NAME, "rootIndex");
    checkPathExists(ns, INDEX_CONTENT_NODE_NAME);
    PropertyState ps = ns.getProperty(REINDEX_PROPERTY_NAME);
    assertNotNull(ps);
    assertFalse(ps.getValue(Type.BOOLEAN));
    // next, lookup
    PropertyIndexLookup lookup = new PropertyIndexLookup(indexed);
    assertEquals(ImmutableSet.of("testRoot"), find(lookup, "foo", "abc"));
}
Also used : EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) PropertyIndexLookup(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexLookup) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Test(org.junit.Test)

Aggregations

PropertyIndexLookup (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexLookup)14 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)13 Test (org.junit.Test)13 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)8 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)7 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)7 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)6 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)5 ProxyNodeStore (org.apache.jackrabbit.oak.spi.state.ProxyNodeStore)4 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)3 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)2 IndexTaskSpliter (org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate.IndexTaskSpliter)1 CorruptIndexInfo (org.apache.jackrabbit.oak.plugins.index.TrackingCorruptIndexHandler.CorruptIndexInfo)1 Clock (org.apache.jackrabbit.oak.stats.Clock)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1