pdtypes

package
v1.1.0-beta.0...-57a73ea Latest Latest
Warning

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

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

Documentation

Overview

Package pdtypes contains type defines under PD.

Mainly copied from PD repo to avoid direct dependency.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ByteSize

type ByteSize uint64

ByteSize is a retype uint64 for TOML and JSON.

func (ByteSize) MarshalJSON

func (b ByteSize) MarshalJSON() ([]byte, error)

MarshalJSON returns the size as a JSON string.

func (*ByteSize) UnmarshalJSON

func (b *ByteSize) UnmarshalJSON(text []byte) error

UnmarshalJSON parses a JSON string into the byte size.

func (*ByteSize) UnmarshalText

func (b *ByteSize) UnmarshalText(text []byte) error

UnmarshalText parses a Toml string into the byte size.

type Duration

type Duration struct {
	time.Duration
}

Duration is a wrapper of time.Duration for TOML and JSON.

func NewDuration

func NewDuration(duration time.Duration) Duration

NewDuration creates a Duration from time.Duration.

func (*Duration) MarshalJSON

func (d *Duration) MarshalJSON() ([]byte, error)

MarshalJSON returns the duration as a JSON string.

func (Duration) MarshalText

func (d Duration) MarshalText() ([]byte, error)

MarshalText returns the duration as a JSON string.

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(text []byte) error

UnmarshalJSON parses a JSON string into the duration.

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(text []byte) error

UnmarshalText parses a TOML string into the duration.

type LabelConstraint

type LabelConstraint struct {
	Key    string            `json:"key,omitempty"`
	Op     LabelConstraintOp `json:"op,omitempty"`
	Values []string          `json:"values,omitempty"`
}

LabelConstraint is used to filter store when trying to place peer of a region.

type LabelConstraintOp

type LabelConstraintOp string

LabelConstraintOp defines how a LabelConstraint matches a store. It can be one of 'in', 'notIn', 'exists', or 'notExists'.

const (
	// In restricts the store label value should in the value list.
	// If label does not exist, `in` is always false.
	In LabelConstraintOp = "in"
	// NotIn restricts the store label value should not in the value list.
	// If label does not exist, `notIn` is always true.
	NotIn LabelConstraintOp = "notIn"
	// Exists restricts the store should have the label.
	Exists LabelConstraintOp = "exists"
	// NotExists restricts the store should not have the label.
	NotExists LabelConstraintOp = "notExists"
)

type MetaPeer

type MetaPeer struct {
	*metapb.Peer
	// RoleName is `Role.String()`.
	// Since Role is serialized as int by json by default,
	// introducing it will make the output of pd-ctl easier to identify Role.
	RoleName string `json:"role_name"`
	// IsLearner is `Role == "Learner"`.
	// Since IsLearner was changed to Role in kvproto in 5.0, this field was introduced to ensure api compatibility.
	IsLearner bool `json:"is_learner,omitempty"`
}

MetaPeer is api compatible with *metapb.Peer.

type MetaStore

type MetaStore struct {
	*metapb.Store
	StateName string `json:"state_name"`
}

MetaStore contains meta information about a store.

type PDPeerStats

type PDPeerStats struct {
	*pdpb.PeerStats
	Peer MetaPeer `json:"peer"`
}

PDPeerStats is api compatible with *pdpb.PeerStats.

type PeerRoleType

type PeerRoleType string

PeerRoleType is the expected peer type of the placement rule.

const (
	// Voter can either match a leader peer or follower peer
	Voter PeerRoleType = "voter"
	// Leader matches a leader.
	Leader PeerRoleType = "leader"
	// Follower matches a follower.
	Follower PeerRoleType = "follower"
	// Learner matches a learner.
	Learner PeerRoleType = "learner"
)

type Region

type Region struct {
	Meta   *metapb.Region
	Leader *metapb.Peer
}

Region is a mock of PD's core.RegionInfo. For testing purpose.

func NewRegionInfo

func NewRegionInfo(meta *metapb.Region, leader *metapb.Peer) *Region

NewRegionInfo returns a new RegionInfo.

type RegionInfo

