server

package
v0.0.0-...-b3bb260 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2024 License: Apache-2.0 Imports: 42 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotBootstrapped is error info for cluster not bootstrapped.
	ErrNotBootstrapped = errors.New("TiKV cluster not bootstrapped, please start TiKV first")
	// ErrServerNotStarted is error info for server not started.
	ErrServerNotStarted = errors.New("The server has not been started")
	// 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)
	}
	// ErrStoreNotFound is error info for store not found.
	ErrStoreNotFound = func(storeID uint64) error {
		return errors.Errorf("store %v not found", storeID)
	}
)
View Source
var (
	PDReleaseVersion = "None"
	PDBuildTS        = "None"
	PDGitHash        = "None"
	PDGitBranch      = "None"
)

Version information.

View Source
var EnableZap = false

EnableZap enable the zap logger in embed etcd.

Functions

func GetMembers

func GetMembers(etcdClient *clientv3.Client) ([]*schedulerpb.Member, error)

GetMembers return a slice of Members.

func InitHTTPClient

func InitHTTPClient(svr *Server) error

InitHTTPClient initials a http client.

func LogPDInfo

func LogPDInfo()

LogPDInfo prints the PD version information.

func NewTestMultiConfig

func NewTestMultiConfig(c *check.C, count int) []*config.Config

NewTestMultiConfig is only for test to create multiple pd configurations. Because PD client also needs this, so export here.

func NewTestServer

func NewTestServer(c *check.C) (*Server, CleanupFunc, error)

NewTestServer creates a pd server for testing.

func NewTestSingleConfig

func NewTestSingleConfig(c *check.C) *config.Config

NewTestSingleConfig is only for test to create one pd. Because PD client also needs this, so export here.

func PrintConfigCheckMsg

func PrintConfigCheckMsg(cfg *config.Config)

PrintConfigCheckMsg prints the message about configuration checks.

func PrintPDInfo

func PrintPDInfo()

PrintPDInfo prints the PD version information without log info.

Types

type CleanupFunc

type CleanupFunc func()

CleanupFunc closes test pd server(s) and deletes any files left behind.

type ClusterStatus

type ClusterStatus struct {
	RaftBootstrapTime time.Time `json:"raft_bootstrap_time,omitempty"`
	IsInitialized     bool      `json:"is_initialized"`
}

ClusterStatus saves some state information

type RaftCluster

type RaftCluster struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

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

func (c *RaftCluster) AllocPeer(storeID uint64) (*metapb.Peer, error)

AllocPeer allocs a new peer on a store.

func (*RaftCluster) AttachAvailableFunc

func (c *RaftCluster) AttachAvailableFunc(storeID uint64, f func() bool)

AttachAvailableFunc attaches an available function to a specific store.

func (*RaftCluster) BlockStore

func (c *RaftCluster) BlockStore(storeID uint64) error

BlockStore stops balancer from selecting the store.

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

func (c *RaftCluster) GetAverageRegionSize() int64

GetAverageRegionSize returns the average region approximate size.

func (*RaftCluster) GetConfig

func (c *RaftCluster) GetConfig() *metapb.Cluster

GetConfig gets config from cluster.

func (*RaftCluster) GetCoordinator

func (c *RaftCluster) GetCoordinator() *coordinator

GetCoordinator returns the coordinator.

func (*RaftCluster) GetFollowerStores

func (c *RaftCluster) GetFollowerStores(region *core.RegionInfo) []*core.StoreInfo

GetFollowerStores returns all stores that contains the region's follower peer.

func (*RaftCluster) GetFollowersWithLock

func (c *RaftCluster) GetFollowersWithLock(storeID uint64, callback func(core.RegionsContainer))

GetFollowersWithLock return leaders subtree by storeID

func (*RaftCluster) GetHeartbeatStreams

func (c *RaftCluster) GetHeartbeatStreams() *heartbeatStreams

