Search in sources :

Example 1 with ConflictValidatorProvider

use of org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider 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, new ConflictHook(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) ConflictHook(org.apache.jackrabbit.oak.plugins.commit.ConflictHook) 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 2 with ConflictValidatorProvider

use of org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider 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;
        }
    }), new ConflictHook(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) ConflictHook(org.apache.jackrabbit.oak.plugins.commit.ConflictHook) 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)

Example 3 with ConflictValidatorProvider

use of org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider in project jackrabbit-oak by apache.

the class NodeStoreTest method addExistingNode.

@Test
public void addExistingNode() throws CommitFailedException {
    // FIXME OAK-1550 Incorrect handling of addExistingNode conflict in NodeStore
    assumeTrue(fixture != NodeStoreFixtures.DOCUMENT_MEM);
    assumeTrue(fixture != NodeStoreFixtures.DOCUMENT_NS);
    assumeTrue(fixture != NodeStoreFixtures.DOCUMENT_RDB);
    CommitHook hook = new CompositeHook(new ConflictHook(JcrConflictHandler.createJcrConflictHandler()), new EditorHook(new ConflictValidatorProvider()));
    NodeBuilder b1 = store.getRoot().builder();
    NodeBuilder b2 = store.getRoot().builder();
    // rather the in memory one from AbstractRebaseDiff
    for (int k = 0; k < 1002; k++) {
        b1.setChildNode("n" + k);
        b2.setChildNode("m" + k);
    }
    b1.setChildNode("conflict");
    b2.setChildNode("conflict");
    store.merge(b1, hook, CommitInfo.EMPTY);
    store.merge(b2, hook, CommitInfo.EMPTY);
}
Also used : CompositeHook(org.apache.jackrabbit.oak.spi.commit.CompositeHook) CommitHook(org.apache.jackrabbit.oak.spi.commit.CommitHook) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) ConflictHook(org.apache.jackrabbit.oak.plugins.commit.ConflictHook) ConflictValidatorProvider(org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider) Test(org.junit.Test) OakBaseTest(org.apache.jackrabbit.oak.OakBaseTest)

Example 4 with ConflictValidatorProvider

use of org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider in project jackrabbit-oak by apache.

the class NodeStoreTest method addChangeChangedJCRLastModified.

@Test
public void addChangeChangedJCRLastModified() throws CommitFailedException {
    CommitHook hook = new CompositeHook(new ConflictHook(JcrConflictHandler.createJcrConflictHandler()), new EditorHook(new ConflictValidatorProvider()));
    NodeBuilder b = store.getRoot().builder();
    Calendar calendar = Calendar.getInstance();
    b.setChildNode("addExistingNodeJCRLastModified").setProperty(JCR_LASTMODIFIED, calendar);
    store.merge(b, hook, CommitInfo.EMPTY);
    NodeBuilder b1 = store.getRoot().builder();
    NodeBuilder b2 = store.getRoot().builder();
    calendar.add(Calendar.MINUTE, 1);
    b1.setChildNode("addExistingNodeJCRLastModified").setProperty(JCR_LASTMODIFIED, calendar);
    calendar.add(Calendar.MINUTE, 1);
    b2.setChildNode("addExistingNodeJCRLastModified").setProperty(JCR_LASTMODIFIED, calendar);
    b1.setChildNode("conflict");
    b2.setChildNode("conflict");
    store.merge(b1, hook, CommitInfo.EMPTY);
    store.merge(b2, hook, CommitInfo.EMPTY);
}
Also used : CompositeHook(org.apache.jackrabbit.oak.spi.commit.CompositeHook) CommitHook(org.apache.jackrabbit.oak.spi.commit.CommitHook) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) Calendar(java.util.Calendar) ConflictHook(org.apache.jackrabbit.oak.plugins.commit.ConflictHook) ConflictValidatorProvider(org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider) Test(org.junit.Test) OakBaseTest(org.apache.jackrabbit.oak.OakBaseTest)

Example 5 with ConflictValidatorProvider

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

Aggregations

ConflictValidatorProvider (org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider)10 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)8 ConflictHook (org.apache.jackrabbit.oak.plugins.commit.ConflictHook)7 CompositeHook (org.apache.jackrabbit.oak.spi.commit.CompositeHook)7 AnnotatingConflictHandler (org.apache.jackrabbit.oak.plugins.commit.AnnotatingConflictHandler)4 CommitHook (org.apache.jackrabbit.oak.spi.commit.CommitHook)4 Test (org.junit.Test)4 OakBaseTest (org.apache.jackrabbit.oak.OakBaseTest)3 NamespaceEditorProvider (org.apache.jackrabbit.oak.plugins.name.NamespaceEditorProvider)3 TypeEditorProvider (org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider)3 EditorProvider (org.apache.jackrabbit.oak.spi.commit.EditorProvider)3 Calendar (java.util.Calendar)2 Oak (org.apache.jackrabbit.oak.Oak)2 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)2 InitialContent (org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent)2 VersionHook (org.apache.jackrabbit.oak.plugins.version.VersionHook)2 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)2 CompositeEditorProvider (org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider)2 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)2 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)2