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:
		@@ -189,20 +189,6 @@ class AccountBroker(DatabaseBroker):
 | 
				
			|||||||
                self._db_version = 1
 | 
					                self._db_version = 1
 | 
				
			||||||
        return self._db_version
 | 
					        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):
 | 
					    def _commit_puts_load(self, item_list, entry):
 | 
				
			||||||
        """See :func:`swift.common.db.DatabaseBroker._commit_puts_load`"""
 | 
					        """See :func:`swift.common.db.DatabaseBroker._commit_puts_load`"""
 | 
				
			||||||
        # check to see if the update includes policy_index or not
 | 
					        # check to see if the update includes policy_index or not
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -356,7 +356,14 @@ class DatabaseBroker(object):
 | 
				
			|||||||
        self.update_metadata(cleared_meta)
 | 
					        self.update_metadata(cleared_meta)
 | 
				
			||||||
        # then mark the db as deleted
 | 
					        # then mark the db as deleted
 | 
				
			||||||
        with self.get() as conn:
 | 
					        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()
 | 
					            conn.commit()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @property
 | 
					    @property
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -626,20 +626,6 @@ class ContainerBroker(DatabaseBroker):
 | 
				
			|||||||
            SET reported_put_timestamp = 0, reported_delete_timestamp = 0,
 | 
					            SET reported_put_timestamp = 0, reported_delete_timestamp = 0,
 | 
				
			||||||
                reported_object_count = 0, reported_bytes_used = 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):
 | 
					    def _commit_puts_load(self, item_list, entry):
 | 
				
			||||||
        """See :func:`swift.common.db.DatabaseBroker._commit_puts_load`"""
 | 
					        """See :func:`swift.common.db.DatabaseBroker._commit_puts_load`"""
 | 
				
			||||||
        (name, timestamp, size, content_type, etag, deleted) = entry[:6]
 | 
					        (name, timestamp, size, content_type, etag, deleted) = entry[:6]
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -231,6 +231,7 @@ class ExampleBroker(DatabaseBroker):
 | 
				
			|||||||
                delete_timestamp TEXT DEFAULT '0',
 | 
					                delete_timestamp TEXT DEFAULT '0',
 | 
				
			||||||
                hash TEXT default '00000000000000000000000000000000',
 | 
					                hash TEXT default '00000000000000000000000000000000',
 | 
				
			||||||
                id TEXT,
 | 
					                id TEXT,
 | 
				
			||||||
 | 
					                status TEXT DEFAULT '',
 | 
				
			||||||
                status_changed_at TEXT DEFAULT '0',
 | 
					                status_changed_at TEXT DEFAULT '0',
 | 
				
			||||||
                metadata TEXT DEFAULT ''
 | 
					                metadata TEXT DEFAULT ''
 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
@@ -253,10 +254,10 @@ class ExampleBroker(DatabaseBroker):
 | 
				
			|||||||
        ''')
 | 
					        ''')
 | 
				
			||||||
        conn.execute("""
 | 
					        conn.execute("""
 | 
				
			||||||
        INSERT INTO test_stat (
 | 
					        INSERT INTO test_stat (
 | 
				
			||||||
            account, created_at, id, put_timestamp, status_changed_at)
 | 
					            account, created_at, id, put_timestamp, status_changed_at, status)
 | 
				
			||||||
        VALUES (?, ?, ?, ?, ?);
 | 
					        VALUES (?, ?, ?, ?, ?, ?);
 | 
				
			||||||
        """, (self.account, Timestamp.now().internal, str(uuid4()),
 | 
					        """, (self.account, Timestamp.now().internal, str(uuid4()),
 | 
				
			||||||
              put_timestamp, put_timestamp))
 | 
					              put_timestamp, put_timestamp, ''))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def merge_items(self, item_list):
 | 
					    def merge_items(self, item_list):
 | 
				
			||||||
        with self.get() as conn:
 | 
					        with self.get() as conn:
 | 
				
			||||||
