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 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;

View File

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

View File

@ -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());