Search in sources :

Example 6 with IndexPathService

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

the class ReindexIT method newIndexDefinition.

@Test
public void newIndexDefinition() throws Exception {
    createTestData(true);
    addTestContent(fixture, "/testNode/c", "bar", 100);
    fixture.getAsyncIndexUpdate("async").run();
    String explain = getQueryPlan(fixture, "select * from [nt:base] where [bar] is not null");
    assertThat(explain, containsString("traverse"));
    fixture.close();
    IndexCommand command = new IndexCommand();
    String json = "{\n" + "  \"/oak:index/barIndex\": {\n" + "    \"compatVersion\": 2,\n" + "    \"type\": \"lucene\",\n" + "    \"async\": \"async\",\n" + "    \"jcr:primaryType\": \"oak:QueryIndexDefinition\",\n" + "    \"indexRules\": {\n" + "      \"jcr:primaryType\": \"nt:unstructured\",\n" + "      \"nt:base\": {\n" + "        \"jcr:primaryType\": \"nt:unstructured\",\n" + "        \"properties\": {\n" + "          \"jcr:primaryType\": \"nt:unstructured\",\n" + "          \"bar\": {\n" + "            \"name\": \"bar\",\n" + "            \"propertyIndex\": true,\n" + "            \"jcr:primaryType\": \"nt:unstructured\"\n" + "          }\n" + "        }\n" + "      }\n" + "    }\n" + "  }\n" + "}";
    File jsonFile = temporaryFolder.newFile();
    Files.write(json, jsonFile, UTF_8);
    File outDir = temporaryFolder.newFolder();
    File storeDir = fixture.getDir();
    String[] args = { "--index-temp-dir=" + temporaryFolder.newFolder().getAbsolutePath(), "--index-out-dir=" + outDir.getAbsolutePath(), "--index-definitions-file=" + jsonFile.getAbsolutePath(), "--reindex", "--read-write", // -- indicates that options have ended and rest needs to be treated as non option
    "--", storeDir.getAbsolutePath() };
    command.execute(args);
    RepositoryFixture fixture2 = new RepositoryFixture(storeDir);
    explain = getQueryPlan(fixture2, "select * from [nt:base] where [bar] is not null");
    assertThat(explain, containsString("/oak:index/barIndex"));
    IndexPathService idxPathService = new IndexPathServiceImpl(fixture2.getNodeStore());
    List<String> indexPaths = Lists.newArrayList(idxPathService.getIndexPaths());
    assertThat(indexPaths, hasItem("/oak:index/nodetype"));
    assertThat(indexPaths, hasItem("/oak:index/barIndex"));
}
Also used : IndexPathService(org.apache.jackrabbit.oak.plugins.index.IndexPathService) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) IndexPathServiceImpl(org.apache.jackrabbit.oak.plugins.index.IndexPathServiceImpl) File(java.io.File) Test(org.junit.Test)

Example 7 with IndexPathService

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

the class ActiveDeletedBlobCollectorMBeanImplTest method orderOfFlaggingWaitForIndexersAndUpdateIndexFiles.

