Skip to content

Commit a40ea88

Browse files
authored
Add tests to randomly close and re-open searchable snapshots in N-2 version (#119594)
Relates ES-10433
1 parent 7b6d4d1 commit a40ea88

File tree

3 files changed

+60
-3
lines changed

3 files changed

+60
-3
lines changed

qa/lucene-index-compatibility/src/javaRestTest/java/org/elasticsearch/lucene/AbstractIndexCompatibilityTestCase.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.apache.http.entity.ContentType;
1313
import org.apache.http.entity.InputStreamEntity;
1414
import org.elasticsearch.client.Request;
15+
import org.elasticsearch.cluster.metadata.IndexMetadata;
1516
import org.elasticsearch.common.settings.Settings;
1617
import org.elasticsearch.core.Strings;
1718
import org.elasticsearch.index.IndexSettings;
@@ -232,4 +233,9 @@ protected static void updateRandomMappings(String indexName) throws IOException
232233
assertOK(client().performRequest(request));
233234
}
234235

236+
protected static boolean isIndexClosed(String indexName) throws Exception {
237+
var responseBody = createFromResponse(client().performRequest(new Request("GET", "_cluster/state/metadata/" + indexName)));
238+
var state = responseBody.evaluate("metadata.indices." + indexName + ".state");
239+
return IndexMetadata.State.fromString((String) state) == IndexMetadata.State.CLOSE;
240+
}
235241
}

qa/lucene-index-compatibility/src/javaRestTest/java/org/elasticsearch/lucene/FullClusterRestartSearchableSnapshotIndexCompatibilityIT.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ public void testSearchableSnapshot() throws Exception {
7676
var mountedIndex = suffix("index-mounted");
7777
logger.debug("--> mounting index [{}] as [{}]", index, mountedIndex);
7878
mountIndex(repository, snapshot, index, randomBoolean(), mountedIndex);
79-
8079
ensureGreen(mountedIndex);
8180

8281
assertThat(indexVersion(mountedIndex), equalTo(VERSION_MINUS_2));
@@ -88,6 +87,23 @@ public void testSearchableSnapshot() throws Exception {
8887
logger.debug("--> adding replica to test peer-recovery");
8988
updateIndexSettings(mountedIndex, Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1));
9089
ensureGreen(mountedIndex);
90+
91+
logger.debug("--> closing index [{}]", mountedIndex);
92+
closeIndex(mountedIndex);
93+
ensureGreen(mountedIndex);
94+
95+
logger.debug("--> adding replica to test peer-recovery for closed shards");
96+
updateIndexSettings(mountedIndex, Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 2));
97+
ensureGreen(mountedIndex);
98+
99+
logger.debug("--> re-opening index [{}]", mountedIndex);
100+
openIndex(mountedIndex);
101+
ensureGreen(mountedIndex);
102+
103+
assertDocCount(client(), mountedIndex, numDocs);
104+
105+
logger.debug("--> deleting index [{}]", mountedIndex);
106+
deleteIndex(mountedIndex);
91107
}
92108
}
93109

@@ -138,20 +154,36 @@ public void testSearchableSnapshotUpgrade() throws Exception {
138154

139155
assertThat(indexVersion(mountedIndex), equalTo(VERSION_MINUS_2));
140156
assertDocCount(client(), mountedIndex, numDocs);
157+
158+
logger.debug("--> adding replica to test replica upgrade");
159+
updateIndexSettings(mountedIndex, Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1));
160+
ensureGreen(mountedIndex);
161+
162+
if (randomBoolean()) {
163+
logger.debug("--> random closing of index [{}] before upgrade", mountedIndex);
164+
closeIndex(mountedIndex);
165+
ensureGreen(mountedIndex);
166+
}
141167
return;
142168
}
143169

144170
if (isFullyUpgradedTo(VERSION_CURRENT)) {
145171
ensureGreen(mountedIndex);
146172

173+
if (isIndexClosed(mountedIndex)) {
174+
logger.debug("--> re-opening index [{}] after upgrade", mountedIndex);
175+
openIndex(mountedIndex);
176+
ensureGreen(mountedIndex);
177+
}
178+
147179
assertThat(indexVersion(mountedIndex), equalTo(VERSION_MINUS_2));
148180
assertDocCount(client(), mountedIndex, numDocs);
149181

150182
updateRandomIndexSettings(mountedIndex);
151183
updateRandomMappings(mountedIndex);
152184

153185
logger.debug("--> adding replica to test peer-recovery");
154-
updateIndexSettings(mountedIndex, Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1));
186+
updateIndexSettings(mountedIndex, Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 2));
155187
ensureGreen(mountedIndex);
156188
}
157189
}

qa/lucene-index-compatibility/src/javaRestTest/java/org/elasticsearch/lucene/RollingUpgradeSearchableSnapshotIndexCompatibilityIT.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ public void testMountSearchableSnapshot() throws Exception {
7373
try {
7474
logger.debug("--> mounting index [{}] as [{}]", index, mountedIndex);
7575
mountIndex(repository, snapshot, index, randomBoolean(), mountedIndex);
76-
7776
ensureGreen(mountedIndex);
7877

7978
updateRandomIndexSettings(mountedIndex);
@@ -82,6 +81,14 @@ public void testMountSearchableSnapshot() throws Exception {
8281
assertThat(indexVersion(mountedIndex), equalTo(VERSION_MINUS_2));
8382
assertDocCount(client(), mountedIndex, numDocs);
8483

84+
logger.debug("--> closing mounted index [{}]", mountedIndex);
85+
closeIndex(mountedIndex);
86+
ensureGreen(mountedIndex);
87+
88+
logger.debug("--> re-opening index [{}]", mountedIndex);
89+
openIndex(mountedIndex);
90+
ensureGreen(mountedIndex);
91+
8592
logger.debug("--> deleting mounted index [{}]", mountedIndex);
8693
deleteIndex(mountedIndex);
8794

@@ -137,10 +144,22 @@ public void testSearchableSnapshotUpgrade() throws Exception {
137144

138145
ensureGreen(mountedIndex);
139146

147+
if (isIndexClosed(mountedIndex)) {
148+
logger.debug("--> re-opening index [{}] after upgrade", mountedIndex);
149+
openIndex(mountedIndex);
150+
ensureGreen(mountedIndex);
151+
}
152+
140153
updateRandomIndexSettings(mountedIndex);
141154
updateRandomMappings(mountedIndex);
142155

143156
assertThat(indexVersion(mountedIndex), equalTo(VERSION_MINUS_2));
144157
assertDocCount(client(), mountedIndex, numDocs);
158+
159+
if (randomBoolean()) {
160+
logger.debug("--> random closing of index [{}] before upgrade", mountedIndex);
161+
closeIndex(mountedIndex);
162+
ensureGreen(mountedIndex);
163+
}
145164
}
146165
}

0 commit comments

Comments
 (0)