use of org.apache.jackrabbit.oak.plugins.commit.AnnotatingConflictHandler 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);
}
use of org.apache.jackrabbit.oak.plugins.commit.AnnotatingConflictHandler 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;
}
}
}
use of org.apache.jackrabbit.oak.plugins.commit.AnnotatingConflictHandler 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());
}
use of org.apache.jackrabbit.oak.plugins.commit.AnnotatingConflictHandler 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);
}
use of org.apache.jackrabbit.oak.plugins.commit.AnnotatingConflictHandler in project jackrabbit-oak by apache.
the class DocumentNodeStoreTest method commitRootSameAsModifiedPathWithConflicts.
@Test
public void commitRootSameAsModifiedPathWithConflicts() throws Exception {
MemoryDocumentStore store = new MemoryDocumentStore(true);
final DocumentNodeStore ns = builderProvider.newBuilder().setAsyncDelay(0).setDocumentStore(store).getNodeStore();
NodeBuilder builder = ns.getRoot().builder();
builder.child("a").child("b").setProperty("p", 0L);
merge(ns, builder);
final List<Throwable> exceptions = synchronizedList(Lists.newArrayList());
Runnable task = new Runnable() {
CommitHook hook = new CompositeHook(new ConflictHook(new AnnotatingConflictHandler()), new EditorHook(new ConflictValidatorProvider()));
@Override
public void run() {
try {
for (int i = 0; i < 100; i++) {
NodeBuilder builder = ns.getRoot().builder();
NodeBuilder b = builder.child("a").child("b");
PropertyState p = b.getProperty("p");
assertNotNull(p);
long value = p.getValue(Type.LONG) + 1;
b.setProperty(p.getName(), value);
try {
ns.merge(builder, hook, CommitInfo.EMPTY);
} catch (CommitFailedException e) {
if (e.asRepositoryException() instanceof InvalidItemStateException) {
// this is fine and may happen from time to
// time because the test updates the same
// property concurrently
} else {
// anything else is unexpected
exceptions.add(e);
}
}
}
} catch (AssertionError e) {
exceptions.add(e);
}
}
};
List<Thread> threads = Lists.newArrayList();
for (int i = 0; i < 4; i++) {
threads.add(new Thread(task));
}
for (Thread t : threads) {
t.start();
}
for (Thread t : threads) {
t.join();
}
// check updates are consecutive
NodeDocument doc = store.find(NODES, Utils.getIdFromPath("/a/b"));
assertNotNull(doc);
long previousValue = -1;
List<String> values = Lists.newArrayList(doc.getLocalMap("p").values());
for (String v : Lists.reverse(values)) {
long currentValue = Long.parseLong(v);
assertEquals(previousValue + 1, currentValue);
previousValue = currentValue;
}
for (Throwable e : exceptions) {
fail(e.toString());
}
}
Aggregations