GetHeartbeatStreams returns the heartbeat streams.

func (*RaftCluster) GetLeaderScheduleLimit

func (c *RaftCluster) GetLeaderScheduleLimit() uint64

GetLeaderScheduleLimit returns the limit for leader schedule.

func (*RaftCluster) GetLeaderStore

func (c *RaftCluster) GetLeaderStore(region *core.RegionInfo) *core.StoreInfo

GetLeaderStore returns all stores that contains the region's leader peer.

func (*RaftCluster) GetLeadersWithLock

func (c *RaftCluster) GetLeadersWithLock(storeID uint64, callback func(core.RegionsContainer))

GetLeadersWithLock return leaders subtree by storeID

func (*RaftCluster) GetMaxReplicas

func (c *RaftCluster) GetMaxReplicas() int

GetMaxReplicas returns the number of replicas.

func (*RaftCluster) GetMaxStoreDownTime

func (c *RaftCluster) GetMaxStoreDownTime() time.Duration

GetMaxStoreDownTime returns the max down time of a store.

func (*RaftCluster) GetMetaRegions

func (c *RaftCluster) GetMetaRegions() []*metapb.Region

GetMetaRegions gets regions from cluster.

func (*RaftCluster) GetMetaStores

func (c *RaftCluster) GetMetaStores() []*metapb.Store

GetMetaStores gets stores from cluster.

func (*RaftCluster) GetOperatorController

func (c *RaftCluster) GetOperatorController() *schedule.OperatorController

GetOperatorController returns the operator controller.

func (*RaftCluster) GetOpt

func (c *RaftCluster) GetOpt() *config.ScheduleOption

GetOpt returns the scheduling options.

func (*RaftCluster) GetPatrolRegionInterval

func (c *RaftCluster) GetPatrolRegionInterval() time.Duration

GetPatrolRegionInterval returns the interval of patroling region.

func (*RaftCluster) GetPendingRegionsWithLock

func (c *RaftCluster) GetPendingRegionsWithLock(storeID uint64, callback func(core.RegionsContainer))

GetPendingRegionsWithLock return pending regions subtree by storeID

func (*RaftCluster) GetPrevRegionByKey

func (c *RaftCluster) GetPrevRegionByKey(regionKey []byte) (*metapb.Region, *metapb.Peer)

GetPrevRegionByKey gets previous region and leader peer by the region key from cluster.

func (*RaftCluster) GetRegion

func (c *RaftCluster) GetRegion(regionID uint64) *core.RegionInfo

GetRegion searches for a region by ID.

func (*RaftCluster) GetRegionByID

func (c *RaftCluster) GetRegionByID(regionID uint64) (*metapb.Region, *metapb.Peer)

GetRegionByID gets region and leader peer by regionID from cluster.

func (*RaftCluster) GetRegionByKey

func (c *RaftCluster) GetRegionByKey(regionKey []byte) (*metapb.Region, *metapb.Peer)

GetRegionByKey gets region and leader peer by region key from cluster.

func (*RaftCluster) GetRegionCount

func (c *RaftCluster) GetRegionCount() int

GetRegionCount returns total count of regions

func (*RaftCluster) GetRegionInfoByKey

func (c *RaftCluster) GetRegionInfoByKey(regionKey []byte) *core.RegionInfo

GetRegionInfoByKey gets regionInfo by region key from cluster.

func (*RaftCluster) GetRegionScheduleLimit

func (c *RaftCluster) GetRegionScheduleLimit() uint64

GetRegionScheduleLimit returns the limit for region schedule.

func (*RaftCluster) GetRegionStores

func (c *RaftCluster) GetRegionStores(region *core.RegionInfo) []*core.StoreInfo

GetRegionStores returns all stores that contains the region's peer.

func (*RaftCluster) GetRegions

func (c *RaftCluster) GetRegions() []*core.RegionInfo

GetRegions returns all regions' information in detail.

