basho/riak_pb — pull request #52 by seancribbs (2013-08-26 14:55:05+00:00)
Title: Add protocol messages for CRDTs

These messages and codecs implement the basis of client interaction around the new CRDT types of set and map, and the map-embedded types (counter, set, flag, register). The counter type works exactly as before, except that multiple operations can be sent at once.

In the typical read-modify-write flow, the client requests that the server include the opaque "context" with the fetch response. Like a vector clock, this ensures that the modifications made on behalf of the client have a relationship to the data that it saw previously; specifically, this ensures the "observed-remove" behavior of sets and maps, and the population of fallbacks with valid data in the case of a network partition. Instead of directly applying operations as an actor, the client collects a list of modifications and sends them to the server along with the context it received from the fetch. In this sense, we are providing a hybrid CRDT model, containing both state (the context) and operations.

![dt-flow](https://f.cloud.github.com/assets/1772/1026466/da0383de-0e5e-11e3-88a5-10f6d2d02f68.png)

In the case of read-only operations, the client may set `include_context` to `false`, which will reduce the size of the response payload. Whether a context exists is also type-dependent; for example, counters need no context.

There is no "delete" request, as this can be handled directly by KV.

**Caveat**: This requires the Riak Core "bucket type" concept. We decided to go this route so that existing counter usage would not change, but we could still constrain the CRDT type used in a bucket or bucket-type. For example, sending a map operation to a bucket-type that contains sets should result in an error response.