add gc greedy

This commit is contained in:
Martin Sekera 2020-08-29 02:42:54 +02:00
parent 5dda6562a6
commit ad19226d02

45
btv
View file

@ -9,6 +9,7 @@ import json
import os import os
import shlex import shlex
import sys import sys
import time
CONFIG = "/etc/btv/config.ini" CONFIG = "/etc/btv/config.ini"
LOCKFILE = "/run/lock/btv/serialization.lock" LOCKFILE = "/run/lock/btv/serialization.lock"
@ -487,22 +488,41 @@ def do_stream(args):
def do_gc(args=None): def do_gc(args=None):
""" """
Drops old snapshots. Drops old snapshots.
If the only arg is "greedy", drops ALL snapshots except the youngest
Rank 2.
""" """
counts = [0, 0, 0] # Rank 0, 1, 2 if args and "greedy" in args:
limits = [ newest = list_snapshots(2)[-1]
cfg.getint("gc", "rank_0_count"),
cfg.getint("gc", "rank_1_count"),
cfg.getint("gc", "rank_2_count")
]
for snap in reversed(list_snapshots()): if newest:
counts[snap.rank] += 1 print(">>> Dropping all snapshots except the newest Rank 2 in 5 s...")
time.sleep(5)
if counts[snap.rank] > limits[snap.rank]: for snap in list_snapshots():
print(" >> delete Rank %d %s" %(snap.rank, snap.name)) if snap.name != newest.name:
snap.drop()
snap.drop() else:
print("!!! no Rank 2 snapshot exists")
sys.exit(1)
else:
counts = [0, 0, 0] # Rank 0, 1, 2
limits = [
cfg.getint("gc", "rank_0_count"),
cfg.getint("gc", "rank_1_count"),
cfg.getint("gc", "rank_2_count")
]
for snap in reversed(list_snapshots()):
counts[snap.rank] += 1
if counts[snap.rank] > limits[snap.rank]:
print(" >> delete Rank %d %s" %(snap.rank, snap.name))
snap.drop()
verb_router = { verb_router = {
"snapshot": do_create, "snapshot": do_create,
@ -537,6 +557,9 @@ Verbs:
gc gc
Drops old local snapshots based on garbage collector settings. Drops old local snapshots based on garbage collector settings.
gc greedy
Drop ALL snapshots except the newest Rank 2.
""".format(cmd=sys.argv[0])) """.format(cmd=sys.argv[0]))
if __name__ == "__main__": if __name__ == "__main__":