|
21 | 21 | import org.elasticsearch.logging.LogManager; |
22 | 22 | import org.elasticsearch.logging.Logger; |
23 | 23 |
|
24 | | -import java.util.HashMap; |
| 24 | +import java.util.LinkedHashMap; |
25 | 25 | import java.util.Map; |
26 | 26 | import java.util.stream.Collectors; |
27 | 27 |
|
@@ -76,7 +76,7 @@ public class UndesiredAllocationsTracker { |
76 | 76 | ); |
77 | 77 |
|
78 | 78 | private final TimeProvider timeProvider; |
79 | | - private final Map<String, UndesiredAllocation> undesiredAllocations = new HashMap<>(); |
| 79 | + private final LinkedHashMap<String, UndesiredAllocation> undesiredAllocations = new LinkedHashMap<>(); |
80 | 80 | private final FrequencyCappedAction undesiredAllocationDurationLogInterval; |
81 | 81 | private volatile TimeValue undesiredAllocationDurationLoggingThreshold; |
82 | 82 | private volatile int maxUndesiredAllocationsToTrack; |
@@ -148,18 +148,15 @@ public void maybeLogUndesiredShardsWarning( |
148 | 148 | DesiredBalance desiredBalance |
149 | 149 | ) { |
150 | 150 | final long currentTimeMillis = timeProvider.relativeTimeInMillis(); |
151 | | - long earliestUndesiredTimestamp = Long.MAX_VALUE; |
152 | | - for (var undesiredAllocation : undesiredAllocations.values()) { |
153 | | - if (undesiredAllocation.undesiredSince() < earliestUndesiredTimestamp) { |
154 | | - earliestUndesiredTimestamp = undesiredAllocation.undesiredSince(); |
| 151 | + if (undesiredAllocations.isEmpty() == false) { |
| 152 | + final long earliestUndesiredTimestamp = undesiredAllocations.firstEntry().getValue().undesiredSince(); |
| 153 | + if (earliestUndesiredTimestamp < currentTimeMillis |
| 154 | + && currentTimeMillis - earliestUndesiredTimestamp > undesiredAllocationDurationLoggingThreshold.millis()) { |
| 155 | + undesiredAllocationDurationLogInterval.maybeExecute( |
| 156 | + () -> logDecisionsForUndesiredShardsOverThreshold(routingNodes, routingAllocation, desiredBalance) |
| 157 | + ); |
155 | 158 | } |
156 | 159 | } |
157 | | - if (earliestUndesiredTimestamp < currentTimeMillis |
158 | | - && currentTimeMillis - earliestUndesiredTimestamp > undesiredAllocationDurationLoggingThreshold.millis()) { |
159 | | - undesiredAllocationDurationLogInterval.maybeExecute( |
160 | | - () -> logDecisionsForUndesiredShardsOverThreshold(routingNodes, routingAllocation, desiredBalance) |
161 | | - ); |
162 | | - } |
163 | 160 | } |
164 | 161 |
|
165 | 162 | private void logDecisionsForUndesiredShardsOverThreshold( |
|
0 commit comments