|
25 | 25 | import org.opensearch.test.junit.annotations.TestLogging;
|
26 | 26 |
|
27 | 27 | import java.util.ArrayList;
|
| 28 | +import java.util.Arrays; |
28 | 29 | import java.util.List;
|
29 | 30 | import java.util.Map;
|
30 | 31 | import java.util.concurrent.TimeUnit;
|
@@ -169,14 +170,16 @@ public void testSingleIndexShardAllocation() throws Exception {
|
169 | 170 |
|
170 | 171 | // Remove a node
|
171 | 172 | internalCluster().stopRandomNode(InternalTestCluster.nameFilter(nodeNames.get(0)));
|
172 |
| - ensureGreen(TimeValue.timeValueSeconds(60)); |
| 173 | + internalCluster().validateClusterFormed(); |
| 174 | + ensureGreen(TimeValue.timeValueSeconds(100)); |
173 | 175 | state = client().admin().cluster().prepareState().execute().actionGet().getState();
|
174 | 176 | logger.info(ShardAllocations.printShardDistribution(state));
|
175 | 177 | verifyPerIndexPrimaryBalance();
|
176 | 178 |
|
177 | 179 | // Add a new node
|
178 | 180 | internalCluster().startDataOnlyNode();
|
179 |
| - ensureGreen(TimeValue.timeValueSeconds(60)); |
| 181 | + internalCluster().validateClusterFormed(); |
| 182 | + ensureGreen(TimeValue.timeValueSeconds(100)); |
180 | 183 | state = client().admin().cluster().prepareState().execute().actionGet().getState();
|
181 | 184 | logger.info(ShardAllocations.printShardDistribution(state));
|
182 | 185 | verifyPerIndexPrimaryBalance();
|
@@ -250,24 +253,32 @@ public void testAllocationAndRebalanceWithDisruption() throws Exception {
|
250 | 253 | internalCluster().startClusterManagerOnlyNode();
|
251 | 254 | final int maxReplicaCount = 2;
|
252 | 255 | final int maxShardCount = 2;
|
253 |
| - // Create higher number of nodes than number of shards to reduce chances of SameShardAllocationDecider kicking-in |
| 256 | + final int numberOfIndices = randomIntBetween(1, 3); |
| 257 | + final int maxPossibleShards = numberOfIndices * maxShardCount * (1 + maxReplicaCount); |
| 258 | + |
| 259 | + List<List<Integer>> shardAndReplicaCounts = new ArrayList<>(); |
| 260 | + int shardCount, replicaCount, totalShards = 0; |
| 261 | + for (int i = 0; i < numberOfIndices; i++) { |
| 262 | + shardCount = randomIntBetween(1, maxShardCount); |
| 263 | + replicaCount = randomIntBetween(1, maxReplicaCount); |
| 264 | + shardAndReplicaCounts.add(Arrays.asList(shardCount, replicaCount)); |
| 265 | + totalShards += shardCount * (1 + replicaCount); |
| 266 | + } |
| 267 | + // Create a strictly higher number of nodes than the number of shards to reduce chances of SameShardAllocationDecider kicking-in |
254 | 268 | // and preventing primary relocations
|
255 |
| - final int nodeCount = randomIntBetween(5, 10); |
256 |
| - final int numberOfIndices = randomIntBetween(1, 10); |
| 269 | + final int nodeCount = randomIntBetween(totalShards, maxPossibleShards) + 1; |
257 | 270 | final float buffer = randomIntBetween(1, 4) * 0.10f;
|
258 |
| - |
259 | 271 | logger.info("--> Creating {} nodes", nodeCount);
|
260 | 272 | final List<String> nodeNames = new ArrayList<>();
|
261 | 273 | for (int i = 0; i < nodeCount; i++) {
|
262 | 274 | nodeNames.add(internalCluster().startNode());
|
263 | 275 | }
|
264 | 276 | setAllocationRelocationStrategy(true, true, buffer);
|
265 | 277 |
|
266 |
| - int shardCount, replicaCount; |
267 | 278 | ClusterState state;
|
268 | 279 | for (int i = 0; i < numberOfIndices; i++) {
|
269 |
| - shardCount = randomIntBetween(1, maxShardCount); |
270 |
| - replicaCount = randomIntBetween(1, maxReplicaCount); |
| 280 | + shardCount = shardAndReplicaCounts.get(i).get(0); |
| 281 | + replicaCount = shardAndReplicaCounts.get(i).get(1); |
271 | 282 | logger.info("--> Creating index test{} with primary {} and replica {}", i, shardCount, replicaCount);
|
272 | 283 | createIndex("test" + i, shardCount, replicaCount, i % 2 == 0);
|
273 | 284 | ensureGreen(TimeValue.timeValueSeconds(60));
|
|
0 commit comments