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

package cluster

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

Index

Package Files

certs.go cluster.go docker.go dockercluster.go http.go testconfig.pb.go

Constants

const CockroachBinaryInContainer = "/cockroach/cockroach"

CockroachBinaryInContainer is the container-side path to the CockroachDB binary.

const DefaultTCP nat.Port = base.DefaultPort + "/tcp"

DefaultTCP is the default SQL/RPC port specification.

Variables

var (
    ErrInvalidLengthTestconfig = fmt.Errorf("proto: negative length found during unmarshaling")
    ErrIntOverflowTestconfig   = fmt.Errorf("proto: integer overflow")
)
var CockroachBinary = flag.String("b", func() string {
    rootPkg, err := build.Import("github.com/cockroachdb/cockroach", "", build.FindOnly)
    if err != nil {
        panic(err)
    }

    return filepath.Join(rootPkg.Dir, "cockroach-linux-2.6.32-gnu-amd64")
}(), "the host-side binary to run")

CockroachBinary is the path to the host-side binary to use.

var HTTPClient = http.Client{
    Timeout: base.NetworkTimeout,
    Transport: &http.Transport{
        TLSClientConfig: &tls.Config{
            InsecureSkipVerify: true,
        },
    },
}

HTTPClient is an http.Client configured for querying a cluster. We need to run with "InsecureSkipVerify" (at least on Docker) due to the fact that we cannot use a fixed hostname to reach the cluster. This in turn means that we do not have a verified server name in the certs.

var InitMode_name = map[int32]string{
    0:  "INIT_COMMAND",
    1:  "INIT_BOOTSTRAP_NODE_ZERO",
    2:  "INIT_NONE",
}
var InitMode_value = map[string]int32{
    "INIT_COMMAND":             0,
    "INIT_BOOTSTRAP_NODE_ZERO": 1,
    "INIT_NONE":                2,
}

func Consistent Uses

func Consistent(ctx context.Context, c Cluster, i int) error

Consistent performs a replication consistency check on all the ranges in the cluster. It depends on a majority of the nodes being up, and does the check against the node at index i.

func GenerateCerts Uses

func GenerateCerts(ctx context.Context) func()

GenerateCerts generates CA and client certificates and private keys to be used with a cluster. It returns a function that will clean up the generated files.

type Cluster Uses

type Cluster interface {
    // NumNodes returns the number of nodes in the cluster, running or not.
    NumNodes() int
    // NewDB returns a sql.DB client for the given node.
    NewDB(context.Context, int) (*gosql.DB, error)
    // PGUrl returns a URL string for the given node postgres server.
    PGUrl(context.Context, int) string
    // InternalIP returns the address used for inter-node communication.
    InternalIP(ctx context.Context, i int) net.IP
    // Assert verifies that the cluster state is as expected (i.e. no unexpected
    // restarts or node deaths occurred). Tests can call this periodically to
    // ascertain cluster health.
    Assert(context.Context, testing.TB)
    // AssertAndStop performs the same test as Assert but then proceeds to
    // dismantle the cluster.
    AssertAndStop(context.Context, testing.TB)
    // ExecCLI runs `./cockroach <args>`, while filling in required flags such as
    // --insecure, --certs-dir, --host.
    //
    // Returns stdout, stderr, and an error.
    ExecCLI(ctx context.Context, i int, args []string) (string, string, error)
    // Kill terminates the cockroach process running on the given node number.
    // The given integer must be in the range [0,NumNodes()-1].
    Kill(context.Context, int) error
    // Restart terminates the cockroach process running on the given node
    // number, unless it is already stopped, and restarts it.
    // The given integer must be in the range [0,NumNodes()-1].
    Restart(context.Context, int) error
    // URL returns the HTTP(s) endpoint.
    URL(context.Context, int) string
    // Addr returns the host and port from the node in the format HOST:PORT.
    Addr(ctx context.Context, i int, port string) string
    // Hostname returns a node's hostname.
    Hostname(i int) string
}

A Cluster is an abstraction away from a concrete cluster deployment (i.e. a local docker cluster, or an AWS-provisioned one). It exposes a shared set of methods for test-related manipulation.

