Skip to content

Commit

Permalink
Remove dead code from ShardSearchStats (#37421)
Browse files Browse the repository at this point in the history
The clear methodsa are unused and unsafe at this point. This commit
removes the dead code.
  • Loading branch information
s1monw authored Jan 15, 2019
1 parent bf49f54 commit 147c5e6
Showing 1 changed file with 12 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,27 +122,11 @@ public void onFetchPhase(SearchContext searchContext, long tookInNanos) {
});
}

public void clear() {
totalStats.clear();
synchronized (this) {
if (!groupsStats.isEmpty()) {
MapBuilder<String, StatsHolder> typesStatsBuilder = MapBuilder.newMapBuilder();
for (Map.Entry<String, StatsHolder> typeStats : groupsStats.entrySet()) {
if (typeStats.getValue().totalCurrent() > 0) {
typeStats.getValue().clear();
typesStatsBuilder.put(typeStats.getKey(), typeStats.getValue());
}
}
groupsStats = typesStatsBuilder.immutableMap();
}
}
}

private void computeStats(SearchContext searchContext, Consumer<StatsHolder> consumer) {
consumer.accept(totalStats);
if (searchContext.groupStats() != null) {
for (int i = 0; i < searchContext.groupStats().size(); i++) {
consumer.accept(groupStats(searchContext.groupStats().get(i)));
for (String group : searchContext.groupStats()) {
consumer.accept(groupStats(group));
}
}
}
Expand Down Expand Up @@ -184,40 +168,29 @@ public void onFreeScrollContext(SearchContext context) {
}

static final class StatsHolder {
public final MeanMetric queryMetric = new MeanMetric();
public final MeanMetric fetchMetric = new MeanMetric();
final MeanMetric queryMetric = new MeanMetric();
final MeanMetric fetchMetric = new MeanMetric();
/* We store scroll statistics in microseconds because with nanoseconds we run the risk of overflowing the total stats if there are
* many scrolls. For example, on a system with 2^24 scrolls that have been executed, each executing for 2^10 seconds, then using
* nanoseconds would require a numeric representation that can represent at least 2^24 * 2^10 * 10^9 > 2^24 * 2^10 * 2^29 = 2^63
* which exceeds the largest value that can be represented by a long. By using microseconds, we enable capturing one-thousand
* times as many scrolls (i.e., billions of scrolls which at one per second would take 32 years to occur), or scrolls that execute
* for one-thousand times as long (i.e., scrolls that execute for almost twelve days on average).
*/
public final MeanMetric scrollMetric = new MeanMetric();
public final MeanMetric suggestMetric = new MeanMetric();
public final CounterMetric queryCurrent = new CounterMetric();
public final CounterMetric fetchCurrent = new CounterMetric();
public final CounterMetric scrollCurrent = new CounterMetric();
public final CounterMetric suggestCurrent = new CounterMetric();

public SearchStats.Stats stats() {
final MeanMetric scrollMetric = new MeanMetric();
final MeanMetric suggestMetric = new MeanMetric();
final CounterMetric queryCurrent = new CounterMetric();
final CounterMetric fetchCurrent = new CounterMetric();
final CounterMetric scrollCurrent = new CounterMetric();
final CounterMetric suggestCurrent = new CounterMetric();

SearchStats.Stats stats() {
return new SearchStats.Stats(
queryMetric.count(), TimeUnit.NANOSECONDS.toMillis(queryMetric.sum()), queryCurrent.count(),
fetchMetric.count(), TimeUnit.NANOSECONDS.toMillis(fetchMetric.sum()), fetchCurrent.count(),
scrollMetric.count(), TimeUnit.MICROSECONDS.toMillis(scrollMetric.sum()), scrollCurrent.count(),
suggestMetric.count(), TimeUnit.NANOSECONDS.toMillis(suggestMetric.sum()), suggestCurrent.count()
);
}

public long totalCurrent() {
return queryCurrent.count() + fetchCurrent.count() + scrollCurrent.count() + suggestCurrent.count();
}

public void clear() {
queryMetric.clear();
fetchMetric.clear();
scrollMetric.clear();
suggestMetric.clear();
}
}
}

0 comments on commit 147c5e6

Please sign in to comment.