Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MB-6167: snapshot mc files for TAP_FIX_FLAG_BYTEORDER

Change-Id: I6e71f1cb698a3f36e2786940498eac2fcee1ef93
Reviewed-on: http://review.couchbase.org/19499
Reviewed-by: Bin Cui <bin.cui@gmail.com>
Tested-by: Steve Yen <steve.yen@gmail.com>
  • Loading branch information...
commit 3518ebff73901f4dedfef218b0d9b74ec03ec90a 1 parent 695d384
@steveyen steveyen authored
Showing with 28 additions and 21 deletions.
  1. +26 −21 mc_bin_client.py
  2. +2 −0  memcacheConstants.py
View
47 mc_bin_client.py
@@ -45,7 +45,6 @@ def __init__(self, host='127.0.0.1', port=11211, family=socket.AF_INET):
if hasattr(socket, 'AF_UNIX') and family == socket.AF_UNIX:
self.s.connect_ex(host)
else:
- self.s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
self.s.connect_ex((host, port))
self.r=random.Random()
@@ -133,14 +132,9 @@ def decr(self, key, amt=1, init=0, exp=0):
"""Decrement or create the named counter."""
return self.__incrdecr(memcacheConstants.CMD_DECR, key, amt, init, exp)
- def _doMetaCmd(self, cmd, key, exp, flags, value, meta, cas=0):
- meta_type, meta_data = meta
- extra = struct.pack('>III', len(meta_data) + 2, flags, exp)
-
- meta_value = value + \
- struct.pack('BB', meta_type, len(meta_data)) + meta_data
-
- return self._doCmd(cmd, key, meta_value, extra, cas)
+ def _doMetaCmd(self, cmd, key, value, cas, exp, flags, seqno, remote_cas):
+ extra = struct.pack('>IIQQ', flags, exp, seqno, remote_cas)
+ return self._doCmd(cmd, key, value, extra, cas)
def _doRevCmd(self, cmd, key, exp, flags, value, rev, cas=0):
seqno, revid = rev
@@ -153,10 +147,10 @@ def set(self, key, exp, flags, val):
"""Set a value in the memcached server."""
return self._mutate(memcacheConstants.CMD_SET, key, exp, flags, 0, val)
- def setWithMeta(self, key, exp, flags, value, meta):
+ def setWithMeta(self, key, value, exp, flags, seqno, remote_cas):
"""Set a value and its meta data in the memcached server."""
return self._doMetaCmd(memcacheConstants.CMD_SET_WITH_META,
- key, exp, flags, value, meta, cas=0)
+ key, value, 0, exp, flags, seqno, remote_cas)
def setWithRev(self, key, exp, flags, value, rev):
"""Set a value and its revision in the memcached server."""
@@ -167,9 +161,9 @@ def add(self, key, exp, flags, val):
"""Add a value in the memcached server iff it doesn't already exist."""
return self._mutate(memcacheConstants.CMD_ADD, key, exp, flags, 0, val)
- def addWithMeta(self, key, exp, flags, value, meta):
+ def addWithMeta(self, key, value, exp, flags, seqno, remote_cas):
return self._doMetaCmd(memcacheConstants.CMD_ADD_WITH_META,
- key, exp, flags, value, meta)
+ key, value, 0, exp, flags, seqno, remote_cas)
def addWithRev(self, key, exp, flags, value, rev):
return self._doRevCmd(memcacheConstants.CMD_ADD_WITH_META,
@@ -180,6 +174,15 @@ def replace(self, key, exp, flags, val):
return self._mutate(memcacheConstants.CMD_REPLACE, key, exp, flags, 0,
val)
+ def observe(self, key, vbucket):
+ """Observe a key for persistence and replication."""
+ value = struct.pack('>HH', vbucket, len(key)) + key
+ opaque, cas, data = self._doCmd(memcacheConstants.CMD_OBSERVE, '', value)
+ rep_time = (cas & 0xFFFFFFFF)
+ persist_time = (cas >> 32) & 0xFFFFFFFF
+ persisted = struct.unpack('>B', data[4+len(key)])[0]
+ return opaque, rep_time, persist_time, persisted
+
def __parseGet(self, data, klen=0):
flags=struct.unpack(memcacheConstants.GET_RES_FMT, data[-1][:4])[0]
return flags, data[1], data[-1][4 + klen:]
@@ -190,10 +193,11 @@ def get(self, key):
return self.__parseGet(parts)
def __parseMeta(self, data):
- meta_type = struct.unpack('B', data[-1][0])[0]
- length = struct.unpack('B', data[-1][1])[0]
- meta = data[-1][2:2 + length]
- return (meta_type, meta)
+ flags = struct.unpack('I', data[-1][0:4])[0]
+ meta_type = struct.unpack('B', data[-1][4])[0]
+ length = struct.unpack('B', data[-1][5])[0]
+ meta = data[-1][6:6 + length]
+ return (meta_type, flags, meta)
def getMeta(self, key):
"""Get the metadata for a given key within the memcached server."""
@@ -202,11 +206,11 @@ def getMeta(self, key):
def getRev(self, key):
"""Get the revision for a given key within the memcached server."""
- (meta_type, meta_data) = self.getMeta(key)
+ (meta_type, flags, meta_data) = self.getMeta(key)
if meta_type != memcacheConstants.META_REVID:
raise ValueError("Invalid meta type %x" % meta_type)
- seqno = struct.unpack('>I', meta_data[:4])[0]
+ seqno = struct.unpack('>Q', meta_data[:8])[0]
revid = meta_data[4:]
return (seqno, revid)
@@ -292,8 +296,9 @@ def set_vbucket_state(self, vbucket, stateName):
return self._doCmd(memcacheConstants.CMD_SET_VBUCKET_STATE, '', '', state)
def get_vbucket_state(self, vbucket):
- return self._doCmd(memcacheConstants.CMD_GET_VBUCKET_STATE,
- str(vbucket), '')
+ assert isinstance(vbucket, int)
+ self.vbucketId = vbucket
+ return self._doCmd(memcacheConstants.CMD_GET_VBUCKET_STATE, '', '')
def delete_vbucket(self, vbucket):
assert isinstance(vbucket, int)
View
2  memcacheConstants.py
@@ -28,6 +28,7 @@
CMD_TOUCH = 0x1c
CMD_GAT = 0x1d
CMD_GET_REPLICA = 0x83
+CMD_OBSERVE = 0x92
# SASL stuff
CMD_SASL_LIST_MECHS = 0x20
@@ -126,6 +127,7 @@
TAP_FLAG_REQUEST_KEYS_ONLY = 0x20
TAP_FLAG_CHECKPOINT = 0x40
TAP_FLAG_REGISTERED_CLIENT = 0x80
+TAP_FLAG_TAP_FIX_FLAG_BYTEORDER = 0x100
TAP_FLAG_TYPES = {TAP_FLAG_BACKFILL: ">Q",
TAP_FLAG_REGISTERED_CLIENT: ">B"}

0 comments on commit 3518ebf

Please sign in to comment.
Something went wrong with that request. Please try again.