Documentation ¶
Overview ¶
Package server implements the Cockroach storage node. A node corresponds to a single instance of the cockroach binary, running on a single physical machine, which exports the "Node" Go RPC service. Each node multiplexes RPC requests to one or more stores, associated with physical storage devices.
Package server also provides access to administrative tools via the command line and also through a REST API.
Index ¶
- Variables
- func BootstrapCluster(clusterID string, eng engine.Engine) (*client.KV, error)
- type Node
- func (n *Node) AccumulateTS(args *proto.AccumulateTSRequest, reply *proto.AccumulateTSResponse) error
- func (n *Node) AdminSplit(args *proto.AdminSplitRequest, reply *proto.AdminSplitResponse) error
- func (n *Node) ConditionalPut(args *proto.ConditionalPutRequest, reply *proto.ConditionalPutResponse) error
- func (n *Node) Contains(args *proto.ContainsRequest, reply *proto.ContainsResponse) error
- func (n *Node) Delete(args *proto.DeleteRequest, reply *proto.DeleteResponse) error
- func (n *Node) DeleteRange(args *proto.DeleteRangeRequest, reply *proto.DeleteRangeResponse) error
- func (n *Node) EndTransaction(args *proto.EndTransactionRequest, reply *proto.EndTransactionResponse) error
- func (n *Node) EnqueueMessage(args *proto.EnqueueMessageRequest, reply *proto.EnqueueMessageResponse) error
- func (n *Node) EnqueueUpdate(args *proto.EnqueueUpdateRequest, reply *proto.EnqueueUpdateResponse) error
- func (n *Node) Get(args *proto.GetRequest, reply *proto.GetResponse) error
- func (n *Node) Increment(args *proto.IncrementRequest, reply *proto.IncrementResponse) error
- func (n *Node) InternalHeartbeatTxn(args *proto.InternalHeartbeatTxnRequest, ...) error
- func (n *Node) InternalPushTxn(args *proto.InternalPushTxnRequest, reply *proto.InternalPushTxnResponse) error
- func (n *Node) InternalRangeLookup(args *proto.InternalRangeLookupRequest, ...) error
- func (n *Node) InternalResolveIntent(args *proto.InternalResolveIntentRequest, ...) error
- func (n *Node) InternalSnapshotCopy(args *proto.InternalSnapshotCopyRequest, ...) error
- func (n *Node) Put(args *proto.PutRequest, reply *proto.PutResponse) error
- func (n *Node) ReapQueue(args *proto.ReapQueueRequest, reply *proto.ReapQueueResponse) error
- func (n *Node) Scan(args *proto.ScanRequest, reply *proto.ScanResponse) error
- type TestServer
Constants ¶
This section is empty.
Variables ¶
var CmdGetAcct = &commander.Command{ UsageLine: "get-acct [options] <key-prefix>", Short: "fetches and displays an accounting config", Long: ` Fetches and displays the accounting configuration for <key-prefix>. The key prefix should be escaped via URL query escaping if it contains non-ascii bytes or spaces. `, Run: runGetAcct, Flag: *flag.CommandLine, }
A CmdGetAcct command displays the acct config for the specified prefix.
var CmdGetPerms = &commander.Command{ UsageLine: "get-perms [options] <key-prefix>", Short: "fetches and displays the permission config", Long: ` Fetches and displays the permission configuration for <key-prefix>. The key prefix should be escaped via URL query escaping if it contains non-ascii bytes or spaces. `, Run: runGetPerms, Flag: *flag.CommandLine, }
A CmdGetPerms command displays the perm config for the specified prefix.
var CmdGetZone = &commander.Command{ UsageLine: "get-zone [options] <key-prefix>", Short: "fetches and displays the zone config", Long: ` Fetches and displays the zone configuration for <key-prefix>. The key prefix should be escaped via URL query escaping if it contains non-ascii bytes or spaces. `, Run: runGetZone, Flag: *flag.CommandLine, }
A CmdGetZone command displays the zone config for the specified prefix.
var CmdInit = &commander.Command{ UsageLine: "init -gossip=host1:port1[,host2:port2...] " + "-certs=<cert-dir>" + "-stores=(ssd=<data-dir>,hdd|7200rpm=<data-dir>,mem=<capacity-in-bytes>)[,...]", Short: "init new Cockroach cluster and start server", Long: ` Initialize a new Cockroach cluster on this node using the first directory specified in the -stores command line flag as the only replica of the first range. For example: cockroach init -gossip=host1:port1,host2:port2 -stores=ssd=/mnt/ssd1,ssd=/mnt/ssd2 If any specified store is already part of a pre-existing cluster, the bootstrap will fail. After bootstrap initialization: ` + cmdStartLongDescription, Run: runInit, Flag: *flag.CommandLine, }
A CmdInit command initializes a new Cockroach cluster.
var CmdLsAccts = &commander.Command{ UsageLine: "ls-accts [options] [key-regexp]", Short: "list all accounting configs by key prefix", Long: ` List accounting configs. If a regular expression is given, the results of the listing are filtered by key prefixes matching the regexp. The key prefix should be escaped via URL query escaping if it contains non-ascii bytes or spaces. `, Run: runLsAccts, Flag: *flag.CommandLine, }
A CmdLsAccts command displays a list of acct configs by prefix.
var CmdLsPerms = &commander.Command{ UsageLine: "ls-perms [options] [key-regexp]", Short: "list all permisison configs by key prefix", Long: ` List permission configs. If a regular expression is given, the results of the listing are filtered by key prefixes matching the regexp. The key prefix should be escaped via URL query escaping if it contains non-ascii bytes or spaces. `, Run: runLsPerms, Flag: *flag.CommandLine, }
A CmdLsPerms command displays a list of perm configs by prefix.
var CmdLsZones = &commander.Command{ UsageLine: "ls-zones [options] [key-regexp]", Short: "list all zone configs by key prefix", Long: ` List zone configs. If a regular expression is given, the results of the listing are filtered by key prefixes matching the regexp. The key prefix should be escaped via URL query escaping if it contains non-ascii bytes or spaces. `, Run: runLsZones, Flag: *flag.CommandLine, }
A CmdLsZones command displays a list of zone configs by prefix.
var CmdRmAcct = &commander.Command{ UsageLine: "rm-acct [options] <key-prefix>", Short: "remove an accounting config by key prefix", Long: ` Remove an existing accounting config by key prefix. No action is taken if no accounting configuration exists for the specified key prefix. Note that this command can affect only a single accounting config with an exactly matching prefix. The key prefix should be escaped via URL query escaping if it contains non-ascii bytes or spaces. `, Run: runRmAcct, Flag: *flag.CommandLine, }
A CmdRmAcct command removes an acct config by prefix.
var CmdRmPerms = &commander.Command{ UsageLine: "rm-perms [options] <key-prefix>", Short: "remove a permission config by key prefix", Long: ` Remove an existing permission config by key prefix. No action is taken if no permission configuration exists for the specified key prefix. Note that this command can affect only a single perm config with an exactly matching prefix. The key prefix should be escaped via URL query escaping if it contains non-ascii bytes or spaces. `, Run: runRmPerms, Flag: *flag.CommandLine, }
A CmdRmPerms command removes a perm config by prefix.
var CmdRmZone = &commander.Command{ UsageLine: "rm-zone [options] <key-prefix>", Short: "remove a zone config by key prefix", Long: ` Remove an existing zone config by key prefix. No action is taken if no zone configuration exists for the specified key prefix. Note that this command can affect only a single zone config with an exactly matching prefix. The key prefix should be escaped via URL query escaping if it contains non-ascii bytes or spaces. `, Run: runRmZone, Flag: *flag.CommandLine, }
A CmdRmZone command removes a zone config by prefix.
var CmdSetAcct = &commander.Command{ UsageLine: "set-acct [options] <key-prefix> <acct-config-file>", Short: "create or update an accounting config for key prefix", Long: ` Create or update a accounting config for the specified key prefix (first argument: <key-prefix>) to the contents of the specified file (second argument: <acct-config-file>). The key prefix should be escaped via URL query escaping if it contains non-ascii bytes or spaces. The accounting config format has the following YAML schema: cluster_id: cluster For example: cluster_id: test `, Run: runSetAcct, Flag: *flag.CommandLine, }
A CmdSetAcct command creates a new or updates an existing acct config.
var CmdSetPerms = &commander.Command{ UsageLine: "set-perm [options] <key-prefix> <perm-config-file>", Short: "create or update permission config for key prefix", Long: ` Create or update a perm config for the specified key prefix (first argument: <key-prefix>) to the contents of the specified file (second argument: <perm-config-file>). The key prefix should be escaped via URL query escaping if it contains non-ascii bytes or spaces. The permission config format has the following YAML schema: read: - user1 - user2 - ... write: - user1 - user2 - ... For example: read: - readOnlyUser - readWriteUser write: - readWriteUser - WriteOnlyUser Setting permission configs will guarantee that users will have permissions for this key prefix and all sub prefixes of the one that is set `, Run: runSetPerms, Flag: *flag.CommandLine, }
A CmdSetPerms command creates a new or updates an existing perm config.
var CmdSetZone = &commander.Command{ UsageLine: "set-zone [options] <key-prefix> <zone-config-file>", Short: "create or update zone config for key prefix", Long: ` Create or update a zone config for the specified key prefix (first argument: <key-prefix>) to the contents of the specified file (second argument: <zone-config-file>). The key prefix should be escaped via URL query escaping if it contains non-ascii bytes or spaces. The zone config format has the following YAML schema: replicas: - [comma-separated attribute list] - ... range_min_bytes: <size-in-bytes> range_max_bytes: <size-in-bytes> For example: replicas: - [us-east-1a, ssd] - [us-east-1b, ssd] - [us-west-1b, ssd] range_min_bytes: 8388608 range_min_bytes: 67108864 Setting zone configs will guarantee that key ranges will be split such that no key range straddles two zone config specifications. This feature can be taken advantage of to pre-split ranges. `, Run: runSetZone, Flag: *flag.CommandLine, }
A CmdSetZone command creates a new or updates an existing zone config.
var CmdStart = &commander.Command{ UsageLine: "start -gossip=host1:port1[,host2:port2...] " + "-certs=<cert-dir>" + "-stores=(ssd=<data-dir>,hdd|7200rpm=<data-dir>|mem=<capacity-in-bytes>)[,...]", Short: "start node by joining the gossip network", Long: cmdStartLongDescription, Run: runStart, Flag: *flag.CommandLine, }
A CmdStart command starts nodes by joining the gossip network.
Functions ¶
func BootstrapCluster ¶
BootstrapCluster bootstraps a store using the provided engine and cluster ID. The bootstrapped store contains a single range spanning all keys. Initial range lookup metadata is populated for the range.
Returns a KV client for unittest purposes. Caller should close the returned client.
Types ¶
type Node ¶
type Node struct { ClusterID string // UUID for Cockroach cluster Descriptor storage.NodeDescriptor // Node ID, network/physical topology // contains filtered or unexported fields }
A Node manages a map of stores (by store ID) for which it serves traffic. A node is the top-level data structure. There is one node instance per process. A node accepts incoming RPCs and services them by directing the commands contained within RPCs to local stores, which in turn direct the commands to specific ranges. Each node has access to the global, monolithic Key-Value abstraction via its kv.DB reference. Nodes use this to allocate node and store IDs for bootstrapping the node itself or new stores as they're added on subsequent instantiations.
func NewNode ¶
NewNode returns a new instance of Node, interpreting command line flags to initialize the appropriate Store or set of Stores. Registers the storage instance for the RPC service "Node".
func (*Node) AccumulateTS ¶
func (n *Node) AccumulateTS(args *proto.AccumulateTSRequest, reply *proto.AccumulateTSResponse) error
AccumulateTS .
func (*Node) AdminSplit ¶
func (n *Node) AdminSplit(args *proto.AdminSplitRequest, reply *proto.AdminSplitResponse) error
AdminSplit .
func (*Node) ConditionalPut ¶
func (n *Node) ConditionalPut(args *proto.ConditionalPutRequest, reply *proto.ConditionalPutResponse) error
ConditionalPut .
func (*Node) Contains ¶
func (n *Node) Contains(args *proto.ContainsRequest, reply *proto.ContainsResponse) error
Contains .
func (*Node) Delete ¶
func (n *Node) Delete(args *proto.DeleteRequest, reply *proto.DeleteResponse) error
Delete .
func (*Node) DeleteRange ¶
func (n *Node) DeleteRange(args *proto.DeleteRangeRequest, reply *proto.DeleteRangeResponse) error
DeleteRange .
func (*Node) EndTransaction ¶
func (n *Node) EndTransaction(args *proto.EndTransactionRequest, reply *proto.EndTransactionResponse) error
EndTransaction .
func (*Node) EnqueueMessage ¶
func (n *Node) EnqueueMessage(args *proto.EnqueueMessageRequest, reply *proto.EnqueueMessageResponse) error
EnqueueMessage .
func (*Node) EnqueueUpdate ¶
func (n *Node) EnqueueUpdate(args *proto.EnqueueUpdateRequest, reply *proto.EnqueueUpdateResponse) error
EnqueueUpdate .
func (*Node) Increment ¶
func (n *Node) Increment(args *proto.IncrementRequest, reply *proto.IncrementResponse) error
Increment .
func (*Node) InternalHeartbeatTxn ¶
func (n *Node) InternalHeartbeatTxn(args *proto.InternalHeartbeatTxnRequest, reply *proto.InternalHeartbeatTxnResponse) error
InternalHeartbeatTxn .
func (*Node) InternalPushTxn ¶
func (n *Node) InternalPushTxn(args *proto.InternalPushTxnRequest, reply *proto.InternalPushTxnResponse) error
InternalPushTxn .
func (*Node) InternalRangeLookup ¶
func (n *Node) InternalRangeLookup(args *proto.InternalRangeLookupRequest, reply *proto.InternalRangeLookupResponse) error
InternalRangeLookup .
func (*Node) InternalResolveIntent ¶
func (n *Node) InternalResolveIntent(args *proto.InternalResolveIntentRequest, reply *proto.InternalResolveIntentResponse) error
InternalResolveIntent .
func (*Node) InternalSnapshotCopy ¶
func (n *Node) InternalSnapshotCopy(args *proto.InternalSnapshotCopyRequest, reply *proto.InternalSnapshotCopyResponse) error
InternalSnapshotCopy .
func (*Node) ReapQueue ¶
func (n *Node) ReapQueue(args *proto.ReapQueueRequest, reply *proto.ReapQueueResponse) error
ReapQueue .
func (*Node) Scan ¶
func (n *Node) Scan(args *proto.ScanRequest, reply *proto.ScanResponse) error
Scan .
type TestServer ¶
type TestServer struct { // CertDir specifies the directory containing certs for SSL // connections. Default will load insecure TLS config. CertDir string // MaxOffset is the maximum offset for clocks in the cluster. // This is mostly irrelevant except when testing reads within // uncertainty intervals. MaxOffset time.Duration // HTTPAddr and RPCAddr default to localhost with port set // at time of call to Start() to an available port. HTTPAddr, RPCAddr string // contains filtered or unexported fields }
A TestServer encapsulates an in-memory instantiation of a cockroach node with a single store. Example usage of a TestServer follows:
s := &server.TestServer{} if err := s.Start(); err != nil { t.Fatal(err) } defer s.Stop()
TODO(spencer): add support for multiple stores.
func StartTestServer ¶
func StartTestServer(t *testing.T) *TestServer
StartTestServer creates a TestServer instance; on failure, causes a fatal testing error. The new TestServer is returned on success.
func (*TestServer) Gossip ¶
func (ts *TestServer) Gossip() *gossip.Gossip
Gossip returns the gossip instance used by the TestServer.
func (TestServer) ServeHTTP ¶
func (s TestServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP is necessary to implement the http.Handler interface. It will gzip a response if the appropriate request headers are set.
func (*TestServer) Start ¶
func (ts *TestServer) Start() error
Start starts the TestServer by bootstrapping an in-memory store (defaults to maximum of 100M). The server is started, launching the node RPC server and all HTTP endpoints. Use the value of TestServer.HTTPAddr after Start() for client connections.