cache

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

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

Go to latest
Published: Nov 11, 2024 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TaskStatusWaiting means the task hasn't started
	TaskStatusWaiting TaskStatus = "waiting"
	// TaskStatusRunning means this task is running
	TaskStatusRunning = "running"
	// TaskStatusFinished means this task has finished
	TaskStatusFinished = "finished"
)

Variables

This section is empty.

Functions

func EvalExpireTime

func EvalExpireTime(now time.Time, interval string, unit ast.TimeUnitType) (time.Time, error)

EvalExpireTime returns the expired time.

func GetASCIIPrefixDatumFromBytes

func GetASCIIPrefixDatumFromBytes(bs []byte) types.Datum

GetASCIIPrefixDatumFromBytes is used to convert bytes to string datum which only contains ASCII prefix string. The ASCII prefix string only contains visible characters and `\t`, `\n`, `\r`. "abc" -> "abc" "\0abc" -> "" "ab\x01c" -> "ab" "ab\xffc" -> "ab" "ab\rc\xff" -> "ab\rc"

func GetNextBytesHandleDatum

func GetNextBytesHandleDatum(key kv.Key, recordPrefix []byte) (d types.Datum)

GetNextBytesHandleDatum is used for a table with one binary or string column common handle. It returns the minValue whose encoded key is or after argument `key` If it cannot find a valid value, a null datum will be returned.

func GetNextIntDatumFromCommonHandle

func GetNextIntDatumFromCommonHandle(key kv.Key, recordPrefix []byte, unsigned bool) (d types.Datum)

GetNextIntDatumFromCommonHandle is used for common handle tables with int value. It returns the min handle whose encoded key is or after argument `key` If it cannot find a valid value, a null datum will be returned.

func GetNextIntHandle

func GetNextIntHandle(key kv.Key, recordPrefix []byte) kv.Handle

GetNextIntHandle is used for int handle tables. It returns the min handle whose encoded key is or after argument `key` If it cannot find a valid value, a null datum will be returned.

func InsertIntoTTLTask

func InsertIntoTTLTask(sctx sessionctx.Context, jobID string, tableID int64, scanID int, scanRangeStart []types.Datum,
	scanRangeEnd []types.Datum, expireTime time.Time, createdTime time.Time) (string, []any, error)

InsertIntoTTLTask returns an SQL statement to insert a ttl task into mysql.tidb_ttl_task

func PeekWaitingTTLTask

func PeekWaitingTTLTask(hbExpire time.Time) (string, []any)

PeekWaitingTTLTask returns an SQL statement to get `limit` waiting ttl task

func SelectFromTTLTableStatusWithID

func SelectFromTTLTableStatusWithID(tableID int64) (string, []any)

SelectFromTTLTableStatusWithID returns an SQL statement to get the table status from table id

func SelectFromTTLTaskWithID

func SelectFromTTLTaskWithID(jobID string, scanID int64) (string, []any)

SelectFromTTLTaskWithID returns an SQL statement to get all tasks of the specified job and scanID in mysql.tidb_ttl_task

func SelectFromTTLTaskWithJobID

func SelectFromTTLTaskWithJobID(jobID string) (string, []any)

SelectFromTTLTaskWithJobID returns an SQL statement to get all tasks of the specified job in mysql.tidb_ttl_task

func SetMockExpireTime

func SetMockExpireTime(ctx context.Context, tm time.Time) context.Context

SetMockExpireTime can only used in test

Types

type InfoSchemaCache

type InfoSchemaCache struct {
	Tables map[int64]*PhysicalTable
	// contains filtered or unexported fields
}

InfoSchemaCache is the cache for InfoSchema, it builds a map from physical table id to physical table information

func NewInfoSchemaCache

func NewInfoSchemaCache(updateInterval time.Duration) *InfoSchemaCache

NewInfoSchemaCache creates the cache for info schema

func (*InfoSchemaCache) GetInterval

func (bc *InfoSchemaCache) GetInterval() time.Duration

func (*InfoSchemaCache) SetInterval

func (bc *InfoSchemaCache) SetInterval(interval time.Duration)

SetInterval sets the interval of updating cache

func (*InfoSchemaCache) ShouldUpdate

func (bc *InfoSchemaCache) ShouldUpdate() bool

ShouldUpdate returns whether this cache needs update

func (*InfoSchemaCache) Update

func (isc *InfoSchemaCache) Update(se session.Session) error

Update updates the info schema cache

type JobStatus

type JobStatus string

JobStatus represents the current status of a job

const (
	// JobStatusWaiting means the job hasn't started
	JobStatusWaiting JobStatus = "waiting"
	// JobStatusRunning means this job is running
	JobStatusRunning JobStatus = "running"
	// JobStatusCancelling means this job is being canceled, but not canceled yet
	JobStatusCancelling JobStatus = "cancelling"
	// JobStatusCancelled means this job has been canceled successfully
	JobStatusCancelled JobStatus = "cancelled"
	// JobStatusTimeout means this job has timeout
	JobStatusTimeout JobStatus = "timeout"
	// JobStatusFinished means job has been finished
	JobStatusFinished JobStatus = "finished"
)

