Presents https://github.com/mrallen1/udon - an example application which demonstrates how to write a distributed application using riak_core, including handoff implementation. From Erlang Factory SF 2015
20 years now. • Work at Basho Technologies (purveyors of fine databasses) • Coding Erlang for about 3 years now. • Very interested in distributed systems.
table data structure is rebalanced. • riak_core uses consistent hashing to determine where to store data on a primary replica as well as fallbacks if the primary is offline.
state management, • Ring state management, • Vnode placement, • Vnode replication, • Cluster and ring state gossip protocols, • Consistent hashing utilities • Handoff activities • Covering set callbacks (optional)
but not sufficient to build robust distributed apps. • Have to manage a lot of tricky things with a lot of non-‐intuitive failure modes. – Node failure – Vnode placement updates
the application you want to build on top it. – It expects you to have a "key" that links to a blob of data. – The key (or rather its chash) determines its primary vnode and adjacent replicas. – The data itself is opaque and has application context. – Presumably you want behavior semantics that are different than riak_kv with your data.
also some gaps you should know about. – Cluster membership is controlled by a human – Yes, even when a node failure has been (correctly) detected by the cluster manager. – vnode distribution around the ring is sometimes suboptimal (this is not always easy to fix) • You should know that Basho uses/tests/ships its own OTP (but 17.X works fine; YMMV)
hash it using MD5 (object name), make some metadata • Object name is fed into the CHASH function for vnode placement • In the vnode, update some metadata about the object (file version) • Store the metadata as (object.meta) and the data as (object.version) on disk
%% TODO: Get results from more than one node [{Node, _Type}] = riak_core_apl:get_primary_apl( Idx, 1, udon), riak_core_vnode_master:sync_spawn_command( Node, {fetch, PHash}, udon_vnode_master).
goals of a handoff implementation? – Per vnode, get the objects associated with that vnode. – Per object, find/compute the data needed to transfer object state to another node – Serialize the object state and send it – At the receiving end, deserialize and store state
small-‐bytes-‐berlin-‐efl-‐2014.html • YouTube video of above talk: https://youtu.be/rJXM33EieGQ • FlavioDB project: https://github.com/marianoguerra/flaviodb • Udon project: https://github.com/mrallen1/udon • Older resources are still useful from a conceptual understanding but often are “bitrotted” from a running code perspective.