server

package
v0.0.0-...-f211112 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2016 License: Apache-2.0 Imports: 48 Imported by: 0

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

View Source
const SelfGossipAddr = "self"

SelfGossipAddr is a special flag that configures a node to gossip only with itself. This avoids having to specify the port twice for single-node clusters (i.e. once in --host/--port, and again in --gossip).

View Source
const (
	// TestUser is a fixed user used in unittests.
	// It has valid embedded client certs.
	TestUser = "testuser"
)

Variables

This section is empty.

Functions

func BootstrapCluster

func BootstrapCluster(clusterID string, engines []engine.Engine, stopper *stop.Stopper) (*client.DB, error)

BootstrapCluster bootstraps a multiple stores using the provided engines and cluster ID. The first 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.

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() sql.MetadataSchema

GetBootstrapSchema returns the schema which will be used to bootstrap a new server.

func PathForNodeStatus

func PathForNodeStatus(nodeID string) string

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.

Types

type Context

type Context struct {
	// Embed the base context.
	base.Context

	// Addr is the host:port to bind for HTTP/RPC traffic.
	Addr string

	// PGAddr is the host:port to bind for Postgres traffic.
	PGAddr string

	// Stores is specified to enable durable key-value storage.
	// Memory-backed key value stores may be optionally specified
	// via mem=<integer byte size>.
	//
	// Stores specify a comma-separated list of stores specified by a
	// colon-separated list of device attributes followed by '=' and
	// either a filepath for a persistent store or an integer size in bytes for an
	// in-memory store. Device attributes typically include whether the store is
	// flash (ssd), spinny disk (hdd), fusion-io (fio), in-memory (mem); device
	// attributes might also include speeds and other specs (7200rpm, 200kiops, etc.).
	// For example, -store=hdd:7200rpm=/mnt/hda1,ssd=/mnt/ssd01,ssd=/mnt/ssd02,mem=1073741824
	Stores string

	// 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

	// Maximum clock offset for the cluster.
	MaxOffset time.Duration

	// GossipBootstrap is a comma-separated list of node addresses that
	// act as bootstrap hosts for connecting to the gossip network.
	GossipBootstrap string

	// Enables running the node as a single-node in-memory cluster.
	EphemeralSingleNode bool

	// 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.
	Linearizable bool

	// 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 in bytes to use for the memory
	// table. The value is split evenly between the stores if there are more than one.
	MemtableBudget int64

	// BalanceMode determines how this node makes balancing decisions.
	BalanceMode storage.BalanceMode

	// 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

	// ScanInterval determines a duration during which each range should be
	// visited approximately once by the range scanner.
	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.
	ScanMaxIdleTime time.Duration

	// MetricsFrequency determines the frequency at which the server should
	// record internal metrics.
	MetricsFrequency time.Duration

	// TimeUntilStoreDead is the time after which if there is no new gossiped
	// information about a store, it is considered dead.
	TimeUntilStoreDead time.Duration
}

Context holds parameters needed to setup a server. Calling "cli".initFlags(ctx *Context) will initialize Context using command flags. Keep in sync with "cli/flags.go".

func NewContext

func NewContext() *Context

NewContext returns a Context with default values.

func NewTestContext

func NewTestContext() *Context

NewTestContext returns a context for testing. It overrides the Certs with the test certs directory. We need to override the certs loader.

func (*Context) InitDefaults

func (ctx *Context) InitDefaults()

InitDefaults sets up the default values for a Context.

func (*Context) InitNode

func (ctx *Context) InitNode() error

InitNode parses node attributes and initializes the gossip bootstrap resolvers.

func (*Context) InitStores

func (ctx *Context) InitStores(stopper *stop.Stopper) error

InitStores interprets the stores parameter to initialize a slice of engine.Engine objects.

type Node

type Node struct {
	ClusterID  string                 // 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, metaRegistry *metric.Registry, stopper *stop.Stopper) *Node

NewNode returns a new instance of Node.

type Server

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

Server is the cockroach server node.

func NewServer

func NewServer(ctx *Context, stopper *stop.Stopper) (*Server, error)

NewServer creates a Server from a server.Context.

func (*Server) ServeHTTP

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

ServeHTTP is necessary to implement the http.Handler interface. It will snappy a response if the appropriate request headers are set.

func (*Server) Start

func (s *Server) Start(selfBootstrap bool) error

Start runs the RPC and HTTP servers, starts the gossip instance (if selfBootstrap is true, uses the rpc server's address as the gossip bootstrap), and starts the node using the supplied engines slice.

func (*Server) Stop

func (s *Server) Stop()

Stop stops the server.

type TestServer

type TestServer struct {
	// Ctx is the context used by this server.
	Ctx           *Context
	SkipBootstrap bool
	// 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 StartTestServer

func StartTestServer(t util.Tester) *TestServer

StartTestServer starts a in-memory test server.

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) EventFeed

func (ts *TestServer) EventFeed() *util.Feed

EventFeed returns the event feed that the server uses to publish events.

func (*TestServer) Gossip

func (ts *TestServer) Gossip() *gossip.Gossip

Gossip returns the gossip instance used by the TestServer.

func (*TestServer) OpenDBClient

func (ts *TestServer) OpenDBClient(user string) (*client.DB, error)

OpenDBClient opens a KVDB Client connecting to the server with the supplied user.

func (*TestServer) PGAddr

func (ts *TestServer) PGAddr() string

PGAddr returns the Postgres-protocol endpoint's address.

func (*TestServer) PGPort

func (ts *TestServer) PGPort() (string, error)

PGPort returns the port portion of the Postgres-protocol endpoint's address.

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 rpc 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) Stop

func (ts *TestServer) Stop()

Stop stops the TestServer.

func (*TestServer) Stopper

func (ts *TestServer) Stopper() *stop.Stopper

Stopper returns the embedded server's Stopper.

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.

Directories

Path Synopsis
Package status is a generated protocol buffer package.
Package status is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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