localcluster

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2017 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsUnavailableError

func IsUnavailableError(err error) bool

IsUnavailableError returns true iff the error corresponds to a GRPC connection unavailable error.

func MakePerNodeFixedPortsCfg

func MakePerNodeFixedPortsCfg(numNodes int) map[int]NodeConfig

MakePerNodeFixedPortsCfg makes a PerNodeCfg map of the given number of nodes with odd ports starting at 26257 for the RPC endpoint, and even points for the ui.

Types

type Cluster

type Cluster struct {
	Nodes []*Node
	// contains filtered or unexported fields
}

Cluster holds the state for a local cluster, providing methods for common operations, access to the underlying nodes and per-node KV and SQL clients.

func New

func New(cfg ClusterConfig) *Cluster

New creates a Cluster with the given configuration.

func (*Cluster) Client

func (c *Cluster) Client(idx int) *client.DB

Client returns a *client.DB for the node with the given index.

func (*Cluster) Close

func (c *Cluster) Close()

Close stops the cluster, killing all of the nodes.

func (*Cluster) HTTPPort

func (c *Cluster) HTTPPort(nodeIdx int) string

HTTPPort returns the HTTP port of the specified node. Returns zero if unknown.

func (*Cluster) IPAddr

func (c *Cluster) IPAddr(nodeIdx int) string

IPAddr returns the IP address of the specified node.

func (*Cluster) RPCPort

func (c *Cluster) RPCPort(nodeIdx int) string

RPCPort returns the RPC port of the specified node. Returns zero if unknown.

func (*Cluster) RandNode

func (c *Cluster) RandNode(f func(int) int) int

RandNode returns the index of a random alive node.

func (*Cluster) Split

func (c *Cluster) Split(nodeIdx int, splitKey roachpb.Key) error

Split splits the range containing the split key at the specified split key.

func (*Cluster) Start

func (c *Cluster) Start(ctx context.Context)

Start starts a cluster. The numWorkers parameter controls the SQL connection settings to avoid unnecessary connection creation. The allNodeArgs parameter can be used to pass extra arguments to every node. The perNodeArgs parameter can be used to pass extra arguments to an individual node. If not nil, its size must equal the number of nodes.

func (*Cluster) TransferLease

func (c *Cluster) TransferLease(nodeIdx int, r *rand.Rand, key roachpb.Key) (bool, error)

TransferLease transfers the lease for the range containing key to a random alive node in the range.

func (*Cluster) UpdateZoneConfig

func (c *Cluster) UpdateZoneConfig(rangeMinBytes, rangeMaxBytes int64)

UpdateZoneConfig updates the default zone config for the cluster.

type ClusterConfig

type ClusterConfig struct {
	Ephemeral   bool               // when true, wipe DataDir on Close()
	Binary      string             // path to cockroach, defaults go <cockroach_repo>/cockroach
	AllNodeArgs []string           // args to pass to ./cockroach on all nodes
	NumNodes    int                // number of nodes in the cluster
	DataDir     string             // node i will use storage DataDir/<i>
	LogDir      string             // when empty, node i defaults to DataDir/<i>/logs
	PerNodeCfg  map[int]NodeConfig // optional map of nodeIndex -> configuration
	DB          string             // database to configure DB connection for
	NumWorkers  int                // SetMaxOpenConns to use for DB connection
}

A ClusterConfig holds the configuration for a Cluster.

type LocalCluster

type LocalCluster struct {
	*Cluster
}

LocalCluster implements cluster.Cluster.

func (*LocalCluster) Addr

func (b *LocalCluster) Addr(ctx context.Context, i int, port string) string

Addr implements cluster.Cluster.

func (*LocalCluster) Assert

func (b *LocalCluster) Assert(ctx context.Context, t testing.TB)

Assert implements cluster.Cluster.

func (*LocalCluster) AssertAndStop

func (b *LocalCluster) AssertAndStop(ctx context.Context, t testing.TB)

AssertAndStop implements cluster.Cluster.

func (*LocalCluster) ExecCLI

func (b *LocalCluster) ExecCLI(ctx context.Context, i int, cmd []string) (string, string, error)

ExecCLI implements cluster.Cluster.

func (*LocalCluster) Hostname

func (b *LocalCluster) Hostname(i int) string

Hostname implements cluster.Cluster.

func (*LocalCluster) InternalIP

