Documentation ¶
Index ¶
- Variables
- func CheckPDVersion(opt *scheduleOption)
- func GetMembers(etcdClient *clientv3.Client) ([]*pdpb.Member, error)
- func InitHTTPClient(svr *Server) error
- func IsCompatible(clusterVersion, v semver.Version) bool
- func IsDefaultScheduler(typ string) bool
- func LogPDInfo()
- func MinSupportedVersion(v Feature) semver.Version
- func MustParseVersion(v string) *semver.Version
- func NewTestServer() (*Config, *Server, CleanupFunc, error)
- func ParseUrls(s string) ([]url.URL, error)
- func ParseVersion(v string) (*semver.Version, error)
- func PrepareJoinCluster(cfg *Config) error
- func PrintPDInfo()
- func StartMonitor(now func() time.Time, systimeErrHandler func())
- func ValidateLabelString(s string) error
- func ValidateLabels(labels []*metapb.StoreLabel) error
- type CleanupFunc
- type ClusterStatus
- type Config
- type Feature
- type Handler
- func (h *Handler) AddAddPeerOperator(regionID uint64, toStoreID uint64) error
- func (h *Handler) AddAdjacentRegionScheduler(args ...string) error
- func (h *Handler) AddBalanceHotRegionScheduler() error
- func (h *Handler) AddBalanceLeaderScheduler() error
- func (h *Handler) AddBalanceRegionScheduler() error
- func (h *Handler) AddEvictLeaderScheduler(storeID uint64) error
- func (h *Handler) AddGrantLeaderScheduler(storeID uint64) error
- func (h *Handler) AddLabelScheduler() error
- func (h *Handler) AddMergeRegionOperator(regionID uint64, targetID uint64) error
- func (h *Handler) AddRandomMergeScheduler() error
- func (h *Handler) AddRemovePeerOperator(regionID uint64, fromStoreID uint64) error
- func (h *Handler) AddScatterRangeScheduler(args ...string) error
- func (h *Handler) AddScatterRegionOperator(regionID uint64) error
- func (h *Handler) AddScheduler(name string, args ...string) error
- func (h *Handler) AddShuffleLeaderScheduler() error
- func (h *Handler) AddShuffleRegionScheduler() error
- func (h *Handler) AddSplitRegionOperator(regionID uint64, policy string) error
- func (h *Handler) AddTransferLeaderOperator(regionID uint64, storeID uint64) error
- func (h *Handler) AddTransferPeerOperator(regionID uint64, fromStoreID, toStoreID uint64) error
- func (h *Handler) AddTransferRegionOperator(regionID uint64, storeIDs map[uint64]struct{}) error
- func (h *Handler) GetAdminOperators() ([]*schedule.Operator, error)
- func (h *Handler) GetDownPeerRegions() ([]*core.RegionInfo, error)
- func (h *Handler) GetExtraPeerRegions() ([]*core.RegionInfo, error)
- func (h *Handler) GetHistory(start time.Time) ([]schedule.OperatorHistory, error)
- func (h *Handler) GetHotBytesReadStores() map[uint64]uint64
- func (h *Handler) GetHotBytesWriteStores() map[uint64]uint64
- func (h *Handler) GetHotKeysReadStores() map[uint64]uint64
- func (h *Handler) GetHotKeysWriteStores() map[uint64]uint64
- func (h *Handler) GetHotReadRegions() *core.StoreHotRegionInfos
- func (h *Handler) GetHotWriteRegions() *core.StoreHotRegionInfos
- func (h *Handler) GetIncorrectNamespaceRegions() ([]*core.RegionInfo, error)
- func (h *Handler) GetLeaderOperators() ([]*schedule.Operator, error)
- func (h *Handler) GetMissPeerRegions() ([]*core.RegionInfo, error)
- func (h *Handler) GetOperator(regionID uint64) (*schedule.Operator, error)
- func (h *Handler) GetOperators() ([]*schedule.Operator, error)
- func (h *Handler) GetOperatorsOfKind(mask schedule.OperatorKind) ([]*schedule.Operator, error)
- func (h *Handler) GetPendingPeerRegions() ([]*core.RegionInfo, error)
- func (h *Handler) GetRegionOperators() ([]*schedule.Operator, error)
- func (h *Handler) GetSchedulers() ([]string, error)
- func (h *Handler) GetStores() ([]*core.StoreInfo, error)
- func (h *Handler) RemoveOperator(regionID uint64) error
- func (h *Handler) RemoveScheduler(name string) error
- type LabelPropertyConfig
- type NamespaceConfig
- type OperatorRecords
- type OperatorWithStatus
- type RaftCluster
- func (c *RaftCluster) BuryStore(storeID uint64, force bool) error
- func (c *RaftCluster) DropCacheRegion(id uint64)
- func (c *RaftCluster) GetAdjacentRegions(region *core.RegionInfo) (*core.RegionInfo, *core.RegionInfo)
- func (c *RaftCluster) GetConfig() *metapb.Cluster
- func (c *RaftCluster) GetMetaRegions() []*metapb.Region
- func (c *RaftCluster) GetNamespaceClassifier() namespace.Classifier
- func (c *RaftCluster) GetPrevRegionByKey(regionKey []byte) (*metapb.Region, *metapb.Peer)
- func (c *RaftCluster) GetRegionByID(regionID uint64) (*metapb.Region, *metapb.Peer)
- func (c *RaftCluster) GetRegionByKey(regionKey []byte) (*metapb.Region, *metapb.Peer)
- func (c *RaftCluster) GetRegionInfoByID(regionID uint64) *core.RegionInfo
- func (c *RaftCluster) GetRegionInfoByKey(regionKey []byte) *core.RegionInfo
- func (c *RaftCluster) GetRegionStats(startKey, endKey []byte) *core.RegionStats
- func (c *RaftCluster) GetRegions() []*core.RegionInfo
- func (c *RaftCluster) GetStore(storeID uint64) (*core.StoreInfo, error)
- func (c *RaftCluster) GetStoreRegions(storeID uint64) []*core.RegionInfo
- func (c *RaftCluster) GetStores() []*metapb.Store
- func (c *RaftCluster) HandleRegionHeartbeat(region *core.RegionInfo) error
- func (c *RaftCluster) RemoveStore(storeID uint64) error
- func (c *RaftCluster) SetStoreState(storeID uint64, state metapb.StoreState) error
- func (c *RaftCluster) SetStoreWeight(storeID uint64, leader, region float64) error
- func (c *RaftCluster) UpdateStoreLabels(storeID uint64, labels []*metapb.StoreLabel) error
- type Replication
- type ReplicationConfig
- type ScheduleConfig
- type SchedulerConfig
- type SchedulerConfigs
- type SecurityConfig
- type Server
- func (s *Server) AllocID(ctx context.Context, request *pdpb.AllocIDRequest) (*pdpb.AllocIDResponse, error)
- func (s *Server) AskBatchSplit(ctx context.Context, request *pdpb.AskBatchSplitRequest) (*pdpb.AskBatchSplitResponse, error)
- func (s *Server) AskSplit(ctx context.Context, request *pdpb.AskSplitRequest) (*pdpb.AskSplitResponse, error)
- func (s *Server) Bootstrap(ctx context.Context, request *pdpb.BootstrapRequest) (*pdpb.BootstrapResponse, error)
- func (s *Server) CheckHealth(members []*pdpb.Member) map[uint64]*pdpb.Member
- func (s *Server) Close()
- func (s *Server) ClusterID() uint64
- func (s *Server) DeleteLabelProperty(typ, labelKey, labelValue string) error
- func (s *Server) DeleteMemberLeaderPriority(id uint64) error
- func (s *Server) DeleteNamespaceConfig(name string)
- func (s *Server) GetAddr() string
- func (s *Server) GetAllStores(ctx context.Context, request *pdpb.GetAllStoresRequest) (*pdpb.GetAllStoresResponse, error)
- func (s *Server) GetClient() *clientv3.Client
- func (s *Server) GetCluster() *metapb.Cluster
- func (s *Server) GetClusterConfig(ctx context.Context, request *pdpb.GetClusterConfigRequest) (*pdpb.GetClusterConfigResponse, error)
- func (s *Server) GetClusterStatus() (*ClusterStatus, error)
- func (s *Server) GetClusterVersion() semver.Version
- func (s *Server) GetConfig() *Config
- func (s *Server) GetEndpoints() []string
- func (s *Server) GetEtcdLeader() uint64
- func (s *Server) GetGCSafePoint(ctx context.Context, request *pdpb.GetGCSafePointRequest) (*pdpb.GetGCSafePointResponse, error)
- func (s *Server) GetHandler() *Handler
- func (s *Server) GetLabelProperty() LabelPropertyConfig
- func (s *Server) GetLeader() *pdpb.Member
- func (s *Server) GetLeaderID() uint64
- func (s *Server) GetMemberLeaderPriority(id uint64) (int, error)
- func (s *Server) GetMembers(context.Context, *pdpb.GetMembersRequest) (*pdpb.GetMembersResponse, error)
- func (s *Server) GetNamespaceConfig(name string) *NamespaceConfig
- func (s *Server) GetNamespaceConfigWithAdjust(name string) *NamespaceConfig
- func (s *Server) GetOperator(ctx context.Context, request *pdpb.GetOperatorRequest) (*pdpb.GetOperatorResponse, error)
- func (s *Server) GetPrevRegion(ctx context.Context, request *pdpb.GetRegionRequest) (*pdpb.GetRegionResponse, error)
- func (s *Server) GetRaftCluster() *RaftCluster
- func (s *Server) GetRegion(ctx context.Context, request *pdpb.GetRegionRequest) (*pdpb.GetRegionResponse, error)
- func (s *Server) GetRegionByID(ctx context.Context, request *pdpb.GetRegionByIDRequest) (*pdpb.GetRegionResponse, error)
- func (s *Server) GetReplicationConfig() *ReplicationConfig
- func (s *Server) GetScheduleConfig() *ScheduleConfig
- func (s *Server) GetSecurityConfig() *SecurityConfig
- func (s *Server) GetStore(ctx context.Context, request *pdpb.GetStoreRequest) (*pdpb.GetStoreResponse, error)
- func (s *Server) ID() uint64
- func (s *Server) IsBootstrapped(ctx context.Context, request *pdpb.IsBootstrappedRequest) (*pdpb.IsBootstrappedResponse, error)
- func (s *Server) IsLeader() bool
- func (s *Server) IsNamespaceExist(name string) bool
- func (s *Server) MoveEtcdLeader(ctx context.Context, old, new uint64) error
- func (s *Server) Name() string
- func (s *Server) PutClusterConfig(ctx context.Context, request *pdpb.PutClusterConfigRequest) (*pdpb.PutClusterConfigResponse, error)
- func (s *Server) PutStore(ctx context.Context, request *pdpb.PutStoreRequest) (*pdpb.PutStoreResponse, error)
- func (s *Server) RegionHeartbeat(stream pdpb.PD_RegionHeartbeatServer) error
- func (s *Server) ReportBatchSplit(ctx context.Context, request *pdpb.ReportBatchSplitRequest) (*pdpb.ReportBatchSplitResponse, error)
- func (s *Server) ReportSplit(ctx context.Context, request *pdpb.ReportSplitRequest) (*pdpb.ReportSplitResponse, error)
- func (s *Server) ResignLeader(nextLeader string) error
- func (s *Server) Run(ctx context.Context) error
- func (s *Server) ScatterRegion(ctx context.Context, request *pdpb.ScatterRegionRequest) (*pdpb.ScatterRegionResponse, error)
- func (s *Server) SetClusterVersion(v string) error
- func (s *Server) SetLabelProperty(typ, labelKey, labelValue string) error
- func (s *Server) SetLogLevel(level string)
- func (s *Server) SetMemberLeaderPriority(id uint64, priority int) error
- func (s *Server) SetNamespaceConfig(name string, cfg NamespaceConfig)
- func (s *Server) SetReplicationConfig(cfg ReplicationConfig) error
- func (s *Server) SetScheduleConfig(cfg ScheduleConfig) error
- func (s *Server) StoreHeartbeat(ctx context.Context, request *pdpb.StoreHeartbeatRequest) (*pdpb.StoreHeartbeatResponse, error)
- func (s *Server) Tso(stream pdpb.PD_TsoServer) error
- func (s *Server) UpdateGCSafePoint(ctx context.Context, request *pdpb.UpdateGCSafePointRequest) (*pdpb.UpdateGCSafePointResponse, error)
- type StoreLabel
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotBootstrapped is error info for cluster not bootstrapped ErrNotBootstrapped = errors.New("TiKV cluster not bootstrapped, please start TiKV first") // ErrOperatorNotFound is error info for operator not found ErrOperatorNotFound = errors.New("operator not found") // ErrAddOperator is error info for already have an operator when adding operator ErrAddOperator = errors.New("failed to add operator, maybe already have one") // ErrRegionNotAdjacent is error info for region not adjacent ErrRegionNotAdjacent = errors.New("two regions are not adjacent") // ErrRegionNotFound is error info for region not found ErrRegionNotFound = func(regionID uint64) error { return errors.Errorf("region %v not found", regionID) } // ErrRegionAbnormalPeer is error info for region has abonormal peer ErrRegionAbnormalPeer = func(regionID uint64) error { return errors.Errorf("region %v has abnormal peer", regionID) } // ErrRegionIsStale is error info for region is stale ErrRegionIsStale = func(region *metapb.Region, origin *metapb.Region) error { return errors.Errorf("region is stale: region %v origin %v", region, origin) } )
var ( PDReleaseVersion = "None" PDBuildTS = "None" PDGitHash = "None" PDGitBranch = "None" )
Version information.
var DialClient = &http.Client{ Transport: &http.Transport{ DisableKeepAlives: true, }, }
DialClient used to dail http request.
var EnableZap = false
EnableZap enable the zap logger in embed etcd.
Functions ¶
func CheckPDVersion ¶
func CheckPDVersion(opt *scheduleOption)
CheckPDVersion checks if PD needs to be upgraded.
func GetMembers ¶
GetMembers return a slice of Members.
func IsCompatible ¶
IsCompatible checks if the clusterVersion is compatible with the specified version.
func IsDefaultScheduler ¶
IsDefaultScheduler checks whether the scheduler is enable by default.
func MinSupportedVersion ¶
MinSupportedVersion returns the minimum support version for the specified feature.
func MustParseVersion ¶
MustParseVersion wraps ParseVersion and will panic if error is not nil.
func NewTestServer ¶
func NewTestServer() (*Config, *Server, CleanupFunc, error)
NewTestServer creates a pd server for testing.
func ParseVersion ¶
ParseVersion wraps semver.NewVersion and handles compatibility issues.
func PrepareJoinCluster ¶
PrepareJoinCluster sends MemberAdd command to PD cluster, and returns the initial configuration of the PD cluster.
TL;TR: The join functionality is safe. With data, join does nothing, w/o data
and it is not a member of cluster, join does MemberAdd, it returns an error if PD tries to join itself, missing data or join a duplicated PD.
Etcd automatically re-joins the cluster if there is a data directory. So first it checks if there is a data directory or not. If there is, it returns an empty string (etcd will get the correct configurations from the data directory.)
If there is no data directory, there are following cases:
A new PD joins an existing cluster. What join does: MemberAdd, MemberList, then generate initial-cluster.
A failed PD re-joins the previous cluster. What join does: return an error. (etcd reports: raft log corrupted, truncated, or lost?)
A deleted PD joins to previous cluster. What join does: MemberAdd, MemberList, then generate initial-cluster. (it is not in the member list and there is no data, so we can treat it as a new PD.)
If there is a data directory, there are following special cases:
A failed PD tries to join the previous cluster but it has been deleted during its downtime. What join does: return "" (etcd will connect to other peers and find that the PD itself has been removed.)
A deleted PD joins the previous cluster. What join does: return "" (as etcd will read data directory and find that the PD itself has been removed, so an empty string is fine.)
func PrintPDInfo ¶
func PrintPDInfo()
PrintPDInfo prints the PD version information without log info.
func StartMonitor ¶
StartMonitor calls systimeErrHandler if system time jump backward.
func ValidateLabelString ¶
ValidateLabelString checks the legality of the label string. The valid label consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character.
func ValidateLabels ¶
func ValidateLabels(labels []*metapb.StoreLabel) error
ValidateLabels checks the legality of the labels.
Types ¶
type CleanupFunc ¶
type CleanupFunc func()
CleanupFunc closes test pd server(s) and deletes any files left behind.
type ClusterStatus ¶
ClusterStatus saves some state information
type Config ¶
type Config struct { *flag.FlagSet `json:"-"` Version bool `json:"-"` ClientUrls string `toml:"client-urls" json:"client-urls"` PeerUrls string `toml:"peer-urls" json:"peer-urls"` AdvertiseClientUrls string `toml:"advertise-client-urls" json:"advertise-client-urls"` AdvertisePeerUrls string `toml:"advertise-peer-urls" json:"advertise-peer-urls"` Name string `toml:"name" json:"name"` DataDir string `toml:"data-dir" json:"data-dir"` InitialCluster string `toml:"initial-cluster" json:"initial-cluster"` InitialClusterState string `toml:"initial-cluster-state" json:"initial-cluster-state"` // Join to an existing pd cluster, a string of endpoints. Join string `toml:"join" json:"join"` // LeaderLease time, if leader doesn't update its TTL // in etcd after lease time, etcd will expire the leader key // and other servers can campaign the leader again. // Etcd onlys support seoncds TTL, so here is second too. LeaderLease int64 `toml:"lease" json:"lease"` // Log related config. Log logutil.LogConfig `toml:"log" json:"log"` // Backward compatibility. LogFileDeprecated string `toml:"log-file" json:"log-file"` LogLevelDeprecated string `toml:"log-level" json:"log-level"` // TsoSaveInterval is the interval to save timestamp. TsoSaveInterval typeutil.Duration `toml:"tso-save-interval" json:"tso-save-interval"` Metric metricutil.MetricConfig `toml:"metric" json:"metric"` Schedule ScheduleConfig `toml:"schedule" json:"schedule"` Replication ReplicationConfig `toml:"replication" json:"replication"` Namespace map[string]NamespaceConfig `json:"namespace"` ClusterVersion semver.Version `json:"cluster-version"` // QuotaBackendBytes Raise alarms when backend size exceeds the given quota. 0 means use the default quota. // the default size is 2GB, the maximum is 8GB. QuotaBackendBytes typeutil.ByteSize `toml:"quota-backend-bytes" json:"quota-backend-bytes"` // AutoCompactionMode is either 'periodic' or 'revision'. The default value is 'periodic'. AutoCompactionMode string `toml:"auto-compaction-mode" json:"auto-compaction-mode"` // AutoCompactionRetention is either duration string with time unit // (e.g. '5m' for 5-minute), or revision unit (e.g. '5000'). // If no time unit is provided and compaction mode is 'periodic', // the unit defaults to hour. For example, '5' translates into 5-hour. // The default retention is 1 hour. // Before etcd v3.3.x, the type of retention is int. We add 'v2' suffix to make it backward compatible. AutoCompactionRetention string `toml:"auto-compaction-retention" json:"auto-compaction-retention-v2"` // TickInterval is the interval for etcd Raft tick. TickInterval typeutil.Duration `toml:"tick-interval"` // ElectionInterval is the interval for etcd Raft election. ElectionInterval typeutil.Duration `toml:"election-interval"` // Prevote is true to enable Raft Pre-Vote. // If enabled, Raft runs an additional election phase // to check whether it would get enough votes to win // an election, thus minimizing disruptions. PreVote bool `toml:"enable-prevote"` Security SecurityConfig `toml:"security" json:"security"` LabelProperty LabelPropertyConfig `toml:"label-property" json:"label-property"` // For all warnings during parsing. WarningMsgs []string // NamespaceClassifier is for classifying stores/regions into different // namespaces. NamespaceClassifier string `toml:"namespace-classifier" json:"namespace-classifier"` // contains filtered or unexported fields }
Config is the pd server configuration.
func NewTestMultiConfig ¶
NewTestMultiConfig is only for test to create multiple pd configurations. Because PD client also needs this, so export here.
func NewTestSingleConfig ¶
func NewTestSingleConfig() *Config
NewTestSingleConfig is only for test to create one pd. Because PD client also needs this, so export here.
type Feature ¶
type Feature int
Feature supported features.
const ( Base Feature = iota Version2_0 // RegionMerge supports the adjacent regions to be merged. // and PD will periodically check if there is enough small // region to be merged. if there is, will send the corresponding // merge command to the TiKV. RegionMerge // RaftLearner supports add a non-voting member in raft members. // and PD scheduling strategy will replace `addPeer` to `addLearner`,`promotoLearner`. RaftLearner // BatchSplit can speed up the region split. // and PD will response the BatchSplit request. BatchSplit )
Fetures list. The cluster provides corresponding new features if the cluster version greater than or equal to the required minimum version of the feature.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is a helper to export methods to handle API/RPC requests.
func (*Handler) AddAddPeerOperator ¶
AddAddPeerOperator adds an operator to add peer.
func (*Handler) AddAdjacentRegionScheduler ¶
AddAdjacentRegionScheduler adds a balance-adjacent-region-scheduler.
func (*Handler) AddBalanceHotRegionScheduler ¶ added in v1.0.3
AddBalanceHotRegionScheduler adds a balance-hot-region-scheduler.
func (*Handler) AddBalanceLeaderScheduler ¶
AddBalanceLeaderScheduler adds a balance-leader-scheduler.
func (*Handler) AddBalanceRegionScheduler ¶ added in v1.0.3
AddBalanceRegionScheduler adds a balance-region-scheduler.
func (*Handler) AddEvictLeaderScheduler ¶
AddEvictLeaderScheduler adds an evict-leader-scheduler.
func (*Handler) AddGrantLeaderScheduler ¶
AddGrantLeaderScheduler adds a grant-leader-scheduler.
func (*Handler) AddLabelScheduler ¶
AddLabelScheduler adds a label-scheduler.
func (*Handler) AddMergeRegionOperator ¶
AddMergeRegionOperator adds an operator to merge region.
func (*Handler) AddRandomMergeScheduler ¶
AddRandomMergeScheduler adds a random-merge-scheduler.
func (*Handler) AddRemovePeerOperator ¶
AddRemovePeerOperator adds an operator to remove peer.
func (*Handler) AddScatterRangeScheduler ¶
AddScatterRangeScheduler adds a balance-range-leader-scheduler
func (*Handler) AddScatterRegionOperator ¶
AddScatterRegionOperator adds an operator to scatter a region.
func (*Handler) AddScheduler ¶
AddScheduler adds a scheduler.
func (*Handler) AddShuffleLeaderScheduler ¶
AddShuffleLeaderScheduler adds a shuffle-leader-scheduler.
func (*Handler) AddShuffleRegionScheduler ¶
AddShuffleRegionScheduler adds a shuffle-region-scheduler.
func (*Handler) AddSplitRegionOperator ¶
AddSplitRegionOperator adds an operator to split a region.
func (*Handler) AddTransferLeaderOperator ¶
AddTransferLeaderOperator adds an operator to transfer leader to the store.
func (*Handler) AddTransferPeerOperator ¶
AddTransferPeerOperator adds an operator to transfer peer.
func (*Handler) AddTransferRegionOperator ¶
AddTransferRegionOperator adds an operator to transfer region to the stores.
func (*Handler) GetAdminOperators ¶
GetAdminOperators returns the running admin operators.
func (*Handler) GetDownPeerRegions ¶
func (h *Handler) GetDownPeerRegions() ([]*core.RegionInfo, error)
GetDownPeerRegions gets the region with down peer.
func (*Handler) GetExtraPeerRegions ¶
func (h *Handler) GetExtraPeerRegions() ([]*core.RegionInfo, error)
GetExtraPeerRegions gets the region exceeds the specified number of peers.
func (*Handler) GetHistory ¶
GetHistory returns finished operators' history since start.
func (*Handler) GetHotBytesReadStores ¶
GetHotBytesReadStores gets all hot write stores stats.
func (*Handler) GetHotBytesWriteStores ¶
GetHotBytesWriteStores gets all hot write stores stats.
func (*Handler) GetHotKeysReadStores ¶
GetHotKeysReadStores gets all hot write stores stats.
func (*Handler) GetHotKeysWriteStores ¶
GetHotKeysWriteStores gets all hot write stores stats.
func (*Handler) GetHotReadRegions ¶
func (h *Handler) GetHotReadRegions() *core.StoreHotRegionInfos
GetHotReadRegions gets all hot read regions stats.
func (*Handler) GetHotWriteRegions ¶
func (h *Handler) GetHotWriteRegions() *core.StoreHotRegionInfos
GetHotWriteRegions gets all hot write regions stats.
func (*Handler) GetIncorrectNamespaceRegions ¶
func (h *Handler) GetIncorrectNamespaceRegions() ([]*core.RegionInfo, error)
GetIncorrectNamespaceRegions gets the region with incorrect namespace peer.
func (*Handler) GetLeaderOperators ¶
GetLeaderOperators returns the running leader operators.
func (*Handler) GetMissPeerRegions ¶
func (h *Handler) GetMissPeerRegions() ([]*core.RegionInfo, error)
GetMissPeerRegions gets the region less than the specified number of peers.
func (*Handler) GetOperator ¶
GetOperator returns the region operator.
func (*Handler) GetOperators ¶
GetOperators returns the running operators.
func (*Handler) GetOperatorsOfKind ¶
GetOperatorsOfKind returns the running operators of the kind.
func (*Handler) GetPendingPeerRegions ¶
func (h *Handler) GetPendingPeerRegions() ([]*core.RegionInfo, error)
GetPendingPeerRegions gets the region with pending peer.
func (*Handler) GetRegionOperators ¶
GetRegionOperators returns the running region operators.
func (*Handler) GetSchedulers ¶
GetSchedulers returns all names of schedulers.
func (*Handler) RemoveOperator ¶
RemoveOperator removes the region operator.
func (*Handler) RemoveScheduler ¶
RemoveScheduler removes a scheduler by name.
type LabelPropertyConfig ¶
type LabelPropertyConfig map[string][]StoreLabel
LabelPropertyConfig is the config section to set properties to store labels.
type NamespaceConfig ¶
type NamespaceConfig struct { // LeaderScheduleLimit is the max coexist leader schedules. LeaderScheduleLimit uint64 `json:"leader-schedule-limit"` // RegionScheduleLimit is the max coexist region schedules. RegionScheduleLimit uint64 `json:"region-schedule-limit"` // ReplicaScheduleLimit is the max coexist replica schedules. ReplicaScheduleLimit uint64 `json:"replica-schedule-limit"` // MergeScheduleLimit is the max coexist merge schedules. MergeScheduleLimit uint64 `json:"merge-schedule-limit"` // HotRegionScheduleLimit is the max coexist hot region schedules. HotRegionScheduleLimit uint64 `json:"hot-region-schedule-limit"` // MaxReplicas is the number of replicas for each region. MaxReplicas uint64 `json:"max-replicas"` }
NamespaceConfig is to overwrite the global setting for specific namespace
type OperatorRecords ¶
type OperatorRecords struct {
// contains filtered or unexported fields
}
OperatorRecords remains the operator and its status for a while.
func NewOperatorRecords ¶
func NewOperatorRecords() *OperatorRecords
NewOperatorRecords returns a OperatorRecords.
func (*OperatorRecords) Get ¶
func (o *OperatorRecords) Get(id uint64) *OperatorWithStatus
Get gets the operator and its status.
func (*OperatorRecords) Put ¶
func (o *OperatorRecords) Put(op *schedule.Operator, status pdpb.OperatorStatus)
Put puts the operator and its status.
type OperatorWithStatus ¶
type OperatorWithStatus struct { Op *schedule.Operator Status pdpb.OperatorStatus }
OperatorWithStatus records the operator and its status.
type RaftCluster ¶
RaftCluster is used for cluster config management. Raft cluster key format: cluster 1 -> /1/raft, value is metapb.Cluster cluster 2 -> /2/raft For cluster 1 store 1 -> /1/raft/s/1, value is metapb.Store region 1 -> /1/raft/r/1, value is metapb.Region
func (*RaftCluster) BuryStore ¶
func (c *RaftCluster) BuryStore(storeID uint64, force bool) error
BuryStore marks a store as tombstone in cluster. State transition: Case 1: Up -> Tombstone (if force is true); Case 2: Offline -> Tombstone.
func (*RaftCluster) DropCacheRegion ¶
func (c *RaftCluster) DropCacheRegion(id uint64)
DropCacheRegion removes a region from the cache.
func (*RaftCluster) GetAdjacentRegions ¶
func (c *RaftCluster) GetAdjacentRegions(region *core.RegionInfo) (*core.RegionInfo, *core.RegionInfo)
GetAdjacentRegions returns region's info that is adjacent with specific region id.
func (*RaftCluster) GetConfig ¶
func (c *RaftCluster) GetConfig() *metapb.Cluster
GetConfig gets config from cluster.
func (*RaftCluster) GetMetaRegions ¶
func (c *RaftCluster) GetMetaRegions() []*metapb.Region
GetMetaRegions gets regions from cluster.
func (*RaftCluster) GetNamespaceClassifier ¶
func (c *RaftCluster) GetNamespaceClassifier() namespace.Classifier
GetNamespaceClassifier returns current namespace classifier.
func (*RaftCluster) GetPrevRegionByKey ¶
GetPrevRegionByKey gets previous region and leader peer by the region key from cluster.
func (*RaftCluster) GetRegionByID ¶
GetRegionByID gets region and leader peer by regionID from cluster.
func (*RaftCluster) GetRegionByKey ¶
GetRegionByKey gets region and leader peer by region key from cluster.
func (*RaftCluster) GetRegionInfoByID ¶
func (c *RaftCluster) GetRegionInfoByID(regionID uint64) *core.RegionInfo
GetRegionInfoByID gets regionInfo by regionID from cluster.
func (*RaftCluster) GetRegionInfoByKey ¶
func (c *RaftCluster) GetRegionInfoByKey(regionKey []byte) *core.RegionInfo
GetRegionInfoByKey gets regionInfo by region key from cluster.
func (*RaftCluster) GetRegionStats ¶
func (c *RaftCluster) GetRegionStats(startKey, endKey []byte) *core.RegionStats
GetRegionStats returns region statistics from cluster.
func (*RaftCluster) GetRegions ¶
func (c *RaftCluster) GetRegions() []*core.RegionInfo
GetRegions returns all regions info in detail.
func (*RaftCluster) GetStore ¶
func (c *RaftCluster) GetStore(storeID uint64) (*core.StoreInfo, error)
GetStore gets store from cluster.
func (*RaftCluster) GetStoreRegions ¶
func (c *RaftCluster) GetStoreRegions(storeID uint64) []*core.RegionInfo
GetStoreRegions returns all regions info with a given storeID.
func (*RaftCluster) GetStores ¶
func (c *RaftCluster) GetStores() []*metapb.Store
GetStores gets stores from cluster.
func (*RaftCluster) HandleRegionHeartbeat ¶
func (c *RaftCluster) HandleRegionHeartbeat(region *core.RegionInfo) error
HandleRegionHeartbeat processes RegionInfo reports from client.
func (*RaftCluster) RemoveStore ¶
func (c *RaftCluster) RemoveStore(storeID uint64) error
RemoveStore marks a store as offline in cluster. State transition: Up -> Offline.
func (*RaftCluster) SetStoreState ¶
func (c *RaftCluster) SetStoreState(storeID uint64, state metapb.StoreState) error
SetStoreState sets up a store's state.
func (*RaftCluster) SetStoreWeight ¶
func (c *RaftCluster) SetStoreWeight(storeID uint64, leader, region float64) error
SetStoreWeight sets up a store's leader/region balance weight.
func (*RaftCluster) UpdateStoreLabels ¶
func (c *RaftCluster) UpdateStoreLabels(storeID uint64, labels []*metapb.StoreLabel) error
UpdateStoreLabels updates a store's location labels.
type Replication ¶
type Replication struct {
// contains filtered or unexported fields
}
Replication provides some help to do replication.
func (*Replication) GetLocationLabels ¶
func (r *Replication) GetLocationLabels() []string
GetLocationLabels returns the location labels for each region
func (*Replication) GetMaxReplicas ¶
func (r *Replication) GetMaxReplicas() int
GetMaxReplicas returns the number of replicas for each region.
func (*Replication) SetMaxReplicas ¶
func (r *Replication) SetMaxReplicas(replicas int)
SetMaxReplicas set the replicas for each region.
type ReplicationConfig ¶
type ReplicationConfig struct { // MaxReplicas is the number of replicas for each region. MaxReplicas uint64 `toml:"max-replicas,omitempty" 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 typeutil.StringSlice `toml:"location-labels,omitempty" json:"location-labels"` }
ReplicationConfig is the replication configuration.
type ScheduleConfig ¶
type ScheduleConfig struct { // If the snapshot count of one store is greater than this value, // it will never be used as a source or target store. MaxSnapshotCount uint64 `toml:"max-snapshot-count,omitempty" json:"max-snapshot-count"` MaxPendingPeerCount uint64 `toml:"max-pending-peer-count,omitempty" json:"max-pending-peer-count"` // If both the size of region is smaller than MaxMergeRegionSize // and the number of rows in region is smaller than MaxMergeRegionKeys, // it will try to merge with adjacent regions. MaxMergeRegionSize uint64 `toml:"max-merge-region-size,omitempty" json:"max-merge-region-size"` MaxMergeRegionKeys uint64 `toml:"max-merge-region-keys,omitempty" json:"max-merge-region-keys"` // SplitMergeInterval is the minimum interval time to permit merge after split. SplitMergeInterval typeutil.Duration `toml:"split-merge-interval,omitempty" json:"split-merge-interval"` // PatrolRegionInterval is the interval for scanning region during patrol. PatrolRegionInterval typeutil.Duration `toml:"patrol-region-interval,omitempty" json:"patrol-region-interval"` // MaxStoreDownTime is the max duration after which // a store will be considered to be down if it hasn't reported heartbeats. MaxStoreDownTime typeutil.Duration `toml:"max-store-down-time,omitempty" json:"max-store-down-time"` // LeaderScheduleLimit is the max coexist leader schedules. LeaderScheduleLimit uint64 `toml:"leader-schedule-limit,omitempty" json:"leader-schedule-limit"` // RegionScheduleLimit is the max coexist region schedules. RegionScheduleLimit uint64 `toml:"region-schedule-limit,omitempty" json:"region-schedule-limit"` // ReplicaScheduleLimit is the max coexist replica schedules. ReplicaScheduleLimit uint64 `toml:"replica-schedule-limit,omitempty" json:"replica-schedule-limit"` // MergeScheduleLimit is the max coexist merge schedules. MergeScheduleLimit uint64 `toml:"merge-schedule-limit,omitempty" json:"merge-schedule-limit"` // HotRegionScheduleLimit is the max coexist hot region schedules. HotRegionScheduleLimit uint64 `toml:"hot-region-schedule-limit,omitempty" json:"hot-region-schedule-limit"` // HotRegionCacheHitThreshold is the cache hits threshold of the hot region. // If the number of times a region hits the hot cache is greater than this // threshold, it is considered a hot region. HotRegionCacheHitsThreshold uint64 `toml:"hot-region-cache-hits-threshold,omitempty" json:"hot-region-cache-hits-threshold"` // TolerantSizeRatio is the ratio of buffer size for balance scheduler. TolerantSizeRatio float64 `toml:"tolerant-size-ratio,omitempty" json:"tolerant-size-ratio"` // // high space stage transition stage low space stage // |--------------------|-----------------------------|-------------------------| // ^ ^ ^ ^ // 0 HighSpaceRatio * capacity LowSpaceRatio * capacity capacity // // LowSpaceRatio is the lowest usage ratio of store which regraded as low space. // When in low space, store region score increases to very large and varies inversely with available size. LowSpaceRatio float64 `toml:"low-space-ratio,omitempty" json:"low-space-ratio"` // HighSpaceRatio is the highest usage ratio of store which regraded as high space. // High space means there is a lot of spare capacity, and store region score varies directly with used size. HighSpaceRatio float64 `toml:"high-space-ratio,omitempty" json:"high-space-ratio"` // DisableLearner is the option to disable using AddLearnerNode instead of AddNode DisableLearner bool `toml:"disable-raft-learner" json:"disable-raft-learner,string"` // DisableRemoveDownReplica is the option to prevent replica checker from // removing down replicas. DisableRemoveDownReplica bool `toml:"disable-remove-down-replica" json:"disable-remove-down-replica,string"` // DisableReplaceOfflineReplica is the option to prevent replica checker from // repalcing offline replicas. DisableReplaceOfflineReplica bool `toml:"disable-replace-offline-replica" json:"disable-replace-offline-replica,string"` // DisableMakeUpReplica is the option to prevent replica checker from making up // replicas when replica count is less than expected. DisableMakeUpReplica bool `toml:"disable-make-up-replica" json:"disable-make-up-replica,string"` // DisableRemoveExtraReplica is the option to prevent replica checker from // removing extra replicas. DisableRemoveExtraReplica bool `toml:"disable-remove-extra-replica" json:"disable-remove-extra-replica,string"` // DisableLocationReplacement is the option to prevent replica checker from // moving replica to a better location. DisableLocationReplacement bool `toml:"disable-location-replacement" json:"disable-location-replacement,string"` // DisableNamespaceRelocation is the option to prevent namespace checker // from moving replica to the target namespace. DisableNamespaceRelocation bool `toml:"disable-namespace-relocation" json:"disable-namespace-relocation,string"` // Schedulers support for loding customized schedulers Schedulers SchedulerConfigs `toml:"schedulers,omitempty" json:"schedulers-v2"` // json v2 is for the sake of compatible upgrade }
ScheduleConfig is the schedule configuration.
type SchedulerConfig ¶
type SchedulerConfig struct { Type string `toml:"type" json:"type"` Args []string `toml:"args,omitempty" json:"args"` Disable bool `toml:"disable" json:"disable"` }
SchedulerConfig is customized scheduler configuration
type SchedulerConfigs ¶
type SchedulerConfigs []SchedulerConfig
SchedulerConfigs is a slice of customized scheduler configuration.
type SecurityConfig ¶
type SecurityConfig struct { // CAPath is the path of file that contains list of trusted SSL CAs. if set, following four settings shouldn't be empty CAPath string `toml:"cacert-path" json:"cacert-path"` // CertPath is the path of file that contains X509 certificate in PEM format. CertPath string `toml:"cert-path" json:"cert-path"` // KeyPath is the path of file that contains X509 key in PEM format. KeyPath string `toml:"key-path" json:"key-path"` }
SecurityConfig is the configuration for supporting tls.
func (SecurityConfig) ToTLSConfig ¶
func (s SecurityConfig) ToTLSConfig() (*tls.Config, error)
ToTLSConfig generatres tls config.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the pd server.
func CreateServer ¶
CreateServer creates the UNINITIALIZED pd server with given configuration.
func (*Server) AllocID ¶
func (s *Server) AllocID(ctx context.Context, request *pdpb.AllocIDRequest) (*pdpb.AllocIDResponse, error)
AllocID implements gRPC PDServer.
func (*Server) AskBatchSplit ¶
func (s *Server) AskBatchSplit(ctx context.Context, request *pdpb.AskBatchSplitRequest) (*pdpb.AskBatchSplitResponse, error)
AskBatchSplit implements gRPC PDServer.
func (*Server) AskSplit ¶
func (s *Server) AskSplit(ctx context.Context, request *pdpb.AskSplitRequest) (*pdpb.AskSplitResponse, error)
AskSplit implements gRPC PDServer.
func (*Server) Bootstrap ¶
func (s *Server) Bootstrap(ctx context.Context, request *pdpb.BootstrapRequest) (*pdpb.BootstrapResponse, error)
Bootstrap implements gRPC PDServer.
func (*Server) CheckHealth ¶
CheckHealth checks if members are healthy
func (*Server) DeleteLabelProperty ¶
DeleteLabelProperty deletes a label property config.
func (*Server) DeleteMemberLeaderPriority ¶
DeleteMemberLeaderPriority removes a member's priority config.
func (*Server) DeleteNamespaceConfig ¶
DeleteNamespaceConfig deletes the namespace config.
func (*Server) GetAllStores ¶
func (s *Server) GetAllStores(ctx context.Context, request *pdpb.GetAllStoresRequest) (*pdpb.GetAllStoresResponse, error)
GetAllStores implements gRPC PDServer.
func (*Server) GetClusterConfig ¶
func (s *Server) GetClusterConfig(ctx context.Context, request *pdpb.GetClusterConfigRequest) (*pdpb.GetClusterConfigResponse, error)
GetClusterConfig implements gRPC PDServer.
func (*Server) GetClusterStatus ¶
func (s *Server) GetClusterStatus() (*ClusterStatus, error)
GetClusterStatus gets cluster status.
func (*Server) GetClusterVersion ¶
GetClusterVersion returns the version of cluster.
func (*Server) GetEndpoints ¶
GetEndpoints returns the etcd endpoints for outer use.
func (*Server) GetEtcdLeader ¶
GetEtcdLeader returns the etcd leader ID.
func (*Server) GetGCSafePoint ¶
func (s *Server) GetGCSafePoint(ctx context.Context, request *pdpb.GetGCSafePointRequest) (*pdpb.GetGCSafePointResponse, error)
GetGCSafePoint implements gRPC PDServer.
func (*Server) GetHandler ¶
GetHandler returns the handler for API.
func (*Server) GetLabelProperty ¶
func (s *Server) GetLabelProperty() LabelPropertyConfig
GetLabelProperty returns the whole label property config.
func (*Server) GetLeaderID ¶
GetLeaderID returns current leader's member ID.
func (*Server) GetMemberLeaderPriority ¶
GetMemberLeaderPriority loads a member's priority to be elected as the etcd leader.
func (*Server) GetMembers ¶
func (s *Server) GetMembers(context.Context, *pdpb.GetMembersRequest) (*pdpb.GetMembersResponse, error)
GetMembers implements gRPC PDServer.
func (*Server) GetNamespaceConfig ¶
func (s *Server) GetNamespaceConfig(name string) *NamespaceConfig
GetNamespaceConfig get the namespace config.
func (*Server) GetNamespaceConfigWithAdjust ¶
func (s *Server) GetNamespaceConfigWithAdjust(name string) *NamespaceConfig
GetNamespaceConfigWithAdjust get the namespace config that replace zero value with global config value.
func (*Server) GetOperator ¶
func (s *Server) GetOperator(ctx context.Context, request *pdpb.GetOperatorRequest) (*pdpb.GetOperatorResponse, error)
GetOperator gets information about the operator belonging to the speicfy region.
func (*Server) GetPrevRegion ¶
func (s *Server) GetPrevRegion(ctx context.Context, request *pdpb.GetRegionRequest) (*pdpb.GetRegionResponse, error)
GetPrevRegion implements gRPC PDServer
func (*Server) GetRaftCluster ¶
func (s *Server) GetRaftCluster() *RaftCluster
GetRaftCluster gets raft cluster. If cluster has not been bootstrapped, return nil.
func (*Server) GetRegion ¶
func (s *Server) GetRegion(ctx context.Context, request *pdpb.GetRegionRequest) (*pdpb.GetRegionResponse, error)
GetRegion implements gRPC PDServer.
func (*Server) GetRegionByID ¶
func (s *Server) GetRegionByID(ctx context.Context, request *pdpb.GetRegionByIDRequest) (*pdpb.GetRegionResponse, error)
GetRegionByID implements gRPC PDServer.
func (*Server) GetReplicationConfig ¶
func (s *Server) GetReplicationConfig() *ReplicationConfig
GetReplicationConfig get the replication config.
func (*Server) GetScheduleConfig ¶
func (s *Server) GetScheduleConfig() *ScheduleConfig
GetScheduleConfig gets the balance config information.
func (*Server) GetSecurityConfig ¶
func (s *Server) GetSecurityConfig() *SecurityConfig
GetSecurityConfig get the security config.
func (*Server) GetStore ¶
func (s *Server) GetStore(ctx context.Context, request *pdpb.GetStoreRequest) (*pdpb.GetStoreResponse, error)
GetStore implements gRPC PDServer.
func (*Server) IsBootstrapped ¶
func (s *Server) IsBootstrapped(ctx context.Context, request *pdpb.IsBootstrappedRequest) (*pdpb.IsBootstrappedResponse, error)
IsBootstrapped implements gRPC PDServer.
func (*Server) IsNamespaceExist ¶
IsNamespaceExist returns whether the namespace exists.
func (*Server) MoveEtcdLeader ¶
MoveEtcdLeader tries to transfer etcd leader.
func (*Server) PutClusterConfig ¶
func (s *Server) PutClusterConfig(ctx context.Context, request *pdpb.PutClusterConfigRequest) (*pdpb.PutClusterConfigResponse, error)
PutClusterConfig implements gRPC PDServer.
func (*Server) PutStore ¶
func (s *Server) PutStore(ctx context.Context, request *pdpb.PutStoreRequest) (*pdpb.PutStoreResponse, error)
PutStore implements gRPC PDServer.
func (*Server) RegionHeartbeat ¶
func (s *Server) RegionHeartbeat(stream pdpb.PD_RegionHeartbeatServer) error
RegionHeartbeat implements gRPC PDServer.
func (*Server) ReportBatchSplit ¶
func (s *Server) ReportBatchSplit(ctx context.Context, request *pdpb.ReportBatchSplitRequest) (*pdpb.ReportBatchSplitResponse, error)
ReportBatchSplit implements gRPC PDServer.
func (*Server) ReportSplit ¶
func (s *Server) ReportSplit(ctx context.Context, request *pdpb.ReportSplitRequest) (*pdpb.ReportSplitResponse, error)
ReportSplit implements gRPC PDServer.
func (*Server) ResignLeader ¶
ResignLeader resigns current PD's leadership. If nextLeader is empty, all other pd-servers can campaign.
func (*Server) ScatterRegion ¶
func (s *Server) ScatterRegion(ctx context.Context, request *pdpb.ScatterRegionRequest) (*pdpb.ScatterRegionResponse, error)
ScatterRegion implements gRPC PDServer.
func (*Server) SetClusterVersion ¶
SetClusterVersion sets the version of cluster.
func (*Server) SetLabelProperty ¶
SetLabelProperty inserts a label property config.
func (*Server) SetLogLevel ¶ added in v1.0.7
SetLogLevel sets log level.
func (*Server) SetMemberLeaderPriority ¶
SetMemberLeaderPriority saves a member's priority to be elected as the etcd leader.
func (*Server) SetNamespaceConfig ¶
func (s *Server) SetNamespaceConfig(name string, cfg NamespaceConfig)
SetNamespaceConfig sets the namespace config.
func (*Server) SetReplicationConfig ¶
func (s *Server) SetReplicationConfig(cfg ReplicationConfig) error
SetReplicationConfig sets the replication config.
func (*Server) SetScheduleConfig ¶
func (s *Server) SetScheduleConfig(cfg ScheduleConfig) error
SetScheduleConfig sets the balance config information.
func (*Server) StoreHeartbeat ¶
func (s *Server) StoreHeartbeat(ctx context.Context, request *pdpb.StoreHeartbeatRequest) (*pdpb.StoreHeartbeatResponse, error)
StoreHeartbeat implements gRPC PDServer.
func (*Server) Tso ¶
func (s *Server) Tso(stream pdpb.PD_TsoServer) error
Tso implements gRPC PDServer.
func (*Server) UpdateGCSafePoint ¶
func (s *Server) UpdateGCSafePoint(ctx context.Context, request *pdpb.UpdateGCSafePointRequest) (*pdpb.UpdateGCSafePointResponse, error)
UpdateGCSafePoint implements gRPC PDServer.
type StoreLabel ¶
type StoreLabel struct { Key string `toml:"key" json:"key"` Value string `toml:"value" json:"value"` }
StoreLabel is the config item of LabelPropertyConfig.