|
@@ -21,54 +21,32 @@ package org.elasticsearch.index.shard;
|
|
|
|
|
|
import org.elasticsearch.common.metrics.CounterMetric;
|
|
|
import org.elasticsearch.common.metrics.MeanMetric;
|
|
|
-import org.elasticsearch.common.regex.Regex;
|
|
|
-import org.elasticsearch.common.util.Maps;
|
|
|
import org.elasticsearch.index.engine.Engine;
|
|
|
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
-import static java.util.Collections.emptyMap;
|
|
|
-
|
|
|
/**
|
|
|
* Internal class that maintains relevant indexing statistics / metrics.
|
|
|
* @see IndexShard
|
|
|
*/
|
|
|
final class InternalIndexingStats implements IndexingOperationListener {
|
|
|
+
|
|
|
private final StatsHolder totalStats = new StatsHolder();
|
|
|
- private volatile Map<String, StatsHolder> typesStats = emptyMap();
|
|
|
|
|
|
/**
|
|
|
* Returns the stats, including type specific stats. If the types are null/0 length, then nothing
|
|
|
* is returned for them. If they are set, then only types provided will be returned, or
|
|
|
* {@code _all} for all types.
|
|
|
*/
|
|
|
- IndexingStats stats(boolean isThrottled, long currentThrottleInMillis, String... types) {
|
|
|
+ IndexingStats stats(boolean isThrottled, long currentThrottleInMillis) {
|
|
|
IndexingStats.Stats total = totalStats.stats(isThrottled, currentThrottleInMillis);
|
|
|
- Map<String, IndexingStats.Stats> typesSt = null;
|
|
|
- if (types != null && types.length > 0) {
|
|
|
- typesSt = new HashMap<>(typesStats.size());
|
|
|
- if (types.length == 1 && types[0].equals("_all")) {
|
|
|
- for (Map.Entry<String, StatsHolder> entry : typesStats.entrySet()) {
|
|
|
- typesSt.put(entry.getKey(), entry.getValue().stats(isThrottled, currentThrottleInMillis));
|
|
|
- }
|
|
|
- } else {
|
|
|
- for (Map.Entry<String, StatsHolder> entry : typesStats.entrySet()) {
|
|
|
- if (Regex.simpleMatch(types, entry.getKey())) {
|
|
|
- typesSt.put(entry.getKey(), entry.getValue().stats(isThrottled, currentThrottleInMillis));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return new IndexingStats(total, typesSt);
|
|
|
+ return new IndexingStats(total);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Engine.Index preIndex(ShardId shardId, Engine.Index operation) {
|
|
|
if (operation.origin().isRecovery() == false) {
|
|
|
totalStats.indexCurrent.inc();
|
|
|
- typeStats(operation.type()).indexCurrent.inc();
|
|
|
}
|
|
|
return operation;
|
|
|
}
|
|
@@ -81,9 +59,6 @@ final class InternalIndexingStats implements IndexingOperationListener {
|
|
|
long took = result.getTook();
|
|
|
totalStats.indexMetric.inc(took);
|
|
|
totalStats.indexCurrent.dec();
|
|
|
- StatsHolder typeStats = typeStats(index.type());
|
|
|
- typeStats.indexMetric.inc(took);
|
|
|
- typeStats.indexCurrent.dec();
|
|
|
}
|
|
|
break;
|
|
|
case FAILURE:
|
|
@@ -98,9 +73,7 @@ final class InternalIndexingStats implements IndexingOperationListener {
|
|
|
public void postIndex(ShardId shardId, Engine.Index index, Exception ex) {
|
|
|
if (!index.origin().isRecovery()) {
|
|
|
totalStats.indexCurrent.dec();
|
|
|
- typeStats(index.type()).indexCurrent.dec();
|
|
|
totalStats.indexFailed.inc();
|
|
|
- typeStats(index.type()).indexFailed.inc();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -108,7 +81,6 @@ final class InternalIndexingStats implements IndexingOperationListener {
|
|
|
public Engine.Delete preDelete(ShardId shardId, Engine.Delete delete) {
|
|
|
if (!delete.origin().isRecovery()) {
|
|
|
totalStats.deleteCurrent.inc();
|
|
|
- typeStats(delete.type()).deleteCurrent.inc();
|
|
|
}
|
|
|
return delete;
|
|
|
|
|
@@ -122,9 +94,6 @@ final class InternalIndexingStats implements IndexingOperationListener {
|
|
|
long took = result.getTook();
|
|
|
totalStats.deleteMetric.inc(took);
|
|
|
totalStats.deleteCurrent.dec();
|
|
|
- StatsHolder typeStats = typeStats(delete.type());
|
|
|
- typeStats.deleteMetric.inc(took);
|
|
|
- typeStats.deleteCurrent.dec();
|
|
|
}
|
|
|
break;
|
|
|
case FAILURE:
|
|
@@ -139,27 +108,11 @@ final class InternalIndexingStats implements IndexingOperationListener {
|
|
|
public void postDelete(ShardId shardId, Engine.Delete delete, Exception ex) {
|
|
|
if (!delete.origin().isRecovery()) {
|
|
|
totalStats.deleteCurrent.dec();
|
|
|
- typeStats(delete.type()).deleteCurrent.dec();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void noopUpdate(String type) {
|
|
|
+ void noopUpdate() {
|
|
|
totalStats.noopUpdates.inc();
|
|
|
- typeStats(type).noopUpdates.inc();
|
|
|
- }
|
|
|
-
|
|
|
- private StatsHolder typeStats(String type) {
|
|
|
- StatsHolder stats = typesStats.get(type);
|
|
|
- if (stats == null) {
|
|
|
- synchronized (this) {
|
|
|
- stats = typesStats.get(type);
|
|
|
- if (stats == null) {
|
|
|
- stats = new StatsHolder();
|
|
|
- typesStats = Maps.copyMapWithAddedEntry(typesStats, type, stats);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return stats;
|
|
|
}
|
|
|
|
|
|
static class StatsHolder {
|