50
50
51
51
import static org .elasticsearch .cluster .metadata .IndexMetadata .SETTING_NUMBER_OF_REPLICAS ;
52
52
import static org .elasticsearch .cluster .metadata .IndexMetadata .SETTING_NUMBER_OF_SHARDS ;
53
+ import static org .elasticsearch .cluster .routing .ShardMovementWriteLoadSimulator .calculateUtilizationForWriteLoad ;
53
54
54
55
@ ESIntegTestCase .ClusterScope (scope = ESIntegTestCase .Scope .TEST , numDataNodes = 0 )
55
56
public class WriteLoadConstraintDeciderIT extends ESIntegTestCase {
@@ -68,6 +69,8 @@ protected Collection<Class<? extends Plugin>> getMockPlugins() {
68
69
*/
69
70
public void testHighNodeWriteLoadPreventsNewShardAllocation () {
70
71
int randomUtilizationThresholdPercent = randomIntBetween (50 , 100 );
72
+ int numberOfWritePoolThreads = randomIntBetween (2 , 20 );
73
+ float shardWriteLoad = randomFloatBetween (0.0f , 0.01f , false );
71
74
Settings settings = Settings .builder ()
72
75
.put (
73
76
WriteLoadConstraintSettings .WRITE_LOAD_DECIDER_ENABLED_SETTING .getKey (),
@@ -115,7 +118,14 @@ public void testHighNodeWriteLoadPreventsNewShardAllocation() {
115
118
);
116
119
117
120
String indexName = randomIdentifier ();
118
- int randomNumberOfShards = randomIntBetween (15 , 40 ); // Pick a high number of shards, so it is clear assignment is not accidental.
121
+ int randomNumberOfShards = randomIntBetween (10 , 20 ); // Pick a high number of shards, so it is clear assignment is not accidental.
122
+
123
+ // Calculate the maximum utilization a node can report while still being able to accept all relocating shards
124
+ double additionalLoadFromAllShards = calculateUtilizationForWriteLoad (
125
+ shardWriteLoad * randomNumberOfShards ,
126
+ numberOfWritePoolThreads
127
+ );
128
+ int maxUtilizationPercent = randomUtilizationThresholdPercent - (int ) (additionalLoadFromAllShards * 100 ) - 1 ;
119
129
120
130
var verifyAssignmentToFirstNodeListener = ClusterServiceUtils .addMasterTemporaryStateListener (clusterState -> {
121
131
var indexRoutingTable = clusterState .routingTable ().index (indexName );
@@ -154,20 +164,20 @@ public void testHighNodeWriteLoadPreventsNewShardAllocation() {
154
164
final DiscoveryNode thirdDiscoveryNode = getDiscoveryNode (thirdDataNodeName );
155
165
final NodeUsageStatsForThreadPools firstNodeNonHotSpottingNodeStats = createNodeUsageStatsForThreadPools (
156
166
firstDiscoveryNode ,
157
- 2 ,
158
- 0.5f ,
167
+ numberOfWritePoolThreads ,
168
+ randomIntBetween ( 0 , maxUtilizationPercent ) / 100f ,
159
169
0
160
170
);
161
171
final NodeUsageStatsForThreadPools secondNodeNonHotSpottingNodeStats = createNodeUsageStatsForThreadPools (
162
172
secondDiscoveryNode ,
163
- 2 ,
164
- 0.5f ,
173
+ numberOfWritePoolThreads ,
174
+ randomIntBetween ( 0 , maxUtilizationPercent ) / 100f ,
165
175
0
166
176
);
167
177
final NodeUsageStatsForThreadPools thirdNodeHotSpottingNodeStats = createNodeUsageStatsForThreadPools (
168
178
thirdDiscoveryNode ,
169
- 2 ,
170
- randomUtilizationThresholdPercent + 1 / 100 ,
179
+ numberOfWritePoolThreads ,
180
+ ( randomUtilizationThresholdPercent + 1 ) / 100f ,
171
181
0
172
182
);
173
183
@@ -197,12 +207,11 @@ public void testHighNodeWriteLoadPreventsNewShardAllocation() {
197
207
.getMetadata ()
198
208
.getProject ()
199
209
.index (indexName );
200
- double shardWriteLoadDefault = 0.2 ;
201
210
MockTransportService .getInstance (firstDataNodeName )
202
211
.addRequestHandlingBehavior (IndicesStatsAction .NAME + "[n]" , (handler , request , channel , task ) -> {
203
212
List <ShardStats > shardStats = new ArrayList <>(indexMetadata .getNumberOfShards ());
204
213
for (int i = 0 ; i < indexMetadata .getNumberOfShards (); i ++) {
205
- shardStats .add (createShardStats (indexMetadata , i , shardWriteLoadDefault , firstDataNodeId ));
214
+ shardStats .add (createShardStats (indexMetadata , i , shardWriteLoad , firstDataNodeId ));
206
215
}
207
216
TransportIndicesStatsAction instance = internalCluster ().getInstance (TransportIndicesStatsAction .class , firstDataNodeName );
208
217
channel .sendResponse (instance .new NodeResponse (firstDataNodeId , indexMetadata .getNumberOfShards (), shardStats , List .of ()));
0 commit comments