func (*RaftCluster) GetReplicaScheduleLimit

func (c *RaftCluster) GetReplicaScheduleLimit() uint64

GetReplicaScheduleLimit returns the limit for replica schedule.

func (*RaftCluster) GetStore

func (c *RaftCluster) GetStore(storeID uint64) *core.StoreInfo

GetStore gets store from cluster.

func (*RaftCluster) GetStoreRegionCount

func (c *RaftCluster) GetStoreRegionCount(storeID uint64) int

GetStoreRegionCount returns the number of regions for a given store.

func (*RaftCluster) GetStoreRegions

func (c *RaftCluster) GetStoreRegions(storeID uint64) []*core.RegionInfo

GetStoreRegions returns all regions' information with a given storeID.

func (*RaftCluster) GetStores

func (c *RaftCluster) GetStores() []*core.StoreInfo

GetStores returns all stores in the cluster.

func (*RaftCluster) HandleRegionHeartbeat

func (c *RaftCluster) HandleRegionHeartbeat(region *core.RegionInfo) error

HandleRegionHeartbeat processes RegionInfo reports from client.

func (*RaftCluster) RandFollowerRegion

func (c *RaftCluster) RandFollowerRegion(storeID uint64, opts ...core.RegionOption) *core.RegionInfo

RandFollowerRegion returns a random region that has a follower on the store.

func (*RaftCluster) RandLeaderRegion

func (c *RaftCluster) RandLeaderRegion(storeID uint64, opts ...core.RegionOption) *core.RegionInfo

RandLeaderRegion returns a random region that has leader on the store.

func (*RaftCluster) RandPendingRegion

func (c *RaftCluster) RandPendingRegion(storeID uint64, opts ...core.RegionOption) *core.RegionInfo

RandPendingRegion returns a random region that has a pending peer on the store.

func (*RaftCluster) RemoveStore

func (c *RaftCluster) RemoveStore(storeID uint64) error

RemoveStore marks a store as offline in cluster. State transition: Up -> Offline.

func (*RaftCluster) RemoveTombStoneRecords

func (c *RaftCluster) RemoveTombStoneRecords() error

RemoveTombStoneRecords removes the tombStone Records.

func (*RaftCluster) ScanRegions

func (c *RaftCluster) ScanRegions(startKey, endKey []byte, limit int) []*core.RegionInfo

ScanRegions scans region with start key, until the region contains endKey, or total number greater than limit.

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, leaderWeight, regionWeight float64) error

SetStoreWeight sets up a store's leader/region balance weight.

func (*RaftCluster) UnblockStore

func (c *RaftCluster) UnblockStore(storeID uint64)

UnblockStore allows balancer to select the store.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is the pd server.

func CreateServer

func CreateServer(cfg *config.Config) (*Server, error)

CreateServer creates the UNINITIALIZED pd server with given configuration.

func (*Server) AllocID

AllocID implements gRPC PDServer.

func (*Server) AskSplit

AskSplit implements gRPC PDServer.

func (*Server) Bootstrap

Bootstrap implements gRPC PDServer.

func (*Server) CheckHealth

func (s *Server) CheckHealth(members []*schedulerpb.Member) map[uint64]*schedulerpb.Member

CheckHealth checks if members are healthy.

func (*Server) Close

func (s *Server) Close()

Close closes the server.

func (*Server) ClusterID

func (s *Server) ClusterID() uint64

ClusterID returns the cluster ID of this server.

func (*Server) Context

func (s *Server) Context() context.Context

Context returns the loop context of server.

func (*Server) GetAddr

func (s *Server) GetAddr() string

GetAddr returns the server urls for clients.

func (*Server) GetAllStores

GetAllStores implements gRPC PDServer.

func (*Server) GetAllocator

func (s *Server) GetAllocator() *id.AllocatorImpl

GetAllocator returns the ID allocator of server.

func (*Server) GetClient

func (s *Server) GetClient() *clientv3.Client

