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 ¶
- Constants
- Variables
- func AddEventLogToMetadataSchema(schema *sqlbase.MetadataSchema)
- func ExpectedInitialRangeCount() int
- func GetBootstrapSchema() sqlbase.MetadataSchema
- func GetTotalMemory() (int64, error)
- func PathForNodeStatus(nodeID string) string
- func WaitForInitialSplits(db *client.DB) error
- type Context
- type Node
- func (n *Node) Batch(ctx context.Context, args *roachpb.BatchRequest) (br *roachpb.BatchResponse, err error)
- func (n *Node) IsDraining() bool
- func (n *Node) PollFrozen(ctx context.Context, args *roachpb.PollFrozenRequest) (*roachpb.PollFrozenResponse, error)
- func (n *Node) Reserve(ctx context.Context, req *roachpb.ReservationRequest) (*roachpb.ReservationResponse, error)
- func (n *Node) SetDraining(drain bool) error
- type Server
- func (s *Server) Drain(on []serverpb.DrainMode) ([]serverpb.DrainMode, error)
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Server) SetupReportingURLs() error
- func (s *Server) Start() error
- func (s *Server) Stop()
- func (s *Server) Undrain(off []serverpb.DrainMode) []serverpb.DrainMode
- type StoreSpec
- type StoreSpecList
- type TestServer
- func (ts *TestServer) Clock() *hlc.Clock
- func (ts *TestServer) DB() *client.DB
- func (ts *TestServer) Gossip() *gossip.Gossip
- func (ts *TestServer) KVClient() interface{}
- func (ts *TestServer) KVDB() interface{}
- func (ts *TestServer) LeaseManager() interface{}
- func (ts *TestServer) MustGetSQLCounter(name string) int64
- func (ts *TestServer) MustGetSQLNetworkCounter(name string) int64
- func (ts *TestServer) RPCContext() *rpc.Context
- func (ts *TestServer) ServingAddr() string
- func (ts *TestServer) ServingHost() (string, error)
- func (ts *TestServer) ServingPort() (string, error)
- func (ts *TestServer) SetRangeRetryOptions(ro retry.Options)
- func (ts *TestServer) Start() error
- func (ts *TestServer) StartWithStopper(stopper *stop.Stopper) error
- func (ts *TestServer) Stop()
- func (ts *TestServer) Stopper() *stop.Stopper
- func (ts *TestServer) Stores() *storage.Stores
- func (ts *TestServer) TsDB() *ts.DB
- func (ts *TestServer) WaitForInitialSplits() error
- func (ts *TestServer) WriteSummaries() error
Constants ¶
const ( // TestUser is a fixed user used in unittests. // It has valid embedded client certs. TestUser = "testuser" )
Variables ¶
var ( // GracefulDrainModes is the standard succession of drain modes entered // for a graceful shutdown. GracefulDrainModes = []serverpb.DrainMode{serverpb.DrainMode_CLIENT, serverpb.DrainMode_LEADERSHIP} )
var TestServerFactory testingshim.TestServerFactory = testServerFactoryImpl{}
TestServerFactory can be passed to testingshim.InitTestServerFactory
Functions ¶
func AddEventLogToMetadataSchema ¶
func AddEventLogToMetadataSchema(schema *sqlbase.MetadataSchema)
AddEventLogToMetadataSchema adds the range event log table to the supplied MetadataSchema.
func ExpectedInitialRangeCount ¶
func ExpectedInitialRangeCount() int
ExpectedInitialRangeCount returns the expected number of ranges that should be on the server after initial (asynchronous) splits have been completed, assuming no additional information is added outside of the normal bootstrap process.
func GetBootstrapSchema ¶
func GetBootstrapSchema() sqlbase.MetadataSchema
GetBootstrapSchema returns the schema which will be used to bootstrap a new server.
func GetTotalMemory ¶
GetTotalMemory returns either the total system memory or if possible the cgroups available memory.
func PathForNodeStatus ¶
PathForNodeStatus returns the path needed to issue a GET request for node status. If passed an empty nodeID, this returns the path to GET status for all nodes.
func WaitForInitialSplits ¶
WaitForInitialSplits waits for the expected number of initial ranges to be populated in the meta2 table. If the expected range count is not reached within a configured timeout, an error is returned.
Types ¶
type Context ¶
type Context struct { // Embed the base context. *base.Context // Unix socket: for postgres only. SocketFile string // Stores is specified to enable durable key-value storage. Stores StoreSpecList // Attrs specifies a colon-separated list of node topography or machine // capabilities, used to match capabilities or location preferences specified // in zone configs. Attrs string // JoinUsing is a comma-separated list of node addresses that // act as bootstrap hosts for connecting to the gossip network. JoinUsing string // CacheSize is the amount of memory in bytes to use for caching data. // The value is split evenly between the stores if there are more than one. CacheSize int64 // MemtableBudget is the amount of memory, per store, in bytes to use for // the memory table. // This value is no longer settable by the end user. MemtableBudget int64 // Engines is the storage instances specified by Stores. Engines []engine.Engine // NodeAttributes is the parsed representation of Attrs. NodeAttributes roachpb.Attributes // GossipBootstrapResolvers is a list of gossip resolvers used // to find bootstrap nodes for connecting to the gossip network. GossipBootstrapResolvers []resolver.Resolver // Enables linearizable behaviour of operations on this node by making sure // that no commit timestamp is reported back to the client until all other // node clocks have necessarily passed it. // Environment Variable: COCKROACH_LINEARIZABLE Linearizable bool // Maximum clock offset for the cluster. // Environment Variable: COCKROACH_MAX_OFFSET MaxOffset time.Duration // RaftTickInterval is the resolution of the Raft timer. RaftTickInterval time.Duration // MetricsSamplePeriod determines the time between records of // server internal metrics. // Environment Variable: COCKROACH_METRICS_SAMPLE_INTERVAL MetricsSampleInterval time.Duration // ScanInterval determines a duration during which each range should be // visited approximately once by the range scanner. // Environment Variable: COCKROACH_SCAN_INTERVAL ScanInterval time.Duration // ScanMaxIdleTime is the maximum time the scanner will be idle between ranges. // If enabled (> 0), the scanner may complete in less than ScanInterval for small // stores. // Environment Variable: COCKROACH_SCAN_MAX_IDLE_TIME ScanMaxIdleTime time.Duration // ConsistencyCheckInterval determines the time between range consistency checks. // Environment Variable: COCKROACH_CONSISTENCY_CHECK_INTERVAL ConsistencyCheckInterval time.Duration // ConsistencyCheckPanicOnFailure causes the node to panic when it detects a // replication consistency check failure. ConsistencyCheckPanicOnFailure bool // TimeUntilStoreDead is the time after which if there is no new gossiped // information about a store, it is considered dead. // Environment Variable: COCKROACH_TIME_UNTIL_STORE_DEAD TimeUntilStoreDead time.Duration // ReservationsEnabled is a switch used to enable the add replica // reservation system. ReservationsEnabled bool // TestingKnobs is used for internal test controls only. TestingKnobs base.TestingKnobs }
Context holds parameters needed to setup a server.
func MakeTestContext ¶
func MakeTestContext() Context
MakeTestContext returns a context for testing. It overrides the Certs with the test certs directory. We need to override the certs loader.
type Node ¶
type Node struct { ClusterID uuid.UUID // UUID for Cockroach cluster Descriptor roachpb.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 ¶
func NewNode( ctx storage.StoreContext, recorder *status.MetricsRecorder, stopper *stop.Stopper, txnMetrics *kv.TxnMetrics, eventLogger sql.EventLogger, ) *Node
NewNode returns a new instance of Node.
func (*Node) Batch ¶
func (n *Node) Batch( ctx context.Context, args *roachpb.BatchRequest, ) (br *roachpb.BatchResponse, err error)
Batch implements the roachpb.InternalServer interface.
func (*Node) IsDraining ¶
IsDraining returns true if at least one Store housed on this Node is not currently allowing leader leases to be procured or extended.
func (*Node) PollFrozen ¶
func (n *Node) PollFrozen( ctx context.Context, args *roachpb.PollFrozenRequest, ) (*roachpb.PollFrozenResponse, error)
PollFrozen implements the roachpb.InternalServer interface.
func (*Node) Reserve ¶
func (n *Node) Reserve( ctx context.Context, req *roachpb.ReservationRequest, ) (*roachpb.ReservationResponse, error)
Reserve implements the roachpb.InternalServer interface.
func (*Node) SetDraining ¶
SetDraining called with 'true' waits until all Replicas' leader leases have expired or a reasonable amount of time has passed (in which case an error is returned but draining mode is still active). When called with 'false', returns to the normal mode of allowing leader lease acquisition and extensions.
type Server ¶
type Server struct { Tracer opentracing.Tracer // contains filtered or unexported fields }
Server is the cockroach server node.
func (*Server) Drain ¶
Drain idempotently activates the given DrainModes on the Server in the order in which they are supplied. For example, Drain is typically called with [CLIENT,LEADERSHIP] before terminating the process for graceful shutdown. On success, returns all active drain modes after carrying out the request. On failure, the system may be in a partially drained state and should be recovered by calling Undrain() with the same (or a larger) slice of modes.
func (*Server) ServeHTTP ¶
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP is necessary to implement the http.Handler interface.
func (*Server) SetupReportingURLs ¶
SetupReportingURLs parses the phone-home for version updates URL and should be called before a server starts. Where update checks are not useful (eg in tests), skipping this call, or setting env var COCKROACH_SKIP_UPDATE_CHECK=1, skips the acutal network calls (note though the check is treated as having succeeded, meaning the cluster will wait until the next scheduled check to try again).
type StoreSpec ¶
type StoreSpec struct { Path string SizeInBytes int64 SizePercent float64 InMemory bool Attributes roachpb.Attributes }
StoreSpec contains the details that can be specified in the cli pertaining to the --store flag.
type StoreSpecList ¶
type StoreSpecList struct { Specs []StoreSpec // contains filtered or unexported fields }
StoreSpecList contains a slice of StoreSpecs that implements pflag's value interface.
func (*StoreSpecList) Set ¶
func (ssl *StoreSpecList) Set(value string) error
Set adds a new value to the StoreSpecValue. It is the important part of pflag's value interface.
func (StoreSpecList) String ¶
func (ssl StoreSpecList) String() string
String returns a string representation of all the StoreSpecs. This is part of pflag's value interface.
func (*StoreSpecList) Type ¶
func (ssl *StoreSpecList) Type() string
Type returns the underlying type in string form. This is part of pflag's value interface.
type TestServer ¶
type TestServer struct { // Ctx is the context used by this server. Ctx *Context // server is the embedded Cockroach server struct. *Server StoresPerNode int }
A TestServer encapsulates an in-memory instantiation of a cockroach node with a single store. Example usage of a TestServer follows:
s := server.StartTestServer(t) defer s.Stop()
func StartInsecureTestServer ¶
func StartInsecureTestServer(t util.Tester) TestServer
StartInsecureTestServer starts an insecure in-memory test server.
func StartTestServer ¶
func StartTestServer(t util.Tester) TestServer
StartTestServer starts an in-memory test server.
func StartTestServerJoining ¶
func StartTestServerJoining(t util.Tester, other TestServer) TestServer
StartTestServerJoining starts an in-memory test server that attempts to join `other`.
func StartTestServerWithContext ¶
func StartTestServerWithContext(t util.Tester, ctx *Context) TestServer
StartTestServerWithContext starts an in-memory test server. ctx can be nil, in which case a default context will be created.
func (*TestServer) Clock ¶
func (ts *TestServer) Clock() *hlc.Clock
Clock returns the clock used by the TestServer.
func (*TestServer) DB ¶
func (ts *TestServer) DB() *client.DB
DB returns the client.DB instance used by the TestServer.
func (*TestServer) Gossip ¶
func (ts *TestServer) Gossip() *gossip.Gossip
Gossip returns the gossip instance used by the TestServer.
func (*TestServer) KVClient ¶
func (ts *TestServer) KVClient() interface{}
KVClient is part of TestServerInterface.
func (*TestServer) KVDB ¶
func (ts *TestServer) KVDB() interface{}
KVDB is part of TestServerInterface.
func (*TestServer) LeaseManager ¶
func (ts *TestServer) LeaseManager() interface{}
LeaseManager is part of TestServerInterface.
func (*TestServer) MustGetSQLCounter ¶
func (ts *TestServer) MustGetSQLCounter(name string) int64
MustGetSQLCounter returns the value of a counter metric from the server's SQL Executor. Runs in O(# of metrics) time, which is fine for test code.
func (*TestServer) MustGetSQLNetworkCounter ¶
func (ts *TestServer) MustGetSQLNetworkCounter(name string) int64
MustGetSQLNetworkCounter returns the value of a counter metric from the server's SQL server. Runs in O(# of metrics) time, which is fine for test code.
func (*TestServer) RPCContext ¶
func (ts *TestServer) RPCContext() *rpc.Context
RPCContext returns the rpc context used by the TestServer.
func (*TestServer) ServingAddr ¶
func (ts *TestServer) ServingAddr() string
ServingAddr returns the server's address. Should be used by clients.
func (*TestServer) ServingHost ¶
func (ts *TestServer) ServingHost() (string, error)
ServingHost returns the host portion of the rpc server's address.
func (*TestServer) ServingPort ¶
func (ts *TestServer) ServingPort() (string, error)
ServingPort returns the port portion of the rpc server's address.
func (*TestServer) SetRangeRetryOptions ¶
func (ts *TestServer) SetRangeRetryOptions(ro retry.Options)
SetRangeRetryOptions sets the retry options for stores in TestServer.
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.ServingAddr() after Start() for client connections. Use Stop() to shutdown the server after the test completes.
func (*TestServer) StartWithStopper ¶
func (ts *TestServer) StartWithStopper(stopper *stop.Stopper) error
StartWithStopper is the same as Start, but allows passing a stopper explicitly.
func (*TestServer) Stopper ¶
func (ts *TestServer) Stopper() *stop.Stopper
Stopper returns the embedded server's Stopper.
func (*TestServer) Stores ¶
func (ts *TestServer) Stores() *storage.Stores
Stores returns the collection of stores from this TestServer's node.
func (*TestServer) TsDB ¶
func (ts *TestServer) TsDB() *ts.DB
TsDB returns the ts.DB instance used by the TestServer.
func (*TestServer) WaitForInitialSplits ¶
func (ts *TestServer) WaitForInitialSplits() error
WaitForInitialSplits waits for the server to complete its expected initial splits at startup. If the expected range count is not reached within a configured timeout, an error is returned.
func (*TestServer) WriteSummaries ¶
func (ts *TestServer) WriteSummaries() error
WriteSummaries records summaries of time-series data, which is required for any tests that query server stats.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package serverpb is a generated protocol buffer package.
|
Package serverpb is a generated protocol buffer package. |
Package status is a generated protocol buffer package.
|
Package status is a generated protocol buffer package. |