Back to godoc.org

Package utils

v0.0.0 (181c081)
Latest Go to latest
Published: 2 days ago | License: Apache-2.0 | Module: github.com/pingcap/br

Index

Package Files

Constants

const (
	// LockFile represents file name,
	LockFile = "backup.lock"
	// MetaFile represents file name
	MetaFile = "backupmeta"
	// MetaJSONFile represents backup meta json file name
	MetaJSONFile = "backupmeta.json"
	// SavedMetaFile represents saved meta file name for recovering later
	SavedMetaFile = "backupmeta.bak"
)
const (
	// B is number of bytes in one byte.
	B = uint64(1) << (iota * 10)
	// KB is number of bytes in one kibibyte.
	KB
	// MB is number of bytes in one mebibyte.
	MB
	// GB is number of bytes in one gibibyte.
	GB
	// TB is number of bytes in one tebibyte.
	TB
)

Variables

var (
	BRReleaseVersion = "None"
	BRBuildTS        = "None"
	BRGitHash        = "None"
	BRGitBranch      = "None"

	VersionHash = regexp.MustCompile("-[0-9]+-g[0-9a-f]{7,}")
)

Version information.

func ArchiveSize

func ArchiveSize(meta *backup.BackupMeta) uint64

ArchiveSize returns the total size of the backup archive.

func BRInfo

func BRInfo() string

BRInfo returns version information about BR.

func CheckClusterVersion

func CheckClusterVersion(ctx context.Context, client pd.Client) error

CheckClusterVersion check TiKV version.

func ClampInt

func ClampInt(n, min, max int) int

ClampInt restrict a value to a certain interval.

func CompareEndKey

func CompareEndKey(a, b []byte) int

CompareEndKey compared two keys that BOTH represent the EXCLUSIVE ending of some range. An empty end key is the very end, so an empty key is greater than any other keys. Please note that this function is not applicable if any one argument is not an EXCLUSIVE ending of a range.

func EncloseName

func EncloseName(name string) string

EncloseName formats name in sql.

func GetPlacementRules

func GetPlacementRules(pdAddr string, tlsConf *tls.Config) ([]placement.Rule, error)

GetPlacementRules return the current placement rules.

func LoadBackupTables

func LoadBackupTables(meta *backup.BackupMeta) (map[string]*Database, error)

LoadBackupTables loads schemas from BackupMeta.

func LogBRInfo

func LogBRInfo()

LogBRInfo logs version information about BR.

func MaxInt

func MaxInt(x int, xs ...int) int

MaxInt choice biggest integer from its arguments.

func MinInt

func MinInt(x int, xs ...int) int

MinInt choice smallest integer from its arguments.

func NeedAutoID

func NeedAutoID(tblInfo *model.TableInfo) bool

NeedAutoID checks whether the table needs backing up with an autoid.

func ParseKey

func ParseKey(format, key string) ([]byte, error)

ParseKey parse key by given format.

func ResetTS

func ResetTS(pdAddr string, ts uint64, tlsConf *tls.Config) error

ResetTS resets the timestamp of PD to a bigger value.

func SearchPlacementRule

func SearchPlacementRule(tableID int64, placementRules []placement.Rule, role placement.PeerRoleType) *placement.Rule

SearchPlacementRule returns the placement rule matched to the table or nil.

func StartDynamicPProfListener

func StartDynamicPProfListener()

StartDynamicPProfListener starts the listener that will enable pprof when received `startPProfSignal`.

func StartPProfListener

func StartPProfListener(statusAddr string)

StartPProfListener forks a new goroutine listening on specified port and provide pprof info.

func StartProgress

func StartProgress(
	ctx context.Context,
	name string,
	total int64,
	redirectLog bool,
) chan<- struct{}

StartProgress starts progress bar.

func WithRetry

func WithRetry(
	ctx context.Context,
	retryableFunc RetryableFunc,
	backoffer Backoffer,
) error

WithRetry retries a given operation with a backoff policy.

