Skip to content

Commit 6a448d0

Browse files
committed
Add setting for ESA
Signed-off-by: Rishab Nahata <[email protected]>
1 parent 5e83a92 commit 6a448d0

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

server/src/main/java/org/opensearch/common/settings/ClusterSettings.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ public void apply(Settings value, Settings current, Settings previous) {
276276
BalancedShardsAllocator.THRESHOLD_SETTING,
277277
BalancedShardsAllocator.IGNORE_THROTTLE_FOR_REMOTE_RESTORE,
278278
BalancedShardsAllocator.ALLOCATOR_TIMEOUT_SETTING,
279+
BalancedShardsAllocator.FOLLOW_UP_REROUTE_PRIORITY_SETTING,
279280
BreakerSettings.CIRCUIT_BREAKER_LIMIT_SETTING,
280281
BreakerSettings.CIRCUIT_BREAKER_OVERHEAD_SETTING,
281282
BreakerSettings.CIRCUIT_BREAKER_TYPE,
@@ -353,6 +354,7 @@ public void apply(Settings value, Settings current, Settings previous) {
353354
ShardsBatchGatewayAllocator.GATEWAY_ALLOCATOR_BATCH_SIZE,
354355
ShardsBatchGatewayAllocator.PRIMARY_BATCH_ALLOCATOR_TIMEOUT_SETTING,
355356
ShardsBatchGatewayAllocator.REPLICA_BATCH_ALLOCATOR_TIMEOUT_SETTING,
357+
ShardsBatchGatewayAllocator.FOLLOW_UP_REROUTE_PRIORITY_SETTING,
356358
PersistedClusterStateService.SLOW_WRITE_LOGGING_THRESHOLD,
357359
NetworkModule.HTTP_DEFAULT_TYPE_SETTING,
358360
NetworkModule.TRANSPORT_DEFAULT_TYPE_SETTING,

server/src/main/java/org/opensearch/gateway/ShardsBatchGatewayAllocator.java

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import java.util.HashSet;
5454
import java.util.Iterator;
5555
import java.util.List;
56+
import java.util.Locale;
5657
import java.util.Map;
5758
import java.util.Objects;
5859
import java.util.Set;
@@ -82,6 +83,7 @@ public class ShardsBatchGatewayAllocator implements ExistingShardsAllocator {
8283

8384
private TimeValue primaryShardsBatchGatewayAllocatorTimeout;
8485
private TimeValue replicaShardsBatchGatewayAllocatorTimeout;
86+
private volatile Priority followUpRerouteTaskPriority;
8587
public static final TimeValue MIN_ALLOCATOR_TIMEOUT = TimeValue.timeValueSeconds(20);
8688
private final ClusterManagerMetrics clusterManagerMetrics;
8789

@@ -145,6 +147,32 @@ public void validate(TimeValue timeValue) {
145147
Setting.Property.Dynamic
146148
);
147149

150+
/**
151+
* Adjusts the priority of the followup reroute task when current round times out. NORMAL is right for reasonable clusters,
152+
* but for a cluster in a messed up state which is starving NORMAL priority tasks, it might be necessary to raise this higher
153+
* to allocate existing shards.
154+
*/
155+
public static final Setting<Priority> FOLLOW_UP_REROUTE_PRIORITY_SETTING = new Setting<>(
156+
"cluster.routing.allocation.shards_batch_gateway_allocator.schedule_reroute.priority",
157+
Priority.NORMAL.toString(),
158+
ShardsBatchGatewayAllocator::parseReroutePriority,
159+
Setting.Property.NodeScope,
160+
Setting.Property.Dynamic
161+
);
162+
163+
private static Priority parseReroutePriority(String priorityString) {
164+
final Priority priority = Priority.valueOf(priorityString.toUpperCase(Locale.ROOT));
165+
switch (priority) {
166+
case NORMAL:
167+
case HIGH:
168+
case URGENT:
169+
return priority;
170+
}
171+
throw new IllegalArgumentException(
172+
"priority [" + priority + "] not supported for [" + FOLLOW_UP_REROUTE_PRIORITY_SETTING.getKey() + "]"
173+
);
174+
}
175+
148176
private final RerouteService rerouteService;
149177
private final PrimaryShardBatchAllocator primaryShardBatchAllocator;
150178
private final ReplicaShardBatchAllocator replicaShardBatchAllocator;
@@ -179,6 +207,8 @@ public ShardsBatchGatewayAllocator(
179207
this.replicaShardsBatchGatewayAllocatorTimeout = REPLICA_BATCH_ALLOCATOR_TIMEOUT_SETTING.get(settings);
180208
clusterSettings.addSettingsUpdateConsumer(REPLICA_BATCH_ALLOCATOR_TIMEOUT_SETTING, this::setReplicaBatchAllocatorTimeout);
181209
this.clusterManagerMetrics = clusterManagerMetrics;
210+
setFollowUpRerouteTaskPriority(FOLLOW_UP_REROUTE_PRIORITY_SETTING.get(settings));
211+
clusterSettings.addSettingsUpdateConsumer(FOLLOW_UP_REROUTE_PRIORITY_SETTING, this::setFollowUpRerouteTaskPriority);
182212
}
183213

184214
@Override
@@ -309,7 +339,7 @@ public void onComplete() {
309339
assert rerouteService != null;
310340
rerouteService.reroute(
311341
"reroute after existing shards allocator [P] timed out",
312-
Priority.NORMAL,
342+
followUpRerouteTaskPriority,
313343
ActionListener.wrap(
314344
r -> logger.trace("reroute after existing shards allocator timed out completed"),
315345
e -> logger.debug("reroute after existing shards allocator timed out failed", e)
@@ -344,7 +374,7 @@ public void onComplete() {
344374
assert rerouteService != null;
345375
rerouteService.reroute(
346376
"reroute after existing shards allocator [R] timed out",
347-
Priority.NORMAL,
377+
followUpRerouteTaskPriority,
348378
ActionListener.wrap(
349379
r -> logger.trace("reroute after existing shards allocator timed out completed"),
350380
e -> logger.debug("reroute after existing shards allocator timed out failed", e)
@@ -920,4 +950,8 @@ protected void setPrimaryBatchAllocatorTimeout(TimeValue primaryShardsBatchGatew
920950
protected void setReplicaBatchAllocatorTimeout(TimeValue replicaShardsBatchGatewayAllocatorTimeout) {
921951
this.replicaShardsBatchGatewayAllocatorTimeout = replicaShardsBatchGatewayAllocatorTimeout;
922952
}
953+
954+
private void setFollowUpRerouteTaskPriority(Priority followUpRerouteTaskPriority) {
955+
this.followUpRerouteTaskPriority = followUpRerouteTaskPriority;
956+
}
923957
}

0 commit comments

Comments
 (0)