Add timestamp checking in AccountBroker.is_status_deleted

Account-reaper works only at account-server with the first replica, and reaps
account with "deleted" status.

On the other hand, account-replicator doesn't replicate the status, only
replicates *_timestamp.
When swift fails to delete the first account replica, account-reaper never
reaps the account, because the first replica never gets marked as "deleted".

This patch adds a timestamp checking into is_status_deleted method, and
account-reaper will start to reap the account after account-replicator
replicates *_timestamp.

Change-Id: I75e3f15ad217a71b4fd39552cf6db2957597efca
Closes-Bug: #1304755
This commit is contained in:
Takashi Kajinami 2014-04-09 16:33:02 +09:00
parent 698919e67b
commit 41d851387c
2 changed files with 18 additions and 2 deletions

View File

@ -312,9 +312,10 @@ class AccountBroker(DatabaseBroker):
"""Only returns true if the status field is set to DELETED."""
with self.get() as conn:
row = conn.execute('''
SELECT status
SELECT put_timestamp, delete_timestamp, status
FROM account_stat''').fetchone()
return (row['status'] == "DELETED")
return row['status'] == "DELETED" or (
row['delete_timestamp'] > row['put_timestamp'])
def get_policy_stats(self):
"""

View File

@ -91,6 +91,21 @@ class TestAccountBroker(unittest.TestCase):
POLICIES.default.idx)
self.assert_(broker.empty())
def test_is_status_deleted(self):
# Test AccountBroker.is_status_deleted
broker1 = AccountBroker(':memory:', account='a')
broker1.initialize(Timestamp(time()).internal)
self.assert_(not broker1.is_status_deleted())
broker1.delete_db(Timestamp(time()).internal)
self.assert_(broker1.is_status_deleted())
broker2 = AccountBroker(':memory:', account='a')
broker2.initialize(Timestamp(time()).internal)
# Set delete_timestamp greater than put_timestamp
broker2.merge_timestamps(
time(), Timestamp(time()).internal,
Timestamp(time() + 999).internal)
self.assert_(broker2.is_status_deleted())
def test_reclaim(self):
broker = AccountBroker(':memory:', account='test_account')
broker.initialize(Timestamp('1').internal)