Search in sources :

Example 41 with PropertyIndexEditorProvider

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

the class AsyncIndexUpdateTest method failOnConflict.

// OAK-1784
@Test
public void failOnConflict() throws Exception {
    final Map<Thread, Semaphore> locks = Maps.newIdentityHashMap();
    NodeStore store = new MemoryNodeStore() {

        @Nonnull
        @Override
        public NodeState merge(@Nonnull NodeBuilder builder, @Nonnull CommitHook commitHook, @Nonnull CommitInfo info) throws CommitFailedException {
            Semaphore s = locks.get(Thread.currentThread());
            if (s != null) {
                s.acquireUninterruptibly();
            }
            return super.merge(builder, commitHook, info);
        }
    };
    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");
    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");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    Thread t = new Thread(new Runnable() {

        @Override
        public void run() {
            async.run();
        }
    });
    Semaphore s = new Semaphore(0);
    locks.put(t, s);
    t.start();
    // make some unrelated changes to trigger indexing
    builder = store.getRoot().builder();
    builder.setChildNode("dummy").setProperty("foo", "bar");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    while (!s.hasQueuedThreads()) {
        Thread.yield();
    }
    // introduce a conflict
    builder = store.getRoot().builder();
    builder.getChildNode(INDEX_DEFINITIONS_NAME).getChildNode("foo").getChildNode(":index").child("a").remove();
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    s.release(100);
    t.join();
    builder = store.getRoot().builder();
    assertNoConflictMarker(builder);
}
Also used : Nonnull(javax.annotation.Nonnull) CommitHook(org.apache.jackrabbit.oak.spi.commit.CommitHook) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) Semaphore(java.util.concurrent.Semaphore) 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) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) Test(org.junit.Test)

Example 42 with PropertyIndexEditorProvider

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

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

the class AsyncIndexUpdateTest method validatorProviderInvocation.

@Test
public void validatorProviderInvocation() 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);
    CollectingValidatorProvider v = new CollectingValidatorProvider();
    async.setValidatorProviders(ImmutableList.<ValidatorProvider>of(v));
    async.run();
    assertFalse(v.visitedPaths.isEmpty());
    assertThat(v.visitedPaths, hasItem("/:async"));
    assertThat(v.visitedPaths, hasItem("/oak:index/rootIndex"));
}
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 44 with PropertyIndexEditorProvider

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

the class AsyncIndexerServiceTest method changeCollectionEnabled.

@Test
public void changeCollectionEnabled() throws Exception {
    injectDefaultServices();
    Map<String, Object> config = ImmutableMap.<String, Object>of("asyncConfigs", new String[] { "async:5" });
    context.registerService(IndexEditorProvider.class, new PropertyIndexEditorProvider());
    MockOsgi.activate(service, context.bundleContext(), config);
    NodeBuilder builder = nodeStore.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
    nodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    CommitInfoCollector infoCollector = new CommitInfoCollector();
    nodeStore.addObserver(infoCollector);
    AsyncIndexUpdate indexUpdate = getIndexUpdate("async");
    indexUpdate.run();
    CommitContext commitContext = (CommitContext) infoCollector.infos.get(0).getInfo().get(CommitContext.NAME);
    assertNotNull(commitContext);
    ChangeSet changeSet = (ChangeSet) commitContext.get(ChangeCollectorProvider.COMMIT_CONTEXT_OBSERVATION_CHANGESET);
    assertNotNull(changeSet);
}
Also used : CommitContext(org.apache.jackrabbit.oak.spi.commit.CommitContext) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) CommitInfoCollector(org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdateTest.CommitInfoCollector) ChangeSet(org.apache.jackrabbit.oak.plugins.observation.ChangeSet) Test(org.junit.Test)

Example 45 with PropertyIndexEditorProvider

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

the class NodeTypeIndexTest method nodeType.

@Test
public void nodeType() throws Exception {
    NodeBuilder root = store.getRoot().builder();
    // remove "rep:security" as it interferes with tests
    root.getChildNode("rep:security").remove();
    // set "entryCount", so the node type index counts the nodes
    // and the approximation is not used
    root.getChildNode("oak:index").getChildNode("nodetype").setProperty("entryCount", -1);
    addFolder(root, "folder-1");
    addFolder(root, "folder-2");
    addFile(root, "file-1");
    store.merge(root, new EditorHook(new IndexUpdateProvider(new PropertyIndexEditorProvider())), CommitInfo.EMPTY);
    NodeState rootState = store.getRoot();
    NodeTypeIndex index = new NodeTypeIndex(Mounts.defaultMountInfoProvider());
    FilterImpl filter;
    filter = createFilter(rootState, JcrConstants.NT_FOLDER);
    assertEquals(6.0, index.getCost(filter, rootState), 0.0);
    checkCursor(index.query(filter, rootState), "/folder-1", "/folder-2");
    filter = createFilter(rootState, JcrConstants.NT_FILE);
    assertEquals(5.0, index.getCost(filter, rootState), 0.0);
    checkCursor(index.query(filter, rootState), "/file-1");
    filter = createFilter(rootState, JcrConstants.NT_HIERARCHYNODE);
    assertEquals(7.0, index.getCost(filter, rootState), 0.0);
    checkCursor(index.query(filter, rootState), "/folder-1", "/folder-2", "/file-1");
}
Also used : IndexUpdateProvider(org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Aggregations

PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)48 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)35 Test (org.junit.Test)34 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)29 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)17 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)14 ProxyNodeStore (org.apache.jackrabbit.oak.spi.state.ProxyNodeStore)14 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)11 InitialContent (org.apache.jackrabbit.oak.InitialContent)9 Oak (org.apache.jackrabbit.oak.Oak)9 OpenSecurityProvider (org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 AsyncIndexStats (org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate.AsyncIndexStats)6 PropertyIndexLookup (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexLookup)6 Semaphore (java.util.concurrent.Semaphore)5 ReferenceEditorProvider (org.apache.jackrabbit.oak.plugins.index.reference.ReferenceEditorProvider)5 Before (org.junit.Before)5 LogCustomizer (org.apache.jackrabbit.oak.commons.junit.LogCustomizer)4 PropertyIndexProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexProvider)4 TypeEditorProvider (org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider)4