Don't take recovery indexing into account on indexing stats

Closes #17412
This commit is contained in:
Simon Willnauer 2016-03-30 16:42:02 +02:00
parent e25ccb91ae
commit dbcb9a29a5
3 changed files with 44 additions and 24 deletions

View File

@ -128,7 +128,7 @@ public class IndexShard extends AbstractIndexShardComponent {
private final IndexCache indexCache; private final IndexCache indexCache;
private final Store store; private final Store store;
private final InternalIndexingStats internalIndexingStats; private final InternalIndexingStats internalIndexingStats;
private final ShardSearchStats searchStats = new ShardSearchStats();; private final ShardSearchStats searchStats = new ShardSearchStats();
private final ShardGetService getService; private final ShardGetService getService;
private final ShardIndexWarmerService shardWarmerService; private final ShardIndexWarmerService shardWarmerService;
private final ShardRequestCache shardQueryCache; private final ShardRequestCache shardQueryCache;

View File

@ -66,13 +66,16 @@ final class InternalIndexingStats implements IndexingOperationListener {
@Override @Override
public Engine.Index preIndex(Engine.Index operation) { public Engine.Index preIndex(Engine.Index operation) {
if (operation.origin() != Engine.Operation.Origin.RECOVERY) {
totalStats.indexCurrent.inc(); totalStats.indexCurrent.inc();
typeStats(operation.type()).indexCurrent.inc(); typeStats(operation.type()).indexCurrent.inc();
}
return operation; return operation;
} }
@Override @Override
public void postIndex(Engine.Index index, boolean created) { public void postIndex(Engine.Index index, boolean created) {
if (index.origin() != Engine.Operation.Origin.RECOVERY) {
long took = index.endTime() - index.startTime(); long took = index.endTime() - index.startTime();
totalStats.indexMetric.inc(took); totalStats.indexMetric.inc(took);
totalStats.indexCurrent.dec(); totalStats.indexCurrent.dec();
@ -80,24 +83,31 @@ final class InternalIndexingStats implements IndexingOperationListener {
typeStats.indexMetric.inc(took); typeStats.indexMetric.inc(took);
typeStats.indexCurrent.dec(); typeStats.indexCurrent.dec();
} }
}
@Override @Override
public void postIndex(Engine.Index index, Throwable ex) { public void postIndex(Engine.Index index, Throwable ex) {
if (index.origin() != Engine.Operation.Origin.RECOVERY) {
totalStats.indexCurrent.dec(); totalStats.indexCurrent.dec();
typeStats(index.type()).indexCurrent.dec(); typeStats(index.type()).indexCurrent.dec();
totalStats.indexFailed.inc(); totalStats.indexFailed.inc();
typeStats(index.type()).indexFailed.inc(); typeStats(index.type()).indexFailed.inc();
} }
}
@Override @Override
public Engine.Delete preDelete(Engine.Delete delete) { public Engine.Delete preDelete(Engine.Delete delete) {
if (delete.origin() != Engine.Operation.Origin.RECOVERY) {
totalStats.deleteCurrent.inc(); totalStats.deleteCurrent.inc();
typeStats(delete.type()).deleteCurrent.inc(); typeStats(delete.type()).deleteCurrent.inc();
}
return delete; return delete;
} }
@Override @Override
public void postDelete(Engine.Delete delete) { public void postDelete(Engine.Delete delete) {
if (delete.origin() != Engine.Operation.Origin.RECOVERY) {
long took = delete.endTime() - delete.startTime(); long took = delete.endTime() - delete.startTime();
totalStats.deleteMetric.inc(took); totalStats.deleteMetric.inc(took);
totalStats.deleteCurrent.dec(); totalStats.deleteCurrent.dec();
@ -105,12 +115,15 @@ final class InternalIndexingStats implements IndexingOperationListener {
typeStats.deleteMetric.inc(took); typeStats.deleteMetric.inc(took);
typeStats.deleteCurrent.dec(); typeStats.deleteCurrent.dec();
} }
}
@Override @Override
public void postDelete(Engine.Delete delete, Throwable ex) { public void postDelete(Engine.Delete delete, Throwable ex) {
if (delete.origin() != Engine.Operation.Origin.RECOVERY) {
totalStats.deleteCurrent.dec(); totalStats.deleteCurrent.dec();
typeStats(delete.type()).deleteCurrent.dec(); typeStats(delete.type()).deleteCurrent.dec();
} }
}
public void noopUpdate(String type) { public void noopUpdate(String type) {
totalStats.noopUpdates.inc(); totalStats.noopUpdates.inc();

View File

@ -1242,7 +1242,7 @@ public class IndexShardTests extends ESSingleNodeTestCase {
FieldDataStats after = null; FieldDataStats after = null;
try (Engine.Searcher searcher = newShard.acquireSearcher("test")) { try (Engine.Searcher searcher = newShard.acquireSearcher("test")) {
assumeTrue("we have to have more than one segment", searcher.getDirectoryReader().leaves().size() > 1); assumeTrue("we have to have more than one segment", searcher.getDirectoryReader().leaves().size() > 1);
IndexFieldData indexFieldData = ifd.loadGlobal(searcher.getDirectoryReader()); ifd.loadGlobal(searcher.getDirectoryReader());
after = shard.fieldData().stats("foo"); after = shard.fieldData().stats("foo");
assertEquals(after.getEvictions(), before.getEvictions()); assertEquals(after.getEvictions(), before.getEvictions());
// If a field doesn't exist an empty IndexFieldData is returned and that isn't cached: // If a field doesn't exist an empty IndexFieldData is returned and that isn't cached:
@ -1301,6 +1301,13 @@ public class IndexShardTests extends ESSingleNodeTestCase {
}; };
final IndexShard newShard = reinitWithWrapper(indexService, shard, wrapper, listener); final IndexShard newShard = reinitWithWrapper(indexService, shard, wrapper, listener);
try { try {
IndexingStats indexingStats = newShard.indexingStats();
// ensure we are not influencing the indexing stats
assertEquals(0, indexingStats.getTotal().getDeleteCount());
assertEquals(0, indexingStats.getTotal().getDeleteCurrent());
assertEquals(0, indexingStats.getTotal().getIndexCount());
assertEquals(0, indexingStats.getTotal().getIndexCurrent());
assertEquals(0, indexingStats.getTotal().getIndexFailedCount());
assertEquals(2, preIndex.get()); assertEquals(2, preIndex.get());
assertEquals(2, postIndex.get()); assertEquals(2, postIndex.get());
assertEquals(1, preDelete.get()); assertEquals(1, preDelete.get());