Search in sources :

Example 1 with LocalIndexDir

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;
}
Also used : OpenDataException(javax.management.openmbean.OpenDataException) TabularDataSupport(javax.management.openmbean.TabularDataSupport) TabularType(javax.management.openmbean.TabularType) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) LocalIndexDir(org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexDir) IOException(java.io.IOException)

Example 2 with LocalIndexDir

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());
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) LuceneIndexHelper.newLucenePropertyIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition) LuceneIndexHelper.newLuceneIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition) LocalIndexDir(org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexDir) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) File(java.io.File) Test(org.junit.Test)

Example 3 with LocalIndexDir

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());
}
Also used : NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) IndexRootDirectory(org.apache.jackrabbit.oak.plugins.index.lucene.directory.IndexRootDirectory) LocalIndexDir(org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexDir) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) File(java.io.File) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Test(org.junit.Test)

Aggregations

LocalIndexDir (org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexDir)3 File (java.io.File)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)1 OpenDataException (javax.management.openmbean.OpenDataException)1 TabularDataSupport (javax.management.openmbean.TabularDataSupport)1 TabularType (javax.management.openmbean.TabularType)1 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)1 IndexRootDirectory (org.apache.jackrabbit.oak.plugins.index.lucene.directory.IndexRootDirectory)1 LuceneIndexHelper.newLuceneIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition)1 LuceneIndexHelper.newLucenePropertyIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition)1 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)1 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)1 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1