func (b *LocalCluster) InternalIP(ctx context.Context, i int) net.IP

InternalIP implements cluster.Cluster.

func (*LocalCluster) Kill

func (b *LocalCluster) Kill(ctx context.Context, i int) error

Kill implements cluster.Cluster.

func (*LocalCluster) NewClient

func (b *LocalCluster) NewClient(ctx context.Context, i int) (*client.DB, error)

NewClient implements cluster.Cluster.

func (*LocalCluster) NumNodes

func (b *LocalCluster) NumNodes() int

NumNodes implements cluster.Cluster.

func (*LocalCluster) PGUrl

func (b *LocalCluster) PGUrl(ctx context.Context, i int) string

PGUrl implements cluster.Cluster.

func (*LocalCluster) Port

func (b *LocalCluster) Port(ctx context.Context, i int) string

Port implements cluster.Cluster.

func (*LocalCluster) Restart

func (b *LocalCluster) Restart(ctx context.Context, i int) error

Restart implements cluster.Cluster.

func (*LocalCluster) RestartAsync

func (b *LocalCluster) RestartAsync(ctx context.Context, i int) <-chan error

RestartAsync restarts the node. The returned channel receives an error or, once the node is successfully connected to the cluster and serving, nil.

func (*LocalCluster) URL

func (b *LocalCluster) URL(ctx context.Context, i int) string

URL implements cluster.Cluster.

type Node

type Node struct {
	Cfg NodeConfig

	syncutil.Mutex
	// contains filtered or unexported fields
}

Node holds the state for a single node in a local cluster and provides methods for starting, pausing, resuming and stopping the node.

func (*Node) Alive

func (n *Node) Alive() bool

Alive returns true if the node is alive (i.e. not stopped). Note that a paused node is considered alive.

func (*Node) Client

func (n *Node) Client() *client.DB

Client returns a *client.DB set up to talk to this node.

func (*Node) DB

func (n *Node) DB() *gosql.DB

DB returns a Postgres connection set up to talk to the node.

func (*Node) HTTPPort

func (n *Node) HTTPPort() string

HTTPPort returns the ui port (may be empty until known).

func (*Node) IPAddr

func (n *Node) IPAddr() string

IPAddr returns the node's listening address (for ui, inter-node, cli, and Postgres alike).

func (*Node) Kill

func (n *Node) Kill()

Kill stops a node abruptly by sending it SIGKILL.

func (*Node) PGUrl

func (n *Node) PGUrl() string

PGUrl returns the postgres connection string (may be empty until known).

func (*Node) RPCAddr

func (n *Node) RPCAddr() string

RPCAddr returns the RPC + Postgres address, or an empty string if it is not known (for instance since the node is down).

func (*Node) RPCPort

func (n *Node) RPCPort() string

RPCPort returns the RPC + Postgres port.

func (*Node) Start

func (n *Node) Start(ctx context.Context, joins ...string)

Start starts a node.

func (*Node) StartAsync

func (n *Node) StartAsync(ctx context.Context, joins ...string) <-chan error

StartAsync starts a node asynchronously. It returns a channel that receives either an error, or, once the node has started up and is fully functional, `nil`.

StartAsync is a no-op if the node is already running.

func (*Node) StatusClient

func (n *Node) StatusClient() serverpb.StatusClient

StatusClient returns a StatusClient set up to talk to this node.

type NodeConfig

type NodeConfig struct {
	Binary            string   // when specified, overrides the node's binary
	DataDir           string   // when specified, overrides the node's data dir
	LogDir            string   // when specified, overrides the node's log dir
	Addr              string   // listening host, defaults to 127.0.0.1
	ExtraArgs         []string // extra arguments for ./cockroach start
	ExtraEnv          []string // environment variables in format key=value
	RPCPort, HTTPPort int      // zero for auto-assign
	DB                string   // see ClusterConfig
	NumWorkers        int      // see ClusterConfig
}

NodeConfig is a configuration for a node in a Cluster. Options with the zero value are typically populated from the corresponding Cluster's ClusterConfig.

Directories

Path Synopsis
Package tc contains utility methods for using the Linux tc (traffic control) command to mess with the network links between cockroach nodes running on the local machine.
Package tc contains utility methods for using the Linux tc (traffic control) command to mess with the network links between cockroach nodes running on the local machine.

Jump to

Keyboard shortcuts

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