Search in sources :

Example 1 with EditorProvider

use of org.apache.jackrabbit.oak.spi.commit.EditorProvider in project jackrabbit-oak by apache.

the class NodeStoreUtils method mergeWithConcurrentCheck.

public static void mergeWithConcurrentCheck(NodeStore nodeStore, NodeBuilder builder) throws CommitFailedException {
    List<EditorProvider> editorProviders = Lists.newArrayList();
    editorProviders.add(new ConflictValidatorProvider());
    CompositeHook hooks = new CompositeHook(new ConflictHook(new AnnotatingConflictHandler()), new EditorHook(CompositeEditorProvider.compose(editorProviders)));
    nodeStore.merge(builder, hooks, CommitInfo.EMPTY);
}
Also used : CompositeHook(org.apache.jackrabbit.oak.spi.commit.CompositeHook) 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) CompositeEditorProvider(org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider) EditorProvider(org.apache.jackrabbit.oak.spi.commit.EditorProvider)

Example 2 with EditorProvider

use of org.apache.jackrabbit.oak.spi.commit.EditorProvider in project jackrabbit-oak by apache.

the class PrivateStoreValidatorProviderTest method testValidatorServiceRegistered.

@Test
public void testValidatorServiceRegistered() {
    // test service registration, there should be a service for the PrivateStoreValidatorProvider
    MountInfoProvider mountInfoProvider = createMountInfoProvider("/content/readonly");
    context.registerService(MountInfoProvider.class, mountInfoProvider);
    registerValidatorProvider(privateStoreValidatorProvider, true);
    EditorProvider validator = context.getService(EditorProvider.class);
    assertNotNull("No PrivateStoreValidatorProvider available!", validator);
    assertTrue(validator instanceof PrivateStoreValidatorProvider);
    assertTrue(((PrivateStoreValidatorProvider) validator).isFailOnDetection());
    MockOsgi.deactivate(privateStoreValidatorProvider, context.bundleContext());
    assertNull(context.getService(EditorProvider.class));
}
Also used : MountInfoProvider(org.apache.jackrabbit.oak.spi.mount.MountInfoProvider) EditorProvider(org.apache.jackrabbit.oak.spi.commit.EditorProvider) Test(org.junit.Test)

Example 3 with EditorProvider

use of org.apache.jackrabbit.oak.spi.commit.EditorProvider in project jackrabbit-oak by apache.

the class AsyncIndexUpdate method mergeWithConcurrencyCheck.

private static void mergeWithConcurrencyCheck(final NodeStore store, List<ValidatorProvider> validatorProviders, NodeBuilder builder, final String checkpoint, final Long lease, final String name) throws CommitFailedException {
    CommitHook concurrentUpdateCheck = new CommitHook() {

        @Override
        @Nonnull
        public NodeState processCommit(NodeState before, NodeState after, CommitInfo info) throws CommitFailedException {
            // check for concurrent updates by this async task
            NodeState async = before.getChildNode(ASYNC);
            if ((checkpoint == null || Objects.equal(checkpoint, async.getString(name))) && (lease == null || lease == async.getLong(leasify(name)))) {
                return after;
            } else {
                throw newConcurrentUpdateException();
            }
        }
    };
    List<EditorProvider> editorProviders = Lists.newArrayList();
    editorProviders.add(new ConflictValidatorProvider());
    editorProviders.addAll(validatorProviders);
    CompositeHook hooks = new CompositeHook(ResetCommitAttributeHook.INSTANCE, ConflictHook.of(new AnnotatingConflictHandler()), new EditorHook(CompositeEditorProvider.compose(editorProviders)), concurrentUpdateCheck);
    try {
        store.merge(builder, hooks, createCommitInfo());
    } catch (CommitFailedException ex) {
        // OAK-2961
        if (ex.isOfType(CommitFailedException.STATE) && ex.getCode() == 1) {
            throw newConcurrentUpdateException();
        } else {
            throw ex;
        }
    }
}
Also used : CompositeHook(org.apache.jackrabbit.oak.spi.commit.CompositeHook) AnnotatingConflictHandler(org.apache.jackrabbit.oak.plugins.commit.AnnotatingConflictHandler) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) CommitHook(org.apache.jackrabbit.oak.spi.commit.CommitHook) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) ConflictValidatorProvider(org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider) EditorProvider(org.apache.jackrabbit.oak.spi.commit.EditorProvider) CompositeEditorProvider(org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException)

