From 65afabab26c2b6c78f01d41cce17b1a881db5636 Mon Sep 17 00:00:00 2001 From: Anshu Agarwal Date: Thu, 6 Oct 2022 12:53:48 +0530 Subject: [PATCH 1/4] Fix weighted routing metadata deserialization error during node restart Signed-off-by: Anshu Agarwal --- .../opensearch/cluster/metadata/WeightedRoutingMetadata.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/server/src/main/java/org/opensearch/cluster/metadata/WeightedRoutingMetadata.java b/server/src/main/java/org/opensearch/cluster/metadata/WeightedRoutingMetadata.java index 27beb21f28f7c..07cdc949c4529 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/WeightedRoutingMetadata.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/WeightedRoutingMetadata.java @@ -90,8 +90,6 @@ public static WeightedRoutingMetadata fromXContent(XContentParser parser) throws Map weights = new HashMap<>(); WeightedRouting weightedRouting = null; XContentParser.Token token; - // move to the first alias - parser.nextToken(); String awarenessField = null; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { From 522dd107178ff6fd6f002a96a1061dd0267f3c6d Mon Sep 17 00:00:00 2001 From: Anshu Agarwal Date: Thu, 6 Oct 2022 18:58:13 +0530 Subject: [PATCH 2/4] Add changelog Signed-off-by: Anshu Agarwal --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b7b7b29cc904..c959b70c54b11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,6 +72,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Improve Gradle pre-commit checks to pre-empt Jenkins build ([#4660](https://github.com/opensearch-project/OpenSearch/pull/4660)) - Update to Apache Lucene 9.4.0 ([#4661](https://github.com/opensearch-project/OpenSearch/pull/4661)) - Backport Apache Lucene version change for 2.4.0 ([#4677](https://github.com/opensearch-project/OpenSearch/pull/4677)) +- Fix weighted routing metadata deserialization error on process restart ([#4691](https://github.com/opensearch-project/OpenSearch/pull/4691)) ### Deprecated From 9e2206634356e57d5158d80be268d46f9ebb2607 Mon Sep 17 00:00:00 2001 From: Anshu Agarwal Date: Fri, 7 Oct 2022 10:28:18 +0530 Subject: [PATCH 3/4] test to verify the fix Signed-off-by: Anshu Agarwal --- .../cluster/routing/WeightedRoutingIT.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/server/src/internalClusterTest/java/org/opensearch/cluster/routing/WeightedRoutingIT.java b/server/src/internalClusterTest/java/org/opensearch/cluster/routing/WeightedRoutingIT.java index 6cf8292095c6a..55b92aae5754b 100644 --- a/server/src/internalClusterTest/java/org/opensearch/cluster/routing/WeightedRoutingIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/cluster/routing/WeightedRoutingIT.java @@ -242,4 +242,52 @@ public void testGetWeightedRouting_WeightsAreSet() throws IOException { assertEquals(weightedRouting, weightedRoutingResponse.weights()); assertEquals("3.0", weightedRoutingResponse.getLocalNodeWeight()); } + + public void testWeightedRoutingMetadataOnOSProcessRestart() throws IOException { + 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 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) + .get(); + assertEquals(response.isAcknowledged(), true); + + ensureStableCluster(3); + + // routing weights are set in cluster metadata + assertNotNull(internalCluster().clusterService().state().metadata().weightedRoutingMetadata()); + + ensureGreen(); + + // Restart a random data node and check that OS process comes healthy + try { + internalCluster().restartRandomDataNode(); + } catch (Exception e) { + e.printStackTrace(); + } + + ensureGreen(); + + assertNotNull(internalCluster().clusterService().state().metadata().weightedRoutingMetadata()); + } } From cc833863090cea2f1bfc432ef23370b6b0c158c5 Mon Sep 17 00:00:00 2001 From: Anshu Agarwal Date: Fri, 7 Oct 2022 11:38:51 +0530 Subject: [PATCH 4/4] Fix precommit error Signed-off-by: Anshu Agarwal --- .../opensearch/cluster/routing/WeightedRoutingIT.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/server/src/internalClusterTest/java/org/opensearch/cluster/routing/WeightedRoutingIT.java b/server/src/internalClusterTest/java/org/opensearch/cluster/routing/WeightedRoutingIT.java index 55b92aae5754b..61f82877bf12b 100644 --- a/server/src/internalClusterTest/java/org/opensearch/cluster/routing/WeightedRoutingIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/cluster/routing/WeightedRoutingIT.java @@ -243,7 +243,7 @@ public void testGetWeightedRouting_WeightsAreSet() throws IOException { assertEquals("3.0", weightedRoutingResponse.getLocalNodeWeight()); } - public void testWeightedRoutingMetadataOnOSProcessRestart() throws IOException { + public void testWeightedRoutingMetadataOnOSProcessRestart() throws Exception { Settings commonSettings = Settings.builder() .put("cluster.routing.allocation.awareness.attributes", "zone") .put("cluster.routing.allocation.awareness.force.zone.values", "a,b,c") @@ -280,14 +280,8 @@ public void testWeightedRoutingMetadataOnOSProcessRestart() throws IOException { ensureGreen(); // Restart a random data node and check that OS process comes healthy - try { - internalCluster().restartRandomDataNode(); - } catch (Exception e) { - e.printStackTrace(); - } - + internalCluster().restartRandomDataNode(); ensureGreen(); - assertNotNull(internalCluster().clusterService().state().metadata().weightedRoutingMetadata()); } }