Merge "Improve test coverage for metadata reclaim" into feature/deep
This commit is contained in:
commit
1b9d1e0f30
|
@ -910,12 +910,15 @@ class DatabaseBroker(object):
|
||||||
|
|
||||||
def reclaim(self, age_timestamp, sync_timestamp):
|
def reclaim(self, age_timestamp, sync_timestamp):
|
||||||
"""
|
"""
|
||||||
Delete rows from the db_contains_type table that are marked deleted
|
Delete reclaimable rows and metadata from the db.
|
||||||
and whose created_at timestamp is < age_timestamp. Also deletes rows
|
|
||||||
from incoming_sync and outgoing_sync where the updated_at timestamp is
|
|
||||||
< sync_timestamp.
|
|
||||||
|
|
||||||
In addition, this calls the DatabaseBroker's :func:`_reclaim` method.
|
By default this method will delete rows from the db_contains_type table
|
||||||
|
that are marked deleted and whose created_at timestamp is <
|
||||||
|
age_timestamp, and deletes rows from incoming_sync and outgoing_sync
|
||||||
|
where the updated_at timestamp is < sync_timestamp. In addition, this
|
||||||
|
calls the :meth:`_reclaim_metadata` method.
|
||||||
|
|
||||||
|
Subclasses may reclaim other items by overriding :meth:`_reclaim`.
|
||||||
|
|
||||||
:param age_timestamp: max created_at timestamp of object rows to delete
|
:param age_timestamp: max created_at timestamp of object rows to delete
|
||||||
:param sync_timestamp: max update_at timestamp of sync rows to delete
|
:param sync_timestamp: max update_at timestamp of sync rows to delete
|
||||||
|
@ -926,7 +929,7 @@ class DatabaseBroker(object):
|
||||||
self._commit_puts()
|
self._commit_puts()
|
||||||
with self.get() as conn:
|
with self.get() as conn:
|
||||||
self._reclaim(conn, age_timestamp, sync_timestamp)
|
self._reclaim(conn, age_timestamp, sync_timestamp)
|
||||||
DatabaseBroker._reclaim_metadata(self, conn, age_timestamp)
|
self._reclaim_metadata(conn, age_timestamp)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
def _reclaim(self, conn, age_timestamp, sync_timestamp):
|
def _reclaim(self, conn, age_timestamp, sync_timestamp):
|
||||||
|
|
|
@ -1550,7 +1550,7 @@ class ContainerBroker(DatabaseBroker):
|
||||||
try:
|
try:
|
||||||
conn.execute('''
|
conn.execute('''
|
||||||
DELETE FROM shard_ranges WHERE deleted = 1 AND timestamp < ?
|
DELETE FROM shard_ranges WHERE deleted = 1 AND timestamp < ?
|
||||||
AND name!= ?
|
AND name != ?
|
||||||
''', (sync_timestamp, self.path))
|
''', (sync_timestamp, self.path))
|
||||||
except sqlite3.OperationalError as err:
|
except sqlite3.OperationalError as err:
|
||||||
if 'no such table: shard_ranges' not in str(err):
|
if 'no such table: shard_ranges' not in str(err):
|
||||||
|
|
|
@ -1133,9 +1133,9 @@ class TestDatabaseBroker(unittest.TestCase):
|
||||||
|
|
||||||
def test_metadata(self):
|
def test_metadata(self):
|
||||||
def reclaim(broker, timestamp):
|
def reclaim(broker, timestamp):
|
||||||
with broker.get() as conn:
|
# only testing _reclaim_metadata here
|
||||||
broker._reclaim_metadata(conn, timestamp)
|
with patch.object(broker, '_reclaim'):
|
||||||
conn.commit()
|
broker.reclaim(timestamp, timestamp)
|
||||||
# Initializes a good broker for us
|
# Initializes a good broker for us
|
||||||
broker = self.get_replication_info_tester(metadata=True)
|
broker = self.get_replication_info_tester(metadata=True)
|
||||||
# Add our first item
|
# Add our first item
|
||||||
|
|
Loading…
Reference in New Issue