Returns nil if `retryableFunc` succeeded at least once. Otherwise, returns a multierr containing all errors encountered.

func WrapKey

func WrapKey(key []byte) fmt.Stringer

WrapKey wrap a key as a Stringer that can print proper upper hex format.

func WrapKeys

func WrapKeys(keys [][]byte) zapcore.ArrayMarshaler

WrapKeys wrap keys as an ArrayMarshaler that can print proper upper hex format.

func ZapFile

func ZapFile(file *backup.File) zapcore.Field

ZapFile make the zap fields for a file.

func ZapRegion

func ZapRegion(region *metapb.Region) zapcore.Field

ZapRegion make the zap fields for a region.

func ZapRewriteRule

func ZapRewriteRule(rewriteRule *import_sstpb.RewriteRule) zapcore.Field

ZapRewriteRule make the zap fields for a rewrite rule.

func ZapSSTMeta

func ZapSSTMeta(sstMeta *import_sstpb.SSTMeta) zapcore.Field

ZapSSTMeta make the zap fields for a SST meta.

type Backoffer

type Backoffer interface {
	// NextBackoff returns a duration to wait before retrying again
	NextBackoff(err error) time.Duration
	// Attempt returns the remain attempt times
	Attempt() int
}

Backoffer implements a backoff policy for retrying operations.

type Database

type Database struct {
	Info   *model.DBInfo
	Tables []*Table
}

Database wraps the schema and tables of a database.

func (*Database) GetTable

func (db *Database) GetTable(name string) *Table

GetTable returns a table of the database by name.

type ProgressPrinter

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

ProgressPrinter prints a progress bar.

func NewProgressPrinter

func NewProgressPrinter(
	name string,
	total int64,
	redirectLog bool,
) *ProgressPrinter

NewProgressPrinter returns a new progress printer.

func (*ProgressPrinter) UpdateCh

func (pp *ProgressPrinter) UpdateCh() chan<- struct{}

UpdateCh returns an update channel.

type RetryableFunc

type RetryableFunc func() error

RetryableFunc presents a retryable operation.

type Table

type Table struct {
	Db              *model.DBInfo
	Info            *model.TableInfo
	Crc64Xor        uint64
	TotalKvs        uint64
	TotalBytes      uint64
	Files           []*backup.File
	TiFlashReplicas int
}

Table wraps the schema and files of a table.

func (*Table) NoChecksum

func (tbl *Table) NoChecksum() bool

NoChecksum checks whether the table has a calculated checksum.

type UndoFunc

type UndoFunc func(context.Context) error

UndoFunc is a 'undo' operation of some undoable command. (e.g. RemoveSchedulers).

var Nop UndoFunc = func(context.Context) error { return nil }

Nop is the 'zero value' of undo func.

type Worker

type Worker struct {
	ID uint64
}

Worker identified by ID.

type WorkerPool

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

WorkerPool contains a pool of workers.

func NewWorkerPool

func NewWorkerPool(limit uint, name string) *WorkerPool

NewWorkerPool returns a WorkPool.

func (*WorkerPool) Apply

func (pool *WorkerPool) Apply(fn taskFunc)

Apply executes a task.

func (*WorkerPool) ApplyOnErrorGroup

func (pool *WorkerPool) ApplyOnErrorGroup(eg *errgroup.Group, fn func() error)

ApplyOnErrorGroup executes a task in an errorgroup.

func (*WorkerPool) ApplyWithID

func (pool *WorkerPool) ApplyWithID(fn identifiedTaskFunc)

ApplyWithID execute a task and provides it with the worker ID.

func (*WorkerPool) ApplyWithIDInErrorGroup

func (pool *WorkerPool) ApplyWithIDInErrorGroup(eg *errgroup.Group, fn func(id uint64) error)

ApplyWithIDInErrorGroup executes a task in an errorgroup and provides it with the worker ID.

func (*WorkerPool) HasWorker

func (pool *WorkerPool) HasWorker() bool

HasWorker checks if the pool has unallocated workers.

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier