kv

package
v0.0.0-...-2b2087e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 21, 2014 License: Apache-2.0 Imports: 16 Imported by: 0

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

View Source
const (
	// KVKeyPrefix is the prefix for RESTful endpoints used to
	// interact directly with the key-value datastore.
	KVKeyPrefix = "/db/"
)

Variables

View Source
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

func BootstrapConfigs(db DB) error

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

func BootstrapRangeDescriptor(db DB, replica storage.Replica) error

BootstrapRangeDescriptor sets meta1 and meta2 values for KeyMax, using the provided replica.

func GetI

func GetI(db DB, key storage.Key, value interface{}) (bool, int64, error)

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

func PutI(db DB, key storage.Key, value interface{}) error

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

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

func NewDB(gossip *gossip.Gossip) *DistDB

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

func NewLocalDB(rng *storage.Range) *LocalDB

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL