Skip to content

Commit 147c5e6

Browse files
authored
Remove dead code from ShardSearchStats (elastic#37421)
The clear methodsa are unused and unsafe at this point. This commit removes the dead code.
1 parent bf49f54 commit 147c5e6

File tree

1 file changed

+12
-39
lines changed

1 file changed

+12
-39
lines changed

server/src/main/java/org/elasticsearch/index/search/stats/ShardSearchStats.java

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -122,27 +122,11 @@ public void onFetchPhase(SearchContext searchContext, long tookInNanos) {
122122
});
123123
}
124124

125-
public void clear() {
126-
totalStats.clear();
127-
synchronized (this) {
128-
if (!groupsStats.isEmpty()) {
129-
MapBuilder<String, StatsHolder> typesStatsBuilder = MapBuilder.newMapBuilder();
130-
for (Map.Entry<String, StatsHolder> typeStats : groupsStats.entrySet()) {
131-
if (typeStats.getValue().totalCurrent() > 0) {
132-
typeStats.getValue().clear();
133-
typesStatsBuilder.put(typeStats.getKey(), typeStats.getValue());
134-
}
135-
}
136-
groupsStats = typesStatsBuilder.immutableMap();
137-
}
138-
}
139-
}
140-
141125
private void computeStats(SearchContext searchContext, Consumer<StatsHolder> consumer) {
142126
consumer.accept(totalStats);
143127
if (searchContext.groupStats() != null) {
144-
for (int i = 0; i < searchContext.groupStats().size(); i++) {
145-
consumer.accept(groupStats(searchContext.groupStats().get(i)));
128+
for (String group : searchContext.groupStats()) {
129+
consumer.accept(groupStats(group));
146130
}
147131
}
148132
}
@@ -184,40 +168,29 @@ public void onFreeScrollContext(SearchContext context) {
184168
}
185169

186170
static final class StatsHolder {
187-
public final MeanMetric queryMetric = new MeanMetric();
188-
public final MeanMetric fetchMetric = new MeanMetric();
171+
final MeanMetric queryMetric = new MeanMetric();
172+
final MeanMetric fetchMetric = new MeanMetric();
189173
/* We store scroll statistics in microseconds because with nanoseconds we run the risk of overflowing the total stats if there are
190174
* many scrolls. For example, on a system with 2^24 scrolls that have been executed, each executing for 2^10 seconds, then using
191175
* 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
192176
* which exceeds the largest value that can be represented by a long. By using microseconds, we enable capturing one-thousand
193177
* times as many scrolls (i.e., billions of scrolls which at one per second would take 32 years to occur), or scrolls that execute
194178
* for one-thousand times as long (i.e., scrolls that execute for almost twelve days on average).
195179
*/
196-
public final MeanMetric scrollMetric = new MeanMetric();
197-
public final MeanMetric suggestMetric = new MeanMetric();
198-
public final CounterMetric queryCurrent = new CounterMetric();
199-
public final CounterMetric fetchCurrent = new CounterMetric();
200-
public final CounterMetric scrollCurrent = new CounterMetric();
201-
public final CounterMetric suggestCurrent = new CounterMetric();
202-
203-
public SearchStats.Stats stats() {
180+
final MeanMetric scrollMetric = new MeanMetric();
181+
final MeanMetric suggestMetric = new MeanMetric();
182+
final CounterMetric queryCurrent = new CounterMetric();
183+
final CounterMetric fetchCurrent = new CounterMetric();
184+
final CounterMetric scrollCurrent = new CounterMetric();
185+
final CounterMetric suggestCurrent = new CounterMetric();
186+
187+
SearchStats.Stats stats() {
204188
return new SearchStats.Stats(
205189
queryMetric.count(), TimeUnit.NANOSECONDS.toMillis(queryMetric.sum()), queryCurrent.count(),
206190
fetchMetric.count(), TimeUnit.NANOSECONDS.toMillis(fetchMetric.sum()), fetchCurrent.count(),
207191
scrollMetric.count(), TimeUnit.MICROSECONDS.toMillis(scrollMetric.sum()), scrollCurrent.count(),
208192
suggestMetric.count(), TimeUnit.NANOSECONDS.toMillis(suggestMetric.sum()), suggestCurrent.count()
209193
);
210194
}
211-
212-
public long totalCurrent() {
213-
return queryCurrent.count() + fetchCurrent.count() + scrollCurrent.count() + suggestCurrent.count();
214-
}
215-
216-
public void clear() {
217-
queryMetric.clear();
218-
fetchMetric.clear();
219-
scrollMetric.clear();
220-
suggestMetric.clear();
221-
}
222195
}
223196
}

0 commit comments

Comments
 (0)