type RegionInfo struct {
	ID          uint64              `json:"id"`
	StartKey    string              `json:"start_key"`
	EndKey      string              `json:"end_key"`
	RegionEpoch *metapb.RegionEpoch `json:"epoch,omitempty"`
	Peers       []MetaPeer          `json:"peers,omitempty"`

	Leader          MetaPeer      `json:"leader,omitempty"`
	DownPeers       []PDPeerStats `json:"down_peers,omitempty"`
	PendingPeers    []MetaPeer    `json:"pending_peers,omitempty"`
	WrittenBytes    uint64        `json:"written_bytes"`
	ReadBytes       uint64        `json:"read_bytes"`
	WrittenKeys     uint64        `json:"written_keys"`
	ReadKeys        uint64        `json:"read_keys"`
	ApproximateSize int64         `json:"approximate_size"`
	ApproximateKeys int64         `json:"approximate_keys"`

	ReplicationStatus *ReplicationStatus `json:"replication_status,omitempty"`
}

RegionInfo records detail region info for api usage.

type RegionStats

type RegionStats struct {
	Count            int              `json:"count"`
	EmptyCount       int              `json:"empty_count"`
	StorageSize      int64            `json:"storage_size"`
	StorageKeys      int64            `json:"storage_keys"`
	StoreLeaderCount map[uint64]int   `json:"store_leader_count"`
	StorePeerCount   map[uint64]int   `json:"store_peer_count"`
	StoreLeaderSize  map[uint64]int64 `json:"store_leader_size"`
	StoreLeaderKeys  map[uint64]int64 `json:"store_leader_keys"`
	StorePeerSize    map[uint64]int64 `json:"store_peer_size"`
	StorePeerKeys    map[uint64]int64 `json:"store_peer_keys"`
}

RegionStats records a list of regions' statistics and distribution status.

type RegionTree

type RegionTree struct {
	Regions []*Region
}

RegionTree is a mock of PD's region tree. For testing purpose.

func (*RegionTree) ScanRange

func (t *RegionTree) ScanRange(startKey, endKey []byte, limit int) []*Region

ScanRange scans regions intersecting [start key, end key), returns at most `limit` regions. limit <= 0 means no limit.

func (*RegionTree) SetRegion

func (t *RegionTree) SetRegion(region *Region)

SetRegion puts a region to region tree.

type RegionsInfo

type RegionsInfo struct {
	Count   int          `json:"count"`
	Regions []RegionInfo `json:"regions"`
}

RegionsInfo contains some regions with the detailed region info.

type ReplicationConfig

type ReplicationConfig struct {
	// MaxReplicas is the number of replicas for each region.
	MaxReplicas uint64 `toml:"max-replicas" json:"max-replicas"`

	// The label keys specified the location of a store.
	// The placement priorities is implied by the order of label keys.
	// For example, ["zone", "rack"] means that we should place replicas to
	// different zones first, then to different racks if we don't have enough zones.
	LocationLabels StringSlice `toml:"location-labels" json:"location-labels"`
	// StrictlyMatchLabel strictly checks if the label of TiKV is matched with LocationLabels.
	StrictlyMatchLabel bool `toml:"strictly-match-label" json:"strictly-match-label,string"`

	// When PlacementRules feature is enabled. MaxReplicas, LocationLabels and IsolationLabels are not used any more.
	EnablePlacementRules bool `toml:"enable-placement-rules" json:"enable-placement-rules,string"`

	// EnablePlacementRuleCache controls whether use cache during rule checker
	EnablePlacementRulesCache bool `toml:"enable-placement-rules-cache" json:"enable-placement-rules-cache,string"`

	// IsolationLevel is used to isolate replicas explicitly and forcibly if it's not empty.
	// Its value must be empty or one of LocationLabels.
	// Example:
	// location-labels = ["zone", "rack", "host"]
	// isolation-level = "zone"
	// With configuration like above, PD ensure that all replicas be placed in different zones.
	// Even if a zone is down, PD will not try to make up replicas in other zone
	// because other zones already have replicas on it.
	IsolationLevel string `toml:"isolation-level" json:"isolation-level"`
}

