Commit 6c28ac6f authored by Aurélien Campéas's avatar Aurélien Campéas
Browse files

strip: now it does not leave orphan chunks behind

parent 147f4a1c52a0
......@@ -1168,7 +1168,8 @@ insertion_date value_date
with engine.begin() as cn:
tsh.strip(cn, 'xserie', csid)
assert len(snap.garbage()) == 2
# no garbage left
assert len(snap.garbage()) == 0
assert_hist("""
insertion_date value_date
......
......@@ -259,8 +259,9 @@ def check(db_uri, series=None, namespace='tsh'):
@tsh.command(name='garbage')
@click.argument('db-uri')
@click.option('--reclaim', is_flag=True, default=False)
@click.option('--namespace', default='tsh')
def shell(db_uri, namespace='tsh'):
def shell(db_uri, reclaim=False, namespace='tsh'):
from tshistory.snapshot import Snapshot
e = create_engine(find_dburi(db_uri))
tsh = timeseries(namespace)
......@@ -270,6 +271,8 @@ def shell(db_uri, namespace='tsh'):
garb = snap.garbage()
if garb:
print('************************', name, 'garbage =', len(garb))
if reclaim:
snap.reclaim()
@tsh.command(name='shell')
......
......@@ -329,3 +329,9 @@ class Snapshot(SeriesServices):
}
return allchuks - reachable_chunks
def reclaim(self):
todelete = ','.join(str(id) for id in self.garbage())
sql = (f'delete from "{self.tsh.namespace}.snapshot"."{self.name}" '
f'where id in ({todelete})')
self.cn.execute(sql)
......@@ -424,6 +424,9 @@ class timeseries(SeriesServices):
'where cset >= %(csid)s')
cn.execute(sql, csid=csid)
snapshot = Snapshot(cn, self, seriename)
snapshot.reclaim()
def info(self, cn):
"""Gather global statistics on the current tshistory repository
"""
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment