util

package
v1.1.0-beta.0...-d13e52e Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// KeyOpDefaultTimeout is the default timeout for each key operation.
	KeyOpDefaultTimeout = 2 * time.Second
	// KeyOpRetryInterval is the interval between two key operations.
	KeyOpRetryInterval = 30 * time.Millisecond
	// DDLAllSchemaVersions is the path on etcd that is used to store all servers current schema versions.
	DDLAllSchemaVersions = "/tidb/ddl/all_schema_versions"
	// DDLAllSchemaVersionsByJob is the path on etcd that is used to store all servers current schema versions.
	// /tidb/ddl/all_schema_by_job_versions/<job-id>/<tidb-id> ---> <schema-version>
	DDLAllSchemaVersionsByJob = "/tidb/ddl/all_schema_by_job_versions"
	// DDLGlobalSchemaVersion is the path on etcd that is used to store the latest schema versions.
	DDLGlobalSchemaVersion = "/tidb/ddl/global_schema_version"
	// ServerGlobalState is the path on etcd that is used to store the server global state.
	ServerGlobalState = "/tidb/server/global_state"
	// SessionTTL is the etcd session's TTL in seconds.
	SessionTTL = 90
)

Variables

View Source
var MockGlobalStateEntry = &MockGlobalState{
	currentOwner: make(map[ownerKey]string),
}

MockGlobalStateEntry is a mock global state entry.

Functions

func CompleteDeleteRange

func CompleteDeleteRange(sctx sessionctx.Context, dr DelRangeTask, needToRecordDone bool) error

CompleteDeleteRange moves a record from gc_delete_range table to gc_delete_range_done table.

func DeleteDoneRecord

func DeleteDoneRecord(sctx sessionctx.Context, dr DelRangeTask) error

DeleteDoneRecord removes a record from gc_delete_range_done table.

func DeleteKeyFromEtcd

func DeleteKeyFromEtcd(key string, etcdCli *clientv3.Client, retryCnt int, timeout time.Duration) error

DeleteKeyFromEtcd deletes key value from etcd.

func EmulatorGCDisable

func EmulatorGCDisable()

EmulatorGCDisable disables emulator gc. It exports for testing.

func EmulatorGCEnable

func EmulatorGCEnable()

EmulatorGCEnable enables emulator gc. It exports for testing.

func FolderNotEmpty

func FolderNotEmpty(path string) bool

FolderNotEmpty returns true only when the folder is not empty.

func GenKeyExistsErr

func GenKeyExistsErr(key, value []byte, idxInfo *model.IndexInfo, tblInfo *model.TableInfo) error

GenKeyExistsErr builds a ErrKeyExists error.

func GetInternalResourceGroupTaggerForTopSQL

func GetInternalResourceGroupTaggerForTopSQL() tikvrpc.ResourceGroupTagger

GetInternalResourceGroupTaggerForTopSQL only use for testing.

func GetTimeZone

func GetTimeZone(sctx sessionctx.Context) (string, int)

GetTimeZone gets the session location's zone name and offset.

func IsEmulatorGCEnable

func IsEmulatorGCEnable() bool

IsEmulatorGCEnable indicates whether emulator GC enabled. It exports for testing.

func IsInternalResourceGroupTaggerForTopSQL

func IsInternalResourceGroupTaggerForTopSQL(tag []byte) bool

IsInternalResourceGroupTaggerForTopSQL use for testing.

func IsRaftKv2

func IsRaftKv2(ctx context.Context, sctx sessionctx.Context) (bool, error)

IsRaftKv2 checks whether the raft-kv2 is enabled

func LoadDDLReorgVars

func LoadDDLReorgVars(ctx context.Context, sctx sessionctx.Context) error

LoadDDLReorgVars loads ddl reorg variable from mysql.global_variables.

func LoadDDLVars

func LoadDDLVars(ctx sessionctx.Context) error

LoadDDLVars loads ddl variable from mysql.global_variables.

func PutKVToEtcd

func PutKVToEtcd(ctx context.Context, etcdCli *clientv3.Client, retryCnt int, key, val string,
	opts ...clientv3.OpOption) error

