|
53 | 53 | import org.opensearch.common.settings.Settings;
|
54 | 54 | import org.opensearch.node.remotestore.RemoteStoreNodeService;
|
55 | 55 | import org.opensearch.snapshots.EmptySnapshotsInfoService;
|
| 56 | +import org.opensearch.test.FeatureFlagSetter; |
56 | 57 | import org.opensearch.test.gateway.TestGatewayAllocator;
|
57 | 58 |
|
58 | 59 | import java.util.Arrays;
|
59 | 60 | import java.util.Collections;
|
| 61 | +import java.util.HashSet; |
| 62 | +import java.util.Set; |
60 | 63 |
|
61 | 64 | import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_RESIZE_SOURCE_NAME;
|
62 | 65 | import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_RESIZE_SOURCE_UUID;
|
63 | 66 | import static org.opensearch.cluster.routing.ShardRoutingState.INITIALIZING;
|
64 | 67 | import static org.opensearch.cluster.routing.ShardRoutingState.STARTED;
|
65 | 68 | import static org.opensearch.cluster.routing.ShardRoutingState.UNASSIGNED;
|
| 69 | +import static org.opensearch.cluster.routing.allocation.decider.FilterAllocationDecider.SEARCH_REPLICA_ROUTING_INCLUDE_GROUP_SETTING; |
| 70 | +import static org.opensearch.common.util.FeatureFlags.READER_WRITER_SPLIT_EXPERIMENTAL; |
66 | 71 | import static org.opensearch.node.remotestore.RemoteStoreNodeService.MIGRATION_DIRECTION_SETTING;
|
67 | 72 | import static org.opensearch.node.remotestore.RemoteStoreNodeService.REMOTE_STORE_COMPATIBILITY_MODE_SETTING;
|
68 | 73 |
|
@@ -462,4 +467,98 @@ public void testMixedModeRemoteStoreAllocation() {
|
462 | 467 | decision = (Decision.Single) filterAllocationDecider.canAllocate(sr, state.getRoutingNodes().node("node2"), allocation);
|
463 | 468 | assertEquals(decision.toString(), Type.NO, decision.type());
|
464 | 469 | }
|
| 470 | + |
| 471 | + public void testSearchReplicaRoutingDedicatedIncludes() { |
| 472 | + FeatureFlagSetter.set(READER_WRITER_SPLIT_EXPERIMENTAL); |
| 473 | + // we aren't using a settingsModule here so we need to set feature flag gated setting |
| 474 | + Set<Setting<?>> settings = new HashSet<>(ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); |
| 475 | + settings.add(SEARCH_REPLICA_ROUTING_INCLUDE_GROUP_SETTING); |
| 476 | + ClusterSettings clusterSettings = new ClusterSettings(Settings.builder().build(), settings); |
| 477 | + Settings initialSettings = Settings.builder() |
| 478 | + .put("cluster.routing.allocation.search.replica.dedicated.include._id", "node1,node2") |
| 479 | + .build(); |
| 480 | + |
| 481 | + FilterAllocationDecider filterAllocationDecider = new FilterAllocationDecider(initialSettings, clusterSettings); |
| 482 | + AllocationDeciders allocationDeciders = new AllocationDeciders( |
| 483 | + Arrays.asList( |
| 484 | + filterAllocationDecider, |
| 485 | + new SameShardAllocationDecider(Settings.EMPTY, clusterSettings), |
| 486 | + new ReplicaAfterPrimaryActiveAllocationDecider() |
| 487 | + ) |
| 488 | + ); |
| 489 | + AllocationService service = new AllocationService( |
| 490 | + allocationDeciders, |
| 491 | + new TestGatewayAllocator(), |
| 492 | + new BalancedShardsAllocator(Settings.EMPTY), |
| 493 | + EmptyClusterInfoService.INSTANCE, |
| 494 | + EmptySnapshotsInfoService.INSTANCE |
| 495 | + ); |
| 496 | + ClusterState state = createInitialClusterState(service, Settings.EMPTY, Settings.EMPTY); |
| 497 | + RoutingTable routingTable = state.routingTable(); |
| 498 | + RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state.getRoutingNodes(), state, null, null, 0); |
| 499 | + allocation.debugDecision(true); |
| 500 | + |
| 501 | + ShardRouting searchReplica = ShardRouting.newUnassigned( |
| 502 | + routingTable.index("sourceIndex").shard(0).shardId(), |
| 503 | + false, |
| 504 | + true, |
| 505 | + RecoverySource.PeerRecoverySource.INSTANCE, |
| 506 | + new UnassignedInfo(UnassignedInfo.Reason.NODE_LEFT, "") |
| 507 | + ); |
| 508 | + |
| 509 | + ShardRouting regularReplica = ShardRouting.newUnassigned( |
| 510 | + routingTable.index("sourceIndex").shard(0).shardId(), |
| 511 | + false, |
| 512 | + false, |
| 513 | + RecoverySource.PeerRecoverySource.INSTANCE, |
| 514 | + new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "") |
| 515 | + ); |
| 516 | + |
| 517 | + ShardRouting primary = ShardRouting.newUnassigned( |
| 518 | + routingTable.index("sourceIndex").shard(0).shardId(), |
| 519 | + true, |
| 520 | + false, |
| 521 | + RecoverySource.PeerRecoverySource.INSTANCE, |
| 522 | + new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "") |
| 523 | + ); |
| 524 | + |
| 525 | + Decision.Single decision = (Decision.Single) filterAllocationDecider.canAllocate( |
| 526 | + searchReplica, |
| 527 | + state.getRoutingNodes().node("node2"), |
| 528 | + allocation |
| 529 | + ); |
| 530 | + assertEquals(decision.toString(), Type.YES, decision.type()); |
| 531 | + decision = (Decision.Single) filterAllocationDecider.canAllocate(searchReplica, state.getRoutingNodes().node("node1"), allocation); |
| 532 | + assertEquals(decision.toString(), Type.YES, decision.type()); |
| 533 | + |
| 534 | + decision = (Decision.Single) filterAllocationDecider.canAllocate(regularReplica, state.getRoutingNodes().node("node2"), allocation); |
| 535 | + assertEquals(decision.toString(), Type.NO, decision.type()); |
| 536 | + decision = (Decision.Single) filterAllocationDecider.canAllocate(regularReplica, state.getRoutingNodes().node("node1"), allocation); |
| 537 | + assertEquals(decision.toString(), Type.NO, decision.type()); |
| 538 | + |
| 539 | + decision = (Decision.Single) filterAllocationDecider.canAllocate(primary, state.getRoutingNodes().node("node1"), allocation); |
| 540 | + assertEquals(decision.toString(), Type.NO, decision.type()); |
| 541 | + decision = (Decision.Single) filterAllocationDecider.canAllocate(primary, state.getRoutingNodes().node("node2"), allocation); |
| 542 | + assertEquals(decision.toString(), Type.NO, decision.type()); |
| 543 | + |
| 544 | + Settings updatedSettings = Settings.builder() |
| 545 | + .put("cluster.routing.allocation.search.replica.dedicated.include._id", "node2") |
| 546 | + .build(); |
| 547 | + clusterSettings.applySettings(updatedSettings); |
| 548 | + |
| 549 | + decision = (Decision.Single) filterAllocationDecider.canAllocate(searchReplica, state.getRoutingNodes().node("node2"), allocation); |
| 550 | + assertEquals(decision.toString(), Type.YES, decision.type()); |
| 551 | + decision = (Decision.Single) filterAllocationDecider.canAllocate(searchReplica, state.getRoutingNodes().node("node1"), allocation); |
| 552 | + assertEquals(decision.toString(), Type.NO, decision.type()); |
| 553 | + |
| 554 | + decision = (Decision.Single) filterAllocationDecider.canAllocate(regularReplica, state.getRoutingNodes().node("node2"), allocation); |
| 555 | + assertEquals(decision.toString(), Type.NO, decision.type()); |
| 556 | + decision = (Decision.Single) filterAllocationDecider.canAllocate(regularReplica, state.getRoutingNodes().node("node1"), allocation); |
| 557 | + assertEquals(decision.toString(), Type.YES, decision.type()); |
| 558 | + |
| 559 | + decision = (Decision.Single) filterAllocationDecider.canAllocate(primary, state.getRoutingNodes().node("node1"), allocation); |
| 560 | + assertEquals(decision.toString(), Type.YES, decision.type()); |
| 561 | + decision = (Decision.Single) filterAllocationDecider.canAllocate(primary, state.getRoutingNodes().node("node2"), allocation); |
| 562 | + assertEquals(decision.toString(), Type.NO, decision.type()); |
| 563 | + } |
465 | 564 | }
|
0 commit comments