util

package
v0.0.0-...-3633c1a Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2021 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DDLAllSchemaVersions is the path on etcd that is used to store all servers current schema versions.
	// It's exported for testing.
	DDLAllSchemaVersions = "/tidb/ddl/all_schema_versions"
	// DDLGlobalSchemaVersion is the path on etcd that is used to store the latest schema versions.
	// It's exported for testing.
	DDLGlobalSchemaVersion = "/tidb/ddl/global_schema_version"
	// InitialVersion is the initial schema version for every server.
	// It's exported for testing.
	InitialVersion = "0"
)

Variables

View Source
var (
	// CheckVersFirstWaitTime is a waitting time before the owner checks all the servers of the schema version,
	// and it's an exported variable for testing.
	CheckVersFirstWaitTime = 50 * time.Millisecond
	// SyncerSessionTTL is the etcd session's TTL in seconds.
	// and it's an exported variable for testing.
	SyncerSessionTTL = 90
)
View Source
var NeededCleanTTL = int64(-60)

NeededCleanTTL is exported for testing.

Functions

func CompleteDeleteRange

func CompleteDeleteRange(ctx sessionctx.Context, dr DelRangeTask) error

CompleteDeleteRange moves a record from gc_delete_range table to gc_delete_range_done table. NOTE: This function WILL NOT start and run in a new transaction internally.

func DeleteDoneRecord

func DeleteDoneRecord(ctx 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 LoadDDLReorgVars

func LoadDDLReorgVars(ctx 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 LoadGlobalVars

func LoadGlobalVars(ctx sessionctx.Context, varNames []string) error

LoadGlobalVars loads global 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 is configures of etcd Operations.

func RemoveFromGCDeleteRange

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

RemoveFromGCDeleteRange is exported for ddl pkg to use.

func UpdateDeleteRange

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

UpdateDeleteRange is only for emulator.

Types

type DelRangeTask

type DelRangeTask struct {
	JobID, ElementID int64
	StartKey, EndKey []byte
}

DelRangeTask is for run delete-range command in gc_worker.

func LoadDeleteRanges

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

LoadDeleteRanges loads delete range tasks from gc_delete_range table.

func LoadDoneDeleteRanges

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

LoadDoneDeleteRanges loads deleted ranges from gc_delete_range_done table.

func (DelRangeTask) Range

func (t DelRangeTask) Range() ([]byte, []byte)

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

type Event

type Event struct {
	Tp         model.ActionType
	TableInfo  *model.TableInfo
	ColumnInfo *model.ColumnInfo
	IndexInfo  *model.IndexInfo
}

Event is an event that a ddl operation happened.

func (*Event) String

func (e *Event) String() string

String implements fmt.Stringer interface.

type SchemaSyncer

type SchemaSyncer interface {
	// Init sets the global schema version path to etcd if it isn't exist,
	// then watch this path, and initializes the self schema version to etcd.
	Init(ctx context.Context) error
	// UpdateSelfVersion updates the current version to the self path on etcd.
	UpdateSelfVersion(ctx context.Context, version int64) error
	// RemoveSelfVersionPath remove the self path from etcd.
	RemoveSelfVersionPath() error
	// OwnerUpdateGlobalVersion updates the latest version to the global path on etcd until updating is successful or the ctx is done.
	OwnerUpdateGlobalVersion(ctx context.Context, version int64) error
	// GlobalVersionCh gets the chan for watching global version.
	GlobalVersionCh() clientv3.WatchChan
	// WatchGlobalSchemaVer watches the global schema version.
	WatchGlobalSchemaVer(ctx context.Context)
	// MustGetGlobalVersion gets the global version. The only reason it fails is that ctx is done.
	MustGetGlobalVersion(ctx context.Context) (int64, error)
	// Done returns a channel that closes when the syncer is no longer being refreshed.
	Done() <-chan struct{}
	// Restart restarts the syncer when it's on longer being refreshed.
	Restart(ctx context.Context) error
	// OwnerCheckAllVersions checks whether all followers' schema version are equal to
	// the latest schema version. If the result is false, wait for a while and check again util the processing time reach 2 * lease.
	// It returns until all servers' versions are equal to the latest version or the ctx is done.
	OwnerCheckAllVersions(ctx context.Context, latestVer int64) error
	// NotifyCleanExpiredPaths informs to clean up expired paths.
	// The returned value is used for testing.
	NotifyCleanExpiredPaths() bool
	// StartCleanWork starts to clean up tasks.
	StartCleanWork()
	// CloseCleanWork ends cleanup tasks.
	CloseCleanWork()
}

SchemaSyncer is used to synchronize schema version between the DDL worker leader and followers through etcd.

func NewSchemaSyncer

func NewSchemaSyncer(etcdCli *clientv3.Client, id string, oc ownerChecker) SchemaSyncer

NewSchemaSyncer creates a new SchemaSyncer.

Jump to

Keyboard shortcuts

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