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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/93914.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 93914
summary: Fix unhandled exception when blobstore repository contains unexpected file
area: Snapshot/Restore
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.elasticsearch.repositories.ShardGeneration;
import org.elasticsearch.repositories.ShardGenerations;
import org.elasticsearch.repositories.blobstore.BlobStoreRepository;
import org.elasticsearch.repositories.fs.FsRepository;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xcontent.XContentFactory;

Expand Down Expand Up @@ -814,6 +815,19 @@ public void testSnapshotWithMissingShardLevelIndexFile() throws Exception {
assertEquals(0, restoreSnapshotResponse.getRestoreInfo().failedShards());
}

public void testDeletesWithUnexpectedIndexBlob() throws Exception {
Path repo = randomRepoPath();
final String repoName = "test-repo";
createRepository(repoName, FsRepository.TYPE, repo);
final String snapshot = "first-snapshot";
createFullSnapshot(repoName, snapshot);
// create extra file with the index prefix
final var extraFile = Files.createFile(repo.resolve(BlobStoreRepository.INDEX_FILE_PREFIX + randomAlphaOfLength(5)));
assertAcked(startDeleteSnapshot(repoName, snapshot).get());
// delete file again so repo consistency checks pass
Files.delete(extraFile);
}

private void assertRepositoryBlocked(String repo, String existingSnapshot) {
if (getRepositoryMetadata(repo).generation() == RepositoryData.CORRUPTED_REPO_GEN) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,12 @@ private static List<String> staleRootBlobs(RepositoryData repositoryData, Set<St
return allSnapshotIds.contains(foundUUID) == false;
} else if (blob.startsWith(INDEX_FILE_PREFIX)) {
// TODO: Include the current generation here once we remove keeping index-(N-1) around from #writeIndexGen
return repositoryData.getGenId() > Long.parseLong(blob.substring(INDEX_FILE_PREFIX.length()));
try {
return repositoryData.getGenId() > Long.parseLong(blob.substring(INDEX_FILE_PREFIX.length()));
} catch (NumberFormatException nfe) {
// odd case of an extra file with the index- prefix that we can't identify
return false;
}
}
return false;
}).toList();
Expand Down