Search in sources :

Example 76 with Stopwatch

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));
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) Stopwatch(com.google.common.base.Stopwatch) File(java.io.File)

Example 77 with Stopwatch

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());
}
Also used : Stopwatch(com.google.common.base.Stopwatch)

Example 78 with Stopwatch

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);
    }
}
Also used : ApplyDiff(org.apache.jackrabbit.oak.spi.state.ApplyDiff) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) AbstractDocumentNodeState(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState) Stopwatch(com.google.common.base.Stopwatch) AbstractDocumentNodeState(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState) TimerStats(org.apache.jackrabbit.oak.stats.TimerStats) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException)

Example 79 with Stopwatch

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;
}
Also used : Stopwatch(com.google.common.base.Stopwatch) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) Throwables.getStackTraceAsString(com.google.common.base.Throwables.getStackTraceAsString) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException)

Example 80 with Stopwatch

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;
}
Also used : DBCollection(com.mongodb.DBCollection) Stopwatch(com.google.common.base.Stopwatch) QueryBuilder(com.mongodb.QueryBuilder) MongoException(com.mongodb.MongoException) DocumentStoreException(org.apache.jackrabbit.oak.plugins.document.DocumentStoreException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) BulkWriteException(com.mongodb.BulkWriteException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

Stopwatch (com.google.common.base.Stopwatch)314 IOException (java.io.IOException)81 ArrayList (java.util.ArrayList)29 ExecutionException (java.util.concurrent.ExecutionException)28 File (java.io.File)19 Map (java.util.Map)18 Test (org.junit.Test)18 DocumentStoreException (org.apache.jackrabbit.oak.plugins.document.DocumentStoreException)15 HashMap (java.util.HashMap)14 Path (org.apache.hadoop.fs.Path)14 List (java.util.List)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)11 DBCollection (com.mongodb.DBCollection)9 ISE (io.druid.java.util.common.ISE)9 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)8 OptionsParser (com.google.devtools.common.options.OptionsParser)8 MongoException (com.mongodb.MongoException)8 Connection (java.sql.Connection)8 CountDownLatch (java.util.concurrent.CountDownLatch)8