Search in sources :

Example 1 with PropertyIndexLookup

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

the class AsyncIndexUpdateTest method taskSplit.

@Test
public void taskSplit() 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), "changedIndex", true, false, ImmutableSet.of("bar"), null).setProperty(ASYNC_PROPERTY_NAME, "async");
    createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "ignored1", true, false, ImmutableSet.of("baz"), null).setProperty(ASYNC_PROPERTY_NAME, "async-ignored");
    createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "ignored2", true, false, ImmutableSet.of("etc"), null);
    builder.child("testRoot").setProperty("foo", "abc");
    builder.child("testRoot").setProperty("bar", "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");
    builder.child("testRoot").setProperty("bar", "def");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    IndexTaskSpliter splitter = async.getTaskSplitter();
    splitter.registerSplit(newHashSet("/oak:index/changedIndex"), "async-slow");
    async.run();
    Set<String> checkpoints = newHashSet(store.listCheckpoints());
    assertTrue("Expecting two checkpoints", checkpoints.size() == 2);
    assertTrue(checkpoints.remove(firstCp));
    String secondCp = checkpoints.iterator().next();
    NodeState asyncNode = store.getRoot().getChildNode(ASYNC);
    assertEquals(firstCp, asyncNode.getString("async-slow"));
    assertEquals(secondCp, asyncNode.getString("async"));
    assertFalse(newHashSet(asyncNode.getStrings("async-temp")).contains(firstCp));
    NodeState indexNode = store.getRoot().getChildNode(INDEX_DEFINITIONS_NAME);
    assertEquals("async", indexNode.getChildNode("rootIndex").getString("async"));
    assertEquals("async-ignored", indexNode.getChildNode("ignored1").getString("async"));
    assertNull(indexNode.getChildNode("ignored2").getString("async"));
    assertEquals("async-slow", indexNode.getChildNode("changedIndex").getString("async"));
    assertEquals(false, indexNode.getChildNode("changedIndex").getBoolean("reindex"));
    // new index task is on previous checkpoint
    PropertyIndexLookup lookup = new PropertyIndexLookup(store.getRoot());
    assertEquals(ImmutableSet.of("testRoot"), find(lookup, "bar", "abc"));
    assertEquals(ImmutableSet.of(), find(lookup, "bar", "def"));
}
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) PropertyIndexLookup(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexLookup) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 2 with PropertyIndexLookup

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

the class AsyncIndexUpdateTest method testAsyncPause.

@Test
public void testAsyncPause() throws Exception {
    NodeStore 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");
    // merge it back in
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider);
    async.getIndexStats().pause();
    async.run();
    assertFalse(store.getRoot().getChildNode(INDEX_DEFINITIONS_NAME).getChildNode("rootIndex").hasChildNode(INDEX_CONTENT_NODE_NAME));
    async.getIndexStats().resume();
    async.run();
    NodeState root = store.getRoot();
    // first check that the index content nodes exist
    checkPathExists(root, INDEX_DEFINITIONS_NAME, "rootIndex", INDEX_CONTENT_NODE_NAME);
    assertFalse(root.getChildNode(INDEX_DEFINITIONS_NAME).hasChildNode(":conflict"));
    PropertyIndexLookup lookup = new PropertyIndexLookup(root);
    assertEquals(ImmutableSet.of("testRoot"), find(lookup, "foo", "abc"));
}
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) 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) PropertyIndexLookup(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexLookup) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 3 with PropertyIndexLookup

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

the class NodeTypeIndexLookup method isIndexed.

/**
 * Returns <code>true</code> if a node type index lookup exists at the given
 * <code>path</code> or further up the tree.
 *
 * @param path the path to check.
 * @return <code>true</code> if a node type index exists; <code>false</code>
 *         otherwise.
 */
public boolean isIndexed(String path, Filter f) {
    PropertyIndexLookup lookup = new PropertyIndexLookup(root, mountInfoProvider);
    if (lookup.isIndexed(JCR_PRIMARYTYPE, path, f) && lookup.isIndexed(JCR_MIXINTYPES, path, f)) {
        return true;
    }
    if (path.startsWith("/")) {
        path = path.substring(1);
    }
    int slash = path.indexOf('/');
    if (slash == -1) {
        return false;
    }
    NodeState child = root.getChildNode(path.substring(0, slash));
    return new NodeTypeIndexLookup(child, mountInfoProvider).isIndexed(path.substring(slash), f);
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) PropertyIndexLookup(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexLookup)

Example 4 with PropertyIndexLookup

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

the class IndexUpdateTest method testReindexAsync.

/**
 * Async Reindex Test (OAK-2174)
 * <ul>
 * <li>Add some content</li>
 * <li>Add an index definition with the reindex flag and the reindex-async flag set</li>
 * <li>Run the background async job manually</li>
 * <li>Search & verify</li>
 * </ul>
 */
@Test
public void testReindexAsync() throws Exception {
    IndexEditorProvider provider = new PropertyIndexEditorProvider();
    EditorHook hook = new EditorHook(new IndexUpdateProvider(provider));
    NodeStore store = new MemoryNodeStore();
    NodeBuilder builder = store.getRoot().builder();
    createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null).setProperty(REINDEX_ASYNC_PROPERTY_NAME, true);
    builder.child("testRoot").setProperty("foo", "abc");
    // merge it back in
    store.merge(builder, hook, CommitInfo.EMPTY);
    // first check that the async flag exist
    NodeState ns1 = checkPathExists(store.getRoot(), INDEX_DEFINITIONS_NAME, "rootIndex");
    assertTrue(ns1.getProperty(REINDEX_PROPERTY_NAME).getValue(Type.BOOLEAN));
    assertTrue(ns1.getProperty(REINDEX_ASYNC_PROPERTY_NAME).getValue(Type.BOOLEAN));
    assertEquals(ASYNC_REINDEX_VALUE, ns1.getString(ASYNC_PROPERTY_NAME));
    AsyncIndexUpdate async = new AsyncIndexUpdate(ASYNC_REINDEX_VALUE, store, provider, true);
    int max = 5;
    // same behaviour as PropertyIndexAsyncReindex mbean
    boolean done = false;
    int count = 0;
    while (!done || count >= max) {
        async.run();
        done = async.isFinished();
        count++;
    }
    // first check that the index content nodes exist
    NodeState ns = checkPathExists(store.getRoot(), INDEX_DEFINITIONS_NAME, "rootIndex");
    checkPathExists(ns, INDEX_CONTENT_NODE_NAME);
    assertFalse(ns.getProperty(REINDEX_PROPERTY_NAME).getValue(Type.BOOLEAN));
    assertNull(ns.getProperty(ASYNC_PROPERTY_NAME));
    // next, lookup
    PropertyIndexLookup lookup = new PropertyIndexLookup(store.getRoot());
    assertEquals(ImmutableSet.of("testRoot"), find(lookup, "foo", "abc"));
}
Also used : NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) PropertyIndexLookup(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexLookup) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 5 with PropertyIndexLookup

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

the class IndexUpdateTest method testReindexAuto.

/**
 * Auto Reindex Test
 * <ul>
 * <li>Add some content</li>
 * <li>Add an index definition without a reindex flag (see OAK-1874)</li>
 * <li>Search & verify</li>
 * </ul>
 */
@Test
public void testReindexAuto() throws Exception {
    builder.child("testRoot").setProperty("foo", "abc");
    NodeState before = builder.getNodeState();
    createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", false, false, ImmutableSet.of("foo"), null);
    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)16 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)15 Test (org.junit.Test)15 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)10 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 File (java.io.File)2 AsyncIndexUpdate (org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate)2 FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)2 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