cache

package
v0.0.0-...-503c688 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2023 License: Apache-2.0 Imports: 24 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 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 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, []interface{}, error)

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

func PeekWaitingTTLTask

func PeekWaitingTTLTask(hbExpire time.Time) (string, []interface{})

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

func SelectFromTTLTableStatusWithID

func SelectFromTTLTableStatusWithID(tableID int64) (string, []interface{})

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

func SelectFromTTLTaskWithID

func SelectFromTTLTaskWithID(jobID string, scanID int64) (string, []interface{})

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, []interface{})

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

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 model.CIStr
	*model.TableInfo
	// Partition is the partition name
	Partition model.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 NewPhysicalTable

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

NewPhysicalTable create a new PhysicalTable

func (*PhysicalTable) EvalExpireTime

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

EvalExpireTime returns the expired time

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