Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Shard Level Metdata check in BlobStoreTestUtil #75737

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,8 @@ public void testRepairBrokenShardGenerations() throws Exception {
* Tests that a shard snapshot with a corrupted shard index file can still be used for restore and incremental snapshots.
*/
public void testSnapshotWithCorruptedShardIndexFile() throws Exception {
disableRepoConsistencyCheck("This test intentionally corrupts the repository contents");

final Client client = client();
final Path repo = randomRepoPath();
final String indexName = "test-idx";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private String getIndexMetadataId() throws IOException {
private BlobStoreIndexShardSnapshots getBlobStoreIndexShardSnapshots() throws IOException {
BlobStoreRepository blobStoreRepository = (BlobStoreRepository) repository;
final String shardGen = repositoryData.shardGenerations().getShardGen(indexId, shardId.getId());
return blobStoreRepository.getBlobStoreIndexShardSnapshots(indexId, shardId, shardGen);
return blobStoreRepository.getBlobStoreIndexShardSnapshots(indexId, shardId.getId(), shardGen);
}

private ShardSnapshotInfo createIndexShardSnapshotInfo(String indexMetadataId, SnapshotFiles snapshotFiles) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3238,10 +3238,9 @@ public BlobStoreIndexShardSnapshot loadShardSnapshot(BlobContainer shardContaine
* Loads all available snapshots in the repository using the given {@code generation} for a shard. When {@code shardGen}
* is null it tries to load it using the BwC mode, listing the available index- blobs in the shard container.
*/
public BlobStoreIndexShardSnapshots getBlobStoreIndexShardSnapshots(IndexId indexId, ShardId shardId, @Nullable String shardGen)
public BlobStoreIndexShardSnapshots getBlobStoreIndexShardSnapshots(IndexId indexId, int shardId, @Nullable String shardGen)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This API adjustment makes sense in isolation anyway IMO. It's misleading to assume that this logic would filter by ShardId when in fact it merely filters by index id and shard number without reference to the original Index in the ShardId.

throws IOException {
final int shard = shardId.getId();
final BlobContainer shardContainer = shardContainer(indexId, shard);
final BlobContainer shardContainer = shardContainer(indexId, shardId);

Set<String> blobs = Collections.emptySet();
if (shardGen == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshots;
import org.elasticsearch.repositories.GetSnapshotInfoContext;
import org.elasticsearch.repositories.IndexId;
import org.elasticsearch.repositories.RepositoryData;
Expand Down Expand Up @@ -300,6 +301,10 @@ private static void assertSnapshotInfosConsistency(BlobStoreRepository repositor
hasKey(String.format(Locale.ROOT, BlobStoreRepository.SNAPSHOT_NAME_FORMAT, snapshotId.getUUID())));
assertThat(shardPathContents.keySet().stream()
.filter(name -> name.startsWith(BlobStoreRepository.INDEX_FILE_PREFIX)).count(), lessThanOrEqualTo(2L));
final BlobStoreIndexShardSnapshots blobStoreIndexShardSnapshots = repository.getBlobStoreIndexShardSnapshots(
indexId, shardId, repositoryData.shardGenerations().getShardGen(indexId, shardId));
assertTrue(blobStoreIndexShardSnapshots.snapshots().stream()
.anyMatch(snapshotFiles -> snapshotFiles.snapshot().equals(snapshotId.getName())));
}
}
}
Expand Down