util

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: Apache-2.0 Imports: 47 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DescribeSnapMaxReturnResult can be between 5 and 1,000; if MaxResults is given a value larger than 1,000, only 1,000 results are returned.
	DescribeSnapMaxReturnResult = 1000
	// ListSnapMaxReturnResult can be between 100 and 10,000, and charge ~0.6$/1 million request
	ListSnapMaxReturnResult = 10000
	// EbsApiConcurrency can be between 1 and 50 due to aws service quota
	EbsApiConcurrency = 40

	CalculateFullSize    = "full"
	CalculateIncremental = "incremental"
	CalculateAll         = "all"
)

Variables

View Source
var (

	// DefaultVersion is the default tikv and br version
	DefaultVersion = "4.0"
)

Functions

func CalcVolSnapBackupSize added in v1.4.4

func CalcVolSnapBackupSize(ctx context.Context, provider v1alpha1.StorageProvider, level string) (fullBackupSize int64, incrementalBackupSize int64, err error)

CalcVolSnapBackupSize get snapshots from backup meta and then calc the backup size of snapshots.

func ConstructBRGlobalOptionsForBackup

func ConstructBRGlobalOptionsForBackup(backup *v1alpha1.Backup) ([]string, error)

ConstructBRGlobalOptionsForBackup constructs BR global options for backup and also return the remote path.

func ConstructBRGlobalOptionsForRestore

func ConstructBRGlobalOptionsForRestore(restore *v1alpha1.Restore) ([]string, error)

ConstructBRGlobalOptionsForRestore constructs BR global options for restore.

func ConstructDumplingOptionsForBackup added in v1.1.3

func ConstructDumplingOptionsForBackup(backup *v1alpha1.Backup) []string

ConstructDumplingOptionsForBackup constructs dumpling options for backup

func ConstructRcloneArgs added in v1.1.8

func ConstructRcloneArgs(conf string, opts []string, command, source, dest string, verboseLog bool) []string

ConstructRcloneArgs constructs the rclone args

func EnsureDirectoryExist

func EnsureDirectoryExist(dirName string) error

EnsureDirectoryExist create directory if does not exist

func GetBRArchiveSize added in v1.1.7

func GetBRArchiveSize(meta *kvbackup.BackupMeta) uint64

GetBRArchiveSize returns the total size of the backup archive.

func GetBRMetaData added in v1.1.7

func GetBRMetaData(ctx context.Context, provider v1alpha1.StorageProvider) (*kvbackup.BackupMeta, error)

GetBRMetaData get backup metadata from cloud storage

func GetCommitTsFromBRMetaData added in v1.1.3

func GetCommitTsFromBRMetaData(ctx context.Context, provider v1alpha1.StorageProvider) (uint64, error)

GetCommitTsFromBRMetaData get backup position from `EndVersion` in BR backup meta

func GetCommitTsFromMetadata added in v1.1.3

func GetCommitTsFromMetadata(backupPath string) (string, error)

GetCommitTsFromMetadata get commitTs from mydumper's metadata file

metadata file format is as follows:

Started dump at: 2019-06-13 10:00:04
SHOW MASTER STATUS:
	Log: tidb-binlog
	Pos: 409054741514944513
	GTID:

Finished dump at: 2019-06-13 10:00:04

func GetContextForTerminationSignals added in v1.1.10

func GetContextForTerminationSignals(op string) (context.Context, context.CancelFunc)

GetContextForTerminationSignals get a context for some termination signals, and the context will become done after any of these signals triggered.

func GetOptionValueFromEnv

func GetOptionValueFromEnv(option, envPrefix string) string

GetOptionValueFromEnv get option's value from environment variable. If unset, return empty string.

func GetOptions

func GetOptions(provider v1alpha1.StorageProvider) []string

GetOptions gets the rclone options

func GetSliceExcludeOneString added in v1.4.0

func GetSliceExcludeOneString(strs []string, str string) []string