ReplicationConfig is the replication configuration.

type ReplicationStatus

type ReplicationStatus struct {
	State   string `json:"state"`
	StateID uint64 `json:"state_id"`
}

ReplicationStatus represents the replication mode status of the region.

type Rule

type Rule struct {
	GroupID          string            `json:"group_id"`                    // mark the source that add the rule
	ID               string            `json:"id"`                          // unique ID within a group
	Index            int               `json:"index,omitempty"`             // rule apply order in a group, rule with less ID is applied first when indexes are equal
	Override         bool              `json:"override,omitempty"`          // when it is true, all rules with less indexes are disabled
	StartKey         []byte            `json:"-"`                           // range start key
	StartKeyHex      string            `json:"start_key"`                   // hex format start key, for marshal/unmarshal
	EndKey           []byte            `json:"-"`                           // range end key
	EndKeyHex        string            `json:"end_key"`                     // hex format end key, for marshal/unmarshal
	Role             PeerRoleType      `json:"role"`                        // expected role of the peers
	Count            int               `json:"count"`                       // expected count of the peers
	LabelConstraints []LabelConstraint `json:"label_constraints,omitempty"` // used to select stores to place peers
	LocationLabels   []string          `json:"location_labels,omitempty"`   // used to make peers isolated physically
	IsolationLevel   string            `json:"isolation_level,omitempty"`   // used to isolate replicas explicitly and forcibly
	Version          uint64            `json:"version,omitempty"`           // only set at runtime, add 1 each time rules updated, begin from 0.
	CreateTimestamp  uint64            `json:"create_timestamp,omitempty"`  // only set at runtime, recorded rule create timestamp
}

Rule is the placement rule that can be checked against a region. When applying rules (apply means schedule regions to match selected rules), the apply order is defined by the tuple [GroupIndex, GroupID, Index, ID].

type RuleGroup

type RuleGroup struct {
	ID       string `json:"id,omitempty"`
	Index    int    `json:"index,omitempty"`
	Override bool   `json:"override,omitempty"`
}

RuleGroup defines properties of a rule group.

type StoreInfo

type StoreInfo struct {
	Store  *MetaStore   `json:"store"`
	Status *StoreStatus `json:"status"`
}

StoreInfo contains information about a store.

type StoreStatus

type StoreStatus struct {
	Capacity           ByteSize   `json:"capacity"`
	Available          ByteSize   `json:"available"`
	UsedSize           ByteSize   `json:"used_size"`
	LeaderCount        int        `json:"leader_count"`
	LeaderWeight       float64    `json:"leader_weight"`
	LeaderScore        float64    `json:"leader_score"`
	LeaderSize         int64      `json:"leader_size"`
	RegionCount        int        `json:"region_count"`
	RegionWeight       float64    `json:"region_weight"`
	RegionScore        float64    `json:"region_score"`
	RegionSize         int64      `json:"region_size"`
	SlowScore          uint64     `json:"slow_score"`
	SendingSnapCount   uint32     `json:"sending_snap_count,omitempty"`
	ReceivingSnapCount uint32     `json:"receiving_snap_count,omitempty"`
	IsBusy             bool       `json:"is_busy,omitempty"`
	StartTS            *time.Time `json:"start_ts,omitempty"`
	LastHeartbeatTS    *time.Time `json:"last_heartbeat_ts,omitempty"`
	Uptime             *Duration  `json:"uptime,omitempty"`
}

StoreStatus contains status about a store.

type StoresInfo

type StoresInfo struct {
	Count  int          `json:"count"`
	Stores []*StoreInfo `json:"stores"`
}

StoresInfo records stores' info.

type StringSlice

type StringSlice []string

StringSlice is more friendly to json encode/decode

func (StringSlice) MarshalJSON

func (s StringSlice) MarshalJSON() ([]byte, error)

MarshalJSON returns the size as a JSON string.

func (*StringSlice) UnmarshalJSON

func (s *StringSlice) UnmarshalJSON(text []byte) error

UnmarshalJSON parses a JSON string into the byte size.

Jump to

Keyboard shortcuts

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