Search in sources :

Example 1 with IndexingProgressReporter

use of org.apache.jackrabbit.oak.plugins.index.progress.IndexingProgressReporter in project jackrabbit-oak by apache.

the class DocumentStoreIndexerBase method reindex.

public void reindex() throws CommitFailedException, IOException {
    IndexingProgressReporter progressReporter = new IndexingProgressReporter(IndexUpdateCallback.NOOP, NodeTraversalCallback.NOOP);
    configureEstimators(progressReporter);
    NodeState checkpointedState = indexerSupport.retrieveNodeStateForCheckpoint();
    NodeStore copyOnWriteStore = new MemoryNodeStore(checkpointedState);
    indexerSupport.switchIndexLanesAndReindexFlag(copyOnWriteStore);
    NodeBuilder builder = copyOnWriteStore.getRoot().builder();
    CompositeIndexer indexer = prepareIndexers(copyOnWriteStore, builder, progressReporter);
    if (indexer.isEmpty()) {
        return;
    }
    closer.register(indexer);
    FlatFileStore flatFileStore = buildFlatFileStore(checkpointedState, indexer, indexer::shouldInclude, null);
    progressReporter.reset();
    if (flatFileStore.getEntryCount() > 0) {
        FlatFileStore finalFlatFileStore = flatFileStore;
        progressReporter.setNodeCountEstimator((String basePath, Set<String> indexPaths) -> finalFlatFileStore.getEntryCount());
    }
    progressReporter.reindexingTraversalStart("/");
    preIndexOpertaions(indexer.getIndexers());
    Stopwatch indexerWatch = Stopwatch.createStarted();
    for (NodeStateEntry entry : flatFileStore) {
        reportDocumentRead(entry.getPath(), progressReporter);
        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) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) HashSet(java.util.HashSet) Set(java.util.Set) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) FlatFileStore(org.apache.jackrabbit.oak.index.indexer.document.flatfile.FlatFileStore) Stopwatch(com.google.common.base.Stopwatch) IndexingProgressReporter(org.apache.jackrabbit.oak.plugins.index.progress.IndexingProgressReporter) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Example 2 with IndexingProgressReporter

use of org.apache.jackrabbit.oak.plugins.index.progress.IndexingProgressReporter in project jackrabbit-oak by apache.

the class DocumentStoreIndexerIT method bundling.

@Test
public void bundling() throws Exception {
    MongoConnection c = getConnection();
    DocumentNodeStoreBuilder<?> docBuilder = builderProvider.newBuilder().setMongoDB(c.getMongoClient(), c.getDBName());
    DocumentNodeStore store = docBuilder.build();
    Whiteboard wb = new DefaultWhiteboard();
    MongoDocumentStore ds = (MongoDocumentStore) docBuilder.getDocumentStore();
    Registration r1 = wb.register(MongoDocumentStore.class, ds, emptyMap());
    wb.register(StatisticsProvider.class, StatisticsProvider.NOOP, emptyMap());
    configureIndex(store);
    configureBundling(store);
    NodeBuilder builder = store.getRoot().builder();
    NodeBuilder appNB = newNode("app:Asset");
    createChild(appNB, "jcr:content", // not bundled
    "jcr:content/comments", "jcr:content/metadata", // not bundled
    "jcr:content/metadata/xmp", // includes all
    "jcr:content/renditions", "jcr:content/renditions/original", "jcr:content/renditions/original/jcr:content");
    builder.child("test").setChildNode("book.jpg", appNB.getNodeState());
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    // Check that bundling is working
    assertNull(getNodeDocument(ds, "/test/book.jpg/jcr:content"));
    assertNotNull(getNodeDocument(ds, "/test/book.jpg"));
    String checkpoint = store.checkpoint(100000);
    // Shut down this store and restart in readOnly mode
    store.dispose();
    r1.unregister();
    MongoConnection c2 = connectionFactory.getConnection();
    DocumentNodeStoreBuilder<?> docBuilderRO = builderProvider.newBuilder().setReadOnlyMode().setMongoDB(c2.getMongoClient(), c2.getDBName());
    ds = (MongoDocumentStore) docBuilderRO.getDocumentStore();
    store = docBuilderRO.build();
    wb.register(MongoDocumentStore.class, ds, emptyMap());
    ExtendedIndexHelper helper = new ExtendedIndexHelper(store, store.getBlobStore(), wb, temporaryFolder.newFolder(), temporaryFolder.newFolder(), asList(TEST_INDEX_PATH));
    IndexerSupport support = new IndexerSupport(helper, checkpoint);
    CollectingIndexer testIndexer = new CollectingIndexer(p -> p.startsWith("/test"));
    DocumentStoreIndexer index = new DocumentStoreIndexer(helper, support) {

        @Override
        protected CompositeIndexer prepareIndexers(NodeStore nodeStore, NodeBuilder builder, IndexingProgressReporter progressReporter) {
            return new CompositeIndexer(asList(testIndexer));
        }
    };
    index.reindex();
    assertThat(testIndexer.paths, containsInAnyOrder("/test", "/test/book.jpg", "/test/book.jpg/jcr:content", "/test/book.jpg/jcr:content/comments", "/test/book.jpg/jcr:content/metadata", "/test/book.jpg/jcr:content/metadata/xmp", "/test/book.jpg/jcr:content/renditions", "/test/book.jpg/jcr:content/renditions/original", "/test/book.jpg/jcr:content/renditions/original/jcr:content"));
    store.dispose();
}
Also used : CompositeIndexer(org.apache.jackrabbit.oak.index.indexer.document.CompositeIndexer) DefaultWhiteboard(org.apache.jackrabbit.oak.spi.whiteboard.DefaultWhiteboard) DocumentStoreIndexer(org.apache.jackrabbit.oak.index.indexer.document.DocumentStoreIndexer) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) MongoDocumentStore(org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) Registration(org.apache.jackrabbit.oak.spi.whiteboard.Registration) IndexingProgressReporter(org.apache.jackrabbit.oak.plugins.index.progress.IndexingProgressReporter) MongoConnection(org.apache.jackrabbit.oak.plugins.document.util.MongoConnection) Whiteboard(org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard) DefaultWhiteboard(org.apache.jackrabbit.oak.spi.whiteboard.DefaultWhiteboard) Test(org.junit.Test)

Aggregations

DocumentNodeStore (org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore)2 IndexingProgressReporter (org.apache.jackrabbit.oak.plugins.index.progress.IndexingProgressReporter)2 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)2 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)2 Stopwatch (com.google.common.base.Stopwatch)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 CompositeIndexer (org.apache.jackrabbit.oak.index.indexer.document.CompositeIndexer)1 DocumentStoreIndexer (org.apache.jackrabbit.oak.index.indexer.document.DocumentStoreIndexer)1 FlatFileStore (org.apache.jackrabbit.oak.index.indexer.document.flatfile.FlatFileStore)1 DocumentNodeState (org.apache.jackrabbit.oak.plugins.document.DocumentNodeState)1 MongoDocumentStore (org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore)1 MongoConnection (org.apache.jackrabbit.oak.plugins.document.util.MongoConnection)1 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)1 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)1 DefaultWhiteboard (org.apache.jackrabbit.oak.spi.whiteboard.DefaultWhiteboard)1 Registration (org.apache.jackrabbit.oak.spi.whiteboard.Registration)1 Whiteboard (org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard)1 Test (org.junit.Test)1