From 0966c7a724089449306b735756d891d6dc4c267f Mon Sep 17 00:00:00 2001 From: wangxiyuan Date: Tue, 14 Jun 2016 16:29:50 +0800 Subject: [PATCH] Ensure queue exists before get/update the claim Now with redis backend, if the queue is deleted, the request to claim is still work and will return some unexpected result, such as 503 error. So we should ensure the queue exists before get/update the claim. Change-Id: I324e342b0ec49ca2b6aa48e371fc818a53ac1ffb Closes-bug: #1591921 --- zaqar/storage/redis/claims.py | 8 ++++++++ zaqar/tests/unit/storage/test_impl_redis.py | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/zaqar/storage/redis/claims.py b/zaqar/storage/redis/claims.py index 563d660f1..e27bf57a1 100644 --- a/zaqar/storage/redis/claims.py +++ b/zaqar/storage/redis/claims.py @@ -118,6 +118,14 @@ class ClaimController(storage.Claim, scripting.Mixin): client = self._client claims_set_key = utils.scope_claims_set(queue, project, QUEUE_CLAIMS_SUFFIX) + # In some cases, the queue maybe doesn't exist. So we should check + # whether the queue exists. Return False if no such queue exists. + + # Todo(flwang): We should delete all related data after the queue is + # deleted. See the blueprint for more detail: + # https://blueprints.launchpad.net/zaqar/+spec/clear-resources-after-delete-queue + if not self._queue_ctrl._exists(queue, project): + return False # Return False if no such claim exists # TODO(prashanthr_): Discuss the feasibility of a bloom filter. diff --git a/zaqar/tests/unit/storage/test_impl_redis.py b/zaqar/tests/unit/storage/test_impl_redis.py index 88cc9c16c..8c6c0a77a 100644 --- a/zaqar/tests/unit/storage/test_impl_redis.py +++ b/zaqar/tests/unit/storage/test_impl_redis.py @@ -400,6 +400,20 @@ class RedisClaimsTest(base.ClaimControllerTest): self.controller.update, queue_name, claim_id, {}, project=None) + # create a claim and then delete the queue + claim_id, messages = self.controller.create(queue_name, {'ttl': 100, + 'grace': 0}, + project=None) + self.queue_controller.delete(queue_name) + + self.assertRaises(storage.errors.ClaimDoesNotExist, + self.controller.get, queue_name, + claim_id, project=None) + + self.assertRaises(storage.errors.ClaimDoesNotExist, + self.controller.update, queue_name, + claim_id, {}, project=None) + def test_get_claim_after_expires(self): queue_name = 'no-such-claim' self.queue_controller.create(queue_name, project='fake_project')