Search in sources :

Example 66 with MemoryNodeStore

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

the class AsyncIndexUpdateTest method testReindexMissingProvider_NonRoot.

@Test
public void testReindexMissingProvider_NonRoot() throws Exception {
    MemoryNodeStore store = new MemoryNodeStore();
    IndexEditorProvider provider = new PropertyIndexEditorProvider();
    NodeBuilder builder = store.getRoot().builder();
    String missingAsyncName = "missing-async";
    createIndexDefinition(builder.child("subNodeIndex").child(INDEX_DEFINITIONS_NAME), "rootIndex2", true, false, ImmutableSet.of("foo"), null).setProperty(ASYNC_PROPERTY_NAME, missingAsyncName);
    builder.child("subNodeIndex").child("testRoot").setProperty("foo", "abc");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    AsyncIndexUpdate async = new AsyncIndexUpdate(missingAsyncName, 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(missingAsyncName));
    builder = store.getRoot().builder();
    builder.child("subNodeIndex").child("testRoot2").setProperty("foo", "abc");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    // second run, simulate an index going away
    provider = CompositeIndexEditorProvider.compose(new ArrayList<IndexEditorProvider>());
    async = new AsyncIndexUpdate(missingAsyncName, store, provider);
    async.run();
    assertTrue(async.isFailing());
    // don't set reindex=true but skip the update
    NodeState rootIndex2 = NodeStateUtils.getNode(store.getRoot(), "/subNodeIndex/oak:index/rootIndex2");
    assertTrue(rootIndex2.exists());
    PropertyState reindex2 = rootIndex2.getProperty(REINDEX_PROPERTY_NAME);
    assertTrue(reindex2 == null || !reindex2.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(missingAsyncName));
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) 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)

Example 67 with MemoryNodeStore

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

the class AsyncIndexUpdateTest method checkpointLostEventualConsistent.

@Test
public void checkpointLostEventualConsistent() throws Exception {
    MemoryNodeStore store = new MemoryNodeStore();
    final List<NodeState> rootStates = Lists.newArrayList();
    store.addObserver(new Observer() {

        @Override
        public void contentChanged(@Nonnull NodeState root, @Nullable CommitInfo info) {
            rootStates.add(root);
        }
    });
    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();
    //Create another commit so that we have two checkpoints
    builder = store.getRoot().builder();
    builder.child("testRoot2").setProperty("foo", "abc");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    pre.run();
    pre.close();
    //Look for the nodestate just before the final merge in AsyncIndexUpdate
    //i.e. where older checkpoint was still referred and which has been "released"
    //post last run
    Collections.reverse(rootStates);
    final AtomicReference<NodeState> oldRootState = new AtomicReference<NodeState>();
    for (NodeState ns : rootStates) {
        NodeState async = ns.getChildNode(ASYNC);
        String checkpointName = async.getString("async");
        if (store.retrieve(checkpointName) == null && async.getProperty(AsyncIndexUpdate.leasify("async")) == null) {
            oldRootState.set(ns);
            break;
        }
    }
    assertNotNull(oldRootState.get());
    final AtomicBoolean intiLeaseCalled = new AtomicBoolean(false);
    //Here for the call to read existing NodeState we would return the old
    //"stale" state where we have a stale checkpoint
    store = new MemoryNodeStore(store.getRoot()) {

        @Override
        public NodeState getRoot() {
            //Keep returning stale view untill initlease is not invoked
            if (!intiLeaseCalled.get()) {
                return oldRootState.get();
            }
            return super.getRoot();
        }
    };
    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 {
                    intiLeaseCalled.set(true);
                    super.initLease();
                }
            };
        }
    };
    async.run();
    //This run should fail
    assertTrue(async.getIndexStats().isFailing());
    async.close();
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) AtomicReference(java.util.concurrent.atomic.AtomicReference) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) 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) Observer(org.apache.jackrabbit.oak.spi.commit.Observer) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) Test(org.junit.Test)

Example 68 with MemoryNodeStore

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

the class AsyncIndexUpdateTest method abortedRun.

@Test
public void abortedRun() 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");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    final Semaphore asyncLock = new Semaphore(1);
    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
                public void indexUpdate() throws CommitFailedException {
                    try {
                        asyncLock.acquire();
                    } catch (InterruptedException ignore) {
                    }
                    try {
                        super.indexUpdate();
                    } finally {
                        asyncLock.release();
                    }
                }
            };
        }
    };
    runOneCycle(async);
    assertEquals(IndexStatsMBean.STATUS_DONE, async.getIndexStats().getStatus());
    //Below we ensure that we interrupt while the indexing is in progress
    //hence the use of asyncLock which ensures the abort is called at right time
    //Now make some changes to
    builder = store.getRoot().builder();
    builder.child("testRoot2").setProperty("foo", "abc");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    Thread t = new Thread(async);
    //Lock to ensure that AsyncIndexUpdate waits
    asyncLock.acquire();
    t.start();
    //Wait till async gets to wait state i.e. inside run
    while (!asyncLock.hasQueuedThreads()) ;
    assertEquals(IndexStatsMBean.STATUS_RUNNING, async.getIndexStats().getStatus());
    assertThat(async.getIndexStats().abortAndPause(), containsString("Abort request placed"));
    asyncLock.release();
    retry(5, 5, new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            return IndexStatsMBean.STATUS_INTERRUPTED.equals(async.getIndexStats().getStatus());
        }
    });
    //Post abort indexing should be fine
    runOneCycle(async);
    assertTrue(async.getIndexStats().isPaused());
    //Now resume indexing
    async.getIndexStats().resume();
    runOneCycle(async);
    assertEquals(IndexStatsMBean.STATUS_DONE, async.getIndexStats().getStatus());
    assertFalse(async.isClosed());
}
Also used : 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) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) 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) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test)

Example 69 with MemoryNodeStore

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

the class AsyncIndexUpdateTest method closeWithSoftLimit.

@Test
public void closeWithSoftLimit() 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");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    final Semaphore asyncLock = new Semaphore(1);
    final AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider) {

        @Override
        protected AsyncUpdateCallback newAsyncUpdateCallback(NodeStore store, String name, long leaseTimeOut, String beforeCheckpoint, AsyncIndexStats indexStats, AtomicBoolean stopFlag) {
            try {
                asyncLock.acquire();
            } catch (InterruptedException ignore) {
            }
            return super.newAsyncUpdateCallback(store, name, leaseTimeOut, beforeCheckpoint, indexStats, stopFlag);
        }
    };
    async.setCloseTimeOut(1000);
    Thread t = new Thread(new Runnable() {

        @Override
        public void run() {
            async.run();
        }
    });
    Thread closer = new Thread(new Runnable() {

        @Override
        public void run() {
            async.close();
        }
    });
    asyncLock.acquire();
    t.start();
    //Wait till async gets to wait state i.e. inside run
    while (!asyncLock.hasQueuedThreads()) ;
    LogCustomizer lc = createLogCustomizer(Level.DEBUG);
    closer.start();
    //Wait till closer is in waiting state
    while (!async.isClosing()) ;
    //For softLimit case the flag should not be set
    assertFalse(async.isClosed());
    assertLogPhrase(lc.getLogs(), "[WAITING]");
    //Let indexing run complete now
    asyncLock.release();
    //Wait for both threads
    t.join();
    closer.join();
    //Close call should complete
    assertLogPhrase(lc.getLogs(), "[CLOSED OK]");
}
Also used : 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) 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) LogCustomizer(org.apache.jackrabbit.oak.commons.junit.LogCustomizer) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) Test(org.junit.Test)

Example 70 with MemoryNodeStore

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

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