Search in sources :

Example 16 with IndexUpdateProvider

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

the class ReferenceIndexTest method removeWeaklyReferencedNode.

@Test
public void removeWeaklyReferencedNode() throws Exception {
    NodeState root = INITIAL_CONTENT;
    NodeBuilder builder = root.builder();
    NodeState before = builder.getNodeState();
    builder.child("a").setProperty(createProperty(JCR_UUID, "u1", Type.STRING));
    builder.child("b").setProperty(createProperty("foo", "u1", Type.WEAKREFERENCE));
    NodeState after = builder.getNodeState();
    EditorHook hook = new EditorHook(new IndexUpdateProvider(new ReferenceEditorProvider()));
    NodeState indexed = hook.processCommit(before, after, CommitInfo.EMPTY);
    builder = indexed.builder();
    builder.getChildNode("a").remove();
    hook.processCommit(indexed, builder.getNodeState(), CommitInfo.EMPTY);
}
Also used : IndexUpdateProvider(org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 17 with IndexUpdateProvider

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

the class ReferenceIndexTest method basicReferenceHandling.

@Test
public void basicReferenceHandling() throws Exception {
    NodeState root = INITIAL_CONTENT;
    NodeBuilder builder = root.builder();
    NodeState before = builder.getNodeState();
    builder.child("a").setProperty(createProperty("foo", "u1", Type.REFERENCE));
    builder.child("b").setProperty(createProperty("foo", "u1", Type.REFERENCE));
    builder.child("c").setProperty(createProperty("foo", "u2", Type.WEAKREFERENCE));
    NodeState after = builder.getNodeState();
    EditorHook hook = new EditorHook(new IndexUpdateProvider(new ReferenceEditorProvider()));
    NodeState indexed = hook.processCommit(before, after, CommitInfo.EMPTY);
    FilterImpl f = createFilter(indexed, NT_BASE);
    f.restrictProperty("*", Operator.EQUAL, newReference("u1"), PropertyType.REFERENCE);
    assertFilter(f, new ReferenceIndex(), indexed, of("/a", "/b"));
    FilterImpl f2 = createFilter(indexed, NT_BASE);
    f2.restrictProperty("*", Operator.EQUAL, newReference("u2"), PropertyType.WEAKREFERENCE);
    assertFilter(f2, new ReferenceIndex(), indexed, of("/c"));
}
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) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 18 with IndexUpdateProvider

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

the class NodeStoreUtils method mergeWithConcurrentCheck.

static void mergeWithConcurrentCheck(NodeStore nodeStore, NodeBuilder builder, IndexEditorProvider indexEditorProvider) throws CommitFailedException {
    CompositeHook hooks = new CompositeHook(ResetCommitAttributeHook.INSTANCE, new EditorHook(new IndexUpdateProvider(indexEditorProvider, null, true)), new ConflictHook(new AnnotatingConflictHandler()), new EditorHook(CompositeEditorProvider.compose(singletonList(new ConflictValidatorProvider()))));
    nodeStore.merge(builder, hooks, createCommitInfo());
}
Also used : CompositeHook(org.apache.jackrabbit.oak.spi.commit.CompositeHook) IndexUpdateProvider(org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider) AnnotatingConflictHandler(org.apache.jackrabbit.oak.plugins.commit.AnnotatingConflictHandler) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) ConflictHook(org.apache.jackrabbit.oak.plugins.commit.ConflictHook) ConflictValidatorProvider(org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider)

Example 19 with IndexUpdateProvider

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

the class LuceneIndexEditorTest method copyOnWriteAndLocks.

@Test
public void copyOnWriteAndLocks() throws Exception {
    assumeFalse(CIHelper.windows());
    ExecutorService executorService = Executors.newFixedThreadPool(2);
    IndexCopier copier = new IndexCopier(executorService, temporaryFolder.getRoot());
    FailOnDemandEditorProvider failingProvider = new FailOnDemandEditorProvider();
    EditorHook hook = new EditorHook(new IndexUpdateProvider(new CompositeIndexEditorProvider(failingProvider, new LuceneIndexEditorProvider(copier))));
    NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
    NodeBuilder nb = newLuceneIndexDefinitionV2(index, "lucene", of(TYPENAME_STRING));
    IndexUtils.createIndexDefinition(index, "failingIndex", false, false, of("foo"), null);
    // 1. Get initial set indexed. So that next cycle is normal indexing
    NodeState indexed = hook.processCommit(EMPTY_NODE, builder.getNodeState(), CommitInfo.EMPTY);
    builder = indexed.builder();
    NodeState before = indexed;
    builder.child("test").setProperty("a", "fox is jumping");
    NodeState after = builder.getNodeState();
    // 2. Ensure that Lucene gets triggered but close is not called
    failingProvider.setShouldFail(true);
    try {
        hook.processCommit(before, after, CommitInfo.EMPTY);
        fail();
    } catch (CommitFailedException ignore) {
    }
    // 3. Disable the troubling editor
    failingProvider.setShouldFail(false);
    // 4. Now commit should process fine
    hook.processCommit(before, after, CommitInfo.EMPTY);
    executorService.shutdown();
}
Also used : IndexUpdateProvider(org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) ExecutorService(java.util.concurrent.ExecutorService) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) CompositeIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.CompositeIndexEditorProvider) Test(org.junit.Test)

Example 20 with IndexUpdateProvider

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

the class UniqueIndexNodeStoreCheckerTest method populateStore.

private void populateStore(NodeStore ns, Consumer<NodeBuilder> action) throws CommitFailedException {
    NodeBuilder builder = ns.getRoot().builder();
    NodeBuilder index = createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "foo", true, true, ImmutableSet.of("foo"), null);
    index.setProperty("entryCount", -1);
    action.accept(builder);
    ns.merge(builder, new EditorHook(new IndexUpdateProvider(new PropertyIndexEditorProvider().with(mip))), CommitInfo.EMPTY);
}
Also used : IndexUpdateProvider(org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider) 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)

Aggregations

IndexUpdateProvider (org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider)24 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)24 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)14 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)14 Test (org.junit.Test)13 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)6 MountInfoProvider (org.apache.jackrabbit.oak.spi.mount.MountInfoProvider)6 Before (org.junit.Before)6 FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)4 CompositeIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.CompositeIndexEditorProvider)3 IndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider)3 LuceneIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexEditorProvider)3 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)2 CommitHook (org.apache.jackrabbit.oak.spi.commit.CommitHook)2 CompositeHook (org.apache.jackrabbit.oak.spi.commit.CompositeHook)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 ArrayList (java.util.ArrayList)1 Executor (java.util.concurrent.Executor)1 ExecutorService (java.util.concurrent.ExecutorService)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1