GetSliceExcludeString get a slice of strings that excludes the specified substring

func GetStoragePath added in v1.1.8

func GetStoragePath(backup *v1alpha1.Backup) (string, error)

GetStoragePath generate the path of a specific storage

func GracefullyShutDownSubProcess added in v1.5.1

func GracefullyShutDownSubProcess(ctx context.Context, cmd *exec.Cmd)

GracefullyShutDownSubProcess just send SIGTERM to the process of cmd when context done the caller should wait the process of cmd to shut down

func IsDirExist

func IsDirExist(path string) bool

IsDirExist return true if path exist and is a dir, other cases return false

func IsE2EExtendBackupTime added in v1.4.4

func IsE2EExtendBackupTime() bool

func IsE2EExtendBackupTimeAndPanic added in v1.4.4

func IsE2EExtendBackupTimeAndPanic() bool

func IsFileExist

func IsFileExist(file string) bool

IsFileExist return true if file exist and is a regular file, other cases return false

func NewCRCli

func NewCRCli(kubeconfig string) (versioned.Interface, error)

NewCRCli create a CR cli Interface

func NewEventRecorder

func NewEventRecorder(kubeCli kubernetes.Interface, source string) record.EventRecorder

NewEventRecorder return the specify source's recoder

func NewKubeAndCRCli

func NewKubeAndCRCli(kubeconfig string) (kubernetes.Interface, versioned.Interface, error)

NewKubeAndCRCli create both kube cli and CR cli

func NewKubeCli

func NewKubeCli(kubeconfig string) (kubernetes.Interface, error)

NewKubeCli create a kubeCli Interface

func NormalizeBucketURI

func NormalizeBucketURI(bucket string) string

NormalizeBucketURI normal bucket URL for rclone, e.g. s3://bucket -> s3:bucket

func ParseRestoreProgress added in v1.4.0

func ParseRestoreProgress(line string) (step, progress string)

ParseRestoreProgress parse restore progress and return restore step and progress

func ReadAllStdErrToChannel added in v1.5.1

func ReadAllStdErrToChannel(stdErr io.Reader, errMsgCh chan []byte)

ReadAllStdErrToChannel read the stdErr and send the output to channel

func RetriableOnAnyError added in v1.3.7

func RetriableOnAnyError(err error) bool

func RetryOnError added in v1.3.7

func RetryOnError(ctx context.Context, attempts int, sleep time.Duration,
	retriable func(error) bool, fn func() error) error

RetryOnError allows the caller to retry fn in case the error returned by fn. sleep define the interval between two retries.

func Suffix

func Suffix(version string) string

Suffix parses the major and minor version from the string and return the suffix

func ValidCmdFlags

func ValidCmdFlags(cmdPath string, flagSet *pflag.FlagSet)

ValidCmdFlags verify that all flags are set

Types

type GenericOptions

type GenericOptions struct {
	Namespace string
	// ResourceName can be the name of a backup or restore resource
	ResourceName   string
	TLSClient      bool
	TLSCluster     bool
	SkipClientCA   bool
	Host           string
	Port           int32
	Password       string
	User           string
	TiKVVersion    string
	Mode           string
	SubCommand     string
	CommitTS       string
	TruncateUntil  string
	PitrRestoredTs string
	Initialize     bool
}

GenericOptions contains the generic input arguments to the backup/restore command

func (*GenericOptions) GetDSN

func (bo *GenericOptions) GetDSN(enabledTLSClient bool) (string, error)

func (*GenericOptions) GetTikvGCLifeTime

func (bo *GenericOptions) GetTikvGCLifeTime(ctx context.Context, db *sql.DB) (string, error)

func (*GenericOptions) SetTikvGCLifeTime

func (bo *GenericOptions) SetTikvGCLifeTime(ctx context.Context, db *sql.DB, gcTime string) error

func (*GenericOptions) String

func (bo *GenericOptions) String() string

Jump to

Keyboard shortcuts

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