Search in sources :

Example 1 with FlatFileNodeStoreBuilder

use of org.apache.jackrabbit.oak.index.indexer.document.flatfile.FlatFileNodeStoreBuilder in project jackrabbit-oak by apache.

the class DocumentStoreIndexer method reindex.

public void reindex() throws CommitFailedException, IOException {
    configureEstimators();
    NodeState checkpointedState = indexerSupport.retrieveNodeStateForCheckpoint();
    NodeStore copyOnWriteStore = new MemoryNodeStore(checkpointedState);
    indexerSupport.switchIndexLanesAndReindexFlag(copyOnWriteStore);
    NodeBuilder builder = copyOnWriteStore.getRoot().builder();
    CompositeIndexer indexer = prepareIndexers(copyOnWriteStore, builder);
    if (indexer.isEmpty()) {
        return;
    }
    closer.register(indexer);
    // TODO How to ensure we can safely read from secondary
    DocumentNodeState rootDocumentState = (DocumentNodeState) checkpointedState;
    DocumentNodeStore nodeStore = (DocumentNodeStore) indexHelper.getNodeStore();
    NodeStateEntryTraverser nsep = new NodeStateEntryTraverser(rootDocumentState.getRootRevision(), nodeStore, getMongoDocumentStore()).withProgressCallback(this::reportDocumentRead).withPathPredicate(indexer::shouldInclude);
    closer.register(nsep);
    // As first traversal is for dumping change the message prefix
    progressReporter.setMessagePrefix("Dumping");
    // TODO Use flatFileStore only if we have relative nodes to be indexed
    FlatFileStore flatFileStore = new FlatFileNodeStoreBuilder(nsep, indexHelper.getWorkDir()).withBlobStore(indexHelper.getGCBlobStore()).withPreferredPathElements(indexer.getRelativeIndexedNodeNames()).build();
    closer.register(flatFileStore);
    progressReporter.reset();
    if (flatFileStore.getEntryCount() > 0) {
        progressReporter.setNodeCountEstimator((String basePath, Set<String> indexPaths) -> flatFileStore.getEntryCount());
    }
    progressReporter.reindexingTraversalStart("/");
    Stopwatch indexerWatch = Stopwatch.createStarted();
    for (NodeStateEntry entry : flatFileStore) {
        reportDocumentRead(entry.getPath());
        indexer.index(entry);
    }
    progressReporter.reindexingTraversalEnd();
    progressReporter.logReport();
    log.info("Completed the indexing in {}", indexerWatch);
    copyOnWriteStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    indexerSupport.postIndexWork(copyOnWriteStore);
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) DocumentNodeState(org.apache.jackrabbit.oak.plugins.document.DocumentNodeState) HashSet(java.util.HashSet) Set(java.util.Set) FlatFileStore(org.apache.jackrabbit.oak.index.indexer.document.flatfile.FlatFileStore) Stopwatch(com.google.common.base.Stopwatch) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) DocumentNodeState(org.apache.jackrabbit.oak.plugins.document.DocumentNodeState) FlatFileNodeStoreBuilder(org.apache.jackrabbit.oak.index.indexer.document.flatfile.FlatFileNodeStoreBuilder)

Example 2 with FlatFileNodeStoreBuilder

use of org.apache.jackrabbit.oak.index.indexer.document.flatfile.FlatFileNodeStoreBuilder in project jackrabbit-oak by apache.

the class DocumentStoreIndexerBase method buildFlatFileStore.

