Skip to content

Commit

Permalink
Add Assertion About Leaking index-N to Repo Tests (#46774) (#46801)
Browse files Browse the repository at this point in the history
This adds an assert to make sure we're not leaking
index-N blobs on the shard level to the repo consistency checks.
It is ok to have a single redundant index-N blob in a failure scenario
but additional index-N should always be cleaned up before adding more.
  • Loading branch information
original-brownbear authored Sep 18, 2019
1 parent f3e67bd commit f983b67
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -169,9 +170,12 @@ private static void assertSnapshotUUIDs(BlobStoreRepository repository, Reposito
continue;
}
if (snapshotInfo.shardFailures().stream().noneMatch(shardFailure ->
shardFailure.index().equals(index) != false && shardFailure.shardId() == Integer.parseInt(entry.getKey()))) {
assertThat(entry.getValue().listBlobs(),
shardFailure.index().equals(index) && shardFailure.shardId() == Integer.parseInt(entry.getKey()))) {
final Map<String, BlobMetaData> shardPathContents = entry.getValue().listBlobs();
assertThat(shardPathContents,
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));
}
}
}
Expand Down

0 comments on commit f983b67

Please sign in to comment.