Account Server: Refactor HEAD request handler
Deleted unused container checks. As method swift::common::db::AccountBroker::get_container_timestamp becomes unused, it is deleted too, along with the corresponding tests. Change-Id: I61de4549b0abd7103226d6a13f1d9844abaa92d3
This commit is contained in:
@@ -142,14 +142,8 @@ class AccountController(object):
|
|||||||
@timing_stats()
|
@timing_stats()
|
||||||
def HEAD(self, req):
|
def HEAD(self, req):
|
||||||
"""Handle HTTP HEAD request."""
|
"""Handle HTTP HEAD request."""
|
||||||
# TODO(refactor): The account server used to provide a 'account and
|
|
||||||
# container existence check all-in-one' call by doing a HEAD with a
|
|
||||||
# container path. However, container existence is now checked with the
|
|
||||||
# container servers directly so this is no longer needed. We should
|
|
||||||
# refactor out the container existence check here and retest
|
|
||||||
# everything.
|
|
||||||
try:
|
try:
|
||||||
drive, part, account, container = req.split_path(3, 4)
|
drive, part, account = req.split_path(3)
|
||||||
validate_device_partition(drive, part)
|
validate_device_partition(drive, part)
|
||||||
except ValueError, err:
|
except ValueError, err:
|
||||||
return HTTPBadRequest(body=str(err), content_type='text/plain',
|
return HTTPBadRequest(body=str(err), content_type='text/plain',
|
||||||
@@ -157,7 +151,6 @@ class AccountController(object):
|
|||||||
if self.mount_check and not check_mount(self.root, drive):
|
if self.mount_check and not check_mount(self.root, drive):
|
||||||
return HTTPInsufficientStorage(drive=drive, request=req)
|
return HTTPInsufficientStorage(drive=drive, request=req)
|
||||||
broker = self._get_account_broker(drive, part, account)
|
broker = self._get_account_broker(drive, part, account)
|
||||||
if not container:
|
|
||||||
broker.pending_timeout = 0.1
|
broker.pending_timeout = 0.1
|
||||||
broker.stale_reads_ok = True
|
broker.stale_reads_ok = True
|
||||||
if broker.is_deleted():
|
if broker.is_deleted():
|
||||||
@@ -169,10 +162,6 @@ class AccountController(object):
|
|||||||
'X-Account-Bytes-Used': info['bytes_used'],
|
'X-Account-Bytes-Used': info['bytes_used'],
|
||||||
'X-Timestamp': info['created_at'],
|
'X-Timestamp': info['created_at'],
|
||||||
'X-PUT-Timestamp': info['put_timestamp']}
|
'X-PUT-Timestamp': info['put_timestamp']}
|
||||||
if container:
|
|
||||||
container_ts = broker.get_container_timestamp(container)
|
|
||||||
if container_ts is not None:
|
|
||||||
headers['X-Container-Timestamp'] = container_ts
|
|
||||||
headers.update((key, value)
|
headers.update((key, value)
|
||||||
for key, (value, timestamp) in
|
for key, (value, timestamp) in
|
||||||
broker.metadata.iteritems() if value != '')
|
broker.metadata.iteritems() if value != '')
|
||||||
|
@@ -1407,28 +1407,6 @@ class AccountBroker(DatabaseBroker):
|
|||||||
DatabaseBroker._reclaim(self, conn, container_timestamp)
|
DatabaseBroker._reclaim(self, conn, container_timestamp)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
def get_container_timestamp(self, container_name):
|
|
||||||
"""
|
|
||||||
Get the put_timestamp of a container.
|
|
||||||
|
|
||||||
:param container_name: container name
|
|
||||||
|
|
||||||
:returns: put_timestamp of the container
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
self._commit_puts()
|
|
||||||
except LockTimeout:
|
|
||||||
if not self.stale_reads_ok:
|
|
||||||
raise
|
|
||||||
with self.get() as conn:
|
|
||||||
ret = conn.execute('''
|
|
||||||
SELECT put_timestamp FROM container
|
|
||||||
WHERE name = ? AND deleted != 1''',
|
|
||||||
(container_name,)).fetchone()
|
|
||||||
if ret:
|
|
||||||
ret = ret[0]
|
|
||||||
return ret
|
|
||||||
|
|
||||||
def put_container(self, name, put_timestamp, delete_timestamp,
|
def put_container(self, name, put_timestamp, delete_timestamp,
|
||||||
object_count, bytes_used):
|
object_count, bytes_used):
|
||||||
"""
|
"""
|
||||||
|
@@ -1662,21 +1662,6 @@ class TestAccountBroker(unittest.TestCase):
|
|||||||
"SELECT count(*) FROM container "
|
"SELECT count(*) FROM container "
|
||||||
"WHERE deleted = 1").fetchone()[0], 1)
|
"WHERE deleted = 1").fetchone()[0], 1)
|
||||||
|
|
||||||
def test_get_container_timestamp(self):
|
|
||||||
""" Test swift.common.db.AccountBroker.get_container_timestamp """
|
|
||||||
broker = AccountBroker(':memory:', account='a')
|
|
||||||
broker.initialize(normalize_timestamp('1'))
|
|
||||||
|
|
||||||
# Create initial container
|
|
||||||
timestamp = normalize_timestamp(time())
|
|
||||||
broker.put_container('container_name', timestamp, 0, 0, 0)
|
|
||||||
# test extant map
|
|
||||||
ts = broker.get_container_timestamp('container_name')
|
|
||||||
self.assertEquals(ts, timestamp)
|
|
||||||
# test missing map
|
|
||||||
ts = broker.get_container_timestamp('something else')
|
|
||||||
self.assertEquals(ts, None)
|
|
||||||
|
|
||||||
def test_put_container(self):
|
def test_put_container(self):
|
||||||
""" Test swift.common.db.AccountBroker.put_container """
|
""" Test swift.common.db.AccountBroker.put_container """
|
||||||
broker = AccountBroker(':memory:', account='a')
|
broker = AccountBroker(':memory:', account='a')
|
||||||
|
Reference in New Issue
Block a user