Browse Source

Take into account the latest valid snapshot index metadata id (#77412)

Closes #77343
Francisco Fernández Castaño 4 years ago
parent
commit
0dfc4eda3e

+ 6 - 4
server/src/internalClusterTest/java/org/elasticsearch/repositories/IndexSnapshotsServiceIT.java

@@ -124,6 +124,8 @@ public class IndexSnapshotsServiceIT extends AbstractSnapshotIntegTestCase {
         List<String> indices = List.of(indexName, indexName2);
         List<String> indices = List.of(indexName, indexName2);
         createIndex(indexName, indexName2);
         createIndex(indexName, indexName2);
         SnapshotInfo lastSnapshot = null;
         SnapshotInfo lastSnapshot = null;
+        String expectedIndexMetadataId = null;
+
         int numSnapshots = randomIntBetween(5, 25);
         int numSnapshots = randomIntBetween(5, 25);
         for (int i = 0; i < numSnapshots; i++) {
         for (int i = 0; i < numSnapshots; i++) {
             if (randomBoolean()) {
             if (randomBoolean()) {
@@ -134,6 +136,9 @@ public class IndexSnapshotsServiceIT extends AbstractSnapshotIntegTestCase {
             final SnapshotInfo snapshotInfo = createSnapshot(repoName, String.format(Locale.ROOT, "snap-%03d", i), snapshotIndices);
             final SnapshotInfo snapshotInfo = createSnapshot(repoName, String.format(Locale.ROOT, "snap-%03d", i), snapshotIndices);
             if (snapshotInfo.indices().contains(indexName)) {
             if (snapshotInfo.indices().contains(indexName)) {
                 lastSnapshot = snapshotInfo;
                 lastSnapshot = snapshotInfo;
+                ClusterStateResponse clusterStateResponse = admin().cluster().prepareState().execute().actionGet();
+                IndexMetadata indexMetadata = clusterStateResponse.getState().metadata().index(indexName);
+                expectedIndexMetadataId = IndexMetaDataGenerations.buildUniqueIdentifier(indexMetadata);
             }
             }
         }
         }
 
 
@@ -151,10 +156,7 @@ public class IndexSnapshotsServiceIT extends AbstractSnapshotIntegTestCase {
 
 
             final ShardSnapshotInfo shardSnapshotInfo = indexShardSnapshotInfoOpt.get();
             final ShardSnapshotInfo shardSnapshotInfo = indexShardSnapshotInfoOpt.get();
 
 
-            final ClusterStateResponse clusterStateResponse = admin().cluster().prepareState().execute().actionGet();
-            final IndexMetadata indexMetadata = clusterStateResponse.getState().metadata().index(indexName);
-            final String indexMetadataId = IndexMetaDataGenerations.buildUniqueIdentifier(indexMetadata);
-            assertThat(shardSnapshotInfo.getIndexMetadataIdentifier(), equalTo(indexMetadataId));
+            assertThat(shardSnapshotInfo.getIndexMetadataIdentifier(), equalTo(expectedIndexMetadataId));
 
 
             final Snapshot snapshot = shardSnapshotInfo.getSnapshot();
             final Snapshot snapshot = shardSnapshotInfo.getSnapshot();
             assertThat(snapshot, equalTo(lastSnapshot.snapshot()));
             assertThat(snapshot, equalTo(lastSnapshot.snapshot()));