private FlatFileStore buildFlatFileStore(NodeState checkpointedState, CompositeIndexer indexer, Predicate<String> pathPredicate, Set<String> preferredPathElements) throws IOException {
    Stopwatch flatFileStoreWatch = Stopwatch.createStarted();
    int executionCount = 1;
    CompositeException lastException = null;
    List<File> previousDownloadDirs = new ArrayList<>();
    FlatFileStore flatFileStore = null;
    // TODO How to ensure we can safely read from secondary
    DocumentNodeState rootDocumentState = (DocumentNodeState) checkpointedState;
    DocumentNodeStore nodeStore = (DocumentNodeStore) indexHelper.getNodeStore();
    DocumentStoreSplitter splitter = new DocumentStoreSplitter(getMongoDocumentStore());
    List<Long> lastModifiedBreakPoints = splitter.split(Collection.NODES, 0L, 10);
    FlatFileNodeStoreBuilder builder = null;
    int backOffTimeInMillis = 5000;
    MemoryManager memoryManager = new DefaultMemoryManager();
    while (flatFileStore == null && executionCount <= MAX_DOWNLOAD_ATTEMPTS) {
        try {
            builder = new FlatFileNodeStoreBuilder(indexHelper.getWorkDir(), memoryManager).withLastModifiedBreakPoints(lastModifiedBreakPoints).withBlobStore(indexHelper.getGCBlobStore()).withPreferredPathElements((preferredPathElements != null) ? preferredPathElements : indexer.getRelativeIndexedNodeNames()).addExistingDataDumpDir(indexerSupport.getExistingDataDumpDir()).withPathPredicate(pathPredicate).withNodeStateEntryTraverserFactory(new MongoNodeStateEntryTraverserFactory(rootDocumentState.getRootRevision(), nodeStore, getMongoDocumentStore(), traversalLog, indexer));
            for (File dir : previousDownloadDirs) {
                builder.addExistingDataDumpDir(dir);
            }
            flatFileStore = builder.build();
            closer.register(flatFileStore);
        } catch (CompositeException e) {
            e.logAllExceptions("Underlying throwable caught during download", log);
            log.info("Could not build flat file store. Execution count {}. Retries left {}. Time elapsed {}", executionCount, MAX_DOWNLOAD_ATTEMPTS - executionCount, flatFileStoreWatch);
            lastException = e;
            previousDownloadDirs.add(builder.getFlatFileStoreDir());
            if (executionCount < MAX_DOWNLOAD_ATTEMPTS) {
                try {
                    log.info("Waiting for {} millis before retrying", backOffTimeInMillis);
                    Thread.sleep(backOffTimeInMillis);
                    backOffTimeInMillis *= 2;
                } catch (InterruptedException ie) {
                    log.error("Interrupted while waiting before retrying download ", ie);
                }
            }
        }
        executionCount++;
    }
    if (flatFileStore == null) {
        throw new IOException("Could not build flat file store", lastException);
    }
    log.info("Completed the flat file store build in {}", flatFileStoreWatch);
    return flatFileStore;
}
Also used : FlatFileStore(org.apache.jackrabbit.oak.index.indexer.document.flatfile.FlatFileStore) DefaultMemoryManager(org.apache.jackrabbit.oak.index.indexer.document.flatfile.DefaultMemoryManager) Stopwatch(com.google.common.base.Stopwatch) ArrayList(java.util.ArrayList) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) IOException(java.io.IOException) DocumentStoreSplitter(org.apache.jackrabbit.oak.plugins.document.mongo.DocumentStoreSplitter) DefaultMemoryManager(org.apache.jackrabbit.oak.index.indexer.document.flatfile.DefaultMemoryManager) MemoryManager(org.apache.jackrabbit.oak.index.indexer.document.flatfile.MemoryManager) DocumentNodeState(org.apache.jackrabbit.oak.plugins.document.DocumentNodeState) File(java.io.File) FlatFileNodeStoreBuilder(org.apache.jackrabbit.oak.index.indexer.document.flatfile.FlatFileNodeStoreBuilder)

Example 3 with FlatFileNodeStoreBuilder

use of org.apache.jackrabbit.oak.index.indexer.document.flatfile.FlatFileNodeStoreBuilder in project jackrabbit-oak by apache.

the class DocumentStoreIndexerBase method buildFlatFileStore.

private FlatFileStore buildFlatFileStore(NodeState checkpointedState, CompositeIndexer indexer) throws IOException {
    Stopwatch flatFileStoreWatch = Stopwatch.createStarted();
    int executionCount = 1;
    CompositeException lastException = null;
    List<File> previousDownloadDirs = new ArrayList<>();
    FlatFileStore flatFileStore = null;
    // TODO How to ensure we can safely read from secondary
    DocumentNodeState rootDocumentState = (DocumentNodeState) checkpointedState;
    DocumentNodeStore nodeStore = (DocumentNodeStore) indexHelper.getNodeStore();
    DocumentStoreSplitter splitter = new DocumentStoreSplitter(getMongoDocumentStore());
    List<Long> lastModifiedBreakPoints = splitter.split(Collection.NODES, 0L, 10);
    FlatFileNodeStoreBuilder builder = null;
    int backOffTimeInMillis = 5000;
    MemoryManager memoryManager = new DefaultMemoryManager();
    while (flatFileStore == null && executionCount <= MAX_DOWNLOAD_ATTEMPTS) {
        try {
            builder = new FlatFileNodeStoreBuilder(indexHelper.getWorkDir(), memoryManager).withLastModifiedBreakPoints(lastModifiedBreakPoints).withBlobStore(indexHelper.getGCBlobStore()).withPreferredPathElements(indexer.getRelativeIndexedNodeNames()).addExistingDataDumpDir(indexerSupport.getExistingDataDumpDir()).withNodeStateEntryTraverserFactory(new MongoNodeStateEntryTraverserFactory(rootDocumentState.getRootRevision(), nodeStore, getMongoDocumentStore(), traversalLog, indexer));
            for (File dir : previousDownloadDirs) {
                builder.addExistingDataDumpDir(dir);
            }
            flatFileStore = builder.build();
            closer.register(flatFileStore);
        } catch (CompositeException e) {
            e.logAllExceptions("Underlying throwable caught during download", log);
            log.info("Could not build flat file store. Execution count {}. Retries left {}. Time elapsed {}", executionCount, MAX_DOWNLOAD_ATTEMPTS - executionCount, flatFileStoreWatch);
            lastException = e;
            previousDownloadDirs.add(builder.getFlatFileStoreDir());
            if (executionCount < MAX_DOWNLOAD_ATTEMPTS) {
                try {
                    log.info("Waiting for {} millis before retrying", backOffTimeInMillis);
                    Thread.sleep(backOffTimeInMillis);
                    backOffTimeInMillis *= 2;
                } catch (InterruptedException ie) {
                    log.error("Interrupted while waiting before retrying download ", ie);
                }
            }
        }
        executionCount++;
    }
    if (flatFileStore == null) {
        throw new IOException("Could not build flat file store", lastException);
    }
    log.info("Completed the flat file store build in {}", flatFileStoreWatch);
    return flatFileStore;
}
Also used : FlatFileStore(org.apache.jackrabbit.oak.index.indexer.document.flatfile.FlatFileStore) DefaultMemoryManager(org.apache.jackrabbit.oak.index.indexer.document.flatfile.DefaultMemoryManager) Stopwatch(com.google.common.base.Stopwatch) ArrayList(java.util.ArrayList) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) IOException(java.io.IOException) DocumentStoreSplitter(org.apache.jackrabbit.oak.plugins.document.mongo.DocumentStoreSplitter) DefaultMemoryManager(org.apache.jackrabbit.oak.index.indexer.document.flatfile.DefaultMemoryManager) MemoryManager(org.apache.jackrabbit.oak.index.indexer.document.flatfile.MemoryManager) DocumentNodeState(org.apache.jackrabbit.oak.plugins.document.DocumentNodeState) File(java.io.File) FlatFileNodeStoreBuilder(org.apache.jackrabbit.oak.index.indexer.document.flatfile.FlatFileNodeStoreBuilder)

Aggregations

Stopwatch (com.google.common.base.Stopwatch)3 FlatFileNodeStoreBuilder (org.apache.jackrabbit.oak.index.indexer.document.flatfile.FlatFileNodeStoreBuilder)3 FlatFileStore (org.apache.jackrabbit.oak.index.indexer.document.flatfile.FlatFileStore)3 DocumentNodeState (org.apache.jackrabbit.oak.plugins.document.DocumentNodeState)3 DocumentNodeStore (org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore)3 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 DefaultMemoryManager (org.apache.jackrabbit.oak.index.indexer.document.flatfile.DefaultMemoryManager)2 MemoryManager (org.apache.jackrabbit.oak.index.indexer.document.flatfile.MemoryManager)2 DocumentStoreSplitter (org.apache.jackrabbit.oak.plugins.document.mongo.DocumentStoreSplitter)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)1 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)1 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)1 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)1