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