Skip to content

Commit b7a6e09

Browse files
Fix index store type settings ordering for searchable snapshots (#7297) (#7299)
(cherry picked from commit 72ed13b) Signed-off-by: Kunal Kotwani <kkotwani@amazon.com> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent a4a5509 commit b7a6e09

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

server/src/internalClusterTest/java/org/opensearch/snapshots/SearchableSnapshotIT.java

+28
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import org.opensearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest;
1515
import org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse;
1616
import org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest;
17+
import org.opensearch.action.admin.indices.settings.get.GetSettingsRequest;
18+
import org.opensearch.action.admin.indices.settings.get.GetSettingsResponse;
1719
import org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequestBuilder;
1820
import org.opensearch.action.index.IndexRequestBuilder;
1921
import org.opensearch.action.support.master.AcknowledgedResponse;
@@ -28,6 +30,7 @@
2830
import org.opensearch.common.settings.Settings;
2931
import org.opensearch.common.unit.ByteSizeUnit;
3032
import org.opensearch.index.Index;
33+
import org.opensearch.index.IndexModule;
3134
import org.opensearch.index.IndexNotFoundException;
3235
import org.opensearch.index.store.remote.file.CleanerDaemonThreadLeakFilter;
3336
import org.opensearch.index.store.remote.filecache.FileCacheStats;
@@ -101,6 +104,7 @@ public void testCreateSearchableSnapshot() throws Exception {
101104

102105
internalCluster().ensureAtLeastNumSearchNodes(Math.max(numReplicasIndex1, numReplicasIndex2) + 1);
103106
restoreSnapshotAndEnsureGreen(client, snapshotName, repoName);
107+
assertRemoteSnapshotIndexSettings(client, restoredIndexName1, restoredIndexName2);
104108

105109
assertDocCount(restoredIndexName1, 100L);
106110
assertDocCount(restoredIndexName2, 100L);
@@ -196,6 +200,7 @@ public void testCreateSearchableSnapshotWithChunks() throws Exception {
196200

197201
deleteIndicesAndEnsureGreen(client, indexName);
198202
restoreSnapshotAndEnsureGreen(client, snapshotName, repoName);
203+
assertRemoteSnapshotIndexSettings(client, restoredIndexName);
199204

200205
assertDocCount(restoredIndexName, 1000L);
201206
}
@@ -219,6 +224,7 @@ public void testSearchableSnapshotAllocationForLocalAndRemoteShardsOnSameNode()
219224
takeSnapshot(client, snapshotName, repoName, indexName);
220225

221226
restoreSnapshotAndEnsureGreen(client, snapshotName, repoName);
227+
assertRemoteSnapshotIndexSettings(client, restoredIndexName);
222228

223229
assertDocCount(restoredIndexName, 100L);
224230
assertDocCount(indexName, 100L);
@@ -246,6 +252,7 @@ public void testSearchableSnapshotAllocationForFailoverAndRecovery() throws Exce
246252

247253
internalCluster().ensureAtLeastNumSearchNodes(numReplicasIndex + 1);
248254
restoreSnapshotAndEnsureGreen(client, snapshotName, repoName);
255+
assertRemoteSnapshotIndexSettings(client, restoredIndexName);
249256
assertDocCount(restoredIndexName, 100L);
250257

251258
logger.info("--> stop a random search node");
@@ -285,6 +292,7 @@ public void testSearchableSnapshotIndexIsReadOnly() throws Exception {
285292

286293
internalCluster().ensureAtLeastNumSearchNodes(1);
287294
restoreSnapshotAndEnsureGreen(client, snapshotName, repoName);
295+
assertRemoteSnapshotIndexSettings(client, restoredIndexName);
288296

289297
assertIndexingBlocked(restoredIndexName);
290298
assertTrue(client.admin().indices().prepareDelete(restoredIndexName).get().isAcknowledged());
@@ -334,6 +342,7 @@ private void createIndexWithDocsAndEnsureGreen(int numReplicasIndex, int numOfDo
334342
Settings.builder()
335343
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, Integer.toString(numReplicasIndex))
336344
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, "1")
345+
.put(IndexModule.INDEX_STORE_TYPE_SETTING.getKey(), IndexModule.Type.FS.getSettingsKey())
337346
.build()
338347
);
339348
ensureGreen();
@@ -386,6 +395,20 @@ private void restoreSnapshotAndEnsureGreen(Client client, String snapshotName, S
386395
ensureGreen();
387396
}
388397

398+
private void assertRemoteSnapshotIndexSettings(Client client, String... snapshotIndexNames) {
399+
GetSettingsResponse settingsResponse = client.admin()
400+
.indices()
401+
.getSettings(new GetSettingsRequest().indices(snapshotIndexNames))
402+
.actionGet();
403+
assertEquals(snapshotIndexNames.length, settingsResponse.getIndexToSettings().keys().size());
404+
for (String snapshotIndexName : snapshotIndexNames) {
405+
assertEquals(
406+
IndexModule.Type.REMOTE_SNAPSHOT.getSettingsKey(),
407+
settingsResponse.getSetting(snapshotIndexName, IndexModule.INDEX_STORE_TYPE_SETTING.getKey())
408+
);
409+
}
410+
}
411+
389412
private void assertIndexingBlocked(String index) {
390413
try {
391414
final IndexRequestBuilder builder = client().prepareIndex(index);
@@ -411,6 +434,7 @@ public void testUpdateIndexSettings() throws InterruptedException {
411434

412435
internalCluster().ensureAtLeastNumSearchNodes(1);
413436
restoreSnapshotAndEnsureGreen(client, snapshotName, repoName);
437+
assertRemoteSnapshotIndexSettings(client, restoredIndexName);
414438

415439
testUpdateIndexSettingsOnlyNotAllowedSettings(restoredIndexName);
416440
testUpdateIndexSettingsOnlyAllowedSettings(restoredIndexName);
@@ -491,6 +515,8 @@ public void testFileCacheRestore() throws Exception {
491515

492516
internalCluster().ensureAtLeastNumSearchNodes(numReplicasIndex + 1);
493517
restoreSnapshotAndEnsureGreen(client, snapshotName, repoName);
518+
assertRemoteSnapshotIndexSettings(client, restoredIndexName);
519+
494520
assertDocCount(restoredIndexName, 100L);
495521
assertIndexDirectoryDoesNotExist(restoredIndexName);
496522

@@ -598,6 +624,7 @@ public void testPruneFileCacheOnIndexDeletion() throws Exception {
598624
deleteIndicesAndEnsureGreen(client, indexName1);
599625

600626
restoreSnapshotAndEnsureGreen(client, snapshotName, repoName);
627+
assertRemoteSnapshotIndexSettings(client, restoredIndexName1);
601628
assertNodesFileCacheNonEmpty(numNodes);
602629

603630
deleteIndicesAndEnsureGreen(client, restoredIndexName1);
@@ -623,6 +650,7 @@ public void testCacheIndexFilesClearedOnDelete() throws Exception {
623650
takeSnapshot(client, snapshotName, repoName, indexName);
624651
restoreSnapshotAndEnsureGreen(client, snapshotName, repoName);
625652
assertDocCount(restoredIndexName, 100L);
653+
assertRemoteSnapshotIndexSettings(client, restoredIndexName);
626654

627655
// The index count will be 1 since there is only a single restored index "test-idx-copy"
628656
assertCacheDirectoryReplicaAndIndexCount(numShards, 1);

server/src/main/java/org/opensearch/snapshots/RestoreService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1255,12 +1255,12 @@ public void applyClusterState(ClusterChangedEvent event) {
12551255

12561256
private static IndexMetadata addSnapshotToIndexSettings(IndexMetadata metadata, Snapshot snapshot, IndexId indexId) {
12571257
final Settings newSettings = Settings.builder()
1258+
.put(metadata.getSettings())
12581259
.put(IndexModule.INDEX_STORE_TYPE_SETTING.getKey(), IndexModule.Type.REMOTE_SNAPSHOT.getSettingsKey())
12591260
.put(IndexSettings.SEARCHABLE_SNAPSHOT_REPOSITORY.getKey(), snapshot.getRepository())
12601261
.put(IndexSettings.SEARCHABLE_SNAPSHOT_ID_UUID.getKey(), snapshot.getSnapshotId().getUUID())
12611262
.put(IndexSettings.SEARCHABLE_SNAPSHOT_ID_NAME.getKey(), snapshot.getSnapshotId().getName())
12621263
.put(IndexSettings.SEARCHABLE_SNAPSHOT_INDEX_ID.getKey(), indexId.getId())
1263-
.put(metadata.getSettings())
12641264
.build();
12651265
return IndexMetadata.builder(metadata).settings(newSettings).build();
12661266
}

0 commit comments

Comments
 (0)