|
35 | 35 | import org.apache.logging.log4j.LogManager;
|
36 | 36 | import org.apache.logging.log4j.Logger;
|
37 | 37 | import org.apache.lucene.util.IntroSorter;
|
| 38 | +import org.opensearch.cluster.routing.RerouteService; |
38 | 39 | import org.opensearch.cluster.routing.RoutingNode;
|
39 | 40 | import org.opensearch.cluster.routing.RoutingNodes;
|
40 | 41 | import org.opensearch.cluster.routing.ShardMovementStrategy;
|
|
49 | 50 | import org.opensearch.cluster.routing.allocation.RebalanceParameter;
|
50 | 51 | import org.opensearch.cluster.routing.allocation.RoutingAllocation;
|
51 | 52 | import org.opensearch.cluster.routing.allocation.ShardAllocationDecision;
|
| 53 | +import org.opensearch.common.Priority; |
52 | 54 | import org.opensearch.common.inject.Inject;
|
53 | 55 | import org.opensearch.common.settings.ClusterSettings;
|
54 | 56 | import org.opensearch.common.settings.Setting;
|
55 | 57 | import org.opensearch.common.settings.Setting.Property;
|
56 | 58 | import org.opensearch.common.settings.Settings;
|
57 | 59 | import org.opensearch.common.unit.TimeValue;
|
| 60 | +import org.opensearch.core.action.ActionListener; |
58 | 61 |
|
59 | 62 | import java.util.HashMap;
|
60 | 63 | import java.util.HashSet;
|
@@ -202,6 +205,7 @@ public class BalancedShardsAllocator implements ShardsAllocator {
|
202 | 205 | private volatile boolean ignoreThrottleInRestore;
|
203 | 206 | private volatile TimeValue allocatorTimeout;
|
204 | 207 | private long startTime;
|
| 208 | + private RerouteService rerouteService; |
205 | 209 |
|
206 | 210 | public BalancedShardsAllocator(Settings settings) {
|
207 | 211 | this(settings, new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS));
|
@@ -231,6 +235,12 @@ public BalancedShardsAllocator(Settings settings, ClusterSettings clusterSetting
|
231 | 235 | clusterSettings.addSettingsUpdateConsumer(ALLOCATOR_TIMEOUT_SETTING, this::setAllocatorTimeout);
|
232 | 236 | }
|
233 | 237 |
|
| 238 | + @Override |
| 239 | + public void setRerouteService(RerouteService rerouteService) { |
| 240 | + assert this.rerouteService == null : "RerouteService is already set"; |
| 241 | + this.rerouteService = rerouteService; |
| 242 | + } |
| 243 | + |
234 | 244 | /**
|
235 | 245 | * Changes in deprecated setting SHARD_MOVE_PRIMARY_FIRST_SETTING affect value of its replacement setting SHARD_MOVEMENT_STRATEGY_SETTING.
|
236 | 246 | */
|
@@ -342,6 +352,7 @@ public void allocate(RoutingAllocation allocation) {
|
342 | 352 | localShardsBalancer.allocateUnassigned();
|
343 | 353 | localShardsBalancer.moveShards();
|
344 | 354 | localShardsBalancer.balance();
|
| 355 | + scheduleRerouteIfAllocatorTimedOut(); |
345 | 356 |
|
346 | 357 | final ShardsBalancer remoteShardsBalancer = new RemoteShardsBalancer(logger, allocation);
|
347 | 358 | remoteShardsBalancer.allocateUnassigned();
|
@@ -404,6 +415,20 @@ private void failAllocationOfNewPrimaries(RoutingAllocation allocation) {
|
404 | 415 | }
|
405 | 416 | }
|
406 | 417 |
|
| 418 | + private void scheduleRerouteIfAllocatorTimedOut() { |
| 419 | + if (allocatorTimedOut()) { |
| 420 | + assert rerouteService != null : "RerouteService not set to schedule reroute after allocator time out"; |
| 421 | + rerouteService.reroute( |
| 422 | + "reroute after balanced shards allocator timed out", |
| 423 | + Priority.HIGH, |
| 424 | + ActionListener.wrap( |
| 425 | + r -> logger.trace("reroute after balanced shards allocator timed out completed"), |
| 426 | + e -> logger.debug("reroute after balanced shards allocator timed out failed", e) |
| 427 | + ) |
| 428 | + ); |
| 429 | + } |
| 430 | + } |
| 431 | + |
407 | 432 | /**
|
408 | 433 | * Returns the currently configured delta threshold
|
409 | 434 | */
|
|
0 commit comments