@@ -307,6 +308,7 @@ class ExampleBroker(DatabaseBroker):
 | 
				
			|||||||
        conn.execute("""
 | 
					        conn.execute("""
 | 
				
			||||||
            UPDATE test_stat
 | 
					            UPDATE test_stat
 | 
				
			||||||
            SET delete_timestamp = ?,
 | 
					            SET delete_timestamp = ?,
 | 
				
			||||||
 | 
					                status = 'DELETED',
 | 
				
			||||||
                status_changed_at = ?
 | 
					                status_changed_at = ?
 | 
				
			||||||
            WHERE delete_timestamp < ? """, (timestamp, timestamp, timestamp))
 | 
					            WHERE delete_timestamp < ? """, (timestamp, timestamp, timestamp))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -715,38 +717,47 @@ class TestDatabaseBroker(unittest.TestCase):
 | 
				
			|||||||
    def test_delete_db(self):
 | 
					    def test_delete_db(self):
 | 
				
			||||||
        def init_stub(conn, put_timestamp, **kwargs):
 | 
					        def init_stub(conn, put_timestamp, **kwargs):
 | 
				
			||||||
            conn.execute('CREATE TABLE test (one TEXT)')
 | 
					            conn.execute('CREATE TABLE test (one TEXT)')
 | 
				
			||||||
            conn.execute('CREATE TABLE test_stat (id TEXT)')
 | 
					            conn.execute('''CREATE TABLE test_stat (
 | 
				
			||||||
            conn.execute('INSERT INTO test_stat (id) VALUES (?)',
 | 
					                id TEXT, put_timestamp TEXT, delete_timestamp TEXT,
 | 
				
			||||||
                         (str(uuid4),))
 | 
					                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.execute('INSERT INTO test (one) VALUES ("1")')
 | 
				
			||||||
            conn.commit()
 | 
					            conn.commit()
 | 
				
			||||||
        stub_called = [False]
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        def delete_stub(*a, **kw):
 | 
					 | 
				
			||||||
            stub_called[0] = True
 | 
					 | 
				
			||||||
        broker = DatabaseBroker(':memory:')
 | 
					        broker = DatabaseBroker(':memory:')
 | 
				
			||||||
        broker.db_type = 'test'
 | 
					        broker.db_type = 'test'
 | 
				
			||||||
        broker._initialize = init_stub
 | 
					        broker._initialize = init_stub
 | 
				
			||||||
        # Initializes a good broker for us
 | 
					        # Initializes a good broker for us
 | 
				
			||||||
        broker.initialize(normalize_timestamp('1'))
 | 
					        broker.initialize(normalize_timestamp('1'))
 | 
				
			||||||
 | 
					        info = broker.get_info()
 | 
				
			||||||
 | 
					        self.assertEqual('0', info['delete_timestamp'])
 | 
				
			||||||
 | 
					        self.assertEqual('', info['status'])
 | 
				
			||||||
        self.assertIsNotNone(broker.conn)
 | 
					        self.assertIsNotNone(broker.conn)
 | 
				
			||||||
        broker._delete_db = delete_stub
 | 
					        broker.delete_db(normalize_timestamp('2'))
 | 
				
			||||||
        stub_called[0] = False
 | 
					        info = broker.get_info()
 | 
				
			||||||
        broker.delete_db('2')
 | 
					        self.assertEqual(normalize_timestamp('2'), info['delete_timestamp'])
 | 
				
			||||||
        self.assertTrue(stub_called[0])
 | 
					        self.assertEqual('DELETED', info['status'])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        broker = DatabaseBroker(os.path.join(self.testdir, '1.db'))
 | 
					        broker = DatabaseBroker(os.path.join(self.testdir, '1.db'))
 | 
				
			||||||
        broker.db_type = 'test'
 | 
					        broker.db_type = 'test'
 | 
				
			||||||
        broker._initialize = init_stub
 | 
					        broker._initialize = init_stub
 | 
				
			||||||
        broker.initialize(normalize_timestamp('1'))
 | 
					        broker.initialize(normalize_timestamp('1'))
 | 
				
			||||||
        broker._delete_db = delete_stub
 | 
					        info = broker.get_info()
 | 
				
			||||||
        stub_called[0] = False
 | 
					        self.assertEqual('0', info['delete_timestamp'])
 | 
				
			||||||
        broker.delete_db('2')
 | 
					        self.assertEqual('', info['status'])
 | 
				
			||||||
        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'])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # ensure that metadata was cleared
 | 
					        # ensure that metadata was cleared
 | 
				
			||||||
        m2 = broker.metadata
 | 
					        m2 = broker.metadata
 | 
				
			||||||
        self.assertTrue(not any(v[0] for v in m2.values()))
 | 
					        self.assertEqual(m2, {'foo': ['', normalize_timestamp('2')]})
 | 
				
			||||||
        self.assertTrue(all(v[1] == normalize_timestamp('2')
 | 
					 | 
				
			||||||
                            for v in m2.values()))
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_get(self):
 | 
					    def test_get(self):
 | 
				
			||||||
        broker = DatabaseBroker(':memory:')
 | 
					        broker = DatabaseBroker(':memory:')
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user