use of org.apache.jackrabbit.oak.plugins.index.lucene.BadIndexTracker.BadIndexInfo in project jackrabbit-oak by apache.
the class IndexTrackerTest method badIndexAccess.
@Test
public void badIndexAccess() throws Exception {
createIndex("foo");
//1. Create and populate index
NodeState before = builder.getNodeState();
builder.setProperty("foo", "bar");
NodeState after = builder.getNodeState();
NodeState indexed = hook.processCommit(before, after, CommitInfo.EMPTY);
tracker.update(indexed);
IndexNode indexNode = tracker.acquireIndexNode("/oak:index/foo");
indexNode.release();
assertTrue(tracker.getBadIndexTracker().getIndexPaths().isEmpty());
//2. Corrupt the index
builder = indexed.builder();
indexed = corruptIndex("/oak:index/foo");
tracker.update(indexed);
indexNode = tracker.acquireIndexNode("/oak:index/foo");
//Even if the persisted index is corrupted the index should be accessible
//as update would have failed so old copy would be used
assertNotNull(indexNode);
assertFalse(tracker.getBadIndexTracker().getBadPersistedIndexPaths().isEmpty());
//3. Recreate the tracker as we cannot push corrupt index in existing tracker
//As diffAndUpdate would fail and existing IndexNode would not be changed
tracker = new IndexTracker();
tracker.update(indexed);
VirtualTicker ticker = new VirtualTicker();
tracker.getBadIndexTracker().setTicker(ticker);
indexNode = tracker.acquireIndexNode("/oak:index/foo");
//Index must be corrupted hence it must be null
assertNull(indexNode);
assertTrue(tracker.getBadIndexTracker().getIndexPaths().contains("/oak:index/foo"));
BadIndexInfo badIdxInfo = tracker.getBadIndexTracker().getInfo("/oak:index/foo");
assertNotNull(badIdxInfo);
assertEquals(0, badIdxInfo.getAccessCount());
//Try to access again
indexNode = tracker.acquireIndexNode("/oak:index/foo");
assertEquals(1, badIdxInfo.getAccessCount());
assertEquals(0, badIdxInfo.getFailedAccessCount());
indexNode = tracker.acquireIndexNode("/oak:index/foo");
assertEquals(2, badIdxInfo.getAccessCount());
assertEquals(0, badIdxInfo.getFailedAccessCount());
//5. Move clock forward
ticker.addTime(tracker.getBadIndexTracker().getRecheckIntervalMillis() + 1, TimeUnit.MILLISECONDS);
//Now index access must be attempted again
indexNode = tracker.acquireIndexNode("/oak:index/foo");
assertEquals(3, badIdxInfo.getAccessCount());
assertEquals(1, badIdxInfo.getFailedAccessCount());
//6. Now lets reindex to fix the corruption
builder = indexed.builder();
before = indexed;
after = reindex("/oak:index/foo");
indexed = hook.processCommit(before, after, CommitInfo.EMPTY);
tracker.update(indexed);
//7. Now indexNode should be accessible
indexNode = tracker.acquireIndexNode("/oak:index/foo");
assertNotNull(indexNode);
//And this index would not be considered bad
badIdxInfo = tracker.getBadIndexTracker().getInfo("/oak:index/foo");
assertNull(badIdxInfo);
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.BadIndexTracker.BadIndexInfo in project jackrabbit-oak by apache.
the class LuceneIndexMBeanImpl method getBadPersistedIndexStats.
@Override
public TabularData getBadPersistedIndexStats() {
TabularDataSupport tds;
try {
TabularType tt = new TabularType(LuceneIndexMBeanImpl.class.getName(), "Lucene Bad Persisted Index Stats", BadIndexStats.TYPE, new String[] { "path" });
tds = new TabularDataSupport(tt);
Set<String> indexes = indexTracker.getBadIndexTracker().getBadPersistedIndexPaths();
for (String path : indexes) {
BadIndexInfo info = indexTracker.getBadIndexTracker().getPersistedIndexInfo(path);
if (info != null) {
BadIndexStats stats = new BadIndexStats(info);
tds.put(stats.toCompositeData());
}
}
} catch (OpenDataException e) {
throw new IllegalStateException(e);
}
return tds;
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.BadIndexTracker.BadIndexInfo in project jackrabbit-oak by apache.
the class LuceneIndexMBeanImpl method getBadIndexStats.
@Override
public TabularData getBadIndexStats() {
TabularDataSupport tds;
try {
TabularType tt = new TabularType(LuceneIndexMBeanImpl.class.getName(), "Lucene Bad Index Stats", BadIndexStats.TYPE, new String[] { "path" });
tds = new TabularDataSupport(tt);
Set<String> indexes = indexTracker.getBadIndexTracker().getIndexPaths();
for (String path : indexes) {
BadIndexInfo info = indexTracker.getBadIndexTracker().getInfo(path);
if (info != null) {
BadIndexStats stats = new BadIndexStats(info);
tds.put(stats.toCompositeData());
}
}
} catch (OpenDataException e) {
throw new IllegalStateException(e);
}
return tds;
}
Aggregations