Skip to content

Commit

Permalink
CBQE-1127 check bucket type before insert key using mc_bin_client
Browse files Browse the repository at this point in the history
Change-Id: I167b6ec887498953956eda8ca57c6a065254b96b
Reviewed-on: http://review.couchbase.org/27324
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Tommie McAfee <tommie@couchbase.com>
  • Loading branch information
saigon committed Jul 9, 2013
1 parent cd32709 commit 2a7dd34
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/mc_bin_client.py
Expand Up @@ -12,6 +12,8 @@
import struct
import exceptions
import zlib
import urllib2
import json

from memcacheConstants import REQ_MAGIC_BYTE, RES_MAGIC_BYTE
from memcacheConstants import REQ_PKT_FMT, RES_PKT_FMT, MIN_RECV_PACKET
Expand Down Expand Up @@ -46,6 +48,7 @@ def __init__(self, host='127.0.0.1', port=11211, timeout=30):
self._createConn()
self.r = random.Random()
self.vbucket_count = 1024
self.bucketType = self.get_bucket_type()

def _createConn(self):
self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Expand Down Expand Up @@ -535,11 +538,23 @@ def reset_replication_chain(self):
return self._doCmd(memcacheConstants.CMD_RESET_REPLICATION_CHAIN, '', '', '', 0)

def _set_vbucket(self, key, vbucket= -1):
if vbucket < 0:
if vbucket < 0 and "membase" in self.bucketType:
self.vbucketId = (((zlib.crc32(key)) >> 16) & 0x7fff) & (self.vbucket_count - 1)
elif vbucket < 0 and "memcached" in self.bucketType:
self.vbucketId = 0
else:
self.vbucketId = vbucket

def get_bucket_type(self):
# get bucket type from web console
node_url = "http://{0}:8091/pools/default/buckets".format(self.host)
r = json.loads(urllib2.urlopen(node_url).read())
for k in r[0]:
if "bucketType" in k:
return r[0]["bucketType"]
else:
raise exceptions.EOFError("bucketType does not exist in node {0}".format(self.host))

def error_to_str(errno):
if errno == 0x01:
return "Not found"
Expand Down

0 comments on commit 2a7dd34

Please sign in to comment.