forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
52 changed files
with
1,792 additions
and
319 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
...lusterTest/java/org/opensearch/cluster/allocation/SearchReplicaFilteringAllocationIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.cluster.allocation; | ||
|
||
import org.opensearch.cluster.metadata.IndexMetadata; | ||
import org.opensearch.cluster.routing.IndexShardRoutingTable; | ||
import org.opensearch.cluster.routing.ShardRouting; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.common.util.FeatureFlags; | ||
import org.opensearch.indices.replication.common.ReplicationType; | ||
import org.opensearch.test.OpenSearchIntegTestCase; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_REPLICATION_TYPE; | ||
import static org.opensearch.cluster.routing.allocation.decider.SearchReplicaAllocationDecider.SEARCH_REPLICA_ROUTING_INCLUDE_GROUP_SETTING; | ||
|
||
@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0) | ||
public class SearchReplicaFilteringAllocationIT extends OpenSearchIntegTestCase { | ||
|
||
@Override | ||
protected Settings featureFlagSettings() { | ||
return Settings.builder().put(super.featureFlagSettings()).put(FeatureFlags.READER_WRITER_SPLIT_EXPERIMENTAL, Boolean.TRUE).build(); | ||
} | ||
|
||
public void testSearchReplicaDedicatedIncludes() { | ||
List<String> nodesIds = internalCluster().startNodes(3); | ||
final String node_0 = nodesIds.get(0); | ||
final String node_1 = nodesIds.get(1); | ||
final String node_2 = nodesIds.get(2); | ||
assertEquals(3, cluster().size()); | ||
|
||
client().admin() | ||
.cluster() | ||
.prepareUpdateSettings() | ||
.setTransientSettings( | ||
Settings.builder().put(SEARCH_REPLICA_ROUTING_INCLUDE_GROUP_SETTING.getKey() + "_name", node_1 + "," + node_0) | ||
) | ||
.execute() | ||
.actionGet(); | ||
|
||
createIndex( | ||
"test", | ||
Settings.builder() | ||
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_SEARCH_REPLICAS, 1) | ||
.put(SETTING_REPLICATION_TYPE, ReplicationType.SEGMENT) | ||
.build() | ||
); | ||
ensureGreen("test"); | ||
// ensure primary is not on node 0 or 1, | ||
IndexShardRoutingTable routingTable = getRoutingTable(); | ||
assertEquals(node_2, getNodeName(routingTable.primaryShard().currentNodeId())); | ||
|
||
String existingSearchReplicaNode = getNodeName(routingTable.searchOnlyReplicas().get(0).currentNodeId()); | ||
String emptyAllowedNode = existingSearchReplicaNode.equals(node_0) ? node_1 : node_0; | ||
|
||
// set the included nodes to the other open node, search replica should relocate to that node. | ||
client().admin() | ||
.cluster() | ||
.prepareUpdateSettings() | ||
.setTransientSettings(Settings.builder().put(SEARCH_REPLICA_ROUTING_INCLUDE_GROUP_SETTING.getKey() + "_name", emptyAllowedNode)) | ||
.execute() | ||
.actionGet(); | ||
ensureGreen("test"); | ||
|
||
routingTable = getRoutingTable(); | ||
assertEquals(node_2, getNodeName(routingTable.primaryShard().currentNodeId())); | ||
assertEquals(emptyAllowedNode, getNodeName(routingTable.searchOnlyReplicas().get(0).currentNodeId())); | ||
} | ||
|
||
public void testSearchReplicaDedicatedIncludes_DoNotAssignToOtherNodes() { | ||
List<String> nodesIds = internalCluster().startNodes(3); | ||
final String node_0 = nodesIds.get(0); | ||
final String node_1 = nodesIds.get(1); | ||
final String node_2 = nodesIds.get(2); | ||
assertEquals(3, cluster().size()); | ||
|
||
// set filter on 1 node and set search replica count to 2 - should leave 1 unassigned | ||
client().admin() | ||
.cluster() | ||
.prepareUpdateSettings() | ||
.setTransientSettings(Settings.builder().put(SEARCH_REPLICA_ROUTING_INCLUDE_GROUP_SETTING.getKey() + "_name", node_1)) | ||
.execute() | ||
.actionGet(); | ||
|
||
logger.info("--> creating an index with no replicas"); | ||
createIndex( | ||
"test", | ||
Settings.builder() | ||
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_SEARCH_REPLICAS, 2) | ||
.put(SETTING_REPLICATION_TYPE, ReplicationType.SEGMENT) | ||
.build() | ||
); | ||
ensureYellowAndNoInitializingShards("test"); | ||
IndexShardRoutingTable routingTable = getRoutingTable(); | ||
assertEquals(2, routingTable.searchOnlyReplicas().size()); | ||
List<ShardRouting> assignedSearchShards = routingTable.searchOnlyReplicas() | ||
.stream() | ||
.filter(ShardRouting::assignedToNode) | ||
.collect(Collectors.toList()); | ||
assertEquals(1, assignedSearchShards.size()); | ||
assertEquals(node_1, getNodeName(assignedSearchShards.get(0).currentNodeId())); | ||
assertEquals(1, routingTable.searchOnlyReplicas().stream().filter(ShardRouting::unassigned).count()); | ||
} | ||
|
||
private IndexShardRoutingTable getRoutingTable() { | ||
IndexShardRoutingTable routingTable = getClusterState().routingTable().index("test").getShards().get(0); | ||
return routingTable; | ||
} | ||
|
||
private String getNodeName(String id) { | ||
return getClusterState().nodes().get(id).getName(); | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
...ternalClusterTest/java/org/opensearch/indices/replication/SearchReplicaReplicationIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.indices.replication; | ||
|
||
import org.opensearch.cluster.metadata.IndexMetadata; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.common.util.FeatureFlags; | ||
import org.opensearch.test.OpenSearchIntegTestCase; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
|
||
import java.nio.file.Path; | ||
|
||
@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0) | ||
public class SearchReplicaReplicationIT extends SegmentReplicationBaseIT { | ||
|
||
private static final String REPOSITORY_NAME = "test-remote-store-repo"; | ||
protected Path absolutePath; | ||
|
||
private Boolean useRemoteStore; | ||
|
||
@Before | ||
public void randomizeRemoteStoreEnabled() { | ||
useRemoteStore = randomBoolean(); | ||
} | ||
|
||
@Override | ||
protected Settings nodeSettings(int nodeOrdinal) { | ||
if (useRemoteStore) { | ||
if (absolutePath == null) { | ||
absolutePath = randomRepoPath().toAbsolutePath(); | ||
} | ||
return Settings.builder() | ||
.put(super.nodeSettings(nodeOrdinal)) | ||
.put(remoteStoreClusterSettings(REPOSITORY_NAME, absolutePath)) | ||
.build(); | ||
} | ||
return super.nodeSettings(nodeOrdinal); | ||
} | ||
|
||
@After | ||
public void teardown() { | ||
if (useRemoteStore) { | ||
clusterAdmin().prepareCleanupRepository(REPOSITORY_NAME).get(); | ||
} | ||
} | ||
|
||
@Override | ||
public Settings indexSettings() { | ||
return Settings.builder() | ||
.put(super.indexSettings()) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_SEARCH_REPLICAS, 1) | ||
.build(); | ||
} | ||
|
||
@Override | ||
protected Settings featureFlagSettings() { | ||
return Settings.builder().put(super.featureFlagSettings()).put(FeatureFlags.READER_WRITER_SPLIT_EXPERIMENTAL, true).build(); | ||
} | ||
|
||
public void testReplication() throws Exception { | ||
internalCluster().startClusterManagerOnlyNode(); | ||
final String primary = internalCluster().startDataOnlyNode(); | ||
createIndex(INDEX_NAME); | ||
ensureYellowAndNoInitializingShards(INDEX_NAME); | ||
final String replica = internalCluster().startDataOnlyNode(); | ||
ensureGreen(INDEX_NAME); | ||
|
||
final int docCount = 10; | ||
for (int i = 0; i < docCount; i++) { | ||
client().prepareIndex(INDEX_NAME).setId(Integer.toString(i)).setSource("field", "value" + i).execute().get(); | ||
} | ||
refresh(INDEX_NAME); | ||
waitForSearchableDocs(docCount, primary, replica); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.