In the memcached client incr and decr function there is a race condition that needs to be fixed along these lines:
diff --git a/swift/common/memcached.py b/swift/common/memcached.py
index 164c1d8..90266ea 100644 (file)
--- a/swift/common/memcached.py
+++ b/swift/common/memcached.py
@@ -155,8 +155,14 @@ class MemcacheRing(object):
line = fp.readline().strip().split()
if line[0].upper() == 'NOT_FOUND':
line[0] = str(delta)
- sock.sendall('add %s %d %d %s noreply\r\n%s\r\n' % \
+ sock.sendall('add %s %d %d %s\r\n%s\r\n' % \
(key, 0, timeout, len(line[0]), line[0]))
+ line = fp.readline().strip().split()
+ if line[0].upper() == 'NOT_STORED':
+ sock.sendall('incr %s %s\r\n' % (key, delta))
+ line = fp.readline().strip().split()
+ else:
+ line[0] = str(delta)
ret = int(line[0].strip())
self._return_conn(server, fp, sock)
return ret
Unit tests mocking out the client need to be cleaned up and the incr / decr functions should be able to handle negative deltas gracefully.