utils

package
v1.1.0-beta.0...-68ac9ec Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	WriteCFName   = "write"
	DefaultCFName = "default"
)

Variables

This section is empty.

Functions

func EmptyRewriteRulesMap

func EmptyRewriteRulesMap() map[int64]*RewriteRules

EmptyRewriteRule make a map of new, empty rewrite rules.

func EncodeKeyPrefix

func EncodeKeyPrefix(key []byte) []byte

func FindMatchedRewriteRule

func FindMatchedRewriteRule(file AppliedFile, rules *RewriteRules) *import_sstpb.RewriteRule

func GetIndexIDMap

func GetIndexIDMap(newTable, oldTable *model.TableInfo) map[int64]int64

GetIndexIDMap creates a map maping old indexID to new indexID.

func GetPartitionIDMap

func GetPartitionIDMap(newTable, oldTable *model.TableInfo) map[int64]int64

GetPartitionIDMap creates a map maping old physical ID to new physical ID.

func GetRewriteEncodedKeys

func GetRewriteEncodedKeys(file AppliedFile, rewriteRules *RewriteRules) (startKey, endKey []byte, err error)

GetRewriteRawKeys rewrites rules to the encoded key

func GetRewriteRawKeys

func GetRewriteRawKeys(file AppliedFile, rewriteRules *RewriteRules) (startKey, endKey []byte, err error)

GetRewriteRawKeys rewrites rules to the raw key.

func GetRewriteRulesMap

func GetRewriteRulesMap(
	newTable, oldTable *model.TableInfo, newTimeStamp uint64, getDetailRule bool,
) map[int64]*RewriteRules

func GetRewriteTableID

func GetRewriteTableID(tableID int64, rewriteRules *RewriteRules) int64

GetRewriteTableID gets rewrite table id by the rewrite rule and original table id

func GetTableIDMap

func GetTableIDMap(newTable, oldTable *model.TableInfo) map[int64]int64

GetTableIDMap creates a map maping old tableID to new tableID.

func RewriteAndEncodeRawKey

func RewriteAndEncodeRawKey(key []byte, rule *import_sstpb.RewriteRule) []byte

func RewriteRange

func RewriteRange(rg *rtree.Range, rewriteRules *RewriteRules) (*rtree.Range, error)

func TruncateTS

func TruncateTS(key []byte) []byte

func ValidateFileRewriteRule

func ValidateFileRewriteRule(file *backuppb.File, rewriteRules *RewriteRules) error

ValidateFileRewriteRule uses rewrite rules to validate the ranges of a file.

Types

type AppliedFile

type AppliedFile interface {
	GetStartKey() []byte
	GetEndKey() []byte
}

AppliedFile has two types for now. 1. SST file used by full backup/restore. 2. KV file used by pitr restore.

type MergeRangesStat

type MergeRangesStat struct {
	TotalFiles           int
	TotalWriteCFFile     int
	TotalDefaultCFFile   int
	TotalRegions         int
	RegionKeysAvg        int
	RegionBytesAvg       int
	MergedRegions        int
	MergedRegionKeysAvg  int
	MergedRegionBytesAvg int
}

MergeRangesStat holds statistics for the MergeRanges.

func MergeAndRewriteFileRanges

func MergeAndRewriteFileRanges(
	files []*backuppb.File,
	rewriteRules *RewriteRules,
	splitSizeBytes,
	splitKeyCount uint64,
) ([]rtree.RangeStats, *MergeRangesStat, error)

MergeAndRewriteFileRanges returns ranges of the files are merged based on splitSizeBytes and splitKeyCount.

By merging small ranges, it speeds up restoring a backup that contains many small ranges (regions) as it reduces split region and scatter region.

type RewriteRules

type RewriteRules struct {
	Data        []*import_sstpb.RewriteRule
	OldKeyspace []byte
	NewKeyspace []byte
	// used to record checkpoint data
	NewTableID int64
}

RewriteRules contains rules for rewriting keys of tables.

func EmptyRewriteRule

func EmptyRewriteRule() *RewriteRules

EmptyRewriteRule make a new, empty rewrite rule.

func GetRewriteRuleOfTable

func GetRewriteRuleOfTable(
	oldTableID, newTableID int64,
	newTimeStamp uint64,
	indexIDs map[int64]int64,
	getDetailRule bool,
) *RewriteRules

GetRewriteRuleOfTable returns a rewrite rule from t_{oldID} to t_{newID}.

func GetRewriteRules

func GetRewriteRules(
	newTable, oldTable *model.TableInfo, newTimeStamp uint64, getDetailRule bool,
) *RewriteRules

GetRewriteRules returns the rewrite rule of the new table and the old table. getDetailRule is used for normal backup & restore. if set to true, means we collect the rules like tXXX_r, tYYY_i. if set to false, means we only collect the rules contain table_id, tXXX, tYYY.

func (*RewriteRules) Append

func (r *RewriteRules) Append(other RewriteRules)

Append append its argument to this rewrite rules.

func (*RewriteRules) String

func (r *RewriteRules) String() string

Jump to

Keyboard shortcuts

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