This paper has been accepted and will be presented at ACM SIGPLAN Erlang Workshop 13.
Riak PG is prototype implementation of distributed process groups built on top of Riak Core. Its main goals are to provide high availability and deterministic conflict resolution in the event of network partitions. In providing these guarantees, Riak PG provides an “eventually consistent” view of process groups for applications which can tolerate this behaviour.
Riak PG is not meant for production use, but more as an experiment in trying to model high availability process groups in Erlang without the use of coordinated global ETS transactions or consensus.
Similar to the Riak data store, data is replicated a number of times throughout a cluster of nodes using the familiar concepts of consistent hashing and virtual nodes. Both retrieval and modification of process groups are handled by finite state machines, which write updates to a series of virtual nodes responsible for handling each group. We leverage conflict-free replicated data types to ensure that updates to the process group always commute, which guarantees convergence amongst all replicas in the event of partial writes or network partitions.
For compatibility, Riak PG provides the same interface as the built-in Erlang pg2 library. In addition to providing calls to return members of the process group, Riak PG extends this interface to provide calls to return only processes from the process group which are located on the calling node, or any connected node. To illustrate:
To return all members:
To return only local members:
To return only connected members:
Conflict resolution is handled by using a conflict-free replicated data type, specifically an observed-removed set as described by Baquero and Shapiro in A comprehensive study of Convergent and Commutative Replicated Data Types. A dictionary is used to track a series of these sets, one representing each process group. When partitions occur, additions and removals of processes to groups are guaranteed to converge to the correct value.
Here’s an example of read repair, resolving values which have diverged.
Garbage collection of the observed-removed set is definitely problematic, as its growth is unbounded. One such approach for dealing with garbage collection from accumulating tombstones or repeated additions and deletions of the same value is outlined in Baquero and Shapiro’s work in An optimized conflict-free replicated set. Riak PG currently does not implement a garbage collection strategy for the process groups.
Using process monitors to handle the removal of process identifiers from groups as they are terminated is also an area that’s problematic in the event of network partitions. In the case of processes that have joined to groups which don’t contain replicas for that group, and are potentially located across a partition, how do we effectively monitor and ensure we remove the process from the group when it terminates? Riak PG currently does not provide a solution for this, and defers to application code for handling of the retrieval of terminated processes.
While Riak PG provides a higher availability process group registry, lack of garbage collection of the data structures is very problematic when dealing with a large number of processes. This is especially problematic in Erlang because of its use of lightweight processes for modeling computations and handling concurrency.
The code for Riak PG is available on GitHub.
View this story on Hacker News.