Fix the bug redis do not delete the expired keys
When using redis as zmq backend, the keys in redis maybe like follows: "service" "service.host1" "service.host1.host1" "service.host2" "service.host2.host2" "service.host3" "service.host3.host3" If we stopped the service on host1, the key named service.host1 and service.host1.host1 shoule be delete. As the result, the topicexchange message would not sent to host1. But the fact is service.host1 still exsit, and topicexchange message may still sent to host1. To resolve this problem , change the comparison of ttl function from -1 to -2 according to http://redis.io/commands/ttl Change-Id: I5c0af97019fffed6e949eb58d7d60c85f5b08ea1 Closes-Bug:#1417464
This commit is contained in:
parent
ff4eb4db1b
commit
1958f6e549
@ -108,7 +108,12 @@ class MatchMakerRedis(mm_common.HeartbeatMatchMakerBase):
|
||||
self.register(key, host)
|
||||
|
||||
def is_alive(self, topic, host):
|
||||
if self.redis.ttl(host) == -1:
|
||||
# After redis 2.8, if the specialized key doesn't exist,
|
||||
# TTL fuction would return -2. If key exists,
|
||||
# but doesn't have expiration associated,
|
||||
# TTL func would return -1. For more information,
|
||||
# please visit http://redis.io/commands/ttl
|
||||
if self.redis.ttl(host) == -2:
|
||||
self.expire(topic, host)
|
||||
return False
|
||||
return True
|
||||
|
@ -87,3 +87,11 @@ class RedisMatchMakerTest(test_utils.BaseTestCase):
|
||||
self.assertEqual(
|
||||
sorted(self.matcher.redis.smembers('ack_alive')),
|
||||
['ack_alive.controller1'])
|
||||
|
||||
def test_is_alive(self):
|
||||
self.assertEqual(
|
||||
self.matcher.is_alive('conductor', 'conductor.controller1'),
|
||||
True)
|
||||
self.assertEqual(
|
||||
self.matcher.is_alive('conductor', 'conductor.controller2'),
|
||||
False)
|
||||
|
Loading…
Reference in New Issue
Block a user