Skip to content

Commit c9cb885

Browse files
fvennetiermurlock
authored andcommitted
obj: report missing container when checking versioning mode
When handling an object creation operation, and when the container supposed to host the object is missing, an unhandled exception was raised. This exception is now converted to a proper response error. Also rename things and write documentation.
1 parent 2643911 commit c9cb885

File tree

1 file changed

+19
-10
lines changed
  • oioswift/proxy/controllers

1 file changed

+19
-10
lines changed

oioswift/proxy/controllers/obj.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -190,31 +190,40 @@ def GETorHEAD(self, req):
190190

191191
return resp
192192

193-
def versioning_management(self, req):
193+
def enforce_versioning(self, req):
194+
"""
195+
Enforce the versioning mode of a container just before executing
196+
an object operation. This is useful when the current object is not
197+
stored in the "main" container but in a shard, where the versioning
198+
mode may not have been set yet.
199+
"""
194200
if not SUPPORT_VERSIONING:
195201
return None
196202

197-
container_root = req.headers.get('X-Object-Sysmeta-Oio-Bucket-Name')
198-
if container_root is None:
203+
root_container = req.headers.get('X-Object-Sysmeta-Oio-Bucket-Name')
204+
if root_container is None:
199205
return None
200206

207+
# We can't use _get_info_from_caches as it would use local worker cache
208+
# first and an update of versioning mode may not be detected.
201209
memcache = getattr(self.app, 'memcache', None) or \
202210
req.environ.get('swift.cache')
203211
if memcache is None:
204212
return None
205213

206-
key = "/".join(("versioning", self.account_name, container_root))
214+
key = "/".join(("versioning", self.account_name, root_container))
207215
val = memcache.get(key)
208216
if val is not None:
209217
if val != '':
210218
req.headers[FORCEVERSIONING_HEADER] = val
211219
return
212220

213-
# we can't use get_info_cache or set_info as it use local worker cache
214-
# then memcache: an update of versioning may be not detected
215221
oio_headers = {'X-oio-req-id': self.trans_id}
216-
meta = self.app.storage.container_get_properties(
217-
self.account_name, container_root, headers=oio_headers)
222+
try:
223+
meta = self.app.storage.container_get_properties(
224+
self.account_name, root_container, headers=oio_headers)
225+
except exceptions.NoSuchContainer:
226+
raise HTTPNotFound(request=req)
218227

219228
val = meta['system'].get('sys.m2.policy.version', '')
220229
memcache.set(key, val)
@@ -412,7 +421,7 @@ def PUT(self, req):
412421
if aresp:
413422
return aresp
414423

415-
self.versioning_management(req)
424+
self.enforce_versioning(req)
416425

417426
old_slo_manifest = None
418427
old_slo_manifest_etag = None
@@ -705,7 +714,7 @@ def DELETE(self, req):
705714

706715
self._update_x_timestamp(req)
707716

708-
self.versioning_management(req)
717+
self.enforce_versioning(req)
709718

710719
return self._delete_object(req)
711720

0 commit comments

Comments
 (0)