type Container Uses

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

Container provides the programmatic interface for a single docker container.

func (*Container) Addr Uses

func (c *Container) Addr(ctx context.Context, port nat.Port) *net.TCPAddr

Addr returns the TCP address to connect to.

func (*Container) Inspect Uses

func (c *Container) Inspect(ctx context.Context) (types.ContainerJSON, error)

Inspect retrieves detailed info about a container.

func (*Container) Kill Uses

func (c *Container) Kill(ctx context.Context) error

Kill stops a running container, without removing it.

func (*Container) Logs Uses

func (c *Container) Logs(ctx context.Context, w io.Writer) error

Logs outputs the containers logs to the given io.Writer.

func (Container) Name Uses

func (c Container) Name() string

Name returns the container's name.

func (*Container) Remove Uses

func (c *Container) Remove(ctx context.Context) error

Remove removes the container from docker. It is an error to remove a running container.

func (*Container) Restart Uses

func (c *Container) Restart(ctx context.Context, timeout *time.Duration) error

Restart restarts a running container. Container will be killed after 'timeout' seconds if it fails to stop.

func (*Container) Start Uses

func (c *Container) Start(ctx context.Context) error

Start starts a non-running container.

TODO(pmattis): Generalize the setting of parameters here.

func (*Container) Wait Uses

func (c *Container) Wait(ctx context.Context, condition container.WaitCondition) error

Wait waits for a running container to exit.

type DockerCluster Uses

type DockerCluster struct {
    Nodes []*testNode
    // contains filtered or unexported fields
}

DockerCluster manages a local cockroach cluster running on docker. The cluster is composed of a "volumes" container which manages the persistent volumes used for certs and node data and N cockroach nodes.

func CreateDocker Uses

func CreateDocker(
    ctx context.Context, cfg TestConfig, volumesDir string, stopper *stop.Stopper,
) *DockerCluster

CreateDocker creates a Docker-based cockroach cluster. The stopper is used to gracefully shutdown the channel (e.g. when a signal arrives). The cluster must be started before being used and keeps container volumes in the specified volumesDir, including logs and cockroach stores. If volumesDir is empty, a temporary directory is created.

func (*DockerCluster) Addr Uses

func (l *DockerCluster) Addr(ctx context.Context, i int, port string) string

Addr returns the host and port from the node in the format HOST:PORT.

func (*DockerCluster) Assert Uses

func (l *DockerCluster) Assert(ctx context.Context, t testing.TB)

Assert drains the Events channel and compares the actual events with those expected to have been generated by the operations performed on the nodes in the cluster (restart, kill, ...). In the event of a mismatch, the passed Tester receives a fatal error.

func (*DockerCluster) AssertAndStop Uses

func (l *DockerCluster) AssertAndStop(ctx context.Context, t testing.TB)

AssertAndStop calls Assert and then stops the cluster. It is safe to stop the cluster multiple times.

func (*DockerCluster) Cleanup Uses

func (l *DockerCluster) Cleanup(ctx context.Context, preserveLogs bool)

Cleanup removes the cluster's volumes directory, optionally preserving the logs directory.

func (*DockerCluster) ExecCLI Uses

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

ExecCLI runs ./cockroach <args> with sane defaults.

func (*DockerCluster) Hostname Uses

func (l *DockerCluster) Hostname(i int) string

Hostname implements the Cluster interface.

func (*DockerCluster) InternalIP Uses

func (l *DockerCluster) InternalIP(ctx context.Context, i int) net.IP

InternalIP returns the IP address used for inter-node communication.

func (*DockerCluster) Kill Uses

func (l *DockerCluster) Kill(ctx context.Context, i int) error

Kill kills the i-th node.

func (*DockerCluster) NewDB Uses

func (l *DockerCluster) NewDB(ctx context.Context, i int) (*gosql.DB, error)

NewDB implements the Cluster interface.

func (*DockerCluster) NumNodes Uses

func (l *DockerCluster) NumNodes() int

NumNodes returns the number of nodes in the cluster.

