kv

package
v0.0.0-...-02ea31e Latest Latest
Warning

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

Go to latest
Published: May 30, 2015 License: Apache-2.0 Imports: 31 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.

Index

Constants

View Source
const (
	// RESTPrefix is the prefix for RESTful endpoints used to
	// interact directly with the key-value datastore.
	RESTPrefix = "/kv/rest/"
	// EntryPrefix is the prefix for endpoints that interact with individual
	// key-value pairs directly.
	EntryPrefix = RESTPrefix + "entry/"
	// EntryPattern is the pattern used to route requests for individual keys.
	EntryPattern = EntryPrefix + ":key"
	// RangePrefix is the prefix for endpoints that interact with a range of key-value pairs.
	RangePrefix = RESTPrefix + "range"
	// CounterPrefix is the prefix for the endpoint that increments a key by a given amount.
	CounterPrefix = RESTPrefix + "counter/"
	// CounterPattern is the pattern used to route requests for incrementing
	// counters.
	CounterPattern = CounterPrefix + ":key"
)
View Source
const (
	// DBPrefix is the prefix for the key-value database endpoint used
	// to interact with the key-value datastore via HTTP RPC.
	DBPrefix = client.KVDBEndpoint
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DBServer

type DBServer struct {
	// contains filtered or unexported fields
}

A DBServer provides an HTTP server endpoint serving the key-value API. It accepts either JSON or serialized protobuf content types.

func NewDBServer

func NewDBServer(sender client.KVSender) *DBServer

NewDBServer allocates and returns a new DBServer.

func (*DBServer) RegisterRPC

func (s *DBServer) RegisterRPC(rpcServer *rpc.Server) error

RegisterRPC registers the RPC endpoints.

func (*DBServer) ServeHTTP

func (s *DBServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP serves the key-value API by treating the request URL path as the method, the request body as the arguments, and sets the response body as the method reply. The request body is unmarshalled into arguments based on the Content-Type request header. Protobuf and JSON-encoded requests are supported. The response body is encoded according the the request's Accept header, or if not present, in the same format as the request's incoming Content-Type header.

type DistSender

type DistSender struct {
	// contains filtered or unexported fields
}

A DistSender 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 NewDistSender

func NewDistSender(ctx *DistSenderContext, gossip *gossip.Gossip) *DistSender

NewDistSender returns a client.KVSender instance which connects to the Cockroach cluster via the supplied gossip instance. Supplying a DistSenderContext or the fields within is optional. For omitted values, sane defaults will be used.

func (*DistSender) Send

func (ds *DistSender) Send(_ context.Context, call client.Call)

Send implements the client.KVSender interface. It verifies permissions and looks up the appropriate range based on the supplied key and sends the RPC according to the specified options.

If the request spans multiple ranges (which is possible for Scan or DeleteRange requests), Send sends requests to the individual ranges sequentially and combines the results transparently.

This may temporarily adjust the request headers, so the client.Call must not be used concurrently until Send has returned.

type DistSenderContext

type DistSenderContext struct {
	Clock                    *hlc.Clock
	RangeDescriptorCacheSize int32
	// RangeLookupMaxRanges sets how many ranges will be prefetched into the
	// range descriptor cache when dispatching a range lookup request.
	RangeLookupMaxRanges int32
	LeaderCacheSize      int32
	RPCRetryOptions      *retry.Options
	// contains filtered or unexported fields
}

DistSenderContext holds auxiliary objects that can be passed to NewDistSender.

type LocalSender

type LocalSender struct {
	// contains filtered or unexported fields
}

A LocalSender provides methods to access a collection of local stores.

func NewLocalSender

func NewLocalSender() *LocalSender

NewLocalSender returns a local-only sender which directly accesses a collection of stores.

func (*LocalSender) AddStore

func (ls *LocalSender) AddStore(s *storage.Store)

AddStore adds the specified store to the store map.

func (*LocalSender) GetStore

func (ls *LocalSender) GetStore(storeID proto.StoreID) (*storage.Store, error)

GetStore looks up the store by store ID. Returns an error if not found.

func (*LocalSender) GetStoreCount

func (ls *LocalSender) GetStoreCount() int

GetStoreCount returns the number of stores this node is exporting.

func (*LocalSender) GetStoreIDs

func (ls *LocalSender) GetStoreIDs() []proto.StoreID

GetStoreIDs returns all the current store ids in a random order.

func (*LocalSender) HasStore

func (ls *LocalSender) HasStore(storeID proto.StoreID) bool

HasStore returns true if the specified store is owned by this LocalSender.

func (*LocalSender) RemoveStore

func (ls *LocalSender) RemoveStore(s *storage.Store)

RemoveStore removes the specified store from the store map.

func (*LocalSender) Send

func (ls *LocalSender) Send(ctx context.Context, call client.Call)

Send implements the client.KVSender interface. The store is looked up from the store map if specified by header.Replica; otherwise, the command is being executed locally, and the replica is determined via lookup through each store's LookupRange method.

func (*LocalSender) VisitStores

func (ls *LocalSender) VisitStores(visitor func(s *storage.Store) error) error

VisitStores implements a visitor pattern over stores in the storeMap. The specified function is invoked with each store in turn. Stores are visited in a random order.

type LocalTestCluster

type LocalTestCluster struct {
	Manual *hlc.ManualClock
	Clock  *hlc.Clock
	Gossip *gossip.Gossip
	Eng    engine.Engine
	Store  *storage.Store
	KV     *client.KV

	Stopper *util.Stopper
	// contains filtered or unexported fields
}

A LocalTestCluster encapsulates an in-memory instantiation of a cockroach node with a single store using a local sender. Example usage of a LocalTestCluster follows:

s := &server.LocalTestCluster{}
s.Start(t)
defer s.Stop()

Note that the LocalTestCluster is different from server.TestCluster in that it doesn't use a distributed sender and doesn't start a server node. There is no RPC traffic.

func (*LocalTestCluster) Start

func (ltc *LocalTestCluster) Start(t util.Tester)

Start starts the test cluster by bootstrapping an in-memory store (defaults to maximum of 50M). The server is started, launching the node RPC server and all HTTP endpoints. Use the value of TestServer.Addr after Start() for client connections. Use Stop() to shutdown the server after the test completes.

func (*LocalTestCluster) Stop

func (ltc *LocalTestCluster) Stop()

Stop stops the cluster.

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 *client.KV) *RESTServer

NewRESTServer allocates and returns a new server.

func (*RESTServer) ServeHTTP

func (s *RESTServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface.

type TxnCoordSender

type TxnCoordSender struct {
	sync.Mutex // Protects the txns map.
	// contains filtered or unexported fields
}

A TxnCoordSender is an implementation of client.KVSender which wraps a lower-level KVSender (either a LocalSender or a DistSender) to which it sends commands. It acts as a man-in-the-middle, coordinating transaction state for clients. After a transaction is started, the TxnCoordSender starts asynchronously sending heartbeat messages to that transaction's txn record, to keep it live. It also keeps track of each written key or key range over the course of the transaction. When the transaction is committed or aborted, it clears accumulated write intents for the transaction.

func NewTxnCoordSender

func NewTxnCoordSender(wrapped client.KVSender, clock *hlc.Clock, linearizable bool, stopper *util.Stopper) *TxnCoordSender

NewTxnCoordSender creates a new TxnCoordSender for use from a KV distributed DB instance. A TxnCoordSender should be closed when no longer in use via Close(), which also closes the wrapped sender supplied here.

func (*TxnCoordSender) Send

func (tc *TxnCoordSender) Send(_ context.Context, call client.Call)

Send implements the client.KVSender interface. If the call is part of a transaction, the coordinator will initialize the transaction if it's not nil but has an empty ID.

Jump to

Keyboard shortcuts

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