type PhysicalTable

type PhysicalTable struct {
	// ID is the physical ID of the table
	ID int64
	// Schema is the database name of the table
	Schema pmodel.CIStr
	*model.TableInfo
	// Partition is the partition name
	Partition pmodel.CIStr
	// PartitionDef is the partition definition
	PartitionDef *model.PartitionDefinition
	// KeyColumns is the cluster index key columns for the table
	KeyColumns []*model.ColumnInfo
	// KeyColumnTypes is the types of the key columns
	KeyColumnTypes []*types.FieldType
	// TimeColum is the time column used for TTL
	TimeColumn *model.ColumnInfo
}

PhysicalTable is used to provide some information for a physical table in TTL job

func NewBasePhysicalTable

func NewBasePhysicalTable(schema pmodel.CIStr,
	tbl *model.TableInfo,
	partition pmodel.CIStr,
	timeColumn *model.ColumnInfo,
) (*PhysicalTable, error)

NewBasePhysicalTable create a new PhysicalTable with specific timeColumn.

func NewPhysicalTable

func NewPhysicalTable(schema pmodel.CIStr, tbl *model.TableInfo, partition pmodel.CIStr) (*PhysicalTable, error)

NewPhysicalTable create a new PhysicalTable

func (*PhysicalTable) EvalExpireTime

func (t *PhysicalTable) EvalExpireTime(ctx context.Context, se session.Session,
	now time.Time) (time.Time, error)

EvalExpireTime returns the expired time for the current time. It uses the global timezone in session to evaluation the context and the return time is in the same timezone of now argument.

func (*PhysicalTable) SplitScanRanges

func (t *PhysicalTable) SplitScanRanges(ctx context.Context, store kv.Storage, splitCnt int) ([]ScanRange, error)

SplitScanRanges split ranges for TTL scan

func (*PhysicalTable) ValidateKeyPrefix

func (t *PhysicalTable) ValidateKeyPrefix(key []types.Datum) error

ValidateKeyPrefix validates a key prefix

type ScanRange

type ScanRange struct {
	Start []types.Datum
	End   []types.Datum
}

ScanRange is the range to scan. The range is: [Start, End)

type TTLTask

type TTLTask struct {
	JobID            string
	TableID          int64
	ScanID           int64
	ScanRangeStart   []types.Datum
	ScanRangeEnd     []types.Datum
	ExpireTime       time.Time
	OwnerID          string
	OwnerAddr        string
	OwnerHBTime      time.Time
	Status           TaskStatus
	StatusUpdateTime time.Time
	State            *TTLTaskState
	CreatedTime      time.Time
}

TTLTask is a row recorded in mysql.tidb_ttl_task

func RowToTTLTask

func RowToTTLTask(sctx sessionctx.Context, row chunk.Row) (*TTLTask, error)

RowToTTLTask converts a row into TTL task

type TTLTaskState

type TTLTaskState struct {
	TotalRows   uint64 `json:"total_rows"`
	SuccessRows uint64 `json:"success_rows"`
	ErrorRows   uint64 `json:"error_rows"`

	ScanTaskErr string `json:"scan_task_err"`
}

TTLTaskState records the internal states of the ttl task

type TableStatus

type TableStatus struct {
	TableID       int64
	ParentTableID int64

	TableStatistics string

	LastJobID         string
	LastJobStartTime  time.Time
	LastJobFinishTime time.Time
	LastJobTTLExpire  time.Time
	LastJobSummary    string

	CurrentJobID          string
	CurrentJobOwnerID     string
	CurrentJobOwnerAddr   string
	CurrentJobOwnerHBTime time.Time
	CurrentJobStartTime   time.Time
	CurrentJobTTLExpire   time.Time

	CurrentJobState            string
	CurrentJobStatus           JobStatus
	CurrentJobStatusUpdateTime time.Time
}

TableStatus contains the corresponding information in the system table `mysql.tidb_ttl_table_status`

func RowToTableStatus

func RowToTableStatus(sctx sessionctx.Context, row chunk.Row) (*TableStatus, error)

RowToTableStatus converts a row to table status

type TableStatusCache

type TableStatusCache struct {
	Tables map[int64]*TableStatus
	// contains filtered or unexported fields
}

TableStatusCache is the cache for ttl table status, it builds a map from physical table id to the table status

func NewTableStatusCache

func NewTableStatusCache(updateInterval time.Duration) *TableStatusCache

NewTableStatusCache creates cache for ttl table status

func (*TableStatusCache) GetInterval

func (bc *TableStatusCache) GetInterval() time.Duration

func (*TableStatusCache) SetInterval

func (bc *TableStatusCache) SetInterval(interval time.Duration)

SetInterval sets the interval of updating cache

func (*TableStatusCache) ShouldUpdate

func (bc *TableStatusCache) ShouldUpdate() bool

ShouldUpdate returns whether this cache needs update

func (*TableStatusCache) Update

func (tsc *TableStatusCache) Update(ctx context.Context, se session.Session) error

Update updates the table status cache

type TaskStatus

type TaskStatus string

TaskStatus represents the current status of a task

Jump to

Keyboard shortcuts

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