Skip to content

Commit 8bfa772

Browse files
Skip unnecessary string format in ThrottlingAllocationDecider when not in debug mode (opensearch-project#13750) (opensearch-project#13762)
* Skip unnecessary String format in throttling allocation decider when not in debug mode Signed-off-by: Rishab Nahata <rnnahata@amazon.com> Signed-off-by: kkewwei <kkewwei@163.com>
1 parent dbb8dbd commit 8bfa772

File tree

1 file changed

+49
-46
lines changed

1 file changed

+49
-46
lines changed

server/src/main/java/org/opensearch/cluster/routing/allocation/decider/ThrottlingAllocationDecider.java

+49-46
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import org.opensearch.common.settings.Setting.Property;
4545
import org.opensearch.common.settings.Settings;
4646

47-
import java.util.Locale;
4847
import java.util.function.BiFunction;
4948

5049
import static org.opensearch.cluster.routing.allocation.decider.Decision.THROTTLE;
@@ -211,20 +210,9 @@ private Decision allocateInitialShardCopies(ShardRouting shardRouting, RoutingNo
211210
allocation,
212211
currentInRecoveries,
213212
replicasInitialRecoveries,
214-
(x, y) -> getInitialPrimaryNodeOutgoingRecoveries(x, y),
213+
this::getInitialPrimaryNodeOutgoingRecoveries,
215214
replicasInitialRecoveries,
216-
String.format(
217-
Locale.ROOT,
218-
"[%s=%d]",
219-
CLUSTER_ROUTING_ALLOCATION_NODE_INITIAL_REPLICAS_RECOVERIES_SETTING.getKey(),
220-
replicasInitialRecoveries
221-
),
222-
String.format(
223-
Locale.ROOT,
224-
"[%s=%d]",
225-
CLUSTER_ROUTING_ALLOCATION_NODE_INITIAL_REPLICAS_RECOVERIES_SETTING.getKey(),
226-
replicasInitialRecoveries
227-
)
215+
true
228216
);
229217
}
230218

@@ -238,22 +226,9 @@ private Decision allocateNonInitialShardCopies(ShardRouting shardRouting, Routin
238226
allocation,
239227
currentInRecoveries,
240228
concurrentIncomingRecoveries,
241-
(x, y) -> getPrimaryNodeOutgoingRecoveries(x, y),
229+
this::getPrimaryNodeOutgoingRecoveries,
242230
concurrentOutgoingRecoveries,
243-
String.format(
244-
Locale.ROOT,
245-
"[%s=%d] (can also be set via [%s])",
246-
CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_INCOMING_RECOVERIES_SETTING.getKey(),
247-
concurrentIncomingRecoveries,
248-
CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_RECOVERIES_SETTING.getKey()
249-
),
250-
String.format(
251-
Locale.ROOT,
252-
"[%s=%d] (can also be set via [%s])",
253-
CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_OUTGOING_RECOVERIES_SETTING.getKey(),
254-
concurrentOutgoingRecoveries,
255-
CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_RECOVERIES_SETTING.getKey()
256-
)
231+
false
257232
);
258233
}
259234

@@ -274,18 +249,30 @@ private Decision allocateShardCopies(
274249
int inRecoveriesLimit,
275250
BiFunction<ShardRouting, RoutingAllocation, Integer> primaryNodeOutRecoveriesFunc,
276251
int outRecoveriesLimit,
277-
String incomingRecoveriesSettingMsg,
278-
String outGoingRecoveriesSettingMsg
252+
boolean isInitialShardCopies
279253
) {
280254
// Allocating a shard to this node will increase the incoming recoveries
281255
if (currentInRecoveries >= inRecoveriesLimit) {
282-
return allocation.decision(
283-
THROTTLE,
284-
NAME,
285-
"reached the limit of incoming shard recoveries [%d], cluster setting %s",
286-
currentInRecoveries,
287-
incomingRecoveriesSettingMsg
288-
);
256+
if (isInitialShardCopies) {
257+
return allocation.decision(
258+
THROTTLE,
259+
NAME,
260+
"reached the limit of incoming shard recoveries [%d], cluster setting [%s=%d]",
261+
currentInRecoveries,
262+
CLUSTER_ROUTING_ALLOCATION_NODE_INITIAL_REPLICAS_RECOVERIES_SETTING.getKey(),
263+
inRecoveriesLimit
264+
);
265+
} else {
266+
return allocation.decision(
267+
THROTTLE,
268+
NAME,
269+
"reached the limit of incoming shard recoveries [%d], cluster setting [%s=%d] (can also be set via [%s])",
270+
currentInRecoveries,
271+
CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_INCOMING_RECOVERIES_SETTING.getKey(),
272+
inRecoveriesLimit,
273+
CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_RECOVERIES_SETTING.getKey()
274+
);
275+
}
289276
} else {
290277
// search for corresponding recovery source (= primary shard) and check number of outgoing recoveries on that node
291278
ShardRouting primaryShard = allocation.routingNodes().activePrimary(shardRouting.shardId());
@@ -294,14 +281,30 @@ private Decision allocateShardCopies(
294281
}
295282
int primaryNodeOutRecoveries = primaryNodeOutRecoveriesFunc.apply(shardRouting, allocation);
296283
if (primaryNodeOutRecoveries >= outRecoveriesLimit) {
297-
return allocation.decision(
298-
THROTTLE,
299-
NAME,
300-
"reached the limit of outgoing shard recoveries [%d] on the node [%s] which holds the primary, " + "cluster setting %s",
301-
primaryNodeOutRecoveries,
302-
primaryShard.currentNodeId(),
303-
outGoingRecoveriesSettingMsg
304-
);
284+
if (isInitialShardCopies) {
285+
return allocation.decision(
286+
THROTTLE,
287+
NAME,
288+
"reached the limit of outgoing shard recoveries [%d] on the node [%s] which holds the primary, "
289+
+ "cluster setting [%s=%d]",
290+
primaryNodeOutRecoveries,
291+
primaryShard.currentNodeId(),
292+
CLUSTER_ROUTING_ALLOCATION_NODE_INITIAL_REPLICAS_RECOVERIES_SETTING.getKey(),
293+
inRecoveriesLimit
294+
);
295+
} else {
296+
return allocation.decision(
297+
THROTTLE,
298+
NAME,
299+
"reached the limit of outgoing shard recoveries [%d] on the node [%s] which holds the primary, "
300+
+ "cluster setting [%s=%d] (can also be set via [%s])",
301+
primaryNodeOutRecoveries,
302+
primaryShard.currentNodeId(),
303+
CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_OUTGOING_RECOVERIES_SETTING.getKey(),
304+
outRecoveriesLimit,
305+
CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_RECOVERIES_SETTING.getKey()
306+
);
307+
}
305308
} else {
306309
return allocation.decision(
307310
YES,

0 commit comments

Comments
 (0)