GetClient returns builtin etcd client.

func (*Server) GetCluster

func (s *Server) GetCluster() *metapb.Cluster

GetCluster gets cluster.

func (*Server) GetClusterConfig

GetClusterConfig implements gRPC PDServer.

func (*Server) GetClusterStatus

func (s *Server) GetClusterStatus() (*ClusterStatus, error)

GetClusterStatus gets cluster status.

func (*Server) GetConfig

func (s *Server) GetConfig() *config.Config

GetConfig gets the config information.

func (*Server) GetEndpoints

func (s *Server) GetEndpoints() []string

GetEndpoints returns the etcd endpoints for outer use.

func (*Server) GetGCSafePoint

GetGCSafePoint implements gRPC PDServer.

func (*Server) GetLeader

func (s *Server) GetLeader() *schedulerpb.Member

GetLeader returns leader of etcd.

func (*Server) GetMember

func (s *Server) GetMember() *member.Member

GetMember returns the member of server.

func (*Server) GetMemberInfo

func (s *Server) GetMemberInfo() *schedulerpb.Member

GetMemberInfo returns the server member information.

func (*Server) GetMembers

GetMembers implements gRPC PDServer.

func (*Server) GetMetaRegions

func (s *Server) GetMetaRegions() []*metapb.Region

GetMetaRegions gets meta regions from cluster.

func (*Server) GetOperator

GetOperator gets information about the operator belonging to the speicfy region.

func (*Server) GetPrevRegion

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

GetRegion implements gRPC PDServer.

func (*Server) GetRegionByID

GetRegionByID implements gRPC PDServer.

func (*Server) GetReplicationConfig

func (s *Server) GetReplicationConfig() *config.ReplicationConfig

GetReplicationConfig get the replication config.

func (*Server) GetScheduleConfig

func (s *Server) GetScheduleConfig() *config.ScheduleConfig

GetScheduleConfig gets the balance config information.

func (*Server) GetSecurityConfig

func (s *Server) GetSecurityConfig() *config.SecurityConfig

GetSecurityConfig get the security config.

func (*Server) GetStorage

func (s *Server) GetStorage() *core.Storage

GetStorage returns the backend storage of server.

func (*Server) GetStore

GetStore implements gRPC PDServer.

func (*Server) IsBootstrapped

IsBootstrapped implements gRPC PDServer.

func (*Server) IsClosed

func (s *Server) IsClosed() bool

IsClosed checks whether server is closed or not.

func (*Server) Name

func (s *Server) Name() string

Name returns the unique etcd Name for this server in etcd cluster.

func (*Server) PutClusterConfig

PutClusterConfig implements gRPC PDServer.

func (*Server) PutStore

PutStore implements gRPC PDServer.

func (*Server) RegionHeartbeat

func (s *Server) RegionHeartbeat(stream schedulerpb.Scheduler_RegionHeartbeatServer) error

RegionHeartbeat implements gRPC PDServer.

func (*Server) ReportSplit

ReportSplit implements gRPC PDServer.

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

Run runs the pd server.

func (*Server) ScanRegions

ScanRegions implements gRPC PDServer.

func (*Server) ScatterRegion

ScatterRegion implements gRPC PDServer.

func (*Server) SetLogLevel

func (s *Server) SetLogLevel(level string)

SetLogLevel sets log level.

func (*Server) SetReplicationConfig

func (s *Server) SetReplicationConfig(cfg config.ReplicationConfig) error

SetReplicationConfig sets the replication config.

func (*Server) StoreHeartbeat

StoreHeartbeat implements gRPC PDServer.

func (*Server) Tso

Tso implements gRPC PDServer.

func (*Server) UpdateGCSafePoint

UpdateGCSafePoint implements gRPC PDServer.

Directories

Path Synopsis
Package core defines core characteristics of the server.
Package core defines core characteristics of the server.
opt

Jump to

Keyboard shortcuts

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