func (*DockerCluster) OneShot Uses

func (l *DockerCluster) OneShot(
    ctx context.Context,
    ref string,
    ipo types.ImagePullOptions,
    containerConfig container.Config,
    hostConfig container.HostConfig,
    name string,
) error

OneShot runs a container, expecting it to successfully run to completion and die, after which it is removed. Not goroutine safe: only one OneShot can be running at once. Adds the same binds as the cluster containers (certs, binary, etc).

func (*DockerCluster) PGUrl Uses

func (l *DockerCluster) PGUrl(ctx context.Context, i int) string

PGUrl returns a URL string for the given node postgres server.

func (*DockerCluster) Restart Uses

func (l *DockerCluster) Restart(ctx context.Context, i int) error

Restart restarts the given node. If the node isn't running, this starts it.

func (*DockerCluster) RunInitCommand Uses

func (l *DockerCluster) RunInitCommand(ctx context.Context, nodeIdx int)

RunInitCommand runs the `cockroach init` command. Normally called automatically, but exposed for tests that use INIT_NONE. nodeIdx may designate any node in the cluster as the target of the command.

func (*DockerCluster) Start Uses

func (l *DockerCluster) Start(ctx context.Context)

Start starts the cluster.

func (*DockerCluster) URL Uses

func (l *DockerCluster) URL(ctx context.Context, i int) string

URL returns the base url.

type Event Uses

type Event struct {
    NodeIndex int
    Status    string
}

Event for a node containing a node index and the type of event.

type InitMode Uses

type InitMode int32

InitMode specifies different ways to initialize the cluster.

const (
    // INIT_COMMAND starts every node with a join flag and issues the
    // init command.
    INIT_COMMAND InitMode = 0
    // INIT_BOOTSTRAP_NODE_ZERO uses the legacy protocol of omitting the
    // join flag from node zero.
    INIT_BOOTSTRAP_NODE_ZERO InitMode = 1
    // INIT_NONE starts every node with a join flag and leaves the
    // cluster uninitialized.
    INIT_NONE InitMode = 2
)

func (InitMode) Enum Uses

func (x InitMode) Enum() *InitMode

func (InitMode) EnumDescriptor Uses

func (InitMode) EnumDescriptor() ([]byte, []int)

func (InitMode) String Uses

func (x InitMode) String() string

func (*InitMode) UnmarshalJSON Uses

func (x *InitMode) UnmarshalJSON(data []byte) error

type NodeConfig Uses

type NodeConfig struct {
    Version string        `protobuf:"bytes,1,opt,name=version" json:"version"`
    Stores  []StoreConfig `protobuf:"bytes,2,rep,name=stores" json:"stores"`
}

NodeConfig holds the configuration of a collection of similar nodes.

func (*NodeConfig) Descriptor Uses

func (*NodeConfig) Descriptor() ([]byte, []int)

func (*NodeConfig) Marshal Uses

func (m *NodeConfig) Marshal() (dAtA []byte, err error)

func (*NodeConfig) MarshalTo Uses

func (m *NodeConfig) MarshalTo(dAtA []byte) (int, error)

func (*NodeConfig) ProtoMessage Uses

func (*NodeConfig) ProtoMessage()

func (*NodeConfig) Reset Uses

func (m *NodeConfig) Reset()

func (*NodeConfig) Size Uses

func (m *NodeConfig) Size() (n int)

func (*NodeConfig) String Uses

func (m *NodeConfig) String() string

func (*NodeConfig) Unmarshal Uses

func (m *NodeConfig) Unmarshal(dAtA []byte) error

func (*NodeConfig) XXX_DiscardUnknown Uses

func (m *NodeConfig) XXX_DiscardUnknown()

func (*NodeConfig) XXX_Marshal Uses

func (m *NodeConfig) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*NodeConfig) XXX_Merge Uses

func (dst *NodeConfig) XXX_Merge(src proto.Message)

func (*NodeConfig) XXX_Size Uses

func (m *NodeConfig) XXX_Size() int

func (*NodeConfig) XXX_Unmarshal Uses

