Package kv provides a key-value API to an underlying cockroach datastore. Cockroach itself provides a single, monolithic, sorted key value map, distributed over multiple nodes. Each node holds a set of key ranges. Package kv translates between the monolithic, logical map which Cockroach clients experience to the physically distributed key ranges which comprise the whole.

Package kv implements the logic necessary to locate appropriate nodes based on keys being read or written. In some cases, requests may span a range of keys, in which case multiple RPCs may be sent out.

The API is asynchronous and meant to be exploited as such. If an operation requires fetching multiple keys to satisfy a computation, they should be fetched in parallel and only when all are in flight should the caller block. Here's an example of usage:

foo := kvDB.Get(&kv.GetRequest{[]byte("foo")})
bar := kvDB.Get(&kv.GetRequest{[]byte("bar")})

fooVal <-foo
barVal <-bar

// Should check errors, but leaving out for brevity.
if string(fooVal.Value) == string(barVal.Value) {
  // Values are equal; take action.

Imports 5 package(s) ΒΆ