Get rid of _delete_db
It was parctically the same between both, only the table name was different -- and we already have a way to accomodate that. Change-Id: I112bef1cf44c7d6eeaacd30cea27cb71fb2e2406
This commit is contained in:
parent
23e1dba532
commit
30d99f5140
@ -189,20 +189,6 @@ class AccountBroker(DatabaseBroker):
|
||||
self._db_version = 1
|
||||
return self._db_version
|
||||
|
||||
def _delete_db(self, conn, timestamp, force=False):
|
||||
"""
|
||||
Mark the DB as deleted.
|
||||
|
||||
:param conn: DB connection object
|
||||
:param timestamp: timestamp to mark as deleted
|
||||
"""
|
||||
conn.execute("""
|
||||
UPDATE account_stat
|
||||
SET delete_timestamp = ?,
|
||||
status = 'DELETED',
|
||||
status_changed_at = ?
|
||||
WHERE delete_timestamp < ? """, (timestamp, timestamp, timestamp))
|
||||
|
||||
def _commit_puts_load(self, item_list, entry):
|
||||
"""See :func:`swift.common.db.DatabaseBroker._commit_puts_load`"""
|
||||
# check to see if the update includes policy_index or not
|
||||
|
@ -356,7 +356,14 @@ class DatabaseBroker(object):
|
||||
self.update_metadata(cleared_meta)
|
||||
# then mark the db as deleted
|
||||
with self.get() as conn:
|
||||
self._delete_db(conn, timestamp)
|
||||
conn.execute(
|
||||
"""
|
||||
UPDATE %s_stat
|
||||
SET delete_timestamp = ?,
|
||||
status = 'DELETED',
|
||||
status_changed_at = ?
|
||||
WHERE delete_timestamp < ? """ % self.db_type,
|
||||
(timestamp, timestamp, timestamp))
|
||||
conn.commit()
|
||||
|
||||
@property
|
||||
|
@ -626,20 +626,6 @@ class ContainerBroker(DatabaseBroker):
|
||||
SET reported_put_timestamp = 0, reported_delete_timestamp = 0,
|
||||
reported_object_count = 0, reported_bytes_used = 0''')
|
||||
|
||||
def _delete_db(self, conn, timestamp):
|
||||
"""
|
||||
Mark the DB as deleted
|
||||
|
||||
:param conn: DB connection object
|
||||
:param timestamp: timestamp to mark as deleted
|
||||
"""
|
||||
conn.execute("""
|
||||
UPDATE container_stat
|
||||
SET delete_timestamp = ?,
|
||||
status = 'DELETED',
|
||||
status_changed_at = ?
|
||||
WHERE delete_timestamp < ? """, (timestamp, timestamp, timestamp))
|
||||
|
||||
def _commit_puts_load(self, item_list, entry):
|
||||
"""See :func:`swift.common.db.DatabaseBroker._commit_puts_load`"""
|
||||
(name, timestamp, size, content_type, etag, deleted) = entry[:6]
|
||||
|
@ -231,6 +231,7 @@ class ExampleBroker(DatabaseBroker):
|
||||
delete_timestamp TEXT DEFAULT '0',
|
||||
hash TEXT default '00000000000000000000000000000000',
|
||||
id TEXT,
|
||||
status TEXT DEFAULT '',
|
||||
status_changed_at TEXT DEFAULT '0',
|
||||
metadata TEXT DEFAULT ''
|
||||
);
|
||||
@ -253,10 +254,10 @@ class ExampleBroker(DatabaseBroker):
|
||||
''')
|
||||
conn.execute("""
|
||||
INSERT INTO test_stat (
|
||||
account, created_at, id, put_timestamp, status_changed_at)
|
||||
VALUES (?, ?, ?, ?, ?);
|
||||
account, created_at, id, put_timestamp, status_changed_at, status)
|
||||
VALUES (?, ?, ?, ?, ?, ?);
|
||||
""", (self.account, Timestamp.now().internal, str(uuid4()),
|
||||
put_timestamp, put_timestamp))
|
||||
put_timestamp, put_timestamp, ''))
|
||||
|
||||
def merge_items(self, item_list):
|
||||
with self.get() as conn:
|
||||
@ -307,6 +308,7 @@ class ExampleBroker(DatabaseBroker):
|
||||
conn.execute("""
|
||||
UPDATE test_stat
|
||||
SET delete_timestamp = ?,
|
||||
status = 'DELETED',
|
||||
status_changed_at = ?
|
||||
WHERE delete_timestamp < ? """, (timestamp, timestamp, timestamp))
|
||||
|
||||
@ -715,38 +717,47 @@ class TestDatabaseBroker(unittest.TestCase):
|
||||
def test_delete_db(self):
|
||||
def init_stub(conn, put_timestamp, **kwargs):
|
||||
conn.execute('CREATE TABLE test (one TEXT)')
|
||||
conn.execute('CREATE TABLE test_stat (id TEXT)')
|
||||
conn.execute('INSERT INTO test_stat (id) VALUES (?)',
|
||||
(str(uuid4),))
|
||||
conn.execute('''CREATE TABLE test_stat (
|
||||
id TEXT, put_timestamp TEXT, delete_timestamp TEXT,
|
||||
status TEXT, status_changed_at TEXT, metadata TEXT)''')
|
||||
meta = {'foo': ('bar', normalize_timestamp('0'))}
|
||||
conn.execute(
|
||||
'''INSERT INTO test_stat (
|
||||
id, put_timestamp, delete_timestamp, status,
|
||||
status_changed_at, metadata) VALUES (?, ?, ?, ?, ?, ?)''',
|
||||
(str(uuid4), put_timestamp, '0', '', '0', json.dumps(meta)))
|
||||
conn.execute('INSERT INTO test (one) VALUES ("1")')
|
||||
conn.commit()
|
||||
stub_called = [False]
|
||||
|
||||
def delete_stub(*a, **kw):
|
||||
stub_called[0] = True
|
||||
broker = DatabaseBroker(':memory:')
|
||||
broker.db_type = 'test'
|
||||
broker._initialize = init_stub
|
||||
# Initializes a good broker for us
|
||||
broker.initialize(normalize_timestamp('1'))
|
||||
info = broker.get_info()
|
||||
self.assertEqual('0', info['delete_timestamp'])
|
||||
self.assertEqual('', info['status'])
|
||||
self.assertIsNotNone(broker.conn)
|
||||
broker._delete_db = delete_stub
|
||||
stub_called[0] = False
|
||||
broker.delete_db('2')
|
||||
self.assertTrue(stub_called[0])
|
||||
broker.delete_db(normalize_timestamp('2'))
|
||||
info = broker.get_info()
|
||||
self.assertEqual(normalize_timestamp('2'), info['delete_timestamp'])
|
||||
self.assertEqual('DELETED', info['status'])
|
||||
|
||||
broker = DatabaseBroker(os.path.join(self.testdir, '1.db'))
|
||||
broker.db_type = 'test'
|
||||
broker._initialize = init_stub
|
||||
broker.initialize(normalize_timestamp('1'))
|
||||
broker._delete_db = delete_stub
|
||||
stub_called[0] = False
|
||||
broker.delete_db('2')
|
||||
self.assertTrue(stub_called[0])
|
||||
info = broker.get_info()
|
||||
self.assertEqual('0', info['delete_timestamp'])
|
||||
self.assertEqual('', info['status'])
|
||||
broker.delete_db(normalize_timestamp('2'))
|
||||
info = broker.get_info()
|
||||
self.assertEqual(normalize_timestamp('2'), info['delete_timestamp'])
|
||||
self.assertEqual('DELETED', info['status'])
|
||||
|
||||
# ensure that metadata was cleared
|
||||
m2 = broker.metadata
|
||||
self.assertTrue(not any(v[0] for v in m2.values()))
|
||||
self.assertTrue(all(v[1] == normalize_timestamp('2')
|
||||
for v in m2.values()))
|
||||
self.assertEqual(m2, {'foo': ['', normalize_timestamp('2')]})
|
||||
|
||||
def test_get(self):
|
||||
broker = DatabaseBroker(':memory:')
|
||||
|
Loading…
Reference in New Issue
Block a user