db

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package db provides utilities for working with databases.

Index

Constants

This section is empty.

Variables

View Source
var MinVersionForStats = semver.MustSemver("v25.1.0")

MinVersionForStats is the minimum version required for retrieving statistics.

View Source
var Public = Schema{
	Name: Ident("public"),
}

Public is the public schema.

Functions

func Version

func Version(ctx *stopper.Context, conn *pgxpool.Conn) (*semver.CockroachVersion, error)

Version retrieves the CockroachDB version from the connection.

Types

type Database

type Database struct {
	Name Ident
}

Database represents a database in the system.

func (*Database) Create

func (d *Database) Create(ctx *stopper.Context, conn *pgxpool.Conn) error

Create creates the database.

func (*Database) Drop

func (d *Database) Drop(ctx *stopper.Context, conn *pgxpool.Conn) error

Drop removes the database.

func (*Database) String

func (d *Database) String() string

String returns the string representation of the database.

type ExternalConn

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

ExternalConn represents an external connection to blob storage.

func NewExternalConn

func NewExternalConn(
	ctx *stopper.Context, conn *pgxpool.Conn, blob blob.Storage,
) (*ExternalConn, error)

NewExternalConn creates a new external connection.

func (*ExternalConn) BackupInfo

func (c *ExternalConn) BackupInfo(
	ctx *stopper.Context, conn *pgxpool.Conn, loc string, table KvTable,
) ([]TableBackup, error)

BackupInfo retrieves backup information for a specific table.

func (*ExternalConn) Drop

func (c *ExternalConn) Drop(ctx *stopper.Context, conn *pgxpool.Conn) error

Drop removes the external connection.

func (*ExternalConn) ListTableBackups

func (c *ExternalConn) ListTableBackups(
	ctx *stopper.Context, conn *pgxpool.Conn,
) ([]string, error)

ListTableBackups lists all table backups in the external connection.

func (*ExternalConn) Stats

func (c *ExternalConn) Stats(ctx *stopper.Context, conn *pgxpool.Conn) ([]*Stats, error)

Stats retrieves statistics for the external connection.

func (*ExternalConn) String

func (c *ExternalConn) String() string

String returns the string representation of the external connection.

func (*ExternalConn) SuggestedParams

func (c *ExternalConn) SuggestedParams() blob.Params

SuggestedParams returns the suggested parameters for the external connection.

type Ident

type Ident string

Ident is a unique identifier for a database object.

func (Ident) String

func (i Ident) String() string

type KvTable

type KvTable struct {
	Database
	Schema
	Name Ident
}

KvTable represents a key-value table in the database.

func (*KvTable) Backup

func (t *KvTable) Backup(
	ctx *stopper.Context, conn *pgxpool.Conn, dest *ExternalConn, incremental bool,
) error

Backup creates a backup of the table.

func (*KvTable) Create

func (t *KvTable) Create(ctx *stopper.Context, conn *pgxpool.Conn) error

Create creates the table.

func (*KvTable) Drop

func (t *KvTable) Drop(ctx *stopper.Context, conn *pgxpool.Conn) error

Drop removes the table.

func (*KvTable) Fingerprint

func (t *KvTable) Fingerprint(ctx *stopper.Context, conn *pgxpool.Conn) (string, error)

Fingerprint returns a fingerprint for the table.

func (*KvTable) LeaseholderCount added in v0.3.0

func (t *KvTable) LeaseholderCount(ctx *stopper.Context, conn *pgxpool.Conn) (int, error)

LeaseholderCount returns the number of distinct nodes currently holding leases for the table's ranges. Used to observe how SCATTER distributed the ranges before a backup.

func (*KvTable) LocalName

func (t *KvTable) LocalName() string

LocalName returns the local name of the table.

func (*KvTable) PendingJobs added in v0.2.1

func (t *KvTable) PendingJobs(ctx *stopper.Context, conn *pgxpool.Conn) ([]int64, error)

PendingJobs returns a list of job IDs that are still pending (not succeeded or failed).

func (*KvTable) PresplitAndScatter added in v0.3.0

func (t *KvTable) PresplitAndScatter(ctx *stopper.Context, conn *pgxpool.Conn, ranges int) error

PresplitAndScatter presplits the table into `ranges` ranges and scatters them across the cluster so that backup is more likely to exercise every node.

func (*KvTable) Restore

func (t *KvTable) Restore(
	ctx *stopper.Context, conn *pgxpool.Conn, from *ExternalConn, original *KvTable,
) error

Restore restores the table from a backup.

func (*KvTable) Scatter added in v0.3.0

func (t *KvTable) Scatter(ctx *stopper.Context, conn *pgxpool.Conn) error

Scatter distributes the table's ranges across the cluster nodes.

func (*KvTable) SeedRanges added in v0.3.0

func (t *KvTable) SeedRanges(ctx *stopper.Context, conn *pgxpool.Conn, ranges int) error

SeedRanges inserts one deterministic row per range so that scattered ranges have data to export during backup. Call after PresplitAndScatter.

func (*KvTable) Split added in v0.3.0

func (t *KvTable) Split(ctx *stopper.Context, conn *pgxpool.Conn, points []string) error

Split presplits the table at the given primary-key boundaries.

func (*KvTable) String

func (t *KvTable) String() string

String returns the string representation of the table.

func (*KvTable) Upsert

func (t *KvTable) Upsert(ctx *stopper.Context, conn *pgxpool.Conn, key, value string) error

Upsert adds a new row to the table.

type Schema

type Schema struct {
	Name Ident
}

Schema represents a database schema.

func (*Schema) String

func (s *Schema) String() string

String returns the string representation of the schema.

type Stats

type Stats struct {
	Node        int
	Locality    string
	ErrStr      string
	Transferred string
	ReadSpeed   string
	WriteSpeed  string
	Success     bool
	CanDelete   bool
}

Stats represents statistics about the external connection.

type TableBackup

type TableBackup struct {
	Table   KvTable
	Full    bool
	EndTime time.Time
}

TableBackup represents a backup of a table.

type TestEnv

type TestEnv struct {
	Database Database
	KvTable  KvTable
	Blob     blob.Storage
	Pool     *pgxpool.Pool
}

TestEnv encapsulates the resources needed for testing.

func NewTestEnv

func NewTestEnv(ctx *stopper.Context, numRows int) (TestEnv, error)

NewTestEnv creates a new test environment.

func (TestEnv) Cleanup

func (e TestEnv) Cleanup(ctx *stopper.Context) error

Cleanup removes the resources created for testing.

Jump to

Keyboard shortcuts

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