func (m *NodeConfig) XXX_Unmarshal(b []byte) error

type StoreConfig Uses

type StoreConfig struct {
    MaxRanges int32 `protobuf:"varint,2,opt,name=max_ranges,json=maxRanges" json:"max_ranges"`
}

StoreConfig holds the configuration of a collection of similar stores.

func (*StoreConfig) Descriptor Uses

func (*StoreConfig) Descriptor() ([]byte, []int)

func (*StoreConfig) Marshal Uses

func (m *StoreConfig) Marshal() (dAtA []byte, err error)

func (*StoreConfig) MarshalTo Uses

func (m *StoreConfig) MarshalTo(dAtA []byte) (int, error)

func (*StoreConfig) ProtoMessage Uses

func (*StoreConfig) ProtoMessage()

func (*StoreConfig) Reset Uses

func (m *StoreConfig) Reset()

func (*StoreConfig) Size Uses

func (m *StoreConfig) Size() (n int)

func (*StoreConfig) String Uses

func (m *StoreConfig) String() string

func (*StoreConfig) Unmarshal Uses

func (m *StoreConfig) Unmarshal(dAtA []byte) error

func (*StoreConfig) XXX_DiscardUnknown Uses

func (m *StoreConfig) XXX_DiscardUnknown()

func (*StoreConfig) XXX_Marshal Uses

func (m *StoreConfig) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*StoreConfig) XXX_Merge Uses

func (dst *StoreConfig) XXX_Merge(src proto.Message)

func (*StoreConfig) XXX_Size Uses

func (m *StoreConfig) XXX_Size() int

func (*StoreConfig) XXX_Unmarshal Uses

func (m *StoreConfig) XXX_Unmarshal(b []byte) error

type TestConfig Uses

type TestConfig struct {
    Name  string       `protobuf:"bytes,1,opt,name=name" json:"name"`
    Nodes []NodeConfig `protobuf:"bytes,2,rep,name=nodes" json:"nodes"`
    // Duration is the total time that the test should run for. Important for
    // tests such as TestPut that will run indefinitely.
    Duration time.Duration `protobuf:"varint,3,opt,name=duration,casttype=time.Duration" json:"duration"`
    InitMode InitMode      `protobuf:"varint,4,opt,name=init_mode,json=initMode,enum=cockroach.acceptance.cluster.InitMode" json:"init_mode"`
    // When set, the cluster is started as quickly as possible, without waiting
    // for ranges to replicate, or even ports to be opened.
    NoWait bool `protobuf:"varint,5,opt,name=no_wait,json=noWait" json:"no_wait"`
}

func (*TestConfig) Descriptor Uses

func (*TestConfig) Descriptor() ([]byte, []int)

func (*TestConfig) Marshal Uses

func (m *TestConfig) Marshal() (dAtA []byte, err error)

func (*TestConfig) MarshalTo Uses

func (m *TestConfig) MarshalTo(dAtA []byte) (int, error)

func (*TestConfig) ProtoMessage Uses

func (*TestConfig) ProtoMessage()

func (*TestConfig) Reset Uses

func (m *TestConfig) Reset()

func (*TestConfig) Size Uses

func (m *TestConfig) Size() (n int)

func (*TestConfig) String Uses

func (m *TestConfig) String() string

func (*TestConfig) Unmarshal Uses

func (m *TestConfig) Unmarshal(dAtA []byte) error

func (*TestConfig) XXX_DiscardUnknown Uses

func (m *TestConfig) XXX_DiscardUnknown()

func (*TestConfig) XXX_Marshal Uses

func (m *TestConfig) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*TestConfig) XXX_Merge Uses

func (dst *TestConfig) XXX_Merge(src proto.Message)

func (*TestConfig) XXX_Size Uses

func (m *TestConfig) XXX_Size() int

func (*TestConfig) XXX_Unmarshal Uses

func (m *TestConfig) XXX_Unmarshal(b []byte) error

Package cluster imports 48 packages (graph) and is imported by 6 packages. Updated 2019-08-10. Refresh now. Tools for package owners.