pdserver

package
v0.0.0-...-f0aa2c5 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2021 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
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
)
View Source
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

func RedirectEmbedEtcdLog(w io.Writer)

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

type ClusterInfo struct {
	Meta metapb.Cluster `json:"meta"`
}

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 Filter

type Filter interface {
	FilterSource(store *StoreInfo) bool
	FilterTarget(store *StoreInfo) bool
}

Filter is used for filter store

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

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

func (h *RPCHandler) GetLeader(c context.Context, req *pdpb.LeaderReq) (*pdpb.LeaderRsp, error)

GetLeader returns current leader

func (*RPCHandler) GetStore

func (h *RPCHandler) GetStore(c context.Context, req *pdpb.GetStoreReq) (*pdpb.GetStoreRsp, error)

GetStore get store info

func (*RPCHandler) IsClusterBootstrap

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

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

StoreHeartbeat returns store heartbeat response

func (*RPCHandler) WatcherHeartbeat

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 ResourceKind

type ResourceKind int

ResourceKind distinguishes different kinds of resources.

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 NewServer

func NewServer(cfg *Cfg) *Server

NewServer create a pd server

func NewTestMultiServers

func NewTestMultiServers(count int) []*Server

NewTestMultiServers returns multi pd server

func NewTestSingleServer

func NewTestSingleServer() *Server

NewTestSingleServer returns a single pd server

func (*Server) CreateIndex

func (s *Server) CreateIndex(idxDef *pdpb.IndexDef) (err error)

func (*Server) DeleteIndex

func (s *Server) DeleteIndex(id string) (err error)

func (*Server) DeleteStore

func (s *Server) DeleteStore(id uint64, force bool) error

DeleteStore remove the store from cluster all cells on this store will move to another stores

func (*Server) GetCell

func (s *Server) GetCell(id uint64) (*pdapi.CellInfo, error)

GetCell return the cell with the id

func (*Server) GetCellCluster

func (s *Server) GetCellCluster() *CellCluster

GetCellCluster returns current cell cluster if not bootstrap, return nil

func (*Server) GetCfg

func (s *Server) GetCfg() *Cfg

GetCfg returns cfg, just for test

func (*Server) GetClusterID

func (s *Server) GetClusterID() uint64

GetClusterID returns cluster id

func (*Server) GetIndex

func (s *Server) GetIndex(id string) (idxDef *pdpb.IndexDef, err error)

GetIndex returns the info of given index

func (*Server) GetInitParamsValue

func (s *Server) GetInitParamsValue() ([]byte, error)

GetInitParamsValue returns cluster init params bytes

func (*Server) GetLeader

func (s *Server) GetLeader() (*pdpb.Leader, error)

GetLeader returns current leader pd for API

func (*Server) GetLeaderProxy

func (s *Server) GetLeaderProxy() *pd.Client

GetLeaderProxy returns current leader proxy

func (*Server) GetOperator

func (s *Server) GetOperator(id uint64) (interface{}, error)

GetOperator get current operator with id

func (*Server) GetOperators

func (s *Server) GetOperators() ([]interface{}, error)

GetOperators returns the current schedule operators

func (*Server) GetStore

func (s *Server) GetStore(id uint64) (*pdapi.StoreInfo, error)

GetStore return the store with the id

func (*Server) GetSystem

func (s *Server) GetSystem() (*pdapi.System, error)

GetSystem returns the summary of elasticell cluster

func (*Server) InitCluster

func (s *Server) InitCluster(params *pdapi.InitParams) error

InitCluster init cluster

func (*Server) IsLeader

func (s *Server) IsLeader() bool

IsLeader returns whether server is leader or not.

func (*Server) ListCell

func (s *Server) ListCell() ([]*pdapi.CellInfo, error)

ListCell returns all cells info

func (*Server) ListCellInStore

func (s *Server) ListCellInStore(storeID uint64) ([]*pdapi.CellInfo, error)

ListCellInStore returns all cells info in the store

func (*Server) ListIndex

func (s *Server) ListIndex() (idxDefs []*pdpb.IndexDef, err error)

func (*Server) ListStore

func (s *Server) ListStore() ([]*pdapi.StoreInfo, error)

ListStore returns all store info

func (*Server) Name

func (s *Server) Name() string

Name returns name of current pd server

func (*Server) SetStoreLogLevel

func (s *Server) SetStoreLogLevel(set *pdapi.SetLogLevel) error

SetStoreLogLevel set store log level

func (*Server) Start

func (s *Server) Start()

Start start the pd server

func (*Server) Stop

func (s *Server) Stop()

Stop the server

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

func NewStore

func NewStore(cfg *embed.Config) (Store, error)

NewStore create a store

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.

Jump to

Keyboard shortcuts

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