@Test
public void orderOfFlaggingWaitForIndexersAndUpdateIndexFiles() {
    final AtomicBoolean isPaused = new AtomicBoolean();
    final AtomicBoolean hadWaitedForIndex = new AtomicBoolean();
    IndexPathService indexPathService = mock(IndexPathService.class);
    when(indexPathService.getIndexPaths()).then(mockObj -> {
        assertTrue("Must wait for indexers before going to update index files", hadWaitedForIndex.get());
        return indexPaths;
    });
    AsyncIndexInfoService asyncIndexInfoService = MockRegistrar.getAsyncIndexInfoService(newArrayList(new IndexMBeanInfoSupplier("foo-async", () -> {
        assertTrue("Must pause before waiting for indexers", isPaused.get());
        hadWaitedForIndex.set(true);
        return STATUS_DONE;
    }, () -> 2L)));
    ActiveDeletedBlobCollectorMBeanImpl bean = new ActiveDeletedBlobCollectorMBeanImpl(new PauseNotifyingActiveDeletedBlobCollector(() -> {
        isPaused.set(true);
        return null;
    }), wb, nodeStore, indexPathService, asyncIndexInfoService, new MemoryBlobStore(), sameThreadExecutor());
    bean.clock = clock;
    bean.flagActiveDeletionUnsafeForCurrentState();
}
Also used : IndexPathService(org.apache.jackrabbit.oak.plugins.index.IndexPathService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AsyncIndexInfoService(org.apache.jackrabbit.oak.plugins.index.AsyncIndexInfoService) MemoryBlobStore(org.apache.jackrabbit.oak.spi.blob.MemoryBlobStore) Test(org.junit.Test)

Example 8 with IndexPathService

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

the class ActiveDeletedBlobCollectorMBeanImplTest method onlyRunningIndexesRequireToBeWaitedOn.

@Test
public void onlyRunningIndexesRequireToBeWaitedOn() {
    IndexPathService indexPathService = MockRegistrar.getIndexPathsService(indexPaths);
    final StatusSupplier statusSupplier = new StatusSupplier();
    final AtomicLong returnExecCount = new AtomicLong(2L);
    AsyncIndexInfoService asyncIndexInfoService = MockRegistrar.getAsyncIndexInfoService(newArrayList(new IndexMBeanInfoSupplier("foo-async", statusSupplier, returnExecCount::get)));
    ActiveDeletedBlobCollectorMBean bean = getTestBean(indexPathService, asyncIndexInfoService);
    long start = clock.getTime();
    bean.flagActiveDeletionUnsafeForCurrentState();
    long elapsed = clock.getTime() - start;
    assertTrue("Non running index lane was polled for " + TimeUnit.MILLISECONDS.toSeconds(elapsed) + " seconds.", elapsed < TimeUnit.SECONDS.toMillis(5));
    // running index with stalled exec count waits for 2 minutes
    statusSupplier.status = STATUS_RUNNING;
    start = clock.getTime();
    bean.flagActiveDeletionUnsafeForCurrentState();
    elapsed = clock.getTime() - start;
    assertTrue("Running index lane without changing execCnt was polled for " + TimeUnit.MILLISECONDS.toSeconds(elapsed) + " seconds.", elapsed > TimeUnit.SECONDS.toMillis(120) && elapsed < TimeUnit.SECONDS.toMillis(125));
    // running index with not stalled exec count doesn't wait
    statusSupplier.status = STATUS_RUNNING;
    asyncIndexInfoService = MockRegistrar.getAsyncIndexInfoService(newArrayList(new IndexMBeanInfoSupplier("foo-async", statusSupplier, returnExecCount::incrementAndGet)));
    bean = getTestBean(indexPathService, asyncIndexInfoService);
    start = clock.getTime();
    bean.flagActiveDeletionUnsafeForCurrentState();
    elapsed = clock.getTime() - start;
    assertTrue("Running index lane without changing execCnt was polled for " + TimeUnit.MILLISECONDS.toSeconds(elapsed) + " seconds.", elapsed < TimeUnit.SECONDS.toMillis(5));
}
Also used : IndexPathService(org.apache.jackrabbit.oak.plugins.index.IndexPathService) AtomicLong(java.util.concurrent.atomic.AtomicLong) AsyncIndexInfoService(org.apache.jackrabbit.oak.plugins.index.AsyncIndexInfoService) Test(org.junit.Test)

Example 9 with IndexPathService

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

the class HybridIndexTest method prepareLuceneIndexer.

private void prepareLuceneIndexer(File workDir, NodeStore nodeStore) {
    try {
        indexCopierDir = createTemporaryFolderIn(workDir);
        copier = new IndexCopier(executorService, indexCopierDir, true);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    IndexPathService indexPathService = new IndexPathServiceImpl(nodeStore);
    AsyncIndexInfoService asyncIndexInfoService = new AsyncIndexInfoServiceImpl(nodeStore);
    nrtIndexFactory = new NRTIndexFactory(copier, Clock.SIMPLE, TimeUnit.MILLISECONDS.toSeconds(refreshDeltaMillis), StatisticsProvider.NOOP);
    MountInfoProvider mip = Mounts.defaultMountInfoProvider();
    LuceneIndexReaderFactory indexReaderFactory = new DefaultIndexReaderFactory(mip, copier);
    IndexTracker tracker = new IndexTracker(indexReaderFactory, nrtIndexFactory);
    luceneIndexProvider = new LuceneIndexProvider(tracker);
    luceneEditorProvider = new LuceneIndexEditorProvider(copier, tracker, // extractedTextCache
    null, // augmentorFactory
    null, mip);
    queue = new DocumentQueue(queueSize, tracker, executorService, statsProvider);
    localIndexObserver = new LocalIndexObserver(queue, statsProvider);
    luceneEditorProvider.setIndexingQueue(queue);
    if (syncIndexing) {
        PropertyIndexCleaner cleaner = new PropertyIndexCleaner(nodeStore, indexPathService, asyncIndexInfoService, statsProvider);
        regs.add(scheduleWithFixedDelay(whiteboard, cleaner, cleanerIntervalInSecs, true, true));
    }
    Thread.setDefaultUncaughtExceptionHandler((t, e) -> log.warn("Uncaught exception", e));
}
Also used : IndexPathService(org.apache.jackrabbit.oak.plugins.index.IndexPathService) AsyncIndexInfoService(org.apache.jackrabbit.oak.plugins.index.AsyncIndexInfoService) IndexTracker(org.apache.jackrabbit.oak.plugins.index.lucene.IndexTracker) DocumentQueue(org.apache.jackrabbit.oak.plugins.index.lucene.hybrid.DocumentQueue) IOException(java.io.IOException) IndexPathServiceImpl(org.apache.jackrabbit.oak.plugins.index.IndexPathServiceImpl) LuceneIndexReaderFactory(org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReaderFactory) IndexCopier(org.apache.jackrabbit.oak.plugins.index.lucene.IndexCopier) LuceneIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexEditorProvider) LocalIndexObserver(org.apache.jackrabbit.oak.plugins.index.lucene.hybrid.LocalIndexObserver) NRTIndexFactory(org.apache.jackrabbit.oak.plugins.index.lucene.hybrid.NRTIndexFactory) DefaultIndexReaderFactory(org.apache.jackrabbit.oak.plugins.index.lucene.reader.DefaultIndexReaderFactory) LuceneIndexProvider(org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexProvider) MountInfoProvider(org.apache.jackrabbit.oak.spi.mount.MountInfoProvider) AsyncIndexInfoServiceImpl(org.apache.jackrabbit.oak.plugins.index.AsyncIndexInfoServiceImpl) PropertyIndexCleaner(org.apache.jackrabbit.oak.plugins.index.lucene.property.PropertyIndexCleaner)

Aggregations

IndexPathService (org.apache.jackrabbit.oak.plugins.index.IndexPathService)9 AsyncIndexInfoService (org.apache.jackrabbit.oak.plugins.index.AsyncIndexInfoService)8 Test (org.junit.Test)8 IndexPathServiceImpl (org.apache.jackrabbit.oak.plugins.index.IndexPathServiceImpl)3 MemoryBlobStore (org.apache.jackrabbit.oak.spi.blob.MemoryBlobStore)3 File (java.io.File)2 DocumentNodeStore (org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore)2 IOException (java.io.IOException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Nonnull (javax.annotation.Nonnull)1 InitialContent (org.apache.jackrabbit.oak.InitialContent)1 Oak (org.apache.jackrabbit.oak.Oak)1 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)1 ContentRepository (org.apache.jackrabbit.oak.api.ContentRepository)1 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)1 Root (org.apache.jackrabbit.oak.api.Root)1 Tree (org.apache.jackrabbit.oak.api.Tree)1 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)1 AsyncIndexInfoServiceImpl (org.apache.jackrabbit.oak.plugins.index.AsyncIndexInfoServiceImpl)1