Skip to content

Commit

Permalink
Modify integ test to handle strict weighted routing disabled use case
Browse files Browse the repository at this point in the history
Signed-off-by: Anshu Agarwal <[email protected]>
  • Loading branch information
Anshu Agarwal committed Feb 14, 2023
1 parent 7a902f1 commit 740b196
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# CHANGELOG
All notable changes to this project are documented in this file.

Expand Down Expand Up @@ -92,6 +93,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Add support for ppc64le architecture ([#5459](https://github.com/opensearch-project/OpenSearch/pull/5459))
- [Segment Replication] Add primary weight factor for balanced primary distribution ([#6017](https://github.com/opensearch-project/OpenSearch/pull/6017))
- Add a setting to control auto release of OpenSearch managed index creation block ([#6277](https://github.com/opensearch-project/OpenSearch/pull/6277))
- Add support to allow search with preference parameter when strict weighted shard routing is enabled ([#6296](https://github.com/opensearch-project/OpenSearch/pull/6296))

### Dependencies
- Update nebula-publishing-plugin to 19.2.0 ([#5704](https://github.com/opensearch-project/OpenSearch/pull/5704))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.opensearch.action.get.MultiGetResponse;
import org.opensearch.action.index.IndexRequestBuilder;
import org.opensearch.action.search.SearchResponse;
import org.opensearch.cluster.coordination.NoClusterManagerBlockService;
import org.opensearch.cluster.node.DiscoveryNode;
import org.opensearch.cluster.node.DiscoveryNodes;
import org.opensearch.cluster.routing.PreferenceBasedSearchNotAllowedException;
Expand Down Expand Up @@ -839,6 +840,20 @@ public void testStrictWeightedRoutingWithOnlyLocalNode() {
.get();
assertEquals(RestStatus.OK.getStatus(), searchResponse.status().getStatus());

// disable strict weighed routing
client().admin()
.cluster()
.prepareUpdateSettings()
.setTransientSettings(Settings.builder().put("cluster.routing.weighted.strict", false))
.get();

// make search on weighed away node
searchResponse = internalCluster().client(nodeMap.get("c").get(0))
.prepareSearch()
.setSize(4)
.setPreference("_only_local")
.get();
assertEquals(RestStatus.OK.getStatus(), searchResponse.status().getStatus());
}

/**
Expand Down Expand Up @@ -874,6 +889,23 @@ public void testStrictWeightedRoutingWithCustomString() {
assertNoSearchInAZ("c");
assertSearchInAZ("a");
assertSearchInAZ("b");

// disable strict weighed routing
client().admin()
.cluster()
.prepareUpdateSettings()
.setTransientSettings(Settings.builder().put("cluster.routing.weighted.strict", false))
.get();

// make search requests with custom string
searchResponse = internalCluster().client(nodeMap.get("a").get(0))
.prepareSearch()
.setSize(20)
.setPreference(customPreference)
.get();
// assert search on data nodes on az c (weighed away az)
assertSearchInAZ("c");

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,8 @@ private ShardIterator preferenceSearchWithWeightedRouting(
)) return indexShard.onlyNodeActiveInitializingShardsIt(localNodeId);
else {
throw new PreferenceBasedSearchNotAllowedException(
"Preference based routing not allowed on weigh away node with strict weighted shard routing setting"
"Preference based routing not allowed on weigh away node with strict weighted shard routing " +
"enabled"
);
}
case ONLY_NODES:
Expand Down

0 comments on commit 740b196

Please sign in to comment.