Skip to content

Commit 23e8349

Browse files
authored
Enable write load constraint decider via feature flag (#135246)
1 parent d7b7666 commit 23e8349

File tree

3 files changed

+47
-38
lines changed

3 files changed

+47
-38
lines changed

server/src/internalClusterTest/java/org/elasticsearch/index/shard/IndexShardIT.java

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,9 @@ public void testHeapUsageEstimateIsPresent() {
305305
}
306306

307307
public void testNodeWriteLoadsArePresent() {
308+
// Disable write load decider to begin with
309+
setWriteLoadDeciderEnablement(WriteLoadConstraintSettings.WriteLoadDeciderStatus.DISABLED);
310+
308311
InternalClusterInfoService clusterInfoService = (InternalClusterInfoService) getInstanceFromNode(ClusterInfoService.class);
309312
ClusterInfoServiceUtils.refresh(clusterInfoService);
310313
Map<String, NodeUsageStatsForThreadPools> nodeThreadPoolStats = clusterInfoService.getClusterInfo()
@@ -315,15 +318,10 @@ public void testNodeWriteLoadsArePresent() {
315318
assertTrue(nodeThreadPoolStats.isEmpty());
316319

317320
// Enable collection for node write loads.
318-
updateClusterSettings(
319-
Settings.builder()
320-
.put(
321-
WriteLoadConstraintSettings.WRITE_LOAD_DECIDER_ENABLED_SETTING.getKey(),
322-
randomBoolean()
323-
? WriteLoadConstraintSettings.WriteLoadDeciderStatus.ENABLED
324-
: WriteLoadConstraintSettings.WriteLoadDeciderStatus.LOW_THRESHOLD_ONLY
325-
)
326-
.build()
321+
setWriteLoadDeciderEnablement(
322+
randomBoolean()
323+
? WriteLoadConstraintSettings.WriteLoadDeciderStatus.ENABLED
324+
: WriteLoadConstraintSettings.WriteLoadDeciderStatus.LOW_THRESHOLD_ONLY
327325
);
328326
try {
329327
// Force a ClusterInfo refresh to run collection of the node thread pool usage stats.
@@ -346,9 +344,7 @@ public void testNodeWriteLoadsArePresent() {
346344
assertThat(writeThreadPoolStats.maxThreadPoolQueueLatencyMillis(), greaterThanOrEqualTo(0L));
347345
}
348346
} finally {
349-
updateClusterSettings(
350-
Settings.builder().putNull(WriteLoadConstraintSettings.WRITE_LOAD_DECIDER_ENABLED_SETTING.getKey()).build()
351-
);
347+
clearWriteLoadDeciderEnablementSetting();
352348
}
353349
}
354350

@@ -365,27 +361,25 @@ public void testShardWriteLoadsArePresent() {
365361

366362
final InternalClusterInfoService clusterInfoService = (InternalClusterInfoService) getInstanceFromNode(ClusterInfoService.class);
367363

368-
// Not collecting stats yet because allocation write load stats collection is disabled by default.
369-
{
370-
ClusterInfoServiceUtils.refresh(clusterInfoService);
371-
final Map<ShardId, Double> shardWriteLoads = clusterInfoService.getClusterInfo().getShardWriteLoads();
372-
assertNotNull(shardWriteLoads);
373-
assertTrue(shardWriteLoads.isEmpty());
374-
}
375-
376-
// Turn on collection of write-load stats.
377-
updateClusterSettings(
378-
Settings.builder()
379-
.put(
380-
WriteLoadConstraintSettings.WRITE_LOAD_DECIDER_ENABLED_SETTING.getKey(),
381-
randomBoolean()
382-
? WriteLoadConstraintSettings.WriteLoadDeciderStatus.ENABLED
383-
: WriteLoadConstraintSettings.WriteLoadDeciderStatus.LOW_THRESHOLD_ONLY
384-
)
385-
.build()
386-
);
364+
// Explicitly disable write load decider
365+
setWriteLoadDeciderEnablement(WriteLoadConstraintSettings.WriteLoadDeciderStatus.DISABLED);
387366

388367
try {
368+
// Stats should not be collected when the decider is disabled
369+
{
370+
ClusterInfoServiceUtils.refresh(clusterInfoService);
371+
final Map<ShardId, Double> shardWriteLoads = clusterInfoService.getClusterInfo().getShardWriteLoads();
372+
assertNotNull(shardWriteLoads);
373+
assertTrue(shardWriteLoads.isEmpty());
374+
}
375+
376+
// Turn on collection of write-load stats.
377+
setWriteLoadDeciderEnablement(
378+
randomBoolean()
379+
? WriteLoadConstraintSettings.WriteLoadDeciderStatus.ENABLED
380+
: WriteLoadConstraintSettings.WriteLoadDeciderStatus.LOW_THRESHOLD_ONLY
381+
);
382+
389383
// Force a ClusterInfo refresh to run collection of the write-load stats.
390384
ClusterInfoServiceUtils.refresh(clusterInfoService);
391385
final Map<ShardId, Double> shardWriteLoads = clusterInfoService.getClusterInfo().getShardWriteLoads();
@@ -404,12 +398,14 @@ public void testShardWriteLoadsArePresent() {
404398
assertThat(maximumLoadRecorded, greaterThan(0.0));
405399
}
406400
} finally {
407-
updateClusterSettings(
408-
Settings.builder().putNull(WriteLoadConstraintSettings.WRITE_LOAD_DECIDER_ENABLED_SETTING.getKey()).build()
409-
);
401+
clearWriteLoadDeciderEnablementSetting();
410402
}
411403
}
412404

405+
private void clearWriteLoadDeciderEnablementSetting() {
406+
updateClusterSettings(Settings.builder().putNull(WriteLoadConstraintSettings.WRITE_LOAD_DECIDER_ENABLED_SETTING.getKey()).build());
407+
}
408+
413409
public void testMaxHeapPerNodeIsPresent() {
414410
InternalClusterInfoService clusterInfoService = (InternalClusterInfoService) getInstanceFromNode(ClusterInfoService.class);
415411
ClusterInfoServiceUtils.refresh(clusterInfoService);
@@ -764,6 +760,12 @@ public void postDelete(ShardId shardId, Engine.Delete delete, Engine.DeleteResul
764760
}
765761
}
766762

763+
private void setWriteLoadDeciderEnablement(WriteLoadConstraintSettings.WriteLoadDeciderStatus status) {
764+
updateClusterSettings(
765+
Settings.builder().put(WriteLoadConstraintSettings.WRITE_LOAD_DECIDER_ENABLED_SETTING.getKey(), status).build()
766+
);
767+
}
768+
767769
public static final IndexShard recoverShard(IndexShard newShard) throws IOException {
768770
DiscoveryNode localNode = DiscoveryNodeUtils.builder("foo").roles(emptySet()).build();
769771
newShard.markAsRecovering("store", new RecoveryState(newShard.routingEntry(), localNode, null));

server/src/main/java/org/elasticsearch/cluster/routing/allocation/WriteLoadConstraintSettings.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.elasticsearch.common.settings.ClusterSettings;
1616
import org.elasticsearch.common.settings.Setting;
1717
import org.elasticsearch.common.unit.RatioValue;
18+
import org.elasticsearch.common.util.FeatureFlag;
1819
import org.elasticsearch.core.TimeValue;
1920

2021
/**
@@ -23,6 +24,7 @@
2324
public class WriteLoadConstraintSettings {
2425

2526
private static final String SETTING_PREFIX = "cluster.routing.allocation.write_load_decider.";
27+
private static final FeatureFlag WRITE_LOAD_DECIDER_FEATURE_FLAG = new FeatureFlag("write_load_decider");
2628

2729
public enum WriteLoadDeciderStatus {
2830
/**
@@ -59,7 +61,7 @@ public boolean disabled() {
5961
public static final Setting<WriteLoadDeciderStatus> WRITE_LOAD_DECIDER_ENABLED_SETTING = Setting.enumSetting(
6062
WriteLoadDeciderStatus.class,
6163
SETTING_PREFIX + "enabled",
62-
WriteLoadDeciderStatus.DISABLED,
64+
WRITE_LOAD_DECIDER_FEATURE_FLAG.isEnabled() ? WriteLoadDeciderStatus.ENABLED : WriteLoadDeciderStatus.DISABLED,
6365
Setting.Property.Dynamic,
6466
Setting.Property.NodeScope
6567
);

server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/WriteLoadConstraintDeciderTests.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,14 @@ public void testWriteLoadDeciderDisabled() {
4343
String indexName = "test-index";
4444
var testHarness = createClusterStateAndRoutingAllocation(indexName);
4545

46-
// The write load decider is disabled by default.
47-
48-
var writeLoadDecider = createWriteLoadConstraintDecider(Settings.builder().build());
46+
var writeLoadDecider = createWriteLoadConstraintDecider(
47+
Settings.builder()
48+
.put(
49+
WriteLoadConstraintSettings.WRITE_LOAD_DECIDER_ENABLED_SETTING.getKey(),
50+
WriteLoadConstraintSettings.WriteLoadDeciderStatus.DISABLED
51+
)
52+
.build()
53+
);
4954

5055
assertEquals(
5156
Decision.Type.YES,

0 commit comments

Comments
 (0)