storage

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2023 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HotRegionTypes = []string{
	WriteType.String(),
	ReadType.String(),
}

HotRegionTypes stands for hot type.

Functions

func HotRegionStorePath

func HotRegionStorePath(hotRegionType string, updateTime int64, regionID uint64) string

HotRegionStorePath generate hot region store key for HotRegionStorage.

func TryGetLocalRegionStorage

func TryGetLocalRegionStorage(s Storage) endpoint.RegionStorage

TryGetLocalRegionStorage gets the local region storage. Returns nil if not present.

func TryLoadRegionsOnce

func TryLoadRegionsOnce(ctx context.Context, s Storage, f func(region *core.RegionInfo) []*core.RegionInfo) error

TryLoadRegionsOnce loads all regions from storage to RegionsInfo. If the underlying storage is the local region storage, it will only load once.

func TrySwitchRegionStorage

func TrySwitchRegionStorage(s Storage, useLocalRegionStorage bool) endpoint.RegionStorage

TrySwitchRegionStorage try to switch whether the RegionStorage uses local or not, and returns the RegionStorage used after the switch. Returns nil if it cannot be switched.

Types

type HistoryHotRegion

type HistoryHotRegion struct {
	UpdateTime    int64   `json:"update_time"`
	RegionID      uint64  `json:"region_id"`
	PeerID        uint64  `json:"peer_id"`
	StoreID       uint64  `json:"store_id"`
	IsLeader      bool    `json:"is_leader"`
	IsLearner     bool    `json:"is_learner"`
	HotRegionType string  `json:"hot_region_type"`
	HotDegree     int64   `json:"hot_degree"`
	FlowBytes     float64 `json:"flow_bytes"`
	KeyRate       float64 `json:"key_rate"`
	QueryRate     float64 `json:"query_rate"`
	StartKey      string  `json:"start_key"`
	EndKey        string  `json:"end_key"`
	// Encryption metadata for start_key and end_key. encryption_meta.iv is IV for start_key.
	// IV for end_key is calculated from (encryption_meta.iv + len(start_key)).
	// The field is only used by PD and should be ignored otherwise.
	// If encryption_meta is empty (i.e. nil), it means start_key and end_key are unencrypted.
	EncryptionMeta *encryptionpb.EncryptionMeta `json:"encryption_meta,omitempty"`
}

HistoryHotRegion wraps hot region info it is storage format of hot_region_storage

type HistoryHotRegions

type HistoryHotRegions struct {
	HistoryHotRegion []*HistoryHotRegion `json:"history_hot_region"`
}

HistoryHotRegions wraps historyHotRegion it will be returned to TiDB.

NOTE: This type is exported by HTTP API. Please pay more attention when modifying it.

type HotRegionStorage

type HotRegionStorage struct {
	*kv.LevelDBKV
	// contains filtered or unexported fields
}

HotRegionStorage is used to store the hot region info. It will pull the hot region info according to the `pullInterval`, and save/delete data beyond the `remainingDays`. Close() must be called after the use.

func NewHotRegionsStorage

func NewHotRegionsStorage(
	ctx context.Context,
	filePath string,
	ekm *encryption.Manager,
	hotRegionStorageHandler HotRegionStorageHandler,
) (*HotRegionStorage, error)

NewHotRegionsStorage create storage to store hot regions info.

func (*HotRegionStorage) Close

func (h *HotRegionStorage) Close() error

Close closes the kv.

func (*HotRegionStorage) NewIterator

func (h *HotRegionStorage) NewIterator(requireTypes []string, startTime, endTime int64) HotRegionStorageIterator

NewIterator return a iterator which can traverse all data as request.

type HotRegionStorageHandler

type HotRegionStorageHandler interface {
	// PackHistoryHotWriteRegions get read hot region info in HistoryHotRegion form.
	PackHistoryHotReadRegions() ([]HistoryHotRegion, error)
	// PackHistoryHotWriteRegions get write hot region info in HistoryHotRegion form.
	PackHistoryHotWriteRegions() ([]HistoryHotRegion, error)
	// IsLeader return true means this server is leader.
	IsLeader() bool
	// GetHotRegionWriteInterval gets interval for PD to store Hot Region information..
	GetHotRegionsWriteInterval() time.Duration
	// GetHotRegionsReservedDays gets days hot region information is kept.
	GetHotRegionsReservedDays() uint64
}

HotRegionStorageHandler help hot region storage get hot region info.

type HotRegionStorageIterator

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

HotRegionStorageIterator iterates over a historyHotRegion.

func (*HotRegionStorageIterator) Next

Next moves the iterator to the next key/value pair. And return historyHotRegion which it is now pointing to. it will return (nil, nil), if there is no more historyHotRegion.

type HotRegionType

type HotRegionType uint32

HotRegionType stands for hot type.

const (
	WriteType HotRegionType = iota
	ReadType
)

Flags for flow.

func (HotRegionType) String

func (h HotRegionType) String() string

String return HotRegionType in string format.

type Storage

Storage is the interface for the backend storage of the PD.

func NewCoreStorage

func NewCoreStorage(defaultStorage Storage, regionStorage endpoint.RegionStorage) Storage

NewCoreStorage creates a new core storage with the given default and region storage. Usually, the defaultStorage is etcd-backend, and the regionStorage is LevelDB-backend. coreStorage can switch between the defaultStorage and regionStorage to read and write the region info, and all other storage interfaces will use the defaultStorage.

func NewStorageWithEtcdBackend

func NewStorageWithEtcdBackend(client *clientv3.Client, rootPath string) Storage

NewStorageWithEtcdBackend creates a new storage with etcd backend.

func NewStorageWithLevelDBBackend

func NewStorageWithLevelDBBackend(
	ctx context.Context,
	filePath string,
	ekm *encryption.Manager,
) (Storage, error)

NewStorageWithLevelDBBackend creates a new storage with LevelDB backend.

func NewStorageWithMemoryBackend

func NewStorageWithMemoryBackend() Storage

NewStorageWithMemoryBackend creates a new storage with memory backend.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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