Once your client library has received a complete vbucket-to-server map message, it should use its favorite JSON parser to process the map into more useful data structures. An implementation of this kind of JSON parsing in C exists as a helper library in libvbucket, or for Java, jvbucket.
The libvbucket and
jvbucket helper libraries don't do any
connection creation, socket management, protocol serialization,
etc. That's the job of your higher-level library. These helper
libraries instead just know how to parse a JSON
vbucket-to-server map and provide an API to access the map
information.
The vBucketMap value within the returned JSON
describes the vBucket organization. For example:
"serverList":["10.1.4.11:11210","10.1.4.12:11210"], "vBucketMap":[[0,1],[1,0],[1,0],[1,0],:,[0,1],[0,1]]The vBucketMap is zero-based indexed by vbucketId. So, if you have a vbucket whose vbucketId is 4, you'd look up vBucketMap[4]. The entries in the vBucketMap are arrays of integers, where each integer is a zero-based index into the serverList array. The 0th entry in this array describes the primary server for a vbucket. Here's how you read this stuff, based on the above config:
The vbucket with vbucketId of 0 has a configuration of
vBucketMap[0], or [0, 1].
So vbucket 0's primary server is at
serverList[0], or
10.1.4.11:11210.
While vbucket 0's first replica server is at
serverList[1], which is
10.1.4.12:11210.
The vbucket with vbucketId of 1 has a configuration of
vBucketMap[1], or [1, 0].
So vbucket 1's primary server is at
serverList[1], or
10.1.4.12:11210. And vbucket 1's first
replica is at serverList[0], or
10.1.4.11:11210.
This structure and information repeats for every configured vBucket.
If you see a -1 value, it means that there is no server yet at that position. That is, you might see:
"vBucketMap":[[0,-1],[0,-1],[0,-1],[0,-1],:]Sometimes early before the system has been completely configured, you might see variations of:
"serverList":[], "vBucketMap":[]