Search in sources :

Example 1 with AsyncIndexStats

use of org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate.AsyncIndexStats in project jackrabbit-oak by apache.

the class AsyncIndexUpdateTest method cpCleanupWErrors.

@Test
public void cpCleanupWErrors() throws Exception {
    MemoryNodeStore store = new MemoryNodeStore();
    FaultyIndexEditorProvder provider = new FaultyIndexEditorProvder();
    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("Error should have been triggered by the commit", provider.isFailed());
    assertTrue("Expecting no checkpoints", store.listCheckpoints().size() == 0);
    // OAK-3054 failure reports
    AsyncIndexStats stats = async.getIndexStats();
    String since = stats.getFailingSince();
    assertTrue(stats.isFailing());
    assertEquals(1, stats.getConsecutiveFailedExecutions());
    assertEquals(since, stats.getLatestErrorTime());
    TimeUnit.MILLISECONDS.sleep(100);
    async.run();
    assertTrue(stats.isFailing());
    assertEquals(2, stats.getConsecutiveFailedExecutions());
    assertEquals(since, stats.getFailingSince());
    assertNotEquals(since, stats.getLatestErrorTime());
    stats.fixed();
    assertFalse(stats.isFailing());
    assertEquals(0, stats.getConsecutiveFailedExecutions());
    assertEquals("", stats.getFailingSince());
}
Also used : MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) AsyncIndexStats(org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate.AsyncIndexStats) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 2 with AsyncIndexStats

use of org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate.AsyncIndexStats in project jackrabbit-oak by apache.

the class AsyncIndexUpdateTest method traversalCount.

@Test
public void traversalCount() throws Exception {
    MemoryNodeStore store = new MemoryNodeStore();
    PropertyIndexEditorProvider 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 async = new AsyncIndexUpdate("async", store, provider);
    async.run();
    // Get rid of changes in index nodes i.e. /oak:index/rootIndex
    async.run();
    // Do a run without any index property change
    builder = store.getRoot().builder();
    builder.child("a").child("b");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    async.run();
    AsyncIndexStats stats = async.getIndexStats();
    assertEquals(3, stats.getNodesReadCount());
    assertEquals(0, stats.getUpdates());
    // Do a run with a index property change
    builder = store.getRoot().builder();
    builder.child("a").child("b").setProperty("foo", "bar");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    async.run();
    stats = async.getIndexStats();
    assertEquals(3, stats.getNodesReadCount());
    assertEquals(1, stats.getUpdates());
}
Also used : 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) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 3 with AsyncIndexStats

use of org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate.AsyncIndexStats 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 4 with AsyncIndexStats

use of org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate.AsyncIndexStats in project jackrabbit-oak by apache.

the class AsyncIndexUpdateTest method closeWithHardLimit.

@Test
public void closeWithHardLimit() 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);
        }
    };
    // Set a 1 sec close timeout
    async.setCloseTimeOut(1);
    Thread t = new Thread(new Runnable() {

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

        @Override
        public void run() {
            async.close();
        }
    });
    // Lock to ensure that AsyncIndexUpdate waits
    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 stopFlag is set
    while (!async.isClosed()) ;
    assertLogPhrase(lc.getLogs(), "[SOFT LIMIT HIT]");
    // Let indexing run complete now
    asyncLock.release();
    // Wait for both threads
    t.join();
    // Async run would have exited with log message logged
    assertLogPhrase(lc.getLogs(), "The index update interrupted");
    // Wait for close call to complete
    closer.join();
    lc.finished();
}
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 5 with AsyncIndexStats

use of org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate.AsyncIndexStats 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)

Aggregations

AsyncIndexStats (org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate.AsyncIndexStats)7 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)7 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)7 Test (org.junit.Test)7 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)6 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)5 ProxyNodeStore (org.apache.jackrabbit.oak.spi.state.ProxyNodeStore)5 Semaphore (java.util.concurrent.Semaphore)3 LogCustomizer (org.apache.jackrabbit.oak.commons.junit.LogCustomizer)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)1 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)1 Observer (org.apache.jackrabbit.oak.spi.commit.Observer)1 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)1