use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.
the class EditorDiff method childNodeAdded.
@Override
public boolean childNodeAdded(String name, NodeState after) {
try {
NodeState before = MISSING_NODE;
Editor childEditor = editor.childNodeAdded(name, after);
// in diff processing.
if (childEditor != null) {
childEditor.enter(before, after);
EditorDiff diff = new EditorDiff(childEditor);
if (!after.compareAgainstBaseState(before, diff)) {
exception = diff.exception;
return false;
}
childEditor.leave(before, after);
}
return true;
} catch (CommitFailedException e) {
exception = e;
return false;
}
}
use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.
the class EditorDiff method childNodeDeleted.
@Override
public boolean childNodeDeleted(String name, NodeState before) {
try {
NodeState after = MISSING_NODE;
Editor childEditor = editor.childNodeDeleted(name, before);
if (childEditor != null) {
childEditor.enter(before, after);
EditorDiff diff = new EditorDiff(childEditor);
if (!after.compareAgainstBaseState(before, diff)) {
exception = diff.exception;
return false;
}
childEditor.leave(before, after);
}
return true;
} catch (CommitFailedException e) {
exception = e;
return false;
}
}
use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.
the class EditorHook method processCommit.
@Override
@Nonnull
public NodeState processCommit(@Nonnull NodeState before, @Nonnull NodeState after, @Nonnull CommitInfo info) throws CommitFailedException {
checkNotNull(before);
checkNotNull(after);
checkNotNull(info);
NodeBuilder builder = after.builder();
Editor editor = provider.getRootEditor(before, after, builder, info);
CommitFailedException exception = EditorDiff.process(editor, before, after);
if (exception == null) {
return builder.getNodeState();
} else {
throw exception;
}
}
use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.
the class SecondaryStoreObserver method contentChanged.
@Override
public void contentChanged(@Nonnull NodeState root, @Nonnull CommitInfo info) {
//diffManyChildren might pose problem for e.g. data under uuid index
if (!firstEventProcessed) {
log.info("Starting initial sync");
}
Stopwatch w = Stopwatch.createStarted();
AbstractDocumentNodeState target = (AbstractDocumentNodeState) root;
NodeState secondaryRoot = nodeStore.getRoot();
NodeState base = DelegatingDocumentNodeState.wrapIfPossible(secondaryRoot, differ);
NodeBuilder builder = secondaryRoot.builder();
ApplyDiff diff = new PathFilteringDiff(builder, pathFilter, metaPropNames, target);
//Copy the root node meta properties
PathFilteringDiff.copyMetaProperties(target, builder, metaPropNames);
//Apply the rest of properties
target.compareAgainstBaseState(base, diff);
try {
NodeState updatedSecondaryRoot = nodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
secondaryObserver.contentChanged(DelegatingDocumentNodeState.wrap(updatedSecondaryRoot, differ));
TimerStats timer = info.isExternal() ? external : local;
timer.update(w.elapsed(TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS);
if (!firstEventProcessed) {
log.info("Time taken for initial sync {}", w);
firstEventProcessed = true;
}
} catch (CommitFailedException e) {
//TODO
log.warn("Commit to secondary store failed", e);
}
}
use of org.apache.jackrabbit.oak.api.CommitFailedException 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;
}
}
}
Aggregations