use of com.google.common.base.Stopwatch in project jackrabbit-oak by apache.
the class OutOfBandIndexer method reindex.
public void reindex() throws CommitFailedException, IOException {
Stopwatch w = Stopwatch.createStarted();
NodeState checkpointedState = retrieveNodeStateForCheckpoint();
copyOnWriteStore = new MemoryNodeStore(checkpointedState);
NodeState baseState = copyOnWriteStore.getRoot();
//TODO Check for indexPaths being empty
log.info("Proceeding to index {} upto checkpoint {} {}", indexHelper.getIndexPaths(), checkpoint, checkpointInfo);
switchIndexLanesAndReindexFlag();
preformIndexUpdate(baseState);
writeMetaInfo();
File destDir = copyIndexFilesToOutput();
log.info("Indexing completed for indexes {} in {} and index files are copied to {}", indexHelper.getIndexPaths(), w, IndexCommand.getPath(destDir));
}
use of com.google.common.base.Stopwatch in project jackrabbit-oak by apache.
the class DocumentNodeStoreHelper method garbageReport.
public static void garbageReport(DocumentNodeStore dns) {
System.out.print("Collecting top 100 nodes with most blob garbage ");
Stopwatch sw = Stopwatch.createStarted();
Iterable<BlobReferences> refs = scan(dns, new BlobGarbageSizeComparator(), 100);
for (BlobReferences br : refs) {
System.out.println(br);
}
System.out.println("Collected in " + sw.stop());
}
use of com.google.common.base.Stopwatch 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 com.google.common.base.Stopwatch 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 com.google.common.base.Stopwatch in project jackrabbit-oak by apache.
the class MongoDocumentStore method remove.
@Override
public <T extends Document> int remove(Collection<T> collection, String indexedProperty, long startValue, long endValue) throws DocumentStoreException {
log("remove", collection, indexedProperty, startValue, endValue);
int num = 0;
DBCollection dbCollection = getDBCollection(collection);
Stopwatch watch = startWatch();
try {
QueryBuilder queryBuilder = QueryBuilder.start(indexedProperty);
queryBuilder.greaterThan(startValue);
queryBuilder.lessThan(endValue);
try {
num = dbCollection.remove(queryBuilder.get()).getN();
} catch (Exception e) {
throw DocumentStoreException.convert(e, "Remove failed for " + collection + ": " + indexedProperty + " in (" + startValue + ", " + endValue + ")");
} finally {
if (collection == Collection.NODES) {
// this method is currently being used only for Journal collection while GC.
// But, to keep sanctity of the API, we need to acknowledge that Nodes collection
// could've been used. But, in this signature, there's no useful way to invalidate
// cache.
// So, we use the hammer for this task
invalidateCache();
}
}
} finally {
stats.doneRemove(watch.elapsed(TimeUnit.NANOSECONDS), collection, num);
}
return num;
}
Aggregations