As seen in the
the default Riak Core template gives you a
method. I named my application spades, so my files are named
spades_vnode.erl with the function being
All commands we execute as
myapp:command(). (such as
spades:ping().) route through the myapp.erl functions.
In this case, when we call
spades:ping(). the ping().
function in spades.erl is what gets called.
Let’s take a look at the first line of code.
DocIdx is short for Document Index. This appears to be a holdover from before Riak Core was separated from Riak KV. We are using the Consistent Hash (chash) function from the riak_core_util module. By hashing on the “ping” and the current time, we achieve an acceptable level of randomness to distribute our request to a random vnode.
We then create a PreferenceList (PrefList) by using the hash we just created, an N value and a module name.