Documentation
¶
Index ¶
- Constants
- func NewRPCHandler(server *Server) pdpb.PDServiceServer
- func RedirectEmbedEtcdLog(w io.Writer)
- type CellCluster
- type CellInfo
- type Cfg
- type ClusterInfo
- type ClusterStore
- type Filter
- type IDStore
- type IndexStore
- type LeaderStore
- type Operator
- type RPCHandler
- func (h *RPCHandler) AllocID(c context.Context, req *pdpb.AllocIDReq) (*pdpb.AllocIDRsp, error)
- func (h *RPCHandler) AskSplit(c context.Context, req *pdpb.AskSplitReq) (*pdpb.AskSplitRsp, error)
- func (h *RPCHandler) BootstrapCluster(c context.Context, req *pdpb.BootstrapClusterReq) (*pdpb.BootstrapClusterRsp, error)
- func (h *RPCHandler) CellHeartbeat(c context.Context, req *pdpb.CellHeartbeatReq) (*pdpb.CellHeartbeatRsp, error)
- func (h *RPCHandler) GetClusterID(c context.Context, req *pdpb.GetClusterIDReq) (*pdpb.GetClusterIDRsp, error)
- func (h *RPCHandler) GetInitParams(c context.Context, req *pdpb.GetInitParamsReq) (*pdpb.GetInitParamsRsp, error)
- func (h *RPCHandler) GetLastRanges(c context.Context, req *pdpb.GetLastRangesReq) (*pdpb.GetLastRangesRsp, error)
- func (h *RPCHandler) GetLeader(c context.Context, req *pdpb.LeaderReq) (*pdpb.LeaderRsp, error)
- func (h *RPCHandler) GetStore(c context.Context, req *pdpb.GetStoreReq) (*pdpb.GetStoreRsp, error)
- func (h *RPCHandler) IsClusterBootstrap(c context.Context, req *pdpb.IsClusterBootstrapReq) (*pdpb.IsClusterBootstrapRsp, error)
- func (h *RPCHandler) ListStore(c context.Context, req *pdpb.ListStoreReq) (*pdpb.ListStoreRsp, error)
- func (h *RPCHandler) PutStore(c context.Context, req *pdpb.PutStoreReq) (*pdpb.PutStoreRsp, error)
- func (h *RPCHandler) RegisterWatcher(c context.Context, req *pdpb.RegisterWatcherReq) (*pdpb.RegisterWatcherRsp, error)
- func (h *RPCHandler) ReportSplit(c context.Context, req *pdpb.ReportSplitReq) (*pdpb.ReportSplitRsp, error)
- func (h *RPCHandler) StoreHeartbeat(c context.Context, req *pdpb.StoreHeartbeatReq) (*pdpb.StoreHeartbeatRsp, error)
- func (h *RPCHandler) WatcherHeartbeat(c context.Context, req *pdpb.WatcherHeartbeatReq) (*pdpb.WatcherHeartbeatRsp, error)
- type ReplicationCfg
- type ResourceKind
- type Scheduler
- type Selector
- type Server
- func (s *Server) CreateIndex(idxDef *pdpb.IndexDef) (err error)
- func (s *Server) DeleteIndex(id string) (err error)
- func (s *Server) DeleteStore(id uint64, force bool) error
- func (s *Server) GetCell(id uint64) (*pdapi.CellInfo, error)
- func (s *Server) GetCellCluster() *CellCluster
- func (s *Server) GetCfg() *Cfg
- func (s *Server) GetClusterID() uint64
- func (s *Server) GetIndex(id string) (idxDef *pdpb.IndexDef, err error)
- func (s *Server) GetInitParamsValue() ([]byte, error)
- func (s *Server) GetLeader() (*pdpb.Leader, error)
- func (s *Server) GetLeaderProxy() *pd.Client
- func (s *Server) GetOperator(id uint64) (interface{}, error)
- func (s *Server) GetOperators() ([]interface{}, error)
- func (s *Server) GetStore(id uint64) (*pdapi.StoreInfo, error)
- func (s *Server) GetSystem() (*pdapi.System, error)
- func (s *Server) InitCluster(params *pdapi.InitParams) error
- func (s *Server) IsLeader() bool
- func (s *Server) ListCell() ([]*pdapi.CellInfo, error)
- func (s *Server) ListCellInStore(storeID uint64) ([]*pdapi.CellInfo, error)
- func (s *Server) ListIndex() (idxDefs []*pdpb.IndexDef, err error)
- func (s *Server) ListStore() ([]*pdapi.StoreInfo, error)
- func (s *Server) Name() string
- func (s *Server) SetStoreLogLevel(set *pdapi.SetLogLevel) error
- func (s *Server) Start()
- func (s *Server) Stop()
- func (s *Server) TransferLeader(transfer *pdapi.TransferLeader) error
- type Store
- type StoreInfo
- type StoreOperator
- type StoreStatus
Constants ¶
const ( // DefaultTimeout default timeout DefaultTimeout = time.Second * 3 // DefaultRequestTimeout default request timeout DefaultRequestTimeout = 10 * time.Second // DefaultSlowRequestTime default slow request time DefaultSlowRequestTime = time.Second * 1 )
const (
// Version pd server version
Version = "1.0.0"
)
Variables ¶
This section is empty.
Functions ¶
func NewRPCHandler ¶
func NewRPCHandler(server *Server) pdpb.PDServiceServer
NewRPCHandler create a new instance
func RedirectEmbedEtcdLog ¶
RedirectEmbedEtcdLog because of our used embed etcd, so we need redirect etcd log to spec.
Types ¶
type CellCluster ¶
type CellCluster struct {
// contains filtered or unexported fields
}
CellCluster is used for cluster config management.
type CellInfo ¶
type CellInfo struct {
Meta metapb.Cell
LeaderPeer *metapb.Peer
DownPeers []pdpb.PeerStats
PendingPeers []metapb.Peer
}
CellInfo The cell info
type Cfg ¶
type Cfg struct {
Name string
DataPath string
AddrRPC string
DurationLeaderLease int64
DurationHeartbeatWatcher time.Duration
ThresholdPauseWatcher int
URLsClient string
URLsAdvertiseClient string
URLsPeer string
URLsAdvertisePeer string
InitialCluster string
InitialClusterState string
// 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.
LabelsLocation []string
// LimitReplicas is the number of replicas for each cell.
LimitReplicas uint32
// If the snapshot count of one store is greater than this value,
// it will never be used as a source or target store.
LimitSnapshots uint64
// MaxStoreDownTime is the max duration after which
// a store will be considered to be down if it hasn't reported heartbeats.
LimitStoreDownDuration time.Duration
// LimitScheduleLeader is the max coexist leader schedules.
LimitScheduleLeader uint64
// LimitScheduleCell is the max coexist cell schedules.
LimitScheduleCell uint64
// LimitScheduleReplica is the max coexist replica schedules.
LimitScheduleReplica uint64
// ThresholdStorageRate is the max storage rate of used for schduler
ThresholdStorageRate int
}
Cfg pd server Cfg
type ClusterInfo ¶
ClusterInfo The cluster info
type ClusterStore ¶
type ClusterStore interface {
SetInitParams(clusterID uint64, params string) error
GetInitParams(clusterID uint64) ([]byte, error)
GetCurrentClusterMembers() (*clientv3.MemberListResponse, error)
GetClusterID() (uint64, error)
CreateFirstClusterID() (uint64, error)
SetClusterBootstrapped(clusterID uint64, cluster metapb.Cluster, store metapb.Store, cells []metapb.Cell) (bool, error)
LoadClusterMeta(clusterID uint64) (*metapb.Cluster, error)
LoadStoreMeta(clusterID uint64, limit int64, do func(metapb.Store)) error
LoadCellMeta(clusterID uint64, limit int64, do func(metapb.Cell)) error
LoadWatchers(clusterID uint64, limit int64, do func(pdpb.Watcher)) error
SetStoreMeta(clusterID uint64, store metapb.Store) error
SetCellMeta(clusterID uint64, cell metapb.Cell) error
SetWatchers(clusterID uint64, watcher pdpb.Watcher) error
}
ClusterStore is the store interface for cluster info
type IDStore ¶
type IDStore interface {
GetID() (uint64, error)
CreateID(leaderSignature string, value uint64) error
UpdateID(leaderSignature string, old, value uint64) error
}
IDStore is the store interface for id info
type IndexStore ¶
type IndexStore interface {
ListIndex() (idxDefs []*pdpb.IndexDef, err error)
GetIndex(id string) (idxDef *pdpb.IndexDef, err error)
CreateIndex(idxDef *pdpb.IndexDef) (err error)
DeleteIndex(id string) (err error)
}
IndexStore is the store interface for index info
type LeaderStore ¶
type LeaderStore interface {
// CampaignLeader is for leader election
// if we are win the leader election, the enableLeaderFun will call, otherwrise disableLeaderFun will call
CampaignLeader(leaderSignature string, leaderLeaseTTL int64, enableLeaderFun, disableLeaderFun func()) error
// WatchLeader watch leader,
// this funcation will return unitl the leader's lease is timeout
// or server closed
WatchLeader()
// ResignLeader delete leader itself and let others start a new election again.
ResignLeader(leaderSignature string) error
// GetCurrentLeader return current leader
GetCurrentLeader() (*pdpb.Leader, error)
}
LeaderStore is the store interface for leader info
type Operator ¶
type Operator interface {
GetCellID() uint64
GetResourceKind() ResourceKind
Do(cell *CellInfo) (*pdpb.CellHeartbeatRsp, bool)
}
Operator is an interface to scheduler cell
type RPCHandler ¶
type RPCHandler struct {
// contains filtered or unexported fields
}
RPCHandler it's a grpc interface implemention
func (*RPCHandler) AllocID ¶
func (h *RPCHandler) AllocID(c context.Context, req *pdpb.AllocIDReq) (*pdpb.AllocIDRsp, error)
AllocID returns alloc id for kv node
func (*RPCHandler) AskSplit ¶
func (h *RPCHandler) AskSplit(c context.Context, req *pdpb.AskSplitReq) (*pdpb.AskSplitRsp, error)
AskSplit returns ask split response
func (*RPCHandler) BootstrapCluster ¶
func (h *RPCHandler) BootstrapCluster(c context.Context, req *pdpb.BootstrapClusterReq) (*pdpb.BootstrapClusterRsp, error)
BootstrapCluster returns bootstrap cluster response
func (*RPCHandler) CellHeartbeat ¶
func (h *RPCHandler) CellHeartbeat(c context.Context, req *pdpb.CellHeartbeatReq) (*pdpb.CellHeartbeatRsp, error)
CellHeartbeat returns cell heartbeat response
func (*RPCHandler) GetClusterID ¶
func (h *RPCHandler) GetClusterID(c context.Context, req *pdpb.GetClusterIDReq) (*pdpb.GetClusterIDRsp, error)
GetClusterID returns cluster id
func (*RPCHandler) GetInitParams ¶
func (h *RPCHandler) GetInitParams(c context.Context, req *pdpb.GetInitParamsReq) (*pdpb.GetInitParamsRsp, error)
GetInitParams returns cluster init params
func (*RPCHandler) GetLastRanges ¶
func (h *RPCHandler) GetLastRanges(c context.Context, req *pdpb.GetLastRangesReq) (*pdpb.GetLastRangesRsp, error)
GetLastRanges returns lastest key ranges
func (*RPCHandler) GetStore ¶
func (h *RPCHandler) GetStore(c context.Context, req *pdpb.GetStoreReq) (*pdpb.GetStoreRsp, error)
GetStore get store info
func (*RPCHandler) IsClusterBootstrap ¶
func (h *RPCHandler) IsClusterBootstrap(c context.Context, req *pdpb.IsClusterBootstrapReq) (*pdpb.IsClusterBootstrapRsp, error)
IsClusterBootstrap returns cluster is bootstrap already
func (*RPCHandler) ListStore ¶
func (h *RPCHandler) ListStore(c context.Context, req *pdpb.ListStoreReq) (*pdpb.ListStoreRsp, error)
ListStore puts store
func (*RPCHandler) PutStore ¶
func (h *RPCHandler) PutStore(c context.Context, req *pdpb.PutStoreReq) (*pdpb.PutStoreRsp, error)
PutStore puts store
func (*RPCHandler) RegisterWatcher ¶
func (h *RPCHandler) RegisterWatcher(c context.Context, req *pdpb.RegisterWatcherReq) (*pdpb.RegisterWatcherRsp, error)
RegisterWatcher regsiter a watcher for newest cell info notify
func (*RPCHandler) ReportSplit ¶
func (h *RPCHandler) ReportSplit(c context.Context, req *pdpb.ReportSplitReq) (*pdpb.ReportSplitRsp, error)
ReportSplit returns report split response
func (*RPCHandler) StoreHeartbeat ¶
func (h *RPCHandler) StoreHeartbeat(c context.Context, req *pdpb.StoreHeartbeatReq) (*pdpb.StoreHeartbeatRsp, error)
StoreHeartbeat returns store heartbeat response
func (*RPCHandler) WatcherHeartbeat ¶
func (h *RPCHandler) WatcherHeartbeat(c context.Context, req *pdpb.WatcherHeartbeatReq) (*pdpb.WatcherHeartbeatRsp, error)
WatcherHeartbeat update the watcher lastest alive time
type ReplicationCfg ¶
type ReplicationCfg struct {
sync.RWMutex
// MaxReplicas is the number of replicas for each cell.
MaxReplicas uint32 `json:"maxReplicas"`
// 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 []string `json:"location-labels"`
}
ReplicationCfg is the replication configuration.
type Scheduler ¶
type Scheduler interface {
GetName() string
GetResourceKind() ResourceKind
GetResourceLimit() uint64
Prepare(cache *cache) error
Cleanup(cache *cache)
Schedule(cache *cache) Operator
}
Scheduler is an interface to schedule resources.
type Selector ¶
type Selector interface {
SelectSource(stores []*StoreInfo, filters ...Filter) *StoreInfo
SelectTarget(stores []*StoreInfo, filters ...Filter) *StoreInfo
}
Selector is an interface to select source and target store to schedule.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server the pd server
func NewTestMultiServers ¶
NewTestMultiServers returns multi pd server
func NewTestSingleServer ¶
func NewTestSingleServer() *Server
NewTestSingleServer returns a single pd server
func (*Server) DeleteIndex ¶
func (*Server) DeleteStore ¶
DeleteStore remove the store from cluster all cells on this store will move to another stores
func (*Server) GetCellCluster ¶
func (s *Server) GetCellCluster() *CellCluster
GetCellCluster returns current cell cluster if not bootstrap, return nil
func (*Server) GetClusterID ¶
GetClusterID returns cluster id
func (*Server) GetInitParamsValue ¶
GetInitParamsValue returns cluster init params bytes
func (*Server) GetLeaderProxy ¶
GetLeaderProxy returns current leader proxy
func (*Server) GetOperator ¶
GetOperator get current operator with id
func (*Server) GetOperators ¶
GetOperators returns the current schedule operators
func (*Server) InitCluster ¶
func (s *Server) InitCluster(params *pdapi.InitParams) error
InitCluster init cluster
func (*Server) ListCellInStore ¶
ListCellInStore returns all cells info in the store
func (*Server) SetStoreLogLevel ¶
func (s *Server) SetStoreLogLevel(set *pdapi.SetLogLevel) error
SetStoreLogLevel set store log level
func (*Server) TransferLeader ¶
func (s *Server) TransferLeader(transfer *pdapi.TransferLeader) error
TransferLeader transfer cell leader to the spec peer
type Store ¶
type Store interface {
ClusterStore
IDStore
LeaderStore
IndexStore
Close() error
RawClient() *clientv3.Client
}
Store is the store interface for all pd store info
type StoreInfo ¶
type StoreInfo struct {
Meta metapb.Store
Status *StoreStatus
}
StoreInfo store info
type StoreOperator ¶
type StoreOperator interface {
GetStoreID() uint64
Do(store *StoreInfo) (*pdpb.StoreHeartbeatRsp, bool)
}
StoreOperator is an interface to operate store
type StoreStatus ¶
type StoreStatus struct {
Stats *pdpb.StoreStats
LeaderCount uint32
LastHeartbeatTS time.Time
// contains filtered or unexported fields
}
StoreStatus contains information about a store's status.
Source Files
¶
- alloc.go
- api_handler.go
- balancer.go
- balancer_cell.go
- balancer_leader.go
- cache.go
- cache_cell.go
- cache_clone.go
- cache_store.go
- cfg.go
- cfg_embed_etcd.go
- cfg_replication.go
- cluster.go
- coordinator.go
- errors.go
- filter.go
- operator.go
- operator_aggregation.go
- operator_peer.go
- operator_store.go
- operator_transfer.go
- replication.go
- rpc.go
- rpc_handler.go
- rpc_proxy.go
- scheduler.go
- selector.go
- server.go
- server_embed_etcd.go
- server_leader.go
- store.go
- store_cluster.go
- store_id.go
- store_index.go
- store_leader.go
- util.go
- util_mock.go
- version.go
- watcher.go