Skip to content

Commit e622f3e

Browse files
Enhance Shard Level Metdata check in BlobStoreTestUtil (#75737) (#76561)
Adding check that shard level index metadata actually contains the snapshots it's supposed to contain. This would have caught a number of recent bugs.
1 parent 674b834 commit e622f3e

File tree

5 files changed

+12
-9
lines changed

5 files changed

+12
-9
lines changed

server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/plan/ShardSnapshotsServiceIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public BlobStoreIndexShardSnapshot loadShardSnapshot(BlobContainer shardContaine
123123

124124
@Override
125125
public BlobStoreIndexShardSnapshots getBlobStoreIndexShardSnapshots(IndexId indexId,
126-
ShardId shardId,
126+
int shardId,
127127
ShardGeneration shardGen) throws IOException {
128128
if (failLoadShardSnapshots) {
129129
throw new FileNotFoundException("Failed to get blob store index shard snapshots");

server/src/internalClusterTest/java/org/elasticsearch/snapshots/CorruptedBlobStoreRepositoryIT.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,8 @@ public void testRepairBrokenShardGenerations() throws Exception {
524524
* Tests that a shard snapshot with a corrupted shard index file can still be used for restore and incremental snapshots.
525525
*/
526526
public void testSnapshotWithCorruptedShardIndexFile() throws Exception {
527+
disableRepoConsistencyCheck("This test intentionally corrupts the repository contents");
528+
527529
final Client client = client();
528530
final Path repo = randomRepoPath();
529531
final String indexName = "test-idx";

server/src/main/java/org/elasticsearch/repositories/IndexSnapshotsService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ private String getIndexMetadataId() throws IOException {
162162
private BlobStoreIndexShardSnapshots getBlobStoreIndexShardSnapshots() throws IOException {
163163
BlobStoreRepository blobStoreRepository = (BlobStoreRepository) repository;
164164
final ShardGeneration shardGen = repositoryData.shardGenerations().getShardGen(indexId, shardId.getId());
165-
return blobStoreRepository.getBlobStoreIndexShardSnapshots(indexId, shardId, shardGen);
165+
return blobStoreRepository.getBlobStoreIndexShardSnapshots(indexId, shardId.getId(), shardGen);
166166
}
167167

168168
private ShardSnapshotInfo createIndexShardSnapshotInfo(String indexMetadataId, SnapshotFiles snapshotFiles) {

server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3329,13 +3329,9 @@ public BlobStoreIndexShardSnapshot loadShardSnapshot(BlobContainer shardContaine
33293329
* Loads all available snapshots in the repository using the given {@code generation} for a shard. When {@code shardGen}
33303330
* is null it tries to load it using the BwC mode, listing the available index- blobs in the shard container.
33313331
*/
3332-
public BlobStoreIndexShardSnapshots getBlobStoreIndexShardSnapshots(
3333-
IndexId indexId,
3334-
ShardId shardId,
3335-
@Nullable ShardGeneration shardGen
3336-
) throws IOException {
3337-
final int shard = shardId.getId();
3338-
final BlobContainer shardContainer = shardContainer(indexId, shard);
3332+
public BlobStoreIndexShardSnapshots getBlobStoreIndexShardSnapshots(IndexId indexId, int shardId, @Nullable ShardGeneration shardGen)
3333+
throws IOException {
3334+
final BlobContainer shardContainer = shardContainer(indexId, shardId);
33393335

33403336
Set<String> blobs = Collections.emptySet();
33413337
if (shardGen == null) {

test/framework/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreTestUtil.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
3636
import org.elasticsearch.common.xcontent.XContentParser;
3737
import org.elasticsearch.common.xcontent.XContentType;
38+
import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshots;
3839
import org.elasticsearch.repositories.GetSnapshotInfoContext;
3940
import org.elasticsearch.repositories.IndexId;
4041
import org.elasticsearch.repositories.RepositoryData;
@@ -305,6 +306,10 @@ private static void assertSnapshotInfosConsistency(BlobStoreRepository repositor
305306
hasKey(String.format(Locale.ROOT, BlobStoreRepository.SNAPSHOT_NAME_FORMAT, snapshotId.getUUID())));
306307
assertThat(shardPathContents.keySet().stream()
307308
.filter(name -> name.startsWith(BlobStoreRepository.INDEX_FILE_PREFIX)).count(), lessThanOrEqualTo(2L));
309+
final BlobStoreIndexShardSnapshots blobStoreIndexShardSnapshots = repository.getBlobStoreIndexShardSnapshots(
310+
indexId, shardId, repositoryData.shardGenerations().getShardGen(indexId, shardId));
311+
assertTrue(blobStoreIndexShardSnapshots.snapshots().stream()
312+
.anyMatch(snapshotFiles -> snapshotFiles.snapshot().equals(snapshotId.getName())));
308313
}
309314
}
310315
}

0 commit comments

Comments
 (0)