Skip to content

Commit 653bc65

Browse files
committed
Merge branch 'main' into fix_detailed_error_message_showing
2 parents 5557ee0 + a2f95ce commit 653bc65

25 files changed

Lines changed: 1169 additions & 52 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
6262
- [CCR] Add getHistoryOperationsFromTranslog method to fetch the history snapshot from translogs ([#3948](https://github.com/opensearch-project/OpenSearch/pull/3948))
6363
- [Remote Store] Change behaviour in replica recovery for remote translog enabled indices ([#4318](https://github.com/opensearch-project/OpenSearch/pull/4318))
6464
- PUT api for weighted shard routing ([#4272](https://github.com/opensearch-project/OpenSearch/pull/4272))
65+
- GET api for weighted shard routing([#4275](https://github.com/opensearch-project/OpenSearch/pull/4275/))
6566
- Unmute test RelocationIT.testRelocationWhileIndexingRandom ([#4580](https://github.com/opensearch-project/OpenSearch/pull/4580))
6667
- Add DecommissionService and helper to execute awareness attribute decommissioning ([#4084](https://github.com/opensearch-project/OpenSearch/pull/4084))
6768
- Further simplification of the ZIP publication implementation ([#4360](https://github.com/opensearch-project/OpenSearch/pull/4360))
@@ -114,6 +115,8 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
114115
- Fixed misunderstanding message "No OpenSearchException found" when detailed_error disabled ([#4669](https://github.com/opensearch-project/OpenSearch/pull/4669))
115116
- Attempt to fix Github workflow for Gradle Check job ([#4679](https://github.com/opensearch-project/OpenSearch/pull/4679))
116117
- Fix flaky DecommissionControllerTests.testTimesOut ([4683](https://github.com/opensearch-project/OpenSearch/pull/4683))
118+
- Fix new race condition in DecommissionControllerTests ([4688](https://github.com/opensearch-project/OpenSearch/pull/4688))
119+
- Fix SearchStats (de)serialization (caused by https://github.com/opensearch-project/OpenSearch/pull/4616) ([#4697](https://github.com/opensearch-project/OpenSearch/pull/4697))
117120

118121
### Security
119122

client/rest-high-level/src/test/java/org/opensearch/client/RestHighLevelClientTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,7 @@ public void testApiNamingConventions() throws Exception {
890890
"search_shards",
891891
"remote_store.restore",
892892
"cluster.put_weighted_routing",
893+
"cluster.get_weighted_routing",
893894
"cluster.put_decommission_awareness",
894895
"cluster.get_decommission_awareness", };
895896
List<String> booleanReturnMethods = Arrays.asList("security.enable_user", "security.disable_user", "security.change_password");
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"cluster.get_weighted_routing": {
3+
"documentation": {
4+
"url": "https://opensearch.org/docs/latest/opensearch/rest-api/weighted-routing/get",
5+
"description": "Fetches weighted shard routing weights"
6+
},
7+
"stability": "stable",
8+
"url": {
9+
"paths": [
10+
{
11+
"path": "/_cluster/routing/awareness/{attribute}/weights",
12+
"methods": [
13+
"GET"
14+
],
15+
"parts": {
16+
"attribute": {
17+
"type": "string",
18+
"description": "Awareness attribute name"
19+
}
20+
}
21+
}
22+
]
23+
}
24+
}
25+
}

rest-api-spec/src/main/resources/rest-api-spec/test/cat.shards/10_basic.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
22
"Help":
33
- skip:
4-
version: " - 2.9.99"
5-
reason: point in time stats were added in 3.0.0
4+
version: " - 2.3.99"
5+
reason: point in time stats were added in 2.4.0
66
features: node_selector
77
- do:
88
cat.shards:
99
help: true
1010
node_selector:
11-
version: "3.0.0 - "
11+
version: "2.4.0 - "
1212

1313
- match:
1414
$body: |
@@ -88,16 +88,16 @@
8888
path.state .+ \n
8989
$/
9090
---
91-
"Help before - 3.0.0":
91+
"Help before - 2.4.0":
9292
- skip:
93-
version: "3.0.0 - "
94-
reason: point in time stats were added in 3.0.0
93+
version: "2.4.0 - "
94+
reason: point in time stats were added in 2.4.0
9595
features: node_selector
9696
- do:
9797
cat.shards:
9898
help: true
9999
node_selector:
100-
version: " - 2.9.99"
100+
version: " - 2.3.99"
101101

102102
- match:
103103
$body: |

rest-api-spec/src/main/resources/rest-api-spec/test/pit/10_basic.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"Create PIT, Search with PIT ID and Delete":
22
- skip:
3-
version: " - 2.9.99"
4-
reason: "mode to be introduced later than 3.0"
3+
version: " - 2.3.99"
4+
reason: "mode to be introduced later than 2.4.0"
55
- do:
66
indices.create:
77
index: test_pit
Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.cluster.routing;
10+
11+
import org.opensearch.action.admin.cluster.health.ClusterHealthResponse;
12+
import org.opensearch.action.admin.cluster.shards.routing.weighted.get.ClusterGetWeightedRoutingResponse;
13+
import org.opensearch.action.admin.cluster.shards.routing.weighted.put.ClusterPutWeightedRoutingResponse;
14+
import org.opensearch.common.settings.Settings;
15+
import org.opensearch.test.OpenSearchIntegTestCase;
16+
17+
import java.io.IOException;
18+
import java.util.List;
19+
import java.util.Map;
20+
21+
import static org.hamcrest.Matchers.equalTo;
22+
23+
@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0, minNumDataNodes = 3)
24+
public class WeightedRoutingIT extends OpenSearchIntegTestCase {
25+
26+
public void testPutWeightedRouting() {
27+
Settings commonSettings = Settings.builder()
28+
.put("cluster.routing.allocation.awareness.attributes", "zone")
29+
.put("cluster.routing.allocation.awareness.force.zone.values", "a,b,c")
30+
.build();
31+
32+
logger.info("--> starting 6 nodes on different zones");
33+
int nodeCountPerAZ = 2;
34+
35+
logger.info("--> starting a dedicated cluster manager node");
36+
internalCluster().startClusterManagerOnlyNode(Settings.builder().put(commonSettings).build());
37+
38+
logger.info("--> starting 1 nodes on zones 'a' & 'b' & 'c'");
39+
List<String> nodes_in_zone_a = internalCluster().startDataOnlyNodes(
40+
nodeCountPerAZ,
41+
Settings.builder().put(commonSettings).put("node.attr.zone", "a").build()
42+
);
43+
List<String> nodes_in_zone_b = internalCluster().startDataOnlyNodes(
44+
nodeCountPerAZ,
45+
Settings.builder().put(commonSettings).put("node.attr.zone", "b").build()
46+
);
47+
List<String> nodes_in_zone_c = internalCluster().startDataOnlyNodes(
48+
nodeCountPerAZ,
49+
Settings.builder().put(commonSettings).put("node.attr.zone", "c").build()
50+
);
51+
52+
logger.info("--> waiting for nodes to form a cluster");
53+
ClusterHealthResponse health = client().admin().cluster().prepareHealth().setWaitForNodes("7").execute().actionGet();
54+
assertThat(health.isTimedOut(), equalTo(false));
55+
56+
ensureGreen();
57+
58+
logger.info("--> setting shard routing weights for weighted round robin");
59+
Map<String, Double> weights = Map.of("a", 1.0, "b", 2.0, "c", 3.0);
60+
WeightedRouting weightedRouting = new WeightedRouting("zone", weights);
61+
62+
ClusterPutWeightedRoutingResponse response = client().admin()
63+
.cluster()
64+
.prepareWeightedRouting()
65+
.setWeightedRouting(weightedRouting)
66+
.get();
67+
assertEquals(response.isAcknowledged(), true);
68+
69+
// put call made on a data node in zone a
70+
response = internalCluster().client(randomFrom(nodes_in_zone_a.get(0), nodes_in_zone_a.get(1)))
71+
.admin()
72+
.cluster()
73+
.prepareWeightedRouting()
74+
.setWeightedRouting(weightedRouting)
75+
.get();
76+
assertEquals(response.isAcknowledged(), true);
77+
}
78+
79+
public void testPutWeightedRouting_InvalidAwarenessAttribute() {
80+
Settings commonSettings = Settings.builder()
81+
.put("cluster.routing.allocation.awareness.attributes", "zone")
82+
.put("cluster.routing.allocation.awareness.force.zone.values", "a,b,c")
83+
.build();
84+
85+
internalCluster().startNodes(
86+
Settings.builder().put(commonSettings).put("node.attr.zone", "a").build(),
87+
Settings.builder().put(commonSettings).put("node.attr.zone", "b").build(),
88+
Settings.builder().put(commonSettings).put("node.attr.zone", "c").build()
89+
);
90+
91+
logger.info("--> waiting for nodes to form a cluster");
92+
ClusterHealthResponse health = client().admin().cluster().prepareHealth().setWaitForNodes("3").execute().actionGet();
93+
assertThat(health.isTimedOut(), equalTo(false));
94+
95+
ensureGreen();
96+
97+
logger.info("--> setting shard routing weights for weighted round robin");
98+
Map<String, Double> weights = Map.of("a", 1.0, "b", 2.0, "c", 3.0);
99+
WeightedRouting weightedRouting = new WeightedRouting("zone1", weights);
100+
101+
assertThrows(
102+
IllegalArgumentException.class,
103+
() -> client().admin().cluster().prepareWeightedRouting().setWeightedRouting(weightedRouting).get()
104+
);
105+
}
106+
107+
public void testPutWeightedRouting_MoreThanOneZoneHasZeroWeight() {
108+
Settings commonSettings = Settings.builder()
109+
.put("cluster.routing.allocation.awareness.attributes", "zone")
110+
.put("cluster.routing.allocation.awareness.force.zone.values", "a,b,c")
111+
.build();
112+
113+
internalCluster().startNodes(
114+
Settings.builder().put(commonSettings).put("node.attr.zone", "a").build(),
115+
Settings.builder().put(commonSettings).put("node.attr.zone", "b").build(),
116+
Settings.builder().put(commonSettings).put("node.attr.zone", "c").build()
117+
);
118+
119+
logger.info("--> waiting for nodes to form a cluster");
120+
ClusterHealthResponse health = client().admin().cluster().prepareHealth().setWaitForNodes("3").execute().actionGet();
121+
assertThat(health.isTimedOut(), equalTo(false));
122+
123+
ensureGreen();
124+
125+
logger.info("--> setting shard routing weights for weighted round robin");
126+
Map<String, Double> weights = Map.of("a", 1.0, "b", 0.0, "c", 0.0);
127+
WeightedRouting weightedRouting = new WeightedRouting("zone1", weights);
128+
129+
assertThrows(
130+
IllegalArgumentException.class,
131+
() -> client().admin().cluster().prepareWeightedRouting().setWeightedRouting(weightedRouting).get()
132+
);
133+
}
134+
135+
public void testGetWeightedRouting_WeightsNotSet() {
136+
Settings commonSettings = Settings.builder()
137+
.put("cluster.routing.allocation.awareness.attributes", "zone")
138+
.put("cluster.routing.allocation.awareness.force.zone.values", "a,b,c")
139+
.build();
140+
141+
internalCluster().startNodes(
142+
Settings.builder().put(commonSettings).put("node.attr.zone", "a").build(),
143+
Settings.builder().put(commonSettings).put("node.attr.zone", "b").build(),
144+
Settings.builder().put(commonSettings).put("node.attr.zone", "c").build()
145+
);
146+
147+
logger.info("--> waiting for nodes to form a cluster");
148+
ClusterHealthResponse health = client().admin().cluster().prepareHealth().setWaitForNodes("3").execute().actionGet();
149+
assertThat(health.isTimedOut(), equalTo(false));
150+
151+
ensureGreen();
152+
153+
ClusterGetWeightedRoutingResponse weightedRoutingResponse = client().admin()
154+
.cluster()
155+
.prepareGetWeightedRouting()
156+
.setAwarenessAttribute("zone")
157+
.get();
158+
assertNull(weightedRoutingResponse.weights());
159+
}
160+
161+
public void testGetWeightedRouting_WeightsAreSet() throws IOException {
162+
163+
Settings commonSettings = Settings.builder()
164+
.put("cluster.routing.allocation.awareness.attributes", "zone")
165+
.put("cluster.routing.allocation.awareness.force.zone.values", "a,b,c")
166+
.build();
167+
168+
int nodeCountPerAZ = 2;
169+
170+
logger.info("--> starting a dedicated cluster manager node");
171+
internalCluster().startClusterManagerOnlyNode(Settings.builder().put(commonSettings).build());
172+
173+
logger.info("--> starting 2 nodes on zones 'a' & 'b' & 'c'");
174+
List<String> nodes_in_zone_a = internalCluster().startDataOnlyNodes(
175+
nodeCountPerAZ,
176+
Settings.builder().put(commonSettings).put("node.attr.zone", "a").build()
177+
);
178+
List<String> nodes_in_zone_b = internalCluster().startDataOnlyNodes(
179+
nodeCountPerAZ,
180+
Settings.builder().put(commonSettings).put("node.attr.zone", "b").build()
181+
);
182+
List<String> nodes_in_zone_c = internalCluster().startDataOnlyNodes(
183+
nodeCountPerAZ,
184+
Settings.builder().put(commonSettings).put("node.attr.zone", "c").build()
185+
);
186+
187+
logger.info("--> waiting for nodes to form a cluster");
188+
ClusterHealthResponse health = client().admin().cluster().prepareHealth().setWaitForNodes("7").execute().actionGet();
189+
assertThat(health.isTimedOut(), equalTo(false));
190+
191+
ensureGreen();
192+
193+
logger.info("--> setting shard routing weights for weighted round robin");
194+
Map<String, Double> weights = Map.of("a", 1.0, "b", 2.0, "c", 3.0);
195+
WeightedRouting weightedRouting = new WeightedRouting("zone", weights);
196+
// put api call to set weights
197+
ClusterPutWeightedRoutingResponse response = client().admin()
198+
.cluster()
199+
.prepareWeightedRouting()
200+
.setWeightedRouting(weightedRouting)
201+
.get();
202+
assertEquals(response.isAcknowledged(), true);
203+
204+
// get api call to fetch weights
205+
ClusterGetWeightedRoutingResponse weightedRoutingResponse = client().admin()
206+
.cluster()
207+
.prepareGetWeightedRouting()
208+
.setAwarenessAttribute("zone")
209+
.get();
210+
assertEquals(weightedRouting, weightedRoutingResponse.weights());
211+
212+
// get api to fetch local node weight for a node in zone a
213+
weightedRoutingResponse = internalCluster().client(randomFrom(nodes_in_zone_a.get(0), nodes_in_zone_a.get(1)))
214+
.admin()
215+
.cluster()
216+
.prepareGetWeightedRouting()
217+
.setAwarenessAttribute("zone")
218+
.setRequestLocal(true)
219+
.get();
220+
assertEquals(weightedRouting, weightedRoutingResponse.weights());
221+
assertEquals("1.0", weightedRoutingResponse.getLocalNodeWeight());
222+
223+
// get api to fetch local node weight for a node in zone b
224+
weightedRoutingResponse = internalCluster().client(randomFrom(nodes_in_zone_b.get(0), nodes_in_zone_b.get(1)))
225+
.admin()
226+
.cluster()
227+
.prepareGetWeightedRouting()
228+
.setAwarenessAttribute("zone")
229+
.setRequestLocal(true)
230+
.get();
231+
assertEquals(weightedRouting, weightedRoutingResponse.weights());
232+
assertEquals("2.0", weightedRoutingResponse.getLocalNodeWeight());
233+
234+
// get api to fetch local node weight for a node in zone c
235+
weightedRoutingResponse = internalCluster().client(randomFrom(nodes_in_zone_c.get(0), nodes_in_zone_c.get(1)))
236+
.admin()
237+
.cluster()
238+
.prepareGetWeightedRouting()
239+
.setAwarenessAttribute("zone")
240+
.setRequestLocal(true)
241+
.get();
242+
assertEquals(weightedRouting, weightedRoutingResponse.weights());
243+
assertEquals("3.0", weightedRoutingResponse.getLocalNodeWeight());
244+
}
245+
}

server/src/main/java/org/opensearch/action/ActionModule.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@
8383
import org.opensearch.action.admin.cluster.settings.TransportClusterUpdateSettingsAction;
8484
import org.opensearch.action.admin.cluster.shards.ClusterSearchShardsAction;
8585
import org.opensearch.action.admin.cluster.shards.TransportClusterSearchShardsAction;
86+
import org.opensearch.action.admin.cluster.shards.routing.weighted.get.ClusterGetWeightedRoutingAction;
87+
import org.opensearch.action.admin.cluster.shards.routing.weighted.get.TransportGetWeightedRoutingAction;
8688
import org.opensearch.action.admin.cluster.shards.routing.weighted.put.ClusterAddWeightedRoutingAction;
8789
import org.opensearch.action.admin.cluster.shards.routing.weighted.put.TransportAddWeightedRoutingAction;
8890
import org.opensearch.action.admin.cluster.snapshots.clone.CloneSnapshotAction;
@@ -299,6 +301,7 @@
299301
import org.opensearch.rest.action.admin.cluster.RestCloneSnapshotAction;
300302
import org.opensearch.rest.action.admin.cluster.RestClusterAllocationExplainAction;
301303
import org.opensearch.rest.action.admin.cluster.RestClusterGetSettingsAction;
304+
import org.opensearch.rest.action.admin.cluster.RestClusterGetWeightedRoutingAction;
302305
import org.opensearch.rest.action.admin.cluster.RestClusterHealthAction;
303306
import org.opensearch.rest.action.admin.cluster.RestClusterPutWeightedRoutingAction;
304307
import org.opensearch.rest.action.admin.cluster.RestClusterRerouteAction;
@@ -573,6 +576,7 @@ public <Request extends ActionRequest, Response extends ActionResponse> void reg
573576
actions.register(SnapshotsStatusAction.INSTANCE, TransportSnapshotsStatusAction.class);
574577

575578
actions.register(ClusterAddWeightedRoutingAction.INSTANCE, TransportAddWeightedRoutingAction.class);
579+
actions.register(ClusterGetWeightedRoutingAction.INSTANCE, TransportGetWeightedRoutingAction.class);
576580
actions.register(IndicesStatsAction.INSTANCE, TransportIndicesStatsAction.class);
577581
actions.register(IndicesSegmentsAction.INSTANCE, TransportIndicesSegmentsAction.class);
578582
actions.register(IndicesShardStoresAction.INSTANCE, TransportIndicesShardStoresAction.class);
@@ -759,6 +763,7 @@ public void initRestHandlers(Supplier<DiscoveryNodes> nodesInCluster) {
759763
registerHandler.accept(new RestOpenIndexAction());
760764
registerHandler.accept(new RestAddIndexBlockAction());
761765
registerHandler.accept(new RestClusterPutWeightedRoutingAction());
766+
registerHandler.accept(new RestClusterGetWeightedRoutingAction());
762767

763768
registerHandler.accept(new RestUpdateSettingsAction());
764769
registerHandler.accept(new RestGetSettingsAction());

0 commit comments

Comments
 (0)