use of org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexDir in project jackrabbit-oak by apache.
the class IndexCopier method getIndexPathMapping.
//~------------------------------------------< CopyOnReadStatsMBean >
@Override
public TabularData getIndexPathMapping() {
TabularDataSupport tds;
try {
TabularType tt = new TabularType(IndexMappingData.class.getName(), "Lucene Index Stats", IndexMappingData.TYPE, new String[] { "jcrPath" });
tds = new TabularDataSupport(tt);
for (LocalIndexDir indexDir : indexRootDirectory.getAllLocalIndexes()) {
String size = humanReadableByteCount(indexDir.size());
tds.put(new CompositeDataSupport(IndexMappingData.TYPE, IndexMappingData.FIELD_NAMES, new String[] { indexDir.getJcrPath(), indexDir.getFSPath(), size }));
}
} catch (OpenDataException e) {
throw new IllegalStateException(e);
} catch (IOException e) {
throw new IllegalStateException(e);
}
return tds;
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexDir in project jackrabbit-oak by apache.
the class LuceneIndexTest method luceneWithCopyOnReadDirAndReindex.
@Test
public void luceneWithCopyOnReadDirAndReindex() throws Exception {
NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
NodeBuilder defnState = newLucenePropertyIndexDefinition(index, "lucene", ImmutableSet.of("foo", "foo2", "foo3"), null);
IndexDefinition definition = new IndexDefinition(root, defnState.getNodeState(), "/foo");
//1. Create index in two increments
NodeState before = builder.getNodeState();
builder.setProperty("foo", "bar");
NodeState indexed = HOOK.processCommit(before, builder.getNodeState(), CommitInfo.EMPTY);
IndexCopier copier = new IndexCopier(sameThreadExecutor(), new File(getIndexDir()));
tracker = new IndexTracker(copier);
tracker.update(indexed);
assertQuery(tracker, indexed, "foo", "bar");
assertEquals(0, copier.getInvalidFileCount());
builder = indexed.builder();
builder.setProperty("foo2", "bar2");
indexed = HOOK.processCommit(indexed, builder.getNodeState(), CommitInfo.EMPTY);
tracker.update(indexed);
assertQuery(tracker, indexed, "foo2", "bar2");
assertEquals(0, copier.getInvalidFileCount());
//2. Reindex. This would create index with different index content
builder = indexed.builder();
builder.child(INDEX_DEFINITIONS_NAME).child("lucene").setProperty(REINDEX_PROPERTY_NAME, true);
indexed = HOOK.processCommit(indexed, builder.getNodeState(), CommitInfo.EMPTY);
tracker.update(indexed);
defnState = builder.child(INDEX_DEFINITIONS_NAME).child("lucene");
definition = new IndexDefinition(root, defnState.getNodeState(), "/foo");
assertQuery(tracker, indexed, "foo2", "bar2");
//If reindex case handled properly then invalid count should be zero
assertEquals(0, copier.getInvalidFileCount());
assertEquals(2, copier.getIndexRootDirectory().getLocalIndexes("/oak:index/lucene").size());
//3. Update again. Now with close of previous reader
//orphaned directory must be removed
builder = indexed.builder();
builder.setProperty("foo3", "bar3");
indexed = HOOK.processCommit(indexed, builder.getNodeState(), CommitInfo.EMPTY);
tracker.update(indexed);
assertQuery(tracker, indexed, "foo3", "bar3");
assertEquals(0, copier.getInvalidFileCount());
List<LocalIndexDir> idxDirs = copier.getIndexRootDirectory().getLocalIndexes("/oak:index/lucene");
List<LocalIndexDir> nonEmptyDirs = Lists.newArrayList();
for (LocalIndexDir dir : idxDirs) {
if (!dir.isEmpty()) {
nonEmptyDirs.add(dir);
}
}
assertEquals(1, nonEmptyDirs.size());
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexDir in project jackrabbit-oak by apache.
the class IndexCommandIT method reindexOutOfBand.
@Test
public void reindexOutOfBand() throws Exception {
createTestData(true);
fixture.getAsyncIndexUpdate("async").run();
String checkpoint = fixture.getNodeStore().checkpoint(TimeUnit.HOURS.toMillis(24));
//Close the repository so as all changes are flushed
fixture.close();
IndexCommand command = new IndexCommand();
File outDir = temporaryFolder.newFolder();
File storeDir = fixture.getDir();
String[] args = { "--index-temp-dir=" + temporaryFolder.newFolder().getAbsolutePath(), "--index-out-dir=" + outDir.getAbsolutePath(), "--index-paths=/oak:index/fooIndex", "--checkpoint=" + checkpoint, "--reindex", // -- indicates that options have ended and rest needs to be treated as non option
"--", storeDir.getAbsolutePath() };
command.execute(args);
RepositoryFixture fixture2 = new RepositoryFixture(storeDir);
NodeStore store2 = fixture2.getNodeStore();
PropertyState reindexCount = getNode(store2.getRoot(), "/oak:index/fooIndex").getProperty(IndexConstants.REINDEX_COUNT);
assertEquals(1, reindexCount.getValue(Type.LONG).longValue());
File indexes = new File(outDir, OutOfBandIndexer.LOCAL_INDEX_ROOT_DIR);
assertTrue(indexes.exists());
IndexRootDirectory idxRoot = new IndexRootDirectory(indexes);
List<LocalIndexDir> idxDirs = idxRoot.getAllLocalIndexes();
assertEquals(1, idxDirs.size());
}
Aggregations