From 7972ad3d6191af3203a1abb3b9d344e3a0d80092 Mon Sep 17 00:00:00 2001 From: Poojita Raj Date: Tue, 25 Jul 2023 12:09:32 -0700 Subject: [PATCH] add changelog Signed-off-by: Poojita Raj --- CHANGELOG.md | 5 +- .../routing/ShardMovementStrategyTests.java | 52 +++++++++++++++---- 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 68893592ea8d4..09c2c19c07d5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,8 +74,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [Unreleased 2.x] ### Added -- Add server version as REST response header [#6583](https://github.com/opensearch-project/OpenSearch/issues/6583) -- Start replication checkpointTimers on primary before segments upload to remote store. ([#8221]()https://github.com/opensearch-project/OpenSearch/pull/8221) +- Add server version as REST response header ([#6583](https://github.com/opensearch-project/OpenSearch/issues/6583)) +- Start replication checkpointTimers on primary before segments upload to remote store. ([#8221](https://github.com/opensearch-project/OpenSearch/pull/8221)) +- Prioritize replica shard movement during shard relocation ([#8875](https://github.com/opensearch-project/OpenSearch/pull/8875)) ### Dependencies - Bump `org.apache.logging.log4j:log4j-core` from 2.17.1 to 2.20.0 ([#8307](https://github.com/opensearch-project/OpenSearch/pull/8307)) diff --git a/server/src/test/java/org/opensearch/cluster/routing/ShardMovementStrategyTests.java b/server/src/test/java/org/opensearch/cluster/routing/ShardMovementStrategyTests.java index f901800edb813..50799c8eb94e2 100644 --- a/server/src/test/java/org/opensearch/cluster/routing/ShardMovementStrategyTests.java +++ b/server/src/test/java/org/opensearch/cluster/routing/ShardMovementStrategyTests.java @@ -49,12 +49,43 @@ protected void createAndIndex(String index, int replicaCount, int shardCount) { flushAndRefresh(index); } - public void testClusterGreenAfterPartialRelocationPrimaryFirstShardMovementStrategy() throws InterruptedException { - testClusterGreenAfterPartialRelocation(BalancedShardsAllocator.ShardMovementStrategy.PRIMARY_FIRST); + private static Settings.Builder getSettings( + BalancedShardsAllocator.ShardMovementStrategy shardMovementStrategy, + boolean movePrimaryFirst + ) { + return Settings.builder() + .put("cluster.routing.allocation.shard_movement_strategy", shardMovementStrategy) + .put("cluster.routing.allocation.move.primary_first", movePrimaryFirst); } - public void testClusterGreenAfterPartialRelocationReplicaFirstShardMovementStrategy() throws InterruptedException { - testClusterGreenAfterPartialRelocation(BalancedShardsAllocator.ShardMovementStrategy.REPLICA_FIRST); + public void testClusterGreenAfterPartialRelocationPrimaryFirstShardMovementMovePrimarySettingEnabled() throws InterruptedException { + testClusterGreenAfterPartialRelocation(BalancedShardsAllocator.ShardMovementStrategy.PRIMARY_FIRST, true); + } + + public void testClusterGreenAfterPartialRelocationPrimaryFirstShardMovementMovePrimarySettingDisabled() throws InterruptedException { + testClusterGreenAfterPartialRelocation(BalancedShardsAllocator.ShardMovementStrategy.PRIMARY_FIRST, false); + } + + public void testClusterGreenAfterPartialRelocationReplicaFirstShardMovementPrimaryFirstEnabled() throws InterruptedException { + testClusterGreenAfterPartialRelocation(BalancedShardsAllocator.ShardMovementStrategy.REPLICA_FIRST, true); + } + + public void testClusterGreenAfterPartialRelocationReplicaFirstShardMovementPrimaryFirstDisabled() throws InterruptedException { + testClusterGreenAfterPartialRelocation(BalancedShardsAllocator.ShardMovementStrategy.REPLICA_FIRST, false); + } + + public void testClusterGreenAfterPartialRelocationNoPreferenceShardMovementPrimaryFirstEnabled() throws InterruptedException { + testClusterGreenAfterPartialRelocation(BalancedShardsAllocator.ShardMovementStrategy.NO_PREFERENCE, true); + } + + private boolean shouldMovePrimaryShardsFirst( + BalancedShardsAllocator.ShardMovementStrategy shardMovementStrategy, + boolean movePrimaryFirst + ) { + if (shardMovementStrategy == BalancedShardsAllocator.ShardMovementStrategy.NO_PREFERENCE && movePrimaryFirst) { + return true; + } + return shardMovementStrategy == BalancedShardsAllocator.ShardMovementStrategy.PRIMARY_FIRST; } /** @@ -64,8 +95,10 @@ public void testClusterGreenAfterPartialRelocationReplicaFirstShardMovementStrat * nodes in zone1. Depending on the shard movement strategy, we check whether the * primary or replica shards are moved first, and zone2 nodes have all the shards */ - private void testClusterGreenAfterPartialRelocation(BalancedShardsAllocator.ShardMovementStrategy shardMovementStrategy) - throws InterruptedException { + private void testClusterGreenAfterPartialRelocation( + BalancedShardsAllocator.ShardMovementStrategy shardMovementStrategy, + boolean movePrimaryFirst + ) throws InterruptedException { internalCluster().startClusterManagerOnlyNodes(1); final String z1 = "zone-1", z2 = "zone-2"; final int primaryShardCount = 6; @@ -83,9 +116,7 @@ private void testClusterGreenAfterPartialRelocation(BalancedShardsAllocator.Shar // zone nodes excluded to prevent any shard relocation ClusterUpdateSettingsRequest settingsRequest = new ClusterUpdateSettingsRequest(); settingsRequest.persistentSettings( - Settings.builder() - .put("cluster.routing.allocation.shard_movement_strategy", shardMovementStrategy) - .put("cluster.routing.allocation.exclude.zone", z2) + getSettings(shardMovementStrategy, movePrimaryFirst).put("cluster.routing.allocation.exclude.zone", z2) ); client().admin().cluster().updateSettings(settingsRequest).actionGet(); @@ -107,8 +138,7 @@ private void testClusterGreenAfterPartialRelocation(BalancedShardsAllocator.Shar for (ShardRouting shardEntry : routingNode) { // If shard movement strategy is primary first, asserting that primary shards are moved first; else assert // shards are replicas - if ((shardEntry - .primary() == (shardMovementStrategy == BalancedShardsAllocator.ShardMovementStrategy.PRIMARY_FIRST)) + if ((shardEntry.primary() == shouldMovePrimaryShardsFirst(shardMovementStrategy, movePrimaryFirst)) && shardEntry.state() == ShardRoutingState.STARTED) { count++; }