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;
}
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations