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);
}
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;
}
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;
}
Aggregations