Project on Github
Holds the different routing code
The ping function on the vnodes. This function is the same on every vnode, the difference is which vnode is processing the request.
The first function, shown above, pings a random (random enough for our purposes) vnode and returns the partition identifier. The code we’re interested in is in the first line of the function – specifically the chash_key() function.
The chash_key function takes a two-tuple and returns a binary identifier we can use to get a PrefList. Much of the terminology in the Riak Core source refers to Riak KV. In this case, the variables are named Bucket and Key in the chash_key function.
Each function in [chapp.erl](https://github.com/ChristopherBiscardi/Riak-Core-Consistent-Hash-Routing-Example/blob/master/a pps/chapp/src/chapp.erl) has different tuples which affect which vnode gets called.
so if we build the project.
and run the console
we can then execute the various ping() functions as such:
which gives us a tuple that contains
pong and the
partition id that processed the request.
We can see the results from running the ping() function a couple times below. Notice that each time we run ping(), a different partition handles the call.
Looking at the next function
pingsame which we call as
we can see that by calling this function multiple times, we get the same partition handling the call, because the hash of the tuple is always the same.
The pinginput function allows us to take a more interactive look at where our requests go. pinginput uses the input we give it as the second element in the chash_key function tuple.
we can see that by calling this function multiple times with the same input, the same vnode processes the request.
We can also see that by calling pinginput with a different input results in a different vnode handling the request.