Documentation ¶
Overview ¶
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. }
Index ¶
- Constants
- Variables
- func BootstrapConfigs(db DB) error
- func BootstrapRangeDescriptor(db DB, replica storage.Replica) error
- func GetI(db DB, key storage.Key, value interface{}) (bool, int64, error)
- func HTTPAddr() string
- func PutI(db DB, key storage.Key, value interface{}) error
- func UpdateRangeDescriptor(db DB, meta storage.RangeMetadata, locations storage.RangeDescriptor) error
- type DB
- type DistDB
- func (db *DistDB) AccumulateTS(args *storage.AccumulateTSRequest) <-chan *storage.AccumulateTSResponse
- func (db *DistDB) Contains(args *storage.ContainsRequest) <-chan *storage.ContainsResponse
- func (db *DistDB) Delete(args *storage.DeleteRequest) <-chan *storage.DeleteResponse
- func (db *DistDB) DeleteRange(args *storage.DeleteRangeRequest) <-chan *storage.DeleteRangeResponse
- func (db *DistDB) EndTransaction(args *storage.EndTransactionRequest) <-chan *storage.EndTransactionResponse
- func (db *DistDB) EnqueueMessage(args *storage.EnqueueMessageRequest) <-chan *storage.EnqueueMessageResponse
- func (db *DistDB) EnqueueUpdate(args *storage.EnqueueUpdateRequest) <-chan *storage.EnqueueUpdateResponse
- func (db *DistDB) Get(args *storage.GetRequest) <-chan *storage.GetResponse
- func (db *DistDB) Increment(args *storage.IncrementRequest) <-chan *storage.IncrementResponse
- func (db *DistDB) Put(args *storage.PutRequest) <-chan *storage.PutResponse
- func (db *DistDB) ReapQueue(args *storage.ReapQueueRequest) <-chan *storage.ReapQueueResponse
- func (db *DistDB) Scan(args *storage.ScanRequest) <-chan *storage.ScanResponse
- type LocalDB
- func (db *LocalDB) AccumulateTS(args *storage.AccumulateTSRequest) <-chan *storage.AccumulateTSResponse
- func (db *LocalDB) Contains(args *storage.ContainsRequest) <-chan *storage.ContainsResponse
- func (db *LocalDB) Delete(args *storage.DeleteRequest) <-chan *storage.DeleteResponse
- func (db *LocalDB) DeleteRange(args *storage.DeleteRangeRequest) <-chan *storage.DeleteRangeResponse
- func (db *LocalDB) EndTransaction(args *storage.EndTransactionRequest) <-chan *storage.EndTransactionResponse
- func (db *LocalDB) EnqueueMessage(args *storage.EnqueueMessageRequest) <-chan *storage.EnqueueMessageResponse
- func (db *LocalDB) EnqueueUpdate(args *storage.EnqueueUpdateRequest) <-chan *storage.EnqueueUpdateResponse
- func (db *LocalDB) Get(args *storage.GetRequest) <-chan *storage.GetResponse
- func (db *LocalDB) Increment(args *storage.IncrementRequest) <-chan *storage.IncrementResponse
- func (db *LocalDB) Put(args *storage.PutRequest) <-chan *storage.PutResponse
- func (db *LocalDB) ReapQueue(args *storage.ReapQueueRequest) <-chan *storage.ReapQueueResponse
- func (db *LocalDB) Scan(args *storage.ScanRequest) <-chan *storage.ScanResponse
- type RESTServer
Constants ¶
const ( // KVKeyPrefix is the prefix for RESTful endpoints used to // interact directly with the key-value datastore. KVKeyPrefix = "/db/" )
Variables ¶
var Addr = flag.String("addr", "127.0.0.1:8080", "address for connection to cockroach cluster")
Addr is the tcp address used to connect to the Cockroach cluster.
Functions ¶
func BootstrapConfigs ¶
BootstrapConfigs sets default configurations for accounting, permissions, and zones. All configs are specified for the empty key prefix, meaning they apply to the entire database. Permissions are granted to all users and the zone requires three replicas with no other specifications.
func BootstrapRangeDescriptor ¶
BootstrapRangeDescriptor sets meta1 and meta2 values for KeyMax, using the provided replica.
func GetI ¶
GetI fetches the value at the specified key and deserializes it into "value". Returns true on success or false if the key was not found. The timestamp of the write is returned as the second return value. The first result parameter is "ok": true if a value was found for the requested key; false otherwise. An error is returned on error fetching from underlying storage or deserializing value.
func HTTPAddr ¶
func HTTPAddr() string
HTTPAddr returns the fully qualified URL used to connect to the Cockroach cluster.
func PutI ¶
PutI sets the given key to the serialized byte string of the value provided. Uses current time and default expiration.
func UpdateRangeDescriptor ¶
func UpdateRangeDescriptor(db DB, meta storage.RangeMetadata, locations storage.RangeDescriptor) error
UpdateRangeDescriptor updates the range locations metadata for the range specified by the meta parameter. This always involves a write to "meta2", and may require a write to "meta1", in the event that meta.EndKey is a "meta2" key (prefixed by KeyMeta2Prefix).
Types ¶
type DB ¶
type DB interface { Contains(args *storage.ContainsRequest) <-chan *storage.ContainsResponse Get(args *storage.GetRequest) <-chan *storage.GetResponse Put(args *storage.PutRequest) <-chan *storage.PutResponse Increment(args *storage.IncrementRequest) <-chan *storage.IncrementResponse Delete(args *storage.DeleteRequest) <-chan *storage.DeleteResponse DeleteRange(args *storage.DeleteRangeRequest) <-chan *storage.DeleteRangeResponse Scan(args *storage.ScanRequest) <-chan *storage.ScanResponse EndTransaction(args *storage.EndTransactionRequest) <-chan *storage.EndTransactionResponse AccumulateTS(args *storage.AccumulateTSRequest) <-chan *storage.AccumulateTSResponse ReapQueue(args *storage.ReapQueueRequest) <-chan *storage.ReapQueueResponse EnqueueUpdate(args *storage.EnqueueUpdateRequest) <-chan *storage.EnqueueUpdateResponse EnqueueMessage(args *storage.EnqueueMessageRequest) <-chan *storage.EnqueueMessageResponse }
A DB interface provides asynchronous methods to access a key value store.
type DistDB ¶
type DistDB struct {
// contains filtered or unexported fields
}
A DistDB provides methods to access Cockroach's monolithic, distributed key value store. Each method invocation triggers a lookup or lookups to find replica metadata for implicated key ranges. RPCs are sent to one or more of the replicas to satisfy the method invocation.
func NewDB ¶
NewDB returns a key-value datastore client which connects to the Cockroach cluster via the supplied gossip instance.
func (*DistDB) AccumulateTS ¶
func (db *DistDB) AccumulateTS(args *storage.AccumulateTSRequest) <-chan *storage.AccumulateTSResponse
AccumulateTS is used to efficiently accumulate a time series of int64 quantities representing discrete subtimes. For example, a key/value might represent a minute of data. Each would contain 60 int64 counts, each representing a second.
func (*DistDB) Contains ¶
func (db *DistDB) Contains(args *storage.ContainsRequest) <-chan *storage.ContainsResponse
Contains checks for the existence of a key.
func (*DistDB) Delete ¶
func (db *DistDB) Delete(args *storage.DeleteRequest) <-chan *storage.DeleteResponse
Delete .
func (*DistDB) DeleteRange ¶
func (db *DistDB) DeleteRange(args *storage.DeleteRangeRequest) <-chan *storage.DeleteRangeResponse
DeleteRange .
func (*DistDB) EndTransaction ¶
func (db *DistDB) EndTransaction(args *storage.EndTransactionRequest) <-chan *storage.EndTransactionResponse
EndTransaction .
func (*DistDB) EnqueueMessage ¶
func (db *DistDB) EnqueueMessage(args *storage.EnqueueMessageRequest) <-chan *storage.EnqueueMessageResponse
EnqueueMessage enqueues a message for delivery to an inbox.
func (*DistDB) EnqueueUpdate ¶
func (db *DistDB) EnqueueUpdate(args *storage.EnqueueUpdateRequest) <-chan *storage.EnqueueUpdateResponse
EnqueueUpdate enqueues an update for eventual execution.
func (*DistDB) Get ¶
func (db *DistDB) Get(args *storage.GetRequest) <-chan *storage.GetResponse
Get .
func (*DistDB) Increment ¶
func (db *DistDB) Increment(args *storage.IncrementRequest) <-chan *storage.IncrementResponse
Increment .
func (*DistDB) Put ¶
func (db *DistDB) Put(args *storage.PutRequest) <-chan *storage.PutResponse
Put .
func (*DistDB) ReapQueue ¶
func (db *DistDB) ReapQueue(args *storage.ReapQueueRequest) <-chan *storage.ReapQueueResponse
ReapQueue scans and deletes messages from a recipient message queue. ReapQueueRequest invocations must be part of an extant transaction or they fail. Returns the reaped queue messsages, up to the requested maximum. If fewer than the maximum were returned, then the queue is empty.
func (*DistDB) Scan ¶
func (db *DistDB) Scan(args *storage.ScanRequest) <-chan *storage.ScanResponse
Scan .
type LocalDB ¶
type LocalDB struct {
// contains filtered or unexported fields
}
A LocalDB provides methods to access only a local, in-memory key value store. It utilizes a single storage/Range object, backed by a storage/InMem engine.
func NewLocalDB ¶
NewLocalDB returns a local-only KV DB for direct access to a store.
func (*LocalDB) AccumulateTS ¶
func (db *LocalDB) AccumulateTS(args *storage.AccumulateTSRequest) <-chan *storage.AccumulateTSResponse
AccumulateTS passes through to local range.
func (*LocalDB) Contains ¶
func (db *LocalDB) Contains(args *storage.ContainsRequest) <-chan *storage.ContainsResponse
Contains passes through to local range.
func (*LocalDB) Delete ¶
func (db *LocalDB) Delete(args *storage.DeleteRequest) <-chan *storage.DeleteResponse
Delete passes through to local range.
func (*LocalDB) DeleteRange ¶
func (db *LocalDB) DeleteRange(args *storage.DeleteRangeRequest) <-chan *storage.DeleteRangeResponse
DeleteRange passes through to local range.
func (*LocalDB) EndTransaction ¶
func (db *LocalDB) EndTransaction(args *storage.EndTransactionRequest) <-chan *storage.EndTransactionResponse
EndTransaction passes through to local range.
func (*LocalDB) EnqueueMessage ¶
func (db *LocalDB) EnqueueMessage(args *storage.EnqueueMessageRequest) <-chan *storage.EnqueueMessageResponse
EnqueueMessage passes through to local range.
func (*LocalDB) EnqueueUpdate ¶
func (db *LocalDB) EnqueueUpdate(args *storage.EnqueueUpdateRequest) <-chan *storage.EnqueueUpdateResponse
EnqueueUpdate passes through to local range.
func (*LocalDB) Get ¶
func (db *LocalDB) Get(args *storage.GetRequest) <-chan *storage.GetResponse
Get passes through to local range.
func (*LocalDB) Increment ¶
func (db *LocalDB) Increment(args *storage.IncrementRequest) <-chan *storage.IncrementResponse
Increment passes through to local range.
func (*LocalDB) Put ¶
func (db *LocalDB) Put(args *storage.PutRequest) <-chan *storage.PutResponse
Put passes through to local range.
func (*LocalDB) ReapQueue ¶
func (db *LocalDB) ReapQueue(args *storage.ReapQueueRequest) <-chan *storage.ReapQueueResponse
ReapQueue passes through to local range.
func (*LocalDB) Scan ¶
func (db *LocalDB) Scan(args *storage.ScanRequest) <-chan *storage.ScanResponse
Scan passes through to local range.
type RESTServer ¶
type RESTServer struct {
// contains filtered or unexported fields
}
A RESTServer provides a RESTful HTTP API to interact with an underlying key-value store.
func NewRESTServer ¶
func NewRESTServer(db DB) *RESTServer
NewRESTServer allocates and returns a new server.
func (*RESTServer) HandleAction ¶
func (s *RESTServer) HandleAction(w http.ResponseWriter, r *http.Request)
HandleAction arbitrates requests to the appropriate function based on the request’s HTTP method.