Example 4 with EditorProvider

use of org.apache.jackrabbit.oak.spi.commit.EditorProvider in project jackrabbit-oak by apache.

the class IndexUpdateTest method testMissingProviderFailsCommit.

/**
 * OAK-3505 Provide an optionally stricter policy for missing synchronous
 * index editor providers
 */
@Test
public void testMissingProviderFailsCommit() throws Exception {
    final IndexUpdateCallback noop = new IndexUpdateCallback() {

        @Override
        public void indexUpdate() {
        }
    };
    final MissingIndexProviderStrategy mips = new MissingIndexProviderStrategy();
    mips.setFailOnMissingIndexProvider(true);
    EditorHook hook = new EditorHook(new EditorProvider() {

        @Override
        public Editor getRootEditor(NodeState before, NodeState after, NodeBuilder builder, CommitInfo info) throws CommitFailedException {
            return new IndexUpdate(emptyProvider(), null, after, builder, noop).withMissingProviderStrategy(mips);
        }
    });
    NodeState before = builder.getNodeState();
    createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null);
    builder.child(INDEX_DEFINITIONS_NAME).child("azerty");
    builder.child("testRoot").setProperty("foo", "abc");
    NodeState after = builder.getNodeState();
    try {
        hook.processCommit(before, after, CommitInfo.EMPTY);
        fail("commit should fail on missing index provider");
    } catch (CommitFailedException ex) {
    // expected
    }
}
Also used : MissingIndexProviderStrategy(org.apache.jackrabbit.oak.plugins.index.IndexUpdate.MissingIndexProviderStrategy) EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Editor(org.apache.jackrabbit.oak.spi.commit.Editor) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) ReferenceEditorProvider(org.apache.jackrabbit.oak.plugins.index.reference.ReferenceEditorProvider) EditorProvider(org.apache.jackrabbit.oak.spi.commit.EditorProvider) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Test(org.junit.Test)

Example 5 with EditorProvider

use of org.apache.jackrabbit.oak.spi.commit.EditorProvider in project jackrabbit-oak by apache.

the class HierarchyConflictTest method merge.

private static void merge(NodeStore store, NodeBuilder root, final EditorCallback callback) throws CommitFailedException {
    CompositeHook hooks = new CompositeHook(new EditorHook(new EditorProvider() {

        private int numEdits = 0;

        @Override
        public Editor getRootEditor(NodeState before, NodeState after, NodeBuilder builder, CommitInfo info) throws CommitFailedException {
            if (callback != null) {
                if (++numEdits > 1) {
                    // this is a retry, fail the commit
                    throw new CommitFailedException(OAK, 0, "do not retry merge in this test");
                }
                callback.edit(builder);
            }
            return null;
        }
    }), ConflictHook.of(new AnnotatingConflictHandler()), new EditorHook(new ConflictValidatorProvider()));
    store.merge(root, hooks, CommitInfo.EMPTY);
}
Also used : CompositeHook(org.apache.jackrabbit.oak.spi.commit.CompositeHook) AnnotatingConflictHandler(org.apache.jackrabbit.oak.plugins.commit.AnnotatingConflictHandler) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) ConflictValidatorProvider(org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider) EditorProvider(org.apache.jackrabbit.oak.spi.commit.EditorProvider) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException)

Aggregations

EditorProvider (org.apache.jackrabbit.oak.spi.commit.EditorProvider)9 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)6 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)4 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)4 Test (org.junit.Test)4 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)3 AnnotatingConflictHandler (org.apache.jackrabbit.oak.plugins.commit.AnnotatingConflictHandler)3 ConflictValidatorProvider (org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider)3 CommitHook (org.apache.jackrabbit.oak.spi.commit.CommitHook)3 CompositeHook (org.apache.jackrabbit.oak.spi.commit.CompositeHook)3 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)3 CompositeEditorProvider (org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider)2 Editor (org.apache.jackrabbit.oak.spi.commit.Editor)2 MountInfoProvider (org.apache.jackrabbit.oak.spi.mount.MountInfoProvider)2 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 ConflictHook (org.apache.jackrabbit.oak.plugins.commit.ConflictHook)1 DocumentNodeState (org.apache.jackrabbit.oak.plugins.document.DocumentNodeState)1 IndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider)1 MissingIndexProviderStrategy (org.apache.jackrabbit.oak.plugins.index.IndexUpdate.MissingIndexProviderStrategy)1