server

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2025 License: Apache-2.0 Imports: 70 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotStarted        = status.Errorf(codes.Unavailable, "server not started")
	ErrClusterMismatched = status.Errorf(codes.Unavailable, "cluster mismatched")
)

gRPC errors

View Source
var SetUpRestHandler = func(*Service) (http.Handler, apiutil.APIServiceGroup) {
	return dummyRestService{}, apiutil.APIServiceGroup{}
}

SetUpRestHandler is a hook to sets up the REST service.

Functions

func CreateServerWrapper

func CreateServerWrapper(cmd *cobra.Command, args []string)

CreateServerWrapper encapsulates the configuration/log/metrics initialization and create the server

func GenerateConfig

func GenerateConfig(c *config.Config) (*config.Config, error)

GenerateConfig generates a new config with the given options.

func NewService

NewService creates a new scheduling service.

Types

type Cluster

type Cluster struct {
	*core.BasicCluster
	// contains filtered or unexported fields
}

Cluster is used to manage all information for scheduling purpose.

func NewCluster

func NewCluster(
	parentCtx context.Context,
	persistConfig *config.PersistConfig,
	storage storage.Storage,
	basicCluster *core.BasicCluster,
	hbStreams *hbstream.HeartbeatStreams,
	checkMembershipCh chan struct{},
) (*Cluster, error)

NewCluster creates a new cluster.

func (*Cluster) AllocID

func (c *Cluster) AllocID() (uint64, error)

AllocID allocates a new ID.

func (*Cluster) BucketsStats

func (c *Cluster) BucketsStats(degree int, regionIDs ...uint64) map[uint64][]*buckets.BucketStat

BucketsStats returns hot region's buckets stats.

func (*Cluster) GetBasicCluster

func (c *Cluster) GetBasicCluster() *core.BasicCluster

GetBasicCluster returns the basic cluster.

func (*Cluster) GetCheckerConfig

func (c *Cluster) GetCheckerConfig() sc.CheckerConfigProvider

GetCheckerConfig returns the checker config.

func (*Cluster) GetCoordinator

func (c *Cluster) GetCoordinator() *schedule.Coordinator

GetCoordinator returns the coordinator

func (*Cluster) GetHotPeerStat

func (c *Cluster) GetHotPeerStat(rw utils.RWType, regionID, storeID uint64) *statistics.HotPeerStat

GetHotPeerStat returns hot peer stat with specified regionID and storeID.

func (*Cluster) GetHotPeerStats

func (c *Cluster) GetHotPeerStats(rw utils.RWType) map[uint64][]*statistics.HotPeerStat

GetHotPeerStats returns the read or write statistics for hot regions. It returns a map where the keys are store IDs and the values are slices of HotPeerStat. The result only includes peers that are hot enough. GetHotPeerStats is a thread-safe method.

func (*Cluster) GetHotStat

func (c *Cluster) GetHotStat() *statistics.HotStat

GetHotStat gets hot stat.

func (*Cluster) GetKeyRangeManager

func (c *Cluster) GetKeyRangeManager() *keyrange.Manager

GetKeyRangeManager returns the key range manager

func (*Cluster) GetLabelStats

func (c *Cluster) GetLabelStats() *statistics.LabelStatistics

GetLabelStats gets label statistics.

func (*Cluster) GetRegionLabeler

func (c *Cluster) GetRegionLabeler() *labeler.RegionLabeler

GetRegionLabeler returns the region labeler.

func (*Cluster) GetRegionScatterer

func (c *Cluster) GetRegionScatterer() *scatter.RegionScatterer

GetRegionScatterer returns the region scatter.

func (*Cluster) GetRegionSplitter

func (c *Cluster) GetRegionSplitter() *splitter.RegionSplitter

GetRegionSplitter returns the region splitter.

func (*Cluster) GetRegionStats

func (c *Cluster) GetRegionStats() *statistics.RegionStatistics

GetRegionStats gets region statistics.

func (*Cluster) GetRuleManager

func (c *Cluster) GetRuleManager() *placement.RuleManager

