Swift MemcacheRing (set) interface is incompatible with python-memcached
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
OpenStack Object Storage (swift) |
Fix Released
|
Low
|
Unassigned |
Bug Description
The set() interface in MemcacheRing is incompatible with python-memcached.
MemcacheRing:
def set(self, key, value, serialize=True, timeout=0):
"""
Set a key/value pair in memcache
:param key: key
:param value: value
:param serialize: if True, value is serialized with JSON before sending
:param timeout: ttl in memcache
"""
python-memcached:
def set(self, key, val, time=0, min_compress_
The C{key} can optionally be an tuple, with the first element
being the server hash value and the second being the key.
If you want to avoid making this module calculate a hash value.
You may prefer, for example, to keep all of a given user's objects
on the same memcache server, so you could use the user's unique
id as the hash value.
@return: Nonzero on success.
@rtype: int
@param time: Tells memcached the time which this value should expire, either
as a delta number of seconds, or an absolute unix time-since-
value. See the memcached protocol docs section "Storage Commands"
for more info on <exptime>. We default to 0 == cache forever.
@param min_compress_len: The threshold length to kick in auto-compression
of the value using the zlib.compress() routine. If the value being cached is
a string, then the length of the string is measured, else if the value is an
object, then the length of the pickle result is measured. If the resulting
attempt at compression yeilds a larger string than the input, then it is
discarded. For backwards compatability, this parameter defaults to 0,
indicating don't ever try to compress.
'''
Notice the named parameters inconsistencies: "time" and "timeout", "min_compress_len" and "serialize".
This inconsistency makes it difficult to switch between MemcacheRing and python-memcached. For service-neutral middleware such as Keystone auth_token, we have to special-case cache set if MemcacheRing is in used. For example,
if swift_cache:
cache.set(key, value, timeout=60)
else:
cache.set(key, value, time=60)
If would be nice if Swift MemcacheRing interfaces are compatible with python-memcached so service-neutral middlewares doesn't have to worry about which memcache client it is using.
Changed in swift: | |
status: | New → Confirmed |
importance: | Undecided → Low |
Changed in swift: | |
milestone: | none → 1.8.0-rc1 |
status: | Fix Committed → Fix Released |
Changed in swift: | |
milestone: | 1.8.0-rc1 → 1.8.0 |
Alright, so what does Keystone's auth_token care about? Your example mentions "time" vs. "timeout", and that would be a straightforward fix, as they're semantically equivalent.
Does auth_token ever use the "min_compress_len" parameter? Swift's MemcacheRing doesn't compress the stored values, so that parameter is meaningless there. If it's necessary (and only then), MemcacheRing could take a "min_compress_len" keyword arg that it ignores, which would at least give some compatibility.
python-memcached's "key" argument can be either a string or a 2-tuple, while MemcacheRing's can only be a string. Does auth_token ever use the 2-tuple form of that argument?
I don't want to introduce unused compatibility cruft, so if you could enumerate which pieces of incompatibility are causing pain in Keystone-land, that would be helpful.