Put X-Backend-Timestamp in object 404 responses
This way the container reconciler can tell (sometimes) that an object was deleted at a certain time. DocImpact Implements: blueprint storage-policies Change-Id: Idaba3255f4109e5150d6c457f913c600fd8923eb
This commit is contained in:
parent
b9707d497c
commit
0015019ccd
@ -522,8 +522,12 @@ class ObjectController(object):
|
|||||||
pass
|
pass
|
||||||
response.headers['X-Timestamp'] = file_x_ts
|
response.headers['X-Timestamp'] = file_x_ts
|
||||||
resp = request.get_response(response)
|
resp = request.get_response(response)
|
||||||
except (DiskFileNotExist, DiskFileQuarantined):
|
except (DiskFileNotExist, DiskFileQuarantined) as e:
|
||||||
resp = HTTPNotFound(request=request, conditional_response=True)
|
headers = {}
|
||||||
|
if hasattr(e, 'timestamp'):
|
||||||
|
headers['X-Backend-Timestamp'] = e.timestamp
|
||||||
|
resp = HTTPNotFound(request=request, headers=headers,
|
||||||
|
conditional_response=True)
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
@public
|
@public
|
||||||
@ -540,8 +544,12 @@ class ObjectController(object):
|
|||||||
return HTTPInsufficientStorage(drive=device, request=request)
|
return HTTPInsufficientStorage(drive=device, request=request)
|
||||||
try:
|
try:
|
||||||
metadata = disk_file.read_metadata()
|
metadata = disk_file.read_metadata()
|
||||||
except (DiskFileNotExist, DiskFileQuarantined):
|
except (DiskFileNotExist, DiskFileQuarantined) as e:
|
||||||
return HTTPNotFound(request=request, conditional_response=True)
|
headers = {}
|
||||||
|
if hasattr(e, 'timestamp'):
|
||||||
|
headers['X-Backend-Timestamp'] = e.timestamp
|
||||||
|
return HTTPNotFound(request=request, headers=headers,
|
||||||
|
conditional_response=True)
|
||||||
response = Response(request=request, conditional_response=True)
|
response = Response(request=request, conditional_response=True)
|
||||||
response.headers['Content-Type'] = metadata.get(
|
response.headers['Content-Type'] = metadata.get(
|
||||||
'Content-Type', 'application/octet-stream')
|
'Content-Type', 'application/octet-stream')
|
||||||
|
@ -810,6 +810,7 @@ class TestObjectController(unittest.TestCase):
|
|||||||
environ={'REQUEST_METHOD': 'HEAD'})
|
environ={'REQUEST_METHOD': 'HEAD'})
|
||||||
resp = req.get_response(self.object_controller)
|
resp = req.get_response(self.object_controller)
|
||||||
self.assertEquals(resp.status_int, 404)
|
self.assertEquals(resp.status_int, 404)
|
||||||
|
self.assertFalse('X-Backend-Timestamp' in resp.headers)
|
||||||
|
|
||||||
timestamp = normalize_timestamp(time())
|
timestamp = normalize_timestamp(time())
|
||||||
req = Request.blank(
|
req = Request.blank(
|
||||||
@ -872,6 +873,7 @@ class TestObjectController(unittest.TestCase):
|
|||||||
environ={'REQUEST_METHOD': 'HEAD'})
|
environ={'REQUEST_METHOD': 'HEAD'})
|
||||||
resp = req.get_response(self.object_controller)
|
resp = req.get_response(self.object_controller)
|
||||||
self.assertEquals(resp.status_int, 404)
|
self.assertEquals(resp.status_int, 404)
|
||||||
|
self.assertEquals(resp.headers['X-Backend-Timestamp'], timestamp)
|
||||||
|
|
||||||
def test_HEAD_quarantine_zbyte(self):
|
def test_HEAD_quarantine_zbyte(self):
|
||||||
# Test swift.obj.server.ObjectController.GET
|
# Test swift.obj.server.ObjectController.GET
|
||||||
@ -913,6 +915,7 @@ class TestObjectController(unittest.TestCase):
|
|||||||
req = Request.blank('/sda1/p/a/c/o', environ={'REQUEST_METHOD': 'GET'})
|
req = Request.blank('/sda1/p/a/c/o', environ={'REQUEST_METHOD': 'GET'})
|
||||||
resp = req.get_response(self.object_controller)
|
resp = req.get_response(self.object_controller)
|
||||||
self.assertEquals(resp.status_int, 404)
|
self.assertEquals(resp.status_int, 404)
|
||||||
|
self.assertFalse('X-Backend-Timestamp' in resp.headers)
|
||||||
|
|
||||||
timestamp = normalize_timestamp(time())
|
timestamp = normalize_timestamp(time())
|
||||||
req = Request.blank('/sda1/p/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
|
req = Request.blank('/sda1/p/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
|
||||||
@ -994,6 +997,7 @@ class TestObjectController(unittest.TestCase):
|
|||||||
req = Request.blank('/sda1/p/a/c/o', environ={'REQUEST_METHOD': 'GET'})
|
req = Request.blank('/sda1/p/a/c/o', environ={'REQUEST_METHOD': 'GET'})
|
||||||
resp = req.get_response(self.object_controller)
|
resp = req.get_response(self.object_controller)
|
||||||
self.assertEquals(resp.status_int, 404)
|
self.assertEquals(resp.status_int, 404)
|
||||||
|
self.assertEquals(resp.headers['X-Backend-Timestamp'], timestamp)
|
||||||
|
|
||||||
def test_GET_if_match(self):
|
def test_GET_if_match(self):
|
||||||
req = Request.blank('/sda1/p/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
|
req = Request.blank('/sda1/p/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
|
||||||
@ -3025,10 +3029,11 @@ class TestObjectController(unittest.TestCase):
|
|||||||
delete_at_timestamp /
|
delete_at_timestamp /
|
||||||
self.object_controller.expiring_objects_container_divisor *
|
self.object_controller.expiring_objects_container_divisor *
|
||||||
self.object_controller.expiring_objects_container_divisor)
|
self.object_controller.expiring_objects_container_divisor)
|
||||||
|
put_timestamp = normalize_timestamp(test_time - 1000)
|
||||||
req = Request.blank(
|
req = Request.blank(
|
||||||
'/sda1/p/a/c/o',
|
'/sda1/p/a/c/o',
|
||||||
environ={'REQUEST_METHOD': 'PUT'},
|
environ={'REQUEST_METHOD': 'PUT'},
|
||||||
headers={'X-Timestamp': normalize_timestamp(test_time - 1000),
|
headers={'X-Timestamp': put_timestamp,
|
||||||
'X-Delete-At': str(delete_at_timestamp),
|
'X-Delete-At': str(delete_at_timestamp),
|
||||||
'X-Delete-At-Container': delete_at_container,
|
'X-Delete-At-Container': delete_at_container,
|
||||||
'Content-Length': '4',
|
'Content-Length': '4',
|
||||||
@ -3055,6 +3060,8 @@ class TestObjectController(unittest.TestCase):
|
|||||||
headers={'X-Timestamp': normalize_timestamp(t)})
|
headers={'X-Timestamp': normalize_timestamp(t)})
|
||||||
resp = req.get_response(self.object_controller)
|
resp = req.get_response(self.object_controller)
|
||||||
self.assertEquals(resp.status_int, 404)
|
self.assertEquals(resp.status_int, 404)
|
||||||
|
self.assertEquals(resp.headers['X-Backend-Timestamp'],
|
||||||
|
put_timestamp)
|
||||||
finally:
|
finally:
|
||||||
object_server.time.time = orig_time
|
object_server.time.time = orig_time
|
||||||
|
|
||||||
@ -3092,10 +3099,11 @@ class TestObjectController(unittest.TestCase):
|
|||||||
self.object_controller.expiring_objects_container_divisor *
|
self.object_controller.expiring_objects_container_divisor *
|
||||||
self.object_controller.expiring_objects_container_divisor)
|
self.object_controller.expiring_objects_container_divisor)
|
||||||
object_server.time.time = lambda: t
|
object_server.time.time = lambda: t
|
||||||
|
put_timestamp = normalize_timestamp(test_time - 1000)
|
||||||
req = Request.blank(
|
req = Request.blank(
|
||||||
'/sda1/p/a/c/o',
|
'/sda1/p/a/c/o',
|
||||||
environ={'REQUEST_METHOD': 'PUT'},
|
environ={'REQUEST_METHOD': 'PUT'},
|
||||||
headers={'X-Timestamp': normalize_timestamp(test_time - 1000),
|
headers={'X-Timestamp': put_timestamp,
|
||||||
'X-Delete-At': str(delete_at_timestamp),
|
'X-Delete-At': str(delete_at_timestamp),
|
||||||
'X-Delete-At-Container': delete_at_container,
|
'X-Delete-At-Container': delete_at_container,
|
||||||
'Content-Length': '4',
|
'Content-Length': '4',
|
||||||
@ -3122,6 +3130,8 @@ class TestObjectController(unittest.TestCase):
|
|||||||
headers={'X-Timestamp': normalize_timestamp(time())})
|
headers={'X-Timestamp': normalize_timestamp(time())})
|
||||||
resp = req.get_response(self.object_controller)
|
resp = req.get_response(self.object_controller)
|
||||||
self.assertEquals(resp.status_int, 404)
|
self.assertEquals(resp.status_int, 404)
|
||||||
|
self.assertEquals(resp.headers['X-Backend-Timestamp'],
|
||||||
|
put_timestamp)
|
||||||
finally:
|
finally:
|
||||||
object_server.time.time = orig_time
|
object_server.time.time = orig_time
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user