GetRuleManager returns the rule manager.

func (*Cluster) GetSchedulerConfig

func (c *Cluster) GetSchedulerConfig() sc.SchedulerConfigProvider

GetSchedulerConfig returns the scheduler config.

func (*Cluster) GetSharedConfig

func (c *Cluster) GetSharedConfig() sc.SharedConfigProvider

GetSharedConfig returns the shared config.

func (*Cluster) GetStorage

func (c *Cluster) GetStorage() storage.Storage

GetStorage returns the storage.

func (*Cluster) GetStoreConfig

func (c *Cluster) GetStoreConfig() sc.StoreConfigProvider

GetStoreConfig returns the store config.

func (*Cluster) GetStoresLoads

func (c *Cluster) GetStoresLoads() map[uint64][]float64

GetStoresLoads returns load stats of all stores.

func (*Cluster) GetStoresStats

func (c *Cluster) GetStoresStats() *statistics.StoresStats

GetStoresStats returns stores' statistics from cluster. And it will be unnecessary to filter unhealthy store, because it has been solved in process heartbeat

func (*Cluster) HandleRegionHeartbeat

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

HandleRegionHeartbeat processes RegionInfo reports from client.

func (*Cluster) HandleStoreHeartbeat

func (c *Cluster) HandleStoreHeartbeat(heartbeat *schedulingpb.StoreHeartbeatRequest) error

HandleStoreHeartbeat updates the store status.

func (*Cluster) IsBackgroundJobsRunning

func (c *Cluster) IsBackgroundJobsRunning() bool

IsBackgroundJobsRunning returns whether the background jobs are running. Only for test purpose.

func (*Cluster) IsPrepared

func (c *Cluster) IsPrepared() bool

IsPrepared return true if the prepare checker is ready.

func (*Cluster) IsRegionHot

func (c *Cluster) IsRegionHot(region *core.RegionInfo) bool

IsRegionHot checks if a region is in hot state.

func (*Cluster) IsSchedulingHalted

func (c *Cluster) IsSchedulingHalted() bool

IsSchedulingHalted returns whether the scheduling is halted. Currently, the microservice scheduling is halted when:

  • The `HaltScheduling` persist option is set to true.

func (*Cluster) SetPrepared

func (c *Cluster) SetPrepared()

SetPrepared set the prepare check to prepared. Only for test purpose.

func (*Cluster) StartBackgroundJobs

func (c *Cluster) StartBackgroundJobs()

StartBackgroundJobs starts background jobs.

func (*Cluster) StopBackgroundJobs

func (c *Cluster) StopBackgroundJobs()

StopBackgroundJobs stops background jobs.

func (*Cluster) SwitchAPIServerLeader

func (c *Cluster) SwitchAPIServerLeader(new pdpb.PDClient) bool

SwitchAPIServerLeader switches the API server leader.

func (*Cluster) UpdateRegionsLabelLevelStats

func (c *Cluster) UpdateRegionsLabelLevelStats(regions []*core.RegionInfo)

UpdateRegionsLabelLevelStats updates the status of the region label level by types.

type ConfigProvider

type ConfigProvider any

ConfigProvider is used to get scheduling config from the given `bs.server` without modifying its interface.

type Server

type Server struct {
	*server.BaseServer
	diagnosticspb.DiagnosticsServer
	// contains filtered or unexported fields
}

Server is the scheduling server, and it implements bs.Server.

func CreateServer

func CreateServer(ctx context.Context, cfg *config.Config) *Server

CreateServer creates the Server

func NewTestServer

func NewTestServer(ctx context.Context, re *require.Assertions, cfg *config.Config) (*Server, testutil.CleanupFunc, error)

NewTestServer creates a resource manager server for testing.

func (*Server) AddServiceExitCallback

func (s *Server) AddServiceExitCallback(callbacks ...func())

AddServiceExitCallback adds callbacks when the server becomes the leader, if there is embedded etcd, or the primary otherwise.

func (*Server) AddServiceReadyCallback

