Skip to content

Commit 51f7ea0

Browse files
mch2dreamer-89
authored andcommitted
[Backport 2.x] Backport SegmentReplication test muting missing from 2.x. (#5945)
* [Segment Replication] Add snapshot and restore tests for segment replication feature (#3993) * [Segment Replication] Add snapshots tests with segment replication enabled Signed-off-by: Suraj Singh <surajrider@gmail.com> * Fix spotless failures Signed-off-by: Suraj Singh <surajrider@gmail.com> * Add changelog entry, address review comments, add failover test Signed-off-by: Suraj Singh <surajrider@gmail.com> * Fix spotless failures Signed-off-by: Suraj Singh <surajrider@gmail.com> * Address review comments 2 Signed-off-by: Suraj Singh <surajrider@gmail.com> Signed-off-by: Suraj Singh <surajrider@gmail.com> * Remove changelog update. Signed-off-by: Marc Handalian <handalm@amazon.com> * Mute flaky test testStartReplicaAfterPrimaryIndexesDocs. (#5714) Signed-off-by: Marc Handalian <handalm@amazon.com> Signed-off-by: Marc Handalian <handalm@amazon.com> * Fix flaky Segment Replication test testStartReplicaAfterPrimaryIndexesDocs. (#5722) * Fix flaky SR test testStartReplicaAfterPrimaryIndexesDocs. This test was failing because we are validating post recovery if a shard is able to perform segrep while also performing validation if a passed in checkopint. In the post recovery test this checkpoint is always empty, yet the shard will be ahead of this checkpoint after docs are indexed. This change differentiates shard validation from checkpoint validation. Signed-off-by: Marc Handalian <handalm@amazon.com> Fix spotless. Signed-off-by: Marc Handalian <handalm@amazon.com> Fix testIsSegmentReplicationAllowed_WrongEngineType. Signed-off-by: Marc Handalian <handalm@amazon.com> Update warn logs in isSegmentReplicationAllowed. Signed-off-by: Marc Handalian <handalm@amazon.com> * PR feedback. Signed-off-by: Marc Handalian <handalm@amazon.com> Signed-off-by: Marc Handalian <handalm@amazon.com> * [Segment Replication] Mute flaky tests (#5739) Signed-off-by: Suraj Singh <surajrider@gmail.com> Signed-off-by: Suraj Singh <surajrider@gmail.com> * [Segment Replication] Mute flaky tests (#5742) Signed-off-by: Suraj Singh <surajrider@gmail.com> Signed-off-by: Suraj Singh <surajrider@gmail.com> * Fix spotless. Signed-off-by: Marc Handalian <handalm@amazon.com> * Muting flaky SegmentReplication ITs. (#5700) Signed-off-by: Marc Handalian <handalm@amazon.com> Signed-off-by: Marc Handalian <handalm@amazon.com> Signed-off-by: Suraj Singh <surajrider@gmail.com> Signed-off-by: Marc Handalian <handalm@amazon.com> Co-authored-by: Suraj Singh <surajrider@gmail.com>
1 parent 95d7895 commit 51f7ea0

5 files changed

Lines changed: 417 additions & 21 deletions

File tree

server/src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationIT.java

Lines changed: 88 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import org.opensearch.action.admin.indices.segments.IndicesSegmentsRequest;
1717
import org.opensearch.action.admin.indices.segments.ShardSegments;
1818
import org.opensearch.action.support.WriteRequest;
19+
import org.opensearch.action.update.UpdateResponse;
20+
import org.opensearch.client.Requests;
1921
import org.opensearch.cluster.ClusterState;
2022
import org.opensearch.cluster.metadata.IndexMetadata;
2123
import org.opensearch.cluster.node.DiscoveryNode;
@@ -55,15 +57,17 @@
5557
import java.util.stream.Collectors;
5658

5759
import static org.hamcrest.Matchers.equalTo;
58-
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;
60+
import static org.opensearch.index.query.QueryBuilders.matchQuery;
5961
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertHitCount;
62+
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;
63+
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchHits;
6064

6165
@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0)
6266
public class SegmentReplicationIT extends OpenSearchIntegTestCase {
6367

64-
private static final String INDEX_NAME = "test-idx-1";
65-
private static final int SHARD_COUNT = 1;
66-
private static final int REPLICA_COUNT = 1;
68+
protected static final String INDEX_NAME = "test-idx-1";
69+
protected static final int SHARD_COUNT = 1;
70+
protected static final int REPLICA_COUNT = 1;
6771

6872
@Override
6973
protected Collection<Class<? extends Plugin>> nodePlugins() {
@@ -91,6 +95,26 @@ protected Settings featureFlagSettings() {
9195
return Settings.builder().put(super.featureFlagSettings()).put(FeatureFlags.REPLICATION_TYPE, "true").build();
9296
}
9397

98+
public void ingestDocs(int docCount) throws Exception {
99+
try (
100+
BackgroundIndexer indexer = new BackgroundIndexer(
101+
INDEX_NAME,
102+
"_doc",
103+
client(),
104+
-1,
105+
RandomizedTest.scaledRandomIntBetween(2, 5),
106+
false,
107+
random()
108+
)
109+
) {
110+
indexer.start(docCount);
111+
waitForDocs(docCount, indexer);
112+
refresh(INDEX_NAME);
113+
waitForReplicaUpdate();
114+
}
115+
}
116+
117+
@AwaitsFix(bugUrl = "https://github.com/opensearch-project/OpenSearch/issues/5669")
94118
public void testPrimaryStopped_ReplicaPromoted() throws Exception {
95119
final String primary = internalCluster().startNode(featureFlagSettings());
96120
createIndex(INDEX_NAME);
@@ -132,6 +156,7 @@ public void testPrimaryStopped_ReplicaPromoted() throws Exception {
132156
assertSegmentStats(REPLICA_COUNT);
133157
}
134158

159+
@AwaitsFix(bugUrl = "https://github.com/opensearch-project/OpenSearch/issues/5669")
135160
public void testRestartPrimary() throws Exception {
136161
final String primary = internalCluster().startNode(featureFlagSettings());
137162
createIndex(INDEX_NAME);
@@ -266,6 +291,7 @@ public void testAddNewReplicaFailure() throws Exception {
266291
assertFalse(indicesService.hasIndex(resolveIndex(INDEX_NAME)));
267292
}
268293

294+
@AwaitsFix(bugUrl = "https://github.com/opensearch-project/OpenSearch/issues/5669")
269295
public void testReplicationAfterPrimaryRefreshAndFlush() throws Exception {
270296
final String nodeA = internalCluster().startNode(featureFlagSettings());
271297
final String nodeB = internalCluster().startNode(featureFlagSettings());
@@ -497,6 +523,7 @@ public void testCancellation() throws Exception {
497523
assertDocCounts(docCount, primaryNode);
498524
}
499525

526+
@AwaitsFix(bugUrl = "https://github.com/opensearch-project/OpenSearch/issues/5669")
500527
public void testStartReplicaAfterPrimaryIndexesDocs() throws Exception {
501528
final String primaryNode = internalCluster().startNode(featureFlagSettings());
502529
createIndex(INDEX_NAME, Settings.builder().put(indexSettings()).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0).build());
@@ -598,6 +625,61 @@ public void testDeleteOperations() throws Exception {
598625
}
599626
}
600627

628+
@AwaitsFix(bugUrl = "https://github.com/opensearch-project/OpenSearch/issues/5669")
629+
public void testUpdateOperations() throws Exception {
630+
final String primary = internalCluster().startNode(featureFlagSettings());
631+
createIndex(INDEX_NAME);
632+
ensureYellow(INDEX_NAME);
633+
final String replica = internalCluster().startNode(featureFlagSettings());
634+
635+
final int initialDocCount = scaledRandomIntBetween(0, 200);
636+
try (
637+
BackgroundIndexer indexer = new BackgroundIndexer(
638+
INDEX_NAME,
639+
"_doc",
640+
client(),
641+
-1,
642+
RandomizedTest.scaledRandomIntBetween(2, 5),
643+
false,
644+
random()
645+
)
646+
) {
647+
indexer.start(initialDocCount);
648+
waitForDocs(initialDocCount, indexer);
649+
refresh(INDEX_NAME);
650+
waitForReplicaUpdate();
651+
652+
// wait a short amount of time to give replication a chance to complete.
653+
assertHitCount(client(primary).prepareSearch(INDEX_NAME).setSize(0).setPreference("_only_local").get(), initialDocCount);
654+
assertHitCount(client(replica).prepareSearch(INDEX_NAME).setSize(0).setPreference("_only_local").get(), initialDocCount);
655+
656+
final int additionalDocCount = scaledRandomIntBetween(0, 200);
657+
final int expectedHitCount = initialDocCount + additionalDocCount;
658+
indexer.start(additionalDocCount);
659+
waitForDocs(expectedHitCount, indexer);
660+
waitForReplicaUpdate();
661+
662+
assertHitCount(client(primary).prepareSearch(INDEX_NAME).setSize(0).setPreference("_only_local").get(), expectedHitCount);
663+
assertHitCount(client(replica).prepareSearch(INDEX_NAME).setSize(0).setPreference("_only_local").get(), expectedHitCount);
664+
665+
Set<String> ids = indexer.getIds();
666+
String id = ids.toArray()[0].toString();
667+
UpdateResponse updateResponse = client(primary).prepareUpdate(INDEX_NAME, id)
668+
.setDoc(Requests.INDEX_CONTENT_TYPE, "foo", "baz")
669+
.setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL)
670+
.get();
671+
assertFalse("request shouldn't have forced a refresh", updateResponse.forcedRefresh());
672+
assertEquals(2, updateResponse.getVersion());
673+
674+
refresh(INDEX_NAME);
675+
waitForReplicaUpdate();
676+
677+
assertSearchHits(client(primary).prepareSearch(INDEX_NAME).setQuery(matchQuery("foo", "baz")).get(), id);
678+
assertSearchHits(client(replica).prepareSearch(INDEX_NAME).setQuery(matchQuery("foo", "baz")).get(), id);
679+
680+
}
681+
}
682+
601683
private void assertSegmentStats(int numberOfReplicas) throws IOException {
602684
final IndicesSegmentResponse indicesSegmentResponse = client().admin().indices().segments(new IndicesSegmentsRequest()).actionGet();
603685

@@ -689,7 +771,7 @@ public void testDropPrimaryDuringReplication() throws Exception {
689771

690772
/**
691773
* Waits until the replica is caught up to the latest primary segments gen.
692-
* @throws Exception
774+
* @throws Exception if assertion fails
693775
*/
694776
private void waitForReplicaUpdate() throws Exception {
695777
// wait until the replica has the latest segment generation.
@@ -706,7 +788,7 @@ private void waitForReplicaUpdate() throws Exception {
706788
// if we don't have any segments yet, proceed.
707789
final ShardSegments primaryShardSegments = primaryShardSegmentsList.stream().findFirst().get();
708790
logger.debug("Primary Segments: {}", primaryShardSegments.getSegments());
709-
if (primaryShardSegments.getSegments().isEmpty() == false) {
791+
if (primaryShardSegments.getSegments().isEmpty() == false && replicaShardSegments != null) {
710792
final Map<String, Segment> latestPrimarySegments = getLatestSegments(primaryShardSegments);
711793
final Long latestPrimaryGen = latestPrimarySegments.values().stream().findFirst().map(Segment::getGeneration).get();
712794
for (ShardSegments shardSegments : replicaShardSegments) {

0 commit comments

Comments
 (0)