PutKVToEtcd puts key value to etcd. etcdCli is client of etcd. retryCnt is retry time when an error occurs. opts are configures of etcd Operations.

func PutKVToEtcdMono

func PutKVToEtcdMono(ctx context.Context, etcdCli *clientv3.Client, retryCnt int, key, val string,
	opts ...clientv3.OpOption) error

PutKVToEtcdMono puts key value to etcd monotonously. etcdCli is client of etcd. retryCnt is retry time when an error occurs. opts are configures of etcd Operations.

func RemoveFromGCDeleteRange

func RemoveFromGCDeleteRange(sctx sessionctx.Context, jobID, elementID int64) error

RemoveFromGCDeleteRange is exported for ddl pkg to use.

func RemoveMultiFromGCDeleteRange

func RemoveMultiFromGCDeleteRange(ctx context.Context, sctx sessionctx.Context, jobID int64) error

RemoveMultiFromGCDeleteRange is exported for ddl pkg to use.

func UpdateDeleteRange

func UpdateDeleteRange(sctx sessionctx.Context, dr DelRangeTask, newStartKey, oldStartKey kv.Key) error

UpdateDeleteRange is only for emulator.

func WrapKey2String

func WrapKey2String(key []byte) string

WrapKey2String wraps the key to a string.

Types

type DeadTableLockChecker

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

DeadTableLockChecker uses to check dead table locks. If tidb-server panic or killed by others, the table locks hold by the killed tidb-server maybe doesn't released.

func NewDeadTableLockChecker

func NewDeadTableLockChecker(etcdCli *clientv3.Client) DeadTableLockChecker

NewDeadTableLockChecker creates new DeadLockChecker.

func (*DeadTableLockChecker) GetDeadLockedTables

GetDeadLockedTables gets dead locked tables.

type DelRangeTask

type DelRangeTask struct {
	StartKey  kv.Key
	EndKey    kv.Key
	JobID     int64
	ElementID int64
}

DelRangeTask is for run delete-range command in gc_worker.

func LoadDeleteRanges

func LoadDeleteRanges(ctx context.Context, sctx sessionctx.Context, safePoint uint64) (ranges []DelRangeTask, _ error)

LoadDeleteRanges loads delete range tasks from gc_delete_range table.

func LoadDoneDeleteRanges

func LoadDoneDeleteRanges(ctx context.Context, sctx sessionctx.Context, safePoint uint64) (ranges []DelRangeTask, _ error)

LoadDoneDeleteRanges loads deleted ranges from gc_delete_range_done table.

func (DelRangeTask) Range

func (t DelRangeTask) Range() (kv.Key, kv.Key)

Range returns the range [start, end) to delete.

type MockGlobalState

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

MockGlobalState is a mock global state.

func (*MockGlobalState) OwnerKey

func (m *MockGlobalState) OwnerKey(storeID, tp string) *MockGlobalStateSelector

OwnerKey returns a mock global state selector with corresponding owner key.

type MockGlobalStateSelector

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

MockGlobalStateSelector is used to get info from global state.

func (*MockGlobalStateSelector) GetOwner

func (t *MockGlobalStateSelector) GetOwner() string

GetOwner returns the owner.

func (*MockGlobalStateSelector) IsOwner

func (t *MockGlobalStateSelector) IsOwner(owner string) bool

IsOwner returns whether it is the owner.

func (*MockGlobalStateSelector) SetOwner

func (t *MockGlobalStateSelector) SetOwner(owner string) bool

SetOwner sets the owner if the owner is empty.

func (*MockGlobalStateSelector) UnsetOwner

func (t *MockGlobalStateSelector) UnsetOwner(owner string) bool

UnsetOwner unsets the owner.

type Watcher

type Watcher interface {
	// WatchChan returns the chan for watching etcd path.
	WatchChan() clientv3.WatchChan
	// Watch watches the etcd path.
	Watch(ctx context.Context, etcdCli *clientv3.Client, path string)
	// Rewatch rewatches the etcd path.
	Rewatch(ctx context.Context, etcdCli *clientv3.Client, path string)
}

Watcher is responsible for watching the etcd path related operations.

func NewWatcher

func NewWatcher() Watcher

NewWatcher creates a new watcher.

Jump to

Keyboard shortcuts

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