Building app infrastructure in Elixir: Time-traveling state
In the previous post, I discussed making crush into a more-viable data store for mahou. Since then, I’ve implemented forking and joining of key-value pairs in crush, and this post will be discussing the implementation thereof.
Fork-join of keys is conceptually fairly simple. A key stores its current fork, and the list of its ancestors, forks that were merged into it. To make ancestor tracking easier, the revision that said key was at during the join (or merge) is stored as part of the ancestor data:
typedstruct module: Ancestor do field :fork, String.t() field :rev, non_neg_integer() end
Note: Example code is using
Once we can store the ancestors in the value’s state, we have everything that we need to make fork-join work!
At this point, our value state struct looks like this:
typedstruct module: Item do field :value, binary() field :patches, [any()] field
Continue reading →