storage

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2025 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HotRegionTypes = []string{
	utils.Read.String(),
	utils.Write.String(),
}

HotRegionTypes stands for hot type.

Functions

func AreRegionsLoaded

func AreRegionsLoaded(s Storage) bool

AreRegionsLoaded returns whether the regions are loaded.

func HotRegionStorePath

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

HotRegionStorePath generate hot region store key for HotRegionStorage.

func RetrieveRegionStorage

func RetrieveRegionStorage(s Storage) endpoint.RegionStorage

RetrieveRegionStorage retrieve the region storage from the given storage. If it's a `coreStorage`, it will return the regionStorage inside, otherwise it will return the original storage.

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,
	hotRegionStorageHelper HotRegionStorageHelper,
) (*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 HotRegionStorageHelper

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

HotRegionStorageHelper 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 RegionStorage

type RegionStorage struct {
	kv.Base
	// contains filtered or unexported fields
}

RegionStorage is a storage for the PD region meta information based on LevelDB, which will override the default implementation of the `endpoint.RegionStorage`.

func NewRegionStorageWithLevelDBBackend

func NewRegionStorageWithLevelDBBackend(
	ctx context.Context,
	filePath string,
	ekm *encryption.Manager,
) (*RegionStorage, error)

NewRegionStorageWithLevelDBBackend will create a specialized storage to store region meta information based on a LevelDB backend.

func (*RegionStorage) Close

func (s *RegionStorage) Close() error

Close implements the `endpoint.RegionStorage` interface.

func (*RegionStorage) DeleteRegion

func (s *RegionStorage) DeleteRegion(region *metapb.Region) error

DeleteRegion implements the `endpoint.RegionStorage` interface.

func (*RegionStorage) Flush

func (s *RegionStorage) Flush() error

Flush implements the `endpoint.RegionStorage` interface.

func (*RegionStorage) LoadRegion

func (s *RegionStorage) LoadRegion(regionID uint64, region *metapb.Region) (bool, error)

LoadRegion implements the `endpoint.RegionStorage` interface.

func (*RegionStorage) LoadRegions

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

LoadRegions implements the `endpoint.RegionStorage` interface.

func (*RegionStorage) SaveRegion

func (s *RegionStorage) SaveRegion(region *metapb.Region) error

SaveRegion implements the `endpoint.RegionStorage` interface. Instead of saving the region directly, it will encrypt the region and then save it in batch.

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 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