Verified Commit 81537c83 authored by Martin Petráček's avatar Martin Petráček
Browse files

workaround for bug in python3 - causing expection interupting archive

parent df85c901
......@@ -57,7 +57,6 @@ def squash(from_details, to_details, up_to, window, size_threshold):
c = con.cursor()
logging.debug("Squashing flows - from detail_level {} to detail_level {}".format(from_details, to_details))
to_be_deleted = []
c.execute('BEGIN TRANSACTION')
for row in c.execute('SELECT rowid, start, (start+duration) AS end, duration, src_mac, src_ip, src_port, dest_ip, dest_port, proto, app_proto, bytes_send, bytes_received, app_hostname FROM traffic WHERE details = ? AND start < ? ORDER BY start', (from_details, start,)):
if row['rowid'] in to_be_deleted:
continue
......@@ -103,7 +102,7 @@ def squash(from_details, to_details, up_to, window, size_threshold):
to_be_deleted.append(row['rowid'])
for tbd in to_be_deleted:
c.execute('DELETE FROM traffic WHERE rowid = ?', (tbd,))
c.execute('COMMIT')
con.commit()
return len(to_be_deleted)
def load_archive_rules():
......@@ -130,8 +129,14 @@ c.execute('ATTACH DATABASE "/var/lib/pakon.db" AS live')
c.execute('INSERT INTO traffic SELECT start, duration, 0, src_mac, src_ip, src_port, dest_ip, dest_port, proto, app_proto, bytes_send, bytes_received, app_hostname FROM live.traffic WHERE start < ? AND flow_id IS NULL', (start,))
logging.info("moved {} flows from live to archive".format(c.rowcount))
c.execute('DELETE FROM live.traffic WHERE start < ? AND flow_id IS NULL', (start,))
c.execute('VACUUM live')
con.commit()
#workaround for a bug in Python 3.6
#https://bugs.python.org/issue28518
con.isolation_level = None
con.execute('VACUUM live')
con.isolation_level = ''
rules = load_archive_rules()
#if the rules changed (there is detail level that can't be generated using current rules)
......
Markdown is supported
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