Search in sources :

Example 11 with MemoryNodeStore

use of org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore in project jackrabbit-oak by apache.

the class AsyncIndexUpdateTest method commitContext.

@Test
public void commitContext() 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");
    // merge it back in
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider);
    CommitInfoCollector infoCollector = new CommitInfoCollector();
    store.addObserver(infoCollector);
    async.run();
    assertFalse(infoCollector.infos.isEmpty());
    assertNotNull(infoCollector.infos.get(0).getInfo().get(CommitContext.NAME));
}
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 12 with MemoryNodeStore

use of org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore in project jackrabbit-oak by apache.

the class AsyncIndexUpdateTest method cpCleanupWChanges.

@Test
public void cpCleanupWChanges() 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);
    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);
    async.run();
    assertTrue("Expecting one checkpoint", store.listCheckpoints().size() == 1);
    String secondCp = store.listCheckpoints().iterator().next();
    assertFalse("Store should keep only second checkpoint", secondCp.equals(firstCp));
    assertEquals(secondCp, store.getRoot().getChildNode(ASYNC).getString("async"));
}
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) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 13 with MemoryNodeStore

use of org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore in project jackrabbit-oak by apache.

the class AsyncIndexUpdateTest method branchBaseOnCheckpoint.

// OAK-1749
@Test
public void branchBaseOnCheckpoint() throws Exception {
    final Semaphore retrieve = new Semaphore(1);
    final Semaphore checkpoint = new Semaphore(0);
    NodeStore store = new MemoryNodeStore() {

        @CheckForNull
        @Override
        public NodeState retrieve(@Nonnull String checkpoint) {
            retrieve.acquireUninterruptibly();
            try {
                return super.retrieve(checkpoint);
            } finally {
                retrieve.release();
            }
        }

        @Nonnull
        @Override
        public String checkpoint(long lifetime, @Nonnull Map<String, String> properties) {
            try {
                return super.checkpoint(lifetime, properties);
            } finally {
                checkpoint.release();
            }
        }
    };
    IndexEditorProvider provider = new PropertyIndexEditorProvider();
    NodeBuilder builder = store.getRoot().builder();
    createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "foo", false, ImmutableSet.of("foo"), null, TYPE, Collections.singletonMap(ASYNC_PROPERTY_NAME, "async"));
    builder.child("test").setProperty("foo", "a");
    builder.child("child");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    final AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider);
    async.run();
    builder = store.getRoot().builder();
    builder.child("test").setProperty("foo", "b");
    builder.child("child").setProperty("prop", "value");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    Thread t = new Thread(new Runnable() {

        @Override
        public void run() {
            async.run();
        }
    });
    // drain checkpoint permits
    checkpoint.acquireUninterruptibly(checkpoint.availablePermits());
    // block NodeStore.retrieve()
    retrieve.acquireUninterruptibly();
    t.start();
    // wait until async update called checkpoint
    retrieve.release();
    checkpoint.acquireUninterruptibly();
    builder = store.getRoot().builder();
    builder.child("child").remove();
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    // allow async update to proceed with NodeStore.retrieve()
    retrieve.release();
    t.join();
    assertFalse(store.getRoot().hasChildNode("child"));
}
Also used : Nonnull(javax.annotation.Nonnull) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) Semaphore(java.util.concurrent.Semaphore) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) 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) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) Map(java.util.Map) Test(org.junit.Test)

Example 14 with MemoryNodeStore

use of org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore 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 15 with MemoryNodeStore

use of org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore 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)

Aggregations

MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)121 Test (org.junit.Test)83 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)73 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)46 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)39 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)36 MountInfoProvider (org.apache.jackrabbit.oak.spi.mount.MountInfoProvider)21 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)20 Oak (org.apache.jackrabbit.oak.Oak)14 ProxyNodeStore (org.apache.jackrabbit.oak.spi.state.ProxyNodeStore)14 InitialContent (org.apache.jackrabbit.oak.InitialContent)11 OpenSecurityProvider (org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider)11 Before (org.junit.Before)10 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 MountedNodeStore (org.apache.jackrabbit.oak.composite.MountedNodeStore)7 AsyncIndexStats (org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate.AsyncIndexStats)7 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)7 Nonnull (javax.annotation.Nonnull)6 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)6 PropertyIndexLookup (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexLookup)6