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

Fix negative limiting with fewer PARTIAL snapshots than minimum required #58563

Merged
merged 1 commit into from Jun 25, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -184,7 +184,7 @@ public Predicate<SnapshotInfo> getSnapshotDeletionPredicate(final List<SnapshotI
final TimeValue snapshotAge = new TimeValue(nowSupplier.getAsLong() - si.startTime());

if (this.minimumSnapshotCount != null) {
final long eligibleForExpiration = successfulSnapshotCount - minimumSnapshotCount;
final long eligibleForExpiration = Math.max(0, successfulSnapshotCount - minimumSnapshotCount);

// Only the oldest N snapshots are actually eligible, since if we went below this we
// would fall below the configured minimum number of snapshots to keep
Expand Down
Expand Up @@ -227,7 +227,6 @@ private void assertUnsuccessfulNotCountedTowardsMinimum(boolean failure) {
assertThat(conf.getSnapshotDeletionPredicate(infos).test(oldInfo), equalTo(true));
}


public void testMostRecentSuccessfulTimestampIsUsed() {
boolean failureBeforePartial = randomBoolean();
SnapshotRetentionConfiguration conf = new SnapshotRetentionConfiguration(() -> 1, null, 2, 2);
Expand All @@ -243,6 +242,18 @@ public void testMostRecentSuccessfulTimestampIsUsed() {
assertThat(conf.getSnapshotDeletionPredicate(infos).test(s4), equalTo(false));
}

public void testFewerSuccessesThanMinWithPartial() {
SnapshotRetentionConfiguration conf = new SnapshotRetentionConfiguration(() -> 1, TimeValue.timeValueSeconds(5), 10, 20);
SnapshotInfo s1 = makeInfo(1);
SnapshotInfo sP = makePartialInfo(2);
SnapshotInfo s2 = makeInfo(3);

List<SnapshotInfo> infos = Arrays.asList(s1 , sP, s2);
assertThat(conf.getSnapshotDeletionPredicate(infos).test(s1), equalTo(false));
assertThat(conf.getSnapshotDeletionPredicate(infos).test(sP), equalTo(false));
assertThat(conf.getSnapshotDeletionPredicate(infos).test(s2), equalTo(false));
}

private SnapshotInfo makeInfo(long startTime) {
final Map<String, Object> meta = new HashMap<>();
meta.put(SnapshotLifecyclePolicy.POLICY_ID_METADATA_FIELD, REPO);
Expand Down