func (s *Server) AddServiceReadyCallback(callbacks ...func(context.Context) error)

AddServiceReadyCallback adds callbacks when the server becomes the leader, if there is embedded etcd, or the primary otherwise.

func (*Server) Close

func (s *Server) Close()

Close closes the server.

func (*Server) GetAddr

func (s *Server) GetAddr() string

GetAddr returns the server address.

func (*Server) GetAdvertiseListenAddr

func (s *Server) GetAdvertiseListenAddr() string

GetAdvertiseListenAddr returns the advertise address of the server.

func (*Server) GetBackendEndpoints

func (s *Server) GetBackendEndpoints() string

GetBackendEndpoints returns the backend endpoints.

func (*Server) GetBasicCluster

func (s *Server) GetBasicCluster() *core.BasicCluster

GetBasicCluster returns the basic cluster.

func (*Server) GetCluster

func (s *Server) GetCluster() *Cluster

GetCluster returns the cluster.

func (*Server) GetConfig

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

GetConfig gets the config.

func (*Server) GetCoordinator

func (s *Server) GetCoordinator() *schedule.Coordinator

GetCoordinator returns the coordinator.

func (*Server) GetLeaderListenUrls

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

GetLeaderListenUrls gets service endpoints from the leader in election group.

func (*Server) GetParticipant

func (s *Server) GetParticipant() *member.Participant

GetParticipant returns the participant.

func (*Server) GetPersistConfig

func (s *Server) GetPersistConfig() *config.PersistConfig

GetPersistConfig returns the persist config. It's used to test.

func (*Server) GetTLSConfig

func (s *Server) GetTLSConfig() *grpcutil.TLSConfig

GetTLSConfig gets the security config.

func (*Server) IsClosed

func (s *Server) IsClosed() bool

IsClosed checks if the server loop is closed

func (*Server) IsServing

func (s *Server) IsServing() bool

IsServing returns whether the server is the leader, if there is embedded etcd, or the primary otherwise.

func (*Server) Name

func (s *Server) Name() string

Name returns the unique name for this server in the scheduling cluster.

func (*Server) RegisterGRPCService

func (s *Server) RegisterGRPCService(grpcServer *grpc.Server)

RegisterGRPCService registers the grpc service.

func (*Server) Run

func (s *Server) Run() (err error)

Run runs the scheduling server.

func (*Server) ServerLoopWgAdd

func (s *Server) ServerLoopWgAdd(n int)

ServerLoopWgAdd increases the server loop wait group.

func (*Server) ServerLoopWgDone

func (s *Server) ServerLoopWgDone()

ServerLoopWgDone decreases the server loop wait group.

func (*Server) SetLogLevel

func (s *Server) SetLogLevel(level string) error

SetLogLevel sets log level.

func (*Server) SetUpRestHandler

func (s *Server) SetUpRestHandler() (http.Handler, apiutil.APIServiceGroup)

SetUpRestHandler sets up the REST handler.

type Service

type Service struct {
	*Server
}

Service is the scheduling grpc service.

func (*Service) AskBatchSplit

AskBatchSplit implements gRPC SchedulingServer.

func (*Service) GetOperator

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

func (*Service) RegionHeartbeat

func (s *Service) RegionHeartbeat(stream schedulingpb.Scheduling_RegionHeartbeatServer) error

RegionHeartbeat implements gRPC SchedulingServer.

func (*Service) RegisterGRPCService

func (s *Service) RegisterGRPCService(g *grpc.Server)

RegisterGRPCService registers the service to gRPC server.

func (*Service) RegisterRESTHandler

func (s *Service) RegisterRESTHandler(userDefineHandlers map[string]http.Handler) error

RegisterRESTHandler registers the service to REST server.

func (*Service) ScatterRegions

ScatterRegions implements gRPC SchedulingServer.

func (*Service) SplitRegions

SplitRegions split regions by the given split keys

func (*Service) StoreHeartbeat

StoreHeartbeat implements gRPC SchedulingServer.

Directories

Path Synopsis
apis
v1

Jump to

Keyboard shortcuts

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