cockroach: github.com/cockroachdb/cockroach/pkg/acceptance/localcluster Index | Files | Directories

package localcluster

import "github.com/cockroachdb/cockroach/pkg/acceptance/localcluster"

Index

Package Files

cluster.go localcluster.go

func IsUnavailableError Uses

func IsUnavailableError(err error) bool

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

func MakePerNodeFixedPortsCfg Uses

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.

func SourceBinary Uses

func SourceBinary() string

SourceBinary returns the path of the cockroach binary that was built with the local source.

type Cluster Uses

type Cluster struct {
    Cfg ClusterConfig

    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 Uses

func New(cfg ClusterConfig) *Cluster

New creates a Cluster with the given configuration.

func (*Cluster) Close Uses

func (c *Cluster) Close()

Close stops the cluster, killing all of the nodes.

func (*Cluster) IPAddr Uses

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

IPAddr returns the IP address of the specified node.

func (*Cluster) RPCPort Uses

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

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

func (*Cluster) RandNode Uses

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

RandNode returns the index of a random alive node.

func (*Cluster) Split Uses

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 Uses

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 Uses

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 Uses

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

UpdateZoneConfig updates the default zone config for the cluster.

type ClusterConfig Uses

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
    NoWait      bool               // if set, return from Start before cluster ready
}

A ClusterConfig holds the configuration for a Cluster.

type LocalCluster Uses

type LocalCluster struct {
    *Cluster
}

LocalCluster implements cluster.Cluster.

func (*LocalCluster) Addr Uses

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

Addr implements cluster.Cluster.

func (*LocalCluster) Assert Uses

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

Assert implements cluster.Cluster.

func (*LocalCluster) AssertAndStop Uses

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

AssertAndStop implements cluster.Cluster.

func (*LocalCluster) ExecCLI Uses

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

ExecCLI implements cluster.Cluster.

func (*LocalCluster) Hostname Uses

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

Hostname implements cluster.Cluster.

func (*LocalCluster) InternalIP Uses

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

InternalIP implements cluster.Cluster.

func (*LocalCluster) Kill Uses

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

Kill implements cluster.Cluster.

func (*LocalCluster) NewDB Uses

func (b *LocalCluster) NewDB(ctx context.Context, i int) (*gosql.DB, error)

NewDB implements the Cluster interface.

func (*LocalCluster) NumNodes Uses

func (b *LocalCluster) NumNodes() int

NumNodes implements cluster.Cluster.

func (*LocalCluster) PGUrl Uses

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

PGUrl implements cluster.Cluster.

func (*LocalCluster) Port Uses

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

Port implements cluster.Cluster.

func (*LocalCluster) Restart Uses

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

Restart implements cluster.Cluster.

func (*LocalCluster) RestartAsync Uses

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 Uses

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

URL implements cluster.Cluster.

type Node Uses

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) AdvertiseAddr Uses

func (n *Node) AdvertiseAddr() (s string)

AdvertiseAddr returns the Node's AdvertiseAddr or empty if none is available.

func (*Node) Alive Uses

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) DB Uses

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

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

func (*Node) HTTPAddr Uses

func (n *Node) HTTPAddr() string

HTTPAddr returns the HTTP address (once known).

func (*Node) IPAddr Uses

func (n *Node) IPAddr() string

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

func (*Node) Kill Uses

func (n *Node) Kill()

Kill stops a node abruptly by sending it SIGKILL.

func (*Node) PGUrl Uses

func (n *Node) PGUrl() string

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

func (*Node) RPCAddr Uses

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 Uses

func (n *Node) RPCPort() string

RPCPort returns the RPC + Postgres port.

func (*Node) Signal Uses

func (n *Node) Signal(s os.Signal)

Signal sends the given signal to the process. It is a no-op if the process is not running.

func (*Node) Start Uses

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

Start starts a node.

func (*Node) StartAsync Uses

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

StartAsync starts a node asynchronously. It returns a buffered 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 Uses

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

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

func (*Node) Wait Uses

func (n *Node) Wait() *exec.ExitError

Wait waits for the process to terminate and returns its process' Wait(). This is nil if the process terminated with a zero exit code.

type NodeConfig Uses

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

PathSynopsis
tcPackage 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 localcluster imports 39 packages (graph) and is imported by 2 packages. Updated 2019-07-21. Refresh now. Tools for package owners.