Commit 2cacba97 authored by Julien Muchembled's avatar Julien Muchembled

wip

parent 4865fa0e
...@@ -499,7 +499,7 @@ class DatabaseManager(object): ...@@ -499,7 +499,7 @@ class DatabaseManager(object):
def dropPartitions(): def dropPartitions():
dropping = self._dropping dropping = self._dropping
before = drop_count, drop_time = self._drop_stats before = drop_count, drop_time = self._drop_stats
dropped = 0 commit = dropped = 0
while dropping: while dropping:
offset = next(iter(dropping)) offset = next(iter(dropping))
log = dropped log = dropped
...@@ -508,24 +508,34 @@ class DatabaseManager(object): ...@@ -508,24 +508,34 @@ class DatabaseManager(object):
if offset not in dropping: if offset not in dropping:
break break
start = time() start = time()
if 0 < commit < start:
self.commit()
logging.debug('drop: committed')
commit = 0
continue
data_id_list = self._dropPartition(offset, data_id_list = self._dropPartition(offset,
# The efficiency drops when the number of lines to # The efficiency drops when the number of lines to
# delete is too small so do not delete too few. # delete is too small so do not delete too few.
max(100, int(.1 * drop_count / drop_time)) max(100, int(.1 * drop_count / drop_time))
if drop_time else 1000) if drop_time else 1000)
if data_id_list is None: if data_id_list:
dropping.remove(offset) if not commit:
break commit = time() + 1
if log == dropped: if log == dropped:
dropped += 1 dropped += 1
logging.info("dropping partition %s...", offset) logging.info("dropping partition %s...", offset)
logging.debug('drop: pruneData(%s)', len(data_id_list)) if type(data_id_list) is list:
drop_count += self._pruneData(data_id_list) logging.debug('drop: pruneData(%s)',
drop_time += time() - start len(data_id_list))
self.commit() drop_count += self._pruneData(data_id_list)
logging.debug('drop: committed') drop_time += time() - start
self._drop_stats = drop_count, drop_time self._drop_stats = drop_count, drop_time
continue
dropping.remove(offset)
break
if dropped: if dropped:
if commit:
self.commit()
logging.info("%s partition(s) dropped" logging.info("%s partition(s) dropped"
" (stats: count: %s/%s, time: %.4s/%.4s)", " (stats: count: %s/%s, time: %.4s/%.4s)",
dropped, drop_count - before[0], drop_count, dropped, drop_count - before[0], drop_count,
...@@ -537,7 +547,8 @@ class DatabaseManager(object): ...@@ -537,7 +547,8 @@ class DatabaseManager(object):
"""Delete rows for given partition """Delete rows for given partition
Delete at most 'count' rows of from obj: Delete at most 'count' rows of from obj:
- if there's no line to delete, purge trans and return None - if there's no line to delete, purge trans and return
a boolean indicating if any row was deleted (from trans)
- else return data ids of deleted rows - else return data ids of deleted rows
""" """
......
...@@ -417,6 +417,8 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -417,6 +417,8 @@ class MySQLDatabaseManager(DatabaseManager):
return [x for x, in x if x] return [x for x, in x if x]
logging.debug("drop: trans") logging.debug("drop: trans")
q("DELETE FROM trans WHERE `partition`=%s" % offset) q("DELETE FROM trans WHERE `partition`=%s" % offset)
(x,), = q('SELECT ROW_COUNT()')
return x
def _getUnfinishedDataIdList(self): def _getUnfinishedDataIdList(self):
return [x for x, in self.query("SELECT data_id FROM tobj") if x] return [x for x, in self.query("SELECT data_id FROM tobj") if x]
......
...@@ -339,7 +339,7 @@ class SQLiteDatabaseManager(DatabaseManager): ...@@ -339,7 +339,7 @@ class SQLiteDatabaseManager(DatabaseManager):
if x: if x:
q("DELETE" + where, args) q("DELETE" + where, args)
return [x for x, in x if x] return [x for x, in x if x]
q("DELETE FROM trans WHERE partition=?", args[:1]) return q("DELETE FROM trans WHERE partition=?", args[:1]).rowcount
def _getUnfinishedDataIdList(self): def _getUnfinishedDataIdList(self):
return [x for x, in self.query("SELECT data_id FROM tobj") if x] return [x for x, in self.query("SELECT data_id FROM tobj") if x]
......
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