Skip to content

Commit d3dd95a

Browse files
committed
extraction
1 parent f340579 commit d3dd95a

File tree

1 file changed

+33
-23
lines changed

1 file changed

+33
-23
lines changed

server/src/main/java/org/elasticsearch/cluster/InternalClusterInfoService.java

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -201,34 +201,44 @@ void execute() {
201201
logger.trace("starting async refresh");
202202

203203
try (var ignoredRefs = fetchRefs) {
204-
if (diskThresholdEnabled) {
205-
try (var ignored = threadPool.getThreadContext().clearTraceContext()) {
206-
fetchIndicesStats();
207-
}
208-
} else {
209-
logger.trace("skipping collecting disk usage info from cluster, notifying listeners with empty cluster info");
210-
indicesStatsSummary = IndicesStatsSummary.EMPTY;
204+
maybeFetchIndicesStats(diskThresholdEnabled);
205+
maybeFetchNodeStats(diskThresholdEnabled || shardHeapThresholdEnabled);
206+
maybeFetchNodesHeapUsage(shardHeapThresholdEnabled);
207+
}
208+
}
209+
210+
private void maybeFetchIndicesStats(boolean shouldFetch) {
211+
if (shouldFetch) {
212+
try (var ignored = threadPool.getThreadContext().clearTraceContext()) {
213+
fetchIndicesStats();
211214
}
215+
} else {
216+
logger.trace("skipping collecting disk usage info from cluster, notifying listeners with empty indices stats");
217+
indicesStatsSummary = IndicesStatsSummary.EMPTY;
218+
}
219+
}
212220

213-
if (diskThresholdEnabled || shardHeapThresholdEnabled) {
214-
try (var ignored = threadPool.getThreadContext().clearTraceContext()) {
215-
fetchNodeStats();
216-
}
217-
} else {
218-
logger.trace("skipping collecting node stats from cluster, notifying listeners with empty node stats");
219-
leastAvailableSpaceUsages = Map.of();
220-
mostAvailableSpaceUsages = Map.of();
221-
maxHeapPerNode = Map.of();
221+
private void maybeFetchNodeStats(boolean shouldFetch) {
222+
if (shouldFetch) {
223+
try (var ignored = threadPool.getThreadContext().clearTraceContext()) {
224+
fetchNodeStats();
222225
}
226+
} else {
227+
logger.trace("skipping collecting node stats from cluster, notifying listeners with empty node stats");
228+
leastAvailableSpaceUsages = Map.of();
229+
mostAvailableSpaceUsages = Map.of();
230+
maxHeapPerNode = Map.of();
231+
}
232+
}
223233

224-
if (shardHeapThresholdEnabled) {
225-
try (var ignored = threadPool.getThreadContext().clearTraceContext()) {
226-
fetchNodesHeapUsage();
227-
}
228-
} else {
229-
logger.trace("skipping collecting shard heap usage from cluster, notifying listeners with empty shard heap usage");
230-
shardHeapUsagePerNode = Map.of();
234+
private void maybeFetchNodesHeapUsage(boolean shouldFetch) {
235+
if (shouldFetch) {
236+
try (var ignored = threadPool.getThreadContext().clearTraceContext()) {
237+
fetchNodesHeapUsage();
231238
}
239+
} else {
240+
logger.trace("skipping collecting shard heap usage from cluster, notifying listeners with empty shard heap usage");
241+
shardHeapUsagePerNode = Map.of();
232242
}
233243
}
234244

0 commit comments

Comments
 (0)