diff --git a/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java b/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java index 42d68178299..97526b4141f 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java +++ b/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java @@ -128,7 +128,7 @@ public class IndexShard extends AbstractIndexShardComponent { private final IndexCache indexCache; private final Store store; private final InternalIndexingStats internalIndexingStats; - private final ShardSearchStats searchStats = new ShardSearchStats();; + private final ShardSearchStats searchStats = new ShardSearchStats(); private final ShardGetService getService; private final ShardIndexWarmerService shardWarmerService; private final ShardRequestCache shardQueryCache; diff --git a/core/src/main/java/org/elasticsearch/index/shard/InternalIndexingStats.java b/core/src/main/java/org/elasticsearch/index/shard/InternalIndexingStats.java index ce893e2d3d9..1faee2f6510 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/InternalIndexingStats.java +++ b/core/src/main/java/org/elasticsearch/index/shard/InternalIndexingStats.java @@ -66,50 +66,63 @@ final class InternalIndexingStats implements IndexingOperationListener { @Override public Engine.Index preIndex(Engine.Index operation) { - totalStats.indexCurrent.inc(); - typeStats(operation.type()).indexCurrent.inc(); + if (operation.origin() != Engine.Operation.Origin.RECOVERY) { + totalStats.indexCurrent.inc(); + typeStats(operation.type()).indexCurrent.inc(); + } return operation; } @Override public void postIndex(Engine.Index index, boolean created) { - long took = index.endTime() - index.startTime(); - totalStats.indexMetric.inc(took); - totalStats.indexCurrent.dec(); - StatsHolder typeStats = typeStats(index.type()); - typeStats.indexMetric.inc(took); - typeStats.indexCurrent.dec(); + if (index.origin() != Engine.Operation.Origin.RECOVERY) { + long took = index.endTime() - index.startTime(); + totalStats.indexMetric.inc(took); + totalStats.indexCurrent.dec(); + StatsHolder typeStats = typeStats(index.type()); + typeStats.indexMetric.inc(took); + typeStats.indexCurrent.dec(); + } } @Override public void postIndex(Engine.Index index, Throwable ex) { - totalStats.indexCurrent.dec(); - typeStats(index.type()).indexCurrent.dec(); - totalStats.indexFailed.inc(); - typeStats(index.type()).indexFailed.inc(); + if (index.origin() != Engine.Operation.Origin.RECOVERY) { + totalStats.indexCurrent.dec(); + typeStats(index.type()).indexCurrent.dec(); + totalStats.indexFailed.inc(); + typeStats(index.type()).indexFailed.inc(); + } } @Override public Engine.Delete preDelete(Engine.Delete delete) { - totalStats.deleteCurrent.inc(); - typeStats(delete.type()).deleteCurrent.inc(); + if (delete.origin() != Engine.Operation.Origin.RECOVERY) { + totalStats.deleteCurrent.inc(); + typeStats(delete.type()).deleteCurrent.inc(); + } return delete; + } @Override public void postDelete(Engine.Delete delete) { - long took = delete.endTime() - delete.startTime(); - totalStats.deleteMetric.inc(took); - totalStats.deleteCurrent.dec(); - StatsHolder typeStats = typeStats(delete.type()); - typeStats.deleteMetric.inc(took); - typeStats.deleteCurrent.dec(); + if (delete.origin() != Engine.Operation.Origin.RECOVERY) { + long took = delete.endTime() - delete.startTime(); + totalStats.deleteMetric.inc(took); + totalStats.deleteCurrent.dec(); + StatsHolder typeStats = typeStats(delete.type()); + typeStats.deleteMetric.inc(took); + typeStats.deleteCurrent.dec(); + } } @Override public void postDelete(Engine.Delete delete, Throwable ex) { - totalStats.deleteCurrent.dec(); - typeStats(delete.type()).deleteCurrent.dec(); + if (delete.origin() != Engine.Operation.Origin.RECOVERY) { + totalStats.deleteCurrent.dec(); + typeStats(delete.type()).deleteCurrent.dec(); + } } public void noopUpdate(String type) { diff --git a/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java b/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java index 16ffa521bd6..c488fc2b35c 100644 --- a/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java +++ b/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java @@ -1242,7 +1242,7 @@ public class IndexShardTests extends ESSingleNodeTestCase { FieldDataStats after = null; try (Engine.Searcher searcher = newShard.acquireSearcher("test")) { 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"); assertEquals(after.getEvictions(), before.getEvictions()); // 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); 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, postIndex.get()); assertEquals(1, preDelete.get());