Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Segment Replication] Handle failover in mixed cluster mode #9536

Merged
merged 5 commits into from
Aug 31, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add test
Signed-off-by: Poojita Raj <poojiraj@amazon.com>
  • Loading branch information
Poojita-Raj committed Aug 29, 2023
commit b71276e483ba1b6e50c870794e2b4b91ad9a24fc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.opensearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider;
import org.opensearch.common.settings.Settings;
import org.opensearch.indices.cluster.ClusterStateChanges;
import org.opensearch.indices.replication.common.ReplicationType;
import org.opensearch.test.VersionUtils;
import org.opensearch.threadpool.TestThreadPool;
import org.opensearch.threadpool.ThreadPool;
Expand All @@ -69,6 +70,7 @@

import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_REPLICAS;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_SHARDS;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_REPLICATION_TYPE;
import static org.opensearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.opensearch.cluster.routing.ShardRoutingState.STARTED;
import static org.hamcrest.Matchers.equalTo;
Expand Down Expand Up @@ -137,7 +139,15 @@ public void testSimpleFailedNodeTest() {
}
}

public void testRandomClusterPromotesOldestReplica() throws InterruptedException {
testRandomClusterPromotesReplica(true);
}

public void testRandomClusterPromotesNewestReplica() throws InterruptedException {
testRandomClusterPromotesReplica(false);
}

void testRandomClusterPromotesReplica(boolean isSegmentReplicationEnabled) throws InterruptedException {

ThreadPool threadPool = new TestThreadPool(getClass().getName());
ClusterStateChanges cluster = new ClusterStateChanges(xContentRegistry(), threadPool);
Expand All @@ -164,6 +174,9 @@ public void testRandomClusterPromotesNewestReplica() throws InterruptedException
Settings.Builder settingsBuilder = Settings.builder()
.put(SETTING_NUMBER_OF_SHARDS, randomIntBetween(1, 4))
.put(SETTING_NUMBER_OF_REPLICAS, randomIntBetween(2, 4));
if (isSegmentReplicationEnabled) {
settingsBuilder.put(SETTING_REPLICATION_TYPE, ReplicationType.SEGMENT);
}
CreateIndexRequest request = new CreateIndexRequest(name, settingsBuilder.build()).waitForActiveShards(ActiveShardCount.NONE);
state = cluster.createIndex(state, request);
assertTrue(state.metadata().hasIndex(name));
Expand Down Expand Up @@ -206,13 +219,23 @@ public void testRandomClusterPromotesNewestReplica() throws InterruptedException
Version candidateVer = getNodeVersion(sr, compareState);
if (candidateVer != null) {
logger.info("--> candidate on {} node; shard routing: {}", candidateVer, sr);
assertTrue(
"candidate was not on the newest version, new primary is on "
+ newPrimaryVersion
+ " and there is a candidate on "
+ candidateVer,
candidateVer.onOrBefore(newPrimaryVersion)
);
if (isSegmentReplicationEnabled) {
assertTrue(
"candidate was not on the oldest version, new primary is on "
+ newPrimaryVersion
+ " and there is a candidate on "
+ candidateVer,
candidateVer.onOrAfter(newPrimaryVersion)
);
} else {
assertTrue(
"candidate was not on the newest version, new primary is on "
+ newPrimaryVersion
+ " and there is a candidate on "
+ candidateVer,
candidateVer.onOrBefore(newPrimaryVersion)
);
}
}
});
});
Expand Down