Search in sources :

Example 1 with CompositeHook

use of org.apache.jackrabbit.oak.spi.commit.CompositeHook 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 2 with CompositeHook

use of org.apache.jackrabbit.oak.spi.commit.CompositeHook 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 3 with CompositeHook

use of org.apache.jackrabbit.oak.spi.commit.CompositeHook 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 4 with CompositeHook

use of org.apache.jackrabbit.oak.spi.commit.CompositeHook 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 5 with CompositeHook

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

the class NodeStoreUtils method mergeWithConcurrentCheck.

static void mergeWithConcurrentCheck(NodeStore nodeStore, NodeBuilder builder) throws CommitFailedException {
    CompositeHook hooks = new CompositeHook(ResetCommitAttributeHook.INSTANCE, 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) 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)

Aggregations

CompositeHook (org.apache.jackrabbit.oak.spi.commit.CompositeHook)12 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)11 ConflictValidatorProvider (org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider)10 AnnotatingConflictHandler (org.apache.jackrabbit.oak.plugins.commit.AnnotatingConflictHandler)7 ConflictHook (org.apache.jackrabbit.oak.plugins.commit.ConflictHook)7 Test (org.junit.Test)6 CommitHook (org.apache.jackrabbit.oak.spi.commit.CommitHook)5 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)4 OakBaseTest (org.apache.jackrabbit.oak.OakBaseTest)3 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)3 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)3 EditorProvider (org.apache.jackrabbit.oak.spi.commit.EditorProvider)3 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)3 Calendar (java.util.Calendar)2 IndexUpdateProvider (org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider)2 CompositeEditorProvider (org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider)2 InvalidItemStateException (javax.jcr.InvalidItemStateException)1 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)1 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)1 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)1