Skip to content

Commit c5d29a9

Browse files
committed
test fixes
Signed-off-by: Marc Handalian <marc.handalian@gmail.com>
1 parent a42af7e commit c5d29a9

File tree

2 files changed

+42
-31
lines changed

2 files changed

+42
-31
lines changed

server/src/internalClusterTest/java/org/opensearch/indices/settings/SearchOnlyReplicaFeatureFlagIT.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_SEARCH_REPLICAS;
1919
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_REPLICATION_TYPE;
20-
import static org.opensearch.cluster.routing.UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING;
2120

2221
@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.SUITE, numDataNodes = 1)
2322
public class SearchOnlyReplicaFeatureFlagIT extends OpenSearchIntegTestCase {
@@ -32,27 +31,15 @@ protected Settings featureFlagSettings() {
3231
.build();
3332
}
3433

35-
@Override
36-
public Settings indexSettings() {
37-
return Settings.builder()
38-
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
39-
.put(IndexMetadata.SETTING_NUMBER_OF_SEARCH_REPLICAS, 1)
40-
.put(SETTING_REPLICATION_TYPE, ReplicationType.SEGMENT)
41-
.build();
42-
}
43-
4434
public void testCreateFeatureFlagDisabled() {
4535
Settings settings = Settings.builder().put(indexSettings()).put(FeatureFlags.READER_WRITER_SPLIT_EXPERIMENTAL, false).build();
46-
4736
SettingsException settingsException = expectThrows(SettingsException.class, () -> createIndex(TEST_INDEX, settings));
4837
assertTrue(settingsException.getMessage().contains("unknown setting"));
4938
}
5039

5140
public void testUpdateFeatureFlagDisabled() {
5241
Settings settings = Settings.builder()
5342
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
54-
.put(INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), "0ms") // so that after we punt a node we can immediately try to
55-
// reallocate after node left.
5643
.put(SETTING_REPLICATION_TYPE, ReplicationType.SEGMENT)
5744
.build();
5845

server/src/internalClusterTest/java/org/opensearch/indices/settings/SearchOnlyReplicaIT.java

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
package org.opensearch.indices.settings;
1010

11+
import org.opensearch.action.support.WriteRequest;
1112
import org.opensearch.cluster.ClusterState;
1213
import org.opensearch.cluster.metadata.IndexMetadata;
1314
import org.opensearch.cluster.metadata.Metadata;
@@ -24,6 +25,7 @@
2425
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_SEARCH_REPLICAS;
2526
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_REPLICATION_TYPE;
2627
import static org.opensearch.cluster.routing.UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING;
28+
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertHitCount;
2729

2830
@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0)
2931
public class SearchOnlyReplicaIT extends OpenSearchIntegTestCase {
@@ -79,9 +81,9 @@ public void testUpdateDocRepFails() {
7981
assertEquals(expectedFailureMessage, illegalArgumentException.getMessage());
8082
}
8183

82-
public void testSearchReplicasAreNotPrimaryEligible() throws IOException {
83-
int numSearchReplicas = randomIntBetween(0, 3);
84-
int numWriterReplicas = randomIntBetween(0, 3);
84+
public void testFailoverWithSearchReplica_WithWriterReplicas() throws IOException {
85+
int numSearchReplicas = 1;
86+
int numWriterReplicas = 1;
8587
internalCluster().startClusterManagerOnlyNode();
8688
String primaryNodeName = internalCluster().startDataOnlyNode();
8789
createIndex(
@@ -93,29 +95,51 @@ public void testSearchReplicasAreNotPrimaryEligible() throws IOException {
9395
.build()
9496
);
9597
ensureYellow(TEST_INDEX);
96-
for (int i = 0; i < numSearchReplicas + numWriterReplicas; i++) {
97-
internalCluster().startDataOnlyNode();
98-
}
98+
// add 2 nodes for the replicas
99+
internalCluster().startDataOnlyNodes(2);
99100
ensureGreen(TEST_INDEX);
100101

101102
// assert shards are on separate nodes & all active
102103
assertActiveShardCounts(numSearchReplicas, numWriterReplicas);
103104

104105
// stop the primary and ensure search shard is not promoted:
105106
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(primaryNodeName));
106-
ensureRed(TEST_INDEX);
107+
ensureYellowAndNoInitializingShards(TEST_INDEX);
108+
109+
assertActiveShardCounts(numSearchReplicas, 0); // 1 repl is inactive that was promoted to primary
110+
// add back a node
111+
internalCluster().startDataOnlyNode();
112+
ensureGreen(TEST_INDEX);
113+
114+
}
115+
116+
public void testFailoverWithSearchReplica_WithoutWriterReplicas() throws IOException {
117+
int numSearchReplicas = 1;
118+
int numWriterReplicas = 0;
119+
internalCluster().startClusterManagerOnlyNode();
120+
String primaryNodeName = internalCluster().startDataOnlyNode();
121+
createIndex(
122+
TEST_INDEX,
123+
Settings.builder()
124+
.put(indexSettings())
125+
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, numWriterReplicas)
126+
.put(IndexMetadata.SETTING_NUMBER_OF_SEARCH_REPLICAS, numSearchReplicas)
127+
.build()
128+
);
129+
ensureYellow(TEST_INDEX);
130+
client().prepareIndex(TEST_INDEX).setId("1").setSource("foo", "bar").setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
131+
// start a node for our search replica
132+
String replica = internalCluster().startDataOnlyNode();
133+
ensureGreen(TEST_INDEX);
134+
assertActiveSearchShards(numSearchReplicas);
135+
assertHitCount(client(replica).prepareSearch(TEST_INDEX).setSize(0).setPreference("_only_local").get(), 1);
107136

108-
if (numWriterReplicas > 0) {
109-
assertActiveShardCounts(numSearchReplicas, numWriterReplicas - 1); // 1 repl is inactive that was promoted to primary
110-
// add back a node
111-
internalCluster().startDataOnlyNode();
112-
ensureGreen(TEST_INDEX);
113-
} else {
114-
// index falls red and does not recover
115-
// Without any writer replica with n2n replication this is an unrecoverable scenario and snapshot restore is required.
116-
ensureRed(TEST_INDEX);
117-
assertActiveSearchShards(numSearchReplicas);
118-
}
137+
// stop the primary and ensure search shard is not promoted:
138+
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(primaryNodeName));
139+
ensureRed(TEST_INDEX);
140+
assertActiveSearchShards(numSearchReplicas);
141+
// while red our search shard is still searchable
142+
assertHitCount(client(replica).prepareSearch(TEST_INDEX).setSize(0).setPreference("_only_local").get(), 1);
119143
}
120144

121145
public void testSearchReplicaScaling() {

0 commit comments

Comments
 (0)