Merge pull request #42893 from jan--f/snap-sched-fix-multi-retention

snap-schedule: count retained snapshots per retention policy

Reviewed-by: Venky Shankar <vshankar@redhat.com>
This commit is contained in:
Venky Shankar 2021-08-26 18:02:34 +05:30 committed by GitHub
commit 41e52688c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -90,6 +90,7 @@ def get_prune_set(candidates: Set[Tuple[cephfs.DirEntry, datetime]],
if not period_count:
continue
last = None
kept_for_this_period = 0
for snap in sorted(candidates, key=lambda x: x[0].d_name,
reverse=True):
snap_ts = snap[1].strftime(date_pattern)
@ -99,7 +100,8 @@ def get_prune_set(candidates: Set[Tuple[cephfs.DirEntry, datetime]],
log.debug((f'keeping {snap[0].d_name} due to '
f'{period_count}{period}'))
keep.append(snap)
if len(keep) == period_count:
kept_for_this_period += 1
if kept_for_this_period == period_count:
log.debug(('found enough snapshots for '
f'{period_count}{period}'))
break

View File

@ -18,3 +18,20 @@ class TestScheduleClient(object):
prune_set = get_prune_set(candidates, ret)
assert prune_set == set(), 'candidates are pruned despite empty retention'
def test_get_prune_set_two_retention_specs(self):
now = datetime.now()
candidates = set()
for i in range(10):
ts = now - timedelta(hours=i*1)
fake_dir = MagicMock()
fake_dir.d_name = f'scheduled-{ts.strftime(SNAPSHOT_TS_FORMAT)}'
candidates.add((fake_dir, ts))
for i in range(10):
ts = now - timedelta(days=i*1)
fake_dir = MagicMock()
fake_dir.d_name = f'scheduled-{ts.strftime(SNAPSHOT_TS_FORMAT)}'
candidates.add((fake_dir, ts))
# should keep 8 snapshots
ret = {'h': 6, 'd': 2}
prune_set = get_prune_set(candidates, ret)
assert len(prune_set) == len(candidates) - 8, 'wrong size of prune set'