Skip to content

Commit

Permalink
Fix bug with delete shard routing weights on node restart (opensearch…
Browse files Browse the repository at this point in the history
…-project#8057)

Signed-off-by: Rishab Nahata <rnnahata@amazon.com>
Signed-off-by: Shivansh Arora <hishiv@amazon.com>
  • Loading branch information
imRishN authored and shiv0408 committed Apr 25, 2024
1 parent 3addabd commit ad5c4c5
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,53 @@ public void testWeightedRoutingMetadataOnOSProcessRestart() throws Exception {
assertNotNull(internalCluster().clusterService().state().metadata().weightedRoutingMetadata());
}

public void testWeightedRoutingOnOSProcessRestartAfterWeightDelete() throws Exception {
Settings commonSettings = Settings.builder()
.put("cluster.routing.allocation.awareness.attributes", "zone")
.put("cluster.routing.allocation.awareness.force.zone.values", "a,b,c")
.build();

internalCluster().startNodes(
Settings.builder().put(commonSettings).put("node.attr.zone", "a").build(),
Settings.builder().put(commonSettings).put("node.attr.zone", "b").build(),
Settings.builder().put(commonSettings).put("node.attr.zone", "c").build()
);

logger.info("--> waiting for nodes to form a cluster");
ClusterHealthResponse health = client().admin().cluster().prepareHealth().setWaitForNodes("3").execute().actionGet();
assertThat(health.isTimedOut(), equalTo(false));

ensureGreen();

logger.info("--> setting shard routing weights for weighted round robin");
Map<String, Double> weights = Map.of("a", 1.0, "b", 2.0, "c", 3.0);
WeightedRouting weightedRouting = new WeightedRouting("zone", weights);
// put api call to set weights
ClusterPutWeightedRoutingResponse response = client().admin()
.cluster()
.prepareWeightedRouting()
.setWeightedRouting(weightedRouting)
.setVersion(-1)
.get();
assertEquals(response.isAcknowledged(), true);

ensureStableCluster(3);

// routing weights are set in cluster metadata
assertNotNull(internalCluster().clusterService().state().metadata().weightedRoutingMetadata());

ensureGreen();

// delete weighted routing metadata
ClusterDeleteWeightedRoutingResponse deleteResponse = client().admin().cluster().prepareDeleteWeightedRouting().setVersion(0).get();
assertTrue(deleteResponse.isAcknowledged());

// Restart a random data node and check that OS process comes healthy
internalCluster().restartRandomDataNode();
ensureGreen();
assertNotNull(internalCluster().clusterService().state().metadata().weightedRoutingMetadata());
}

public void testDeleteWeightedRouting_WeightsNotSet() {
Settings commonSettings = Settings.builder()
.put("cluster.routing.allocation.awareness.attributes", "zone")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public WeightedRouting(StreamInput in) throws IOException {
}

public boolean isSet() {
return (!this.attributeName.isEmpty() && !this.weights.isEmpty());
return this.attributeName != null && !this.attributeName.isEmpty() && this.weights != null && !this.weights.isEmpty();
}

@Override
Expand Down

0 comments on commit ad5c4c5

Please sign in to comment.