use of org.apache.jackrabbit.oak.spi.commit.CommitInfo 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.spi.commit.CommitInfo in project jackrabbit-oak by apache.
the class AsyncIndexUpdate method updateIndex.
protected boolean updateIndex(NodeState before, String beforeCheckpoint, NodeState after, String afterCheckpoint, String afterTime, AsyncUpdateCallback callback) throws CommitFailedException {
Stopwatch watch = Stopwatch.createStarted();
boolean updatePostRunStatus = true;
boolean progressLogged = false;
// prepare the update callback for tracking index updates
// and maintaining the update lease
callback.prepare(afterCheckpoint);
// check for index tasks split requests, if a split happened, make
// sure to not delete the reference checkpoint, as the other index
// task will take care of it
taskSplitter.maybeSplit(beforeCheckpoint, callback.lease);
IndexUpdate indexUpdate = null;
try {
NodeBuilder builder = store.getRoot().builder();
markFailingIndexesAsCorrupt(builder);
CommitInfo info = new CommitInfo(CommitInfo.OAK_UNKNOWN, CommitInfo.OAK_UNKNOWN, ImmutableMap.of(IndexConstants.CHECKPOINT_CREATION_TIME, afterTime));
indexUpdate = new IndexUpdate(provider, name, after, builder, callback, callback, info, corruptIndexHandler).withMissingProviderStrategy(missingStrategy);
configureRateEstimator(indexUpdate);
CommitFailedException exception = EditorDiff.process(VisibleEditor.wrap(indexUpdate), before, after);
if (exception != null) {
throw exception;
}
builder.child(ASYNC).setProperty(name, afterCheckpoint);
builder.child(ASYNC).setProperty(PropertyStates.createProperty(lastIndexedTo, afterTime, Type.DATE));
if (callback.isDirty() || before == MISSING_NODE) {
if (switchOnSync) {
reindexedDefinitions.addAll(indexUpdate.getReindexedDefinitions());
updatePostRunStatus = false;
} else {
updatePostRunStatus = true;
}
} else {
if (switchOnSync) {
log.debug("[{}] No changes detected after diff; will try to switch to synchronous updates on {}", name, reindexedDefinitions);
// no changes after diff, switch to sync on the async defs
for (String path : reindexedDefinitions) {
NodeBuilder c = builder;
for (String p : elements(path)) {
c = c.getChildNode(p);
}
if (c.exists() && !c.getBoolean(REINDEX_PROPERTY_NAME)) {
c.removeProperty(ASYNC_PROPERTY_NAME);
}
}
reindexedDefinitions.clear();
if (store.release(afterCheckpoint)) {
builder.child(ASYNC).removeProperty(name);
builder.child(ASYNC).removeProperty(lastIndexedTo);
} else {
log.debug("[{}] Unable to release checkpoint {}", name, afterCheckpoint);
}
}
updatePostRunStatus = true;
}
mergeWithConcurrencyCheck(store, validatorProviders, builder, beforeCheckpoint, callback.lease, name);
if (indexUpdate.isReindexingPerformed()) {
log.info("[{}] Reindexing completed for indexes: {} in {} ({} ms)", name, indexUpdate.getReindexStats(), watch, watch.elapsed(TimeUnit.MILLISECONDS));
progressLogged = true;
}
corruptIndexHandler.markWorkingIndexes(indexUpdate.getUpdatedIndexPaths());
} finally {
if (indexUpdate != null) {
if (updatePostRunStatus) {
indexUpdate.commitProgress(IndexCommitCallback.IndexProgress.COMMIT_SUCCEDED);
} else {
indexUpdate.commitProgress(IndexCommitCallback.IndexProgress.COMMIT_FAILED);
}
}
callback.close();
}
if (!progressLogged) {
String msg = "[{}] AsyncIndex update run completed in {}. Indexed {} nodes, {}";
//Log at info level if time taken is more than 5 min
if (watch.elapsed(TimeUnit.MINUTES) >= 5) {
log.info(msg, name, watch, indexStats.getUpdates(), indexUpdate.getIndexingStats());
} else {
log.debug(msg, name, watch, indexStats.getUpdates(), indexUpdate.getIndexingStats());
}
}
return updatePostRunStatus;
}
use of org.apache.jackrabbit.oak.spi.commit.CommitInfo 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.spi.commit.CommitInfo in project jackrabbit-oak by apache.
the class AsyncIndexUpdateTest method startTimePresentInCommitInfo.
@Test
public void startTimePresentInCommitInfo() throws Exception {
MemoryNodeStore store = new MemoryNodeStore();
NodeBuilder builder = store.getRoot().builder();
createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "fooIndex", true, false, ImmutableSet.of("foo"), null).setProperty(ASYNC_PROPERTY_NAME, "async");
builder.child("testRoot1").setProperty("foo", "abc");
// merge it back in
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
IndexingContextCapturingProvider provider = new IndexingContextCapturingProvider();
AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider);
async.run();
assertNotNull(provider.lastIndexingContext);
CommitInfo info = provider.lastIndexingContext.getCommitInfo();
String indexStartTime = (String) info.getInfo().get(IndexConstants.CHECKPOINT_CREATION_TIME);
assertNotNull(indexStartTime);
}
use of org.apache.jackrabbit.oak.spi.commit.CommitInfo in project jackrabbit-oak by apache.
the class IndexUpdateTest method testMissingProviderFailsCommit.
/**
* OAK-3505 Provide an optionally stricter policy for missing synchronous
* index editor providers
*/
@Test
public void testMissingProviderFailsCommit() throws Exception {
final IndexUpdateCallback noop = new IndexUpdateCallback() {
@Override
public void indexUpdate() {
}
};
final MissingIndexProviderStrategy mips = new MissingIndexProviderStrategy();
mips.setFailOnMissingIndexProvider(true);
EditorHook hook = new EditorHook(new EditorProvider() {
@Override
public Editor getRootEditor(NodeState before, NodeState after, NodeBuilder builder, CommitInfo info) throws CommitFailedException {
return new IndexUpdate(emptyProvider(), null, after, builder, noop).withMissingProviderStrategy(mips);
}
});
NodeState before = builder.getNodeState();
createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null);
builder.child(INDEX_DEFINITIONS_NAME).child("azerty");
builder.child("testRoot").setProperty("foo", "abc");
NodeState after = builder.getNodeState();
try {
hook.processCommit(before, after, CommitInfo.EMPTY);
fail("commit should fail on missing index provider");
} catch (CommitFailedException ex) {
// expected
}
}
Aggregations