server

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2023 License: Apache-2.0 Imports: 82 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// PDMode represents that server is in PD mode.
	PDMode = "PD"
	// APIServiceMode represents that server is in API service mode.
	APIServiceMode = "API service"
)

Variables

View Source
var (
	// ErrNotLeader is returned when current server is not the leader and not possible to process request.
	// TODO: work as proxy.
	ErrNotLeader            = status.Errorf(codes.Unavailable, "not leader")
	ErrNotStarted           = status.Errorf(codes.Unavailable, "server not started")
	ErrSendHeartbeatTimeout = status.Errorf(codes.DeadlineExceeded, "send heartbeat timeout")
	ErrNotFoundTSOAddr      = status.Errorf(codes.NotFound, "not found tso address")
)

gRPC errors

View Source
var (
	// SchedulerConfigHandlerPath is the api router path of the schedule config handler.
	SchedulerConfigHandlerPath = "/api/v1/scheduler-config"

	// 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 abnormal peer.
	ErrRegionAbnormalPeer = func(regionID uint64) error {
		return errors.Errorf("region %v has abnormal peer", regionID)
	}
	// ErrStoreNotFound is error info for store not found.
	ErrStoreNotFound = func(storeID uint64) error {
		return errors.Errorf("store %v not found", storeID)
	}
	// ErrPluginNotFound is error info for plugin not found.
	ErrPluginNotFound = func(pluginPath string) error {
		return errors.Errorf("plugin is not found: %s", pluginPath)
	}
)
View Source
var EtcdStartTimeout = time.Minute * 5

EtcdStartTimeout the timeout of the startup etcd.

Functions

func CheckPDVersion

func CheckPDVersion(opt *config.PersistOptions)

CheckPDVersion checks if PD needs to be upgraded.

func NewTestMultiConfig

func NewTestMultiConfig(c *assertutil.Checker, count int) []*config.Config

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

func NewTestSingleConfig

func NewTestSingleConfig(c *assertutil.Checker) *config.Config

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

Types

type GrpcServer

type GrpcServer struct {
	*Server
}

GrpcServer wraps Server to provide grpc service.

func (*GrpcServer) AllocID

func (s *GrpcServer) AllocID(ctx context.Context, request *pdpb.AllocIDRequest) (*pdpb.AllocIDResponse, error)

AllocID implements gRPC PDServer.

func (*GrpcServer) AskBatchSplit

func (s *GrpcServer) AskBatchSplit(ctx context.Context, request *pdpb.AskBatchSplitRequest) (*pdpb.AskBatchSplitResponse, error)

AskBatchSplit implements gRPC PDServer.

func (*GrpcServer) AskSplit

func (s *GrpcServer) AskSplit(ctx context.Context, request *pdpb.AskSplitRequest) (*pdpb.AskSplitResponse, error)

AskSplit implements gRPC PDServer.

func (*GrpcServer) Bootstrap

func (s *GrpcServer) Bootstrap(ctx context.Context, request *pdpb.BootstrapRequest) (*pdpb.BootstrapResponse, error)

Bootstrap implements gRPC PDServer.

func (*GrpcServer) GetAllStores

func (s *GrpcServer) GetAllStores(ctx context.Context, request *pdpb.GetAllStoresRequest) (*pdpb.GetAllStoresResponse, error)

GetAllStores implements gRPC PDServer.

func (*GrpcServer) GetClusterConfig

GetClusterConfig implements gRPC PDServer.

func (*GrpcServer) GetClusterInfo

GetClusterInfo implements gRPC PDServer.

func (*GrpcServer) GetDCLocationInfo

GetDCLocationInfo gets the dc-location info of the given dc-location from PD leader's TSO allocator manager.

func (*GrpcServer) GetExternalTimestamp

GetExternalTimestamp implements gRPC PDServer.

func (*GrpcServer) GetGCSafePoint

GetGCSafePoint implements gRPC PDServer.

func (*GrpcServer) GetMembers

GetMembers implements gRPC PDServer.

func (*GrpcServer) GetOperator

func (s *GrpcServer) GetOperator(ctx context.Context, request *pdpb.GetOperatorRequest) (*pdpb.GetOperatorResponse, error)

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

func (*GrpcServer) GetPrevRegion

func (s *GrpcServer) GetPrevRegion(ctx context.Context, request *pdpb.GetRegionRequest) (*pdpb.GetRegionResponse, error)

GetPrevRegion implements gRPC PDServer

func (*GrpcServer) GetRegion

func (s *GrpcServer) GetRegion(ctx context.Context, request *pdpb.GetRegionRequest) (*pdpb.GetRegionResponse, error)

GetRegion implements gRPC PDServer.

func (*GrpcServer) GetRegionByID

func (s *GrpcServer) GetRegionByID(ctx context.Context, request *pdpb.GetRegionByIDRequest) (*pdpb.GetRegionResponse, error)

GetRegionByID implements gRPC PDServer.

func (*GrpcServer) GetStore

func (s *GrpcServer) GetStore(ctx context.Context, request *pdpb.GetStoreRequest) (*pdpb.GetStoreResponse, error)

GetStore implements gRPC PDServer.

func (*GrpcServer) IsBootstrapped

IsBootstrapped implements gRPC PDServer.

func (*GrpcServer) IsSnapshotRecovering

IsSnapshotRecovering implements gRPC PDServer.

func (*GrpcServer) LoadGlobalConfig

LoadGlobalConfig support 2 ways to load global config from etcd - `Names` iteratively get value from `ConfigPath/Name` but not care about revision - `ConfigPath` if `Names` is nil can get all values and revision of current path

func (*GrpcServer) PutClusterConfig

PutClusterConfig implements gRPC PDServer.

func (*GrpcServer) PutStore

func (s *GrpcServer) PutStore(ctx context.Context, request *pdpb.PutStoreRequest) (*pdpb.PutStoreResponse, error)

PutStore implements gRPC PDServer.

func (*GrpcServer) RegionHeartbeat

func (s *GrpcServer) RegionHeartbeat(stream pdpb.PD_RegionHeartbeatServer) error

RegionHeartbeat implements gRPC PDServer.

func (*GrpcServer) ReportBatchSplit

ReportBatchSplit implements gRPC PDServer.

func (*GrpcServer) ReportBuckets

func (s *GrpcServer) ReportBuckets(stream pdpb.PD_ReportBucketsServer) error

ReportBuckets implements gRPC PDServer

func (*GrpcServer) ReportMinResolvedTS

ReportMinResolvedTS implements gRPC PDServer.

func (*GrpcServer) ReportSplit

func (s *GrpcServer) ReportSplit(ctx context.Context, request *pdpb.ReportSplitRequest) (*pdpb.ReportSplitResponse, error)

ReportSplit implements gRPC PDServer.

func (*GrpcServer) ScanRegions

func (s *GrpcServer) ScanRegions(ctx context.Context, request *pdpb.ScanRegionsRequest) (*pdpb.ScanRegionsResponse, error)

ScanRegions implements gRPC PDServer.

func (*GrpcServer) ScatterRegion

func (s *GrpcServer) ScatterRegion(ctx context.Context, request *pdpb.ScatterRegionRequest) (*pdpb.ScatterRegionResponse, error)

ScatterRegion implements gRPC PDServer.

func (*GrpcServer) SetExternalTimestamp

SetExternalTimestamp implements gRPC PDServer.

func (*GrpcServer) SplitAndScatterRegions

SplitAndScatterRegions split regions by the given split keys, and scatter regions. Only regions which splited successfully will be scattered. scatterFinishedPercentage indicates the percentage of successfully splited regions that are scattered.

func (*GrpcServer) SplitRegions

func (s *GrpcServer) SplitRegions(ctx context.Context, request *pdpb.SplitRegionsRequest) (*pdpb.SplitRegionsResponse, error)

SplitRegions split regions by the given split keys

func (*GrpcServer) StoreGlobalConfig

StoreGlobalConfig store global config into etcd by transaction Since item value needs to support marshal of different struct types, it should be set to `Payload bytes` instead of `Value string`

func (*GrpcServer) StoreHeartbeat

StoreHeartbeat implements gRPC PDServer.

func (*GrpcServer) SyncMaxTS

SyncMaxTS will check whether MaxTS is the biggest one among all Local TSOs this PD is holding when skipCheck is set, and write it into all Local TSO Allocators then if it's indeed the biggest one.

func (*GrpcServer) SyncRegions

func (s *GrpcServer) SyncRegions(stream pdpb.PD_SyncRegionsServer) error

SyncRegions syncs the regions.

func (*GrpcServer) Tso

func (s *GrpcServer) Tso(stream pdpb.PD_TsoServer) error

Tso implements gRPC PDServer.

func (*GrpcServer) UpdateGCSafePoint

UpdateGCSafePoint implements gRPC PDServer.

func (*GrpcServer) UpdateServiceGCSafePoint

UpdateServiceGCSafePoint update the safepoint for specific service

func (*GrpcServer) WatchGlobalConfig

func (s *GrpcServer) WatchGlobalConfig(req *pdpb.WatchGlobalConfigRequest, server pdpb.PD_WatchGlobalConfigServer) error

WatchGlobalConfig will retry on recoverable errors forever until reconnected by Etcd.Watch() as long as the context has not been canceled or timed out. Watch on revision which greater than or equal to the required revision.

type Handler

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

Handler is a helper to export methods to handle API/RPC requests.

func (*Handler) AddAddLearnerOperator

func (h *Handler) AddAddLearnerOperator(regionID uint64, toStoreID uint64) error

AddAddLearnerOperator adds an operator to add learner.

func (*Handler) AddAddPeerOperator

func (h *Handler) AddAddPeerOperator(regionID uint64, toStoreID uint64) error

AddAddPeerOperator adds an operator to add peer.

func (*Handler) AddBalanceHotRegionScheduler

func (h *Handler) AddBalanceHotRegionScheduler() error

AddBalanceHotRegionScheduler adds a balance-hot-region-scheduler.

func (*Handler) AddBalanceLeaderScheduler

func (h *Handler) AddBalanceLeaderScheduler() error

AddBalanceLeaderScheduler adds a balance-leader-scheduler.

func (*Handler) AddBalanceRegionScheduler

func (h *Handler) AddBalanceRegionScheduler() error

AddBalanceRegionScheduler adds a balance-region-scheduler.

func (*Handler) AddBalanceWitnessScheduler

func (h *Handler) AddBalanceWitnessScheduler() error

AddBalanceWitnessScheduler adds a balance-witness-scheduler.

func (*Handler) AddEvictLeaderScheduler

func (h *Handler) AddEvictLeaderScheduler(storeID uint64) error

AddEvictLeaderScheduler adds an evict-leader-scheduler.

func (*Handler) AddEvictOrGrant

func (h *Handler) AddEvictOrGrant(storeID float64, name string) error

AddEvictOrGrant add evict leader scheduler or grant leader scheduler.

func (*Handler) AddEvictSlowStoreScheduler

func (h *Handler) AddEvictSlowStoreScheduler() error

AddEvictSlowStoreScheduler adds a evict-slow-store-scheduler.

func (*Handler) AddEvictSlowTrendScheduler

func (h *Handler) AddEvictSlowTrendScheduler() error

AddEvictSlowTrendScheduler adds a evict-slow-trend-scheduler.

func (*Handler) AddGrantHotRegionScheduler

func (h *Handler) AddGrantHotRegionScheduler(leaderID, peers string) error

AddGrantHotRegionScheduler adds a grant-hot-region-scheduler

func (*Handler) AddGrantLeaderScheduler

func (h *Handler) AddGrantLeaderScheduler(storeID uint64) error

AddGrantLeaderScheduler adds a grant-leader-scheduler.

func (*Handler) AddLabelScheduler

func (h *Handler) AddLabelScheduler() error

AddLabelScheduler adds a label-scheduler.

func (*Handler) AddMergeRegionOperator

func (h *Handler) AddMergeRegionOperator(regionID uint64, targetID uint64) error

AddMergeRegionOperator adds an operator to merge region.

func (*Handler) AddRandomMergeScheduler

func (h *Handler) AddRandomMergeScheduler() error

AddRandomMergeScheduler adds a random-merge-scheduler.

func (*Handler) AddRemovePeerOperator

func (h *Handler) AddRemovePeerOperator(regionID uint64, fromStoreID uint64) error

AddRemovePeerOperator adds an operator to remove peer.

func (*Handler) AddScatterRangeScheduler

func (h *Handler) AddScatterRangeScheduler(args ...string) error

AddScatterRangeScheduler adds a balance-range-leader-scheduler

func (*Handler) AddScatterRegionOperator

func (h *Handler) AddScatterRegionOperator(regionID uint64, group string) error

AddScatterRegionOperator adds an operator to scatter a region.

func (*Handler) AddScatterRegionsOperators

func (h *Handler) AddScatterRegionsOperators(regionIDs []uint64, startRawKey, endRawKey, group string, retryLimit int) (int, error)

AddScatterRegionsOperators add operators to scatter regions and return the processed percentage and error

func (*Handler) AddScheduler

func (h *Handler) AddScheduler(name string, args ...string) error

AddScheduler adds a scheduler.

func (*Handler) AddShuffleHotRegionScheduler

func (h *Handler) AddShuffleHotRegionScheduler(limit uint64) error

AddShuffleHotRegionScheduler adds a shuffle-hot-region-scheduler.

func (*Handler) AddShuffleLeaderScheduler

func (h *Handler) AddShuffleLeaderScheduler() error

AddShuffleLeaderScheduler adds a shuffle-leader-scheduler.

func (*Handler) AddShuffleRegionScheduler

func (h *Handler) AddShuffleRegionScheduler() error

AddShuffleRegionScheduler adds a shuffle-region-scheduler.

func (*Handler) AddSplitBucketScheduler

func (h *Handler) AddSplitBucketScheduler() error

AddSplitBucketScheduler adds a split-bucket-scheduler.

func (*Handler) AddSplitRegionOperator

func (h *Handler) AddSplitRegionOperator(regionID uint64, policyStr string, keys []string) error

AddSplitRegionOperator adds an operator to split a region.

func (*Handler) AddTransferLeaderOperator

func (h *Handler) AddTransferLeaderOperator(regionID uint64, storeID uint64) error

AddTransferLeaderOperator adds an operator to transfer leader to the store.

func (*Handler) AddTransferPeerOperator

func (h *Handler) AddTransferPeerOperator(regionID uint64, fromStoreID, toStoreID uint64) error

AddTransferPeerOperator adds an operator to transfer peer.

func (*Handler) AddTransferRegionOperator

func (h *Handler) AddTransferRegionOperator(regionID uint64, storeIDs map[uint64]placement.PeerRoleType) error

AddTransferRegionOperator adds an operator to transfer region to the stores.

func (*Handler) AddTransferWitnessLeaderScheduler

func (h *Handler) AddTransferWitnessLeaderScheduler() error

AddTransferWitnessLeaderScheduler adds a transfer-witness-leader-scheduler.

func (*Handler) GetAddr

func (h *Handler) GetAddr() string

GetAddr returns the server urls for clients.

func (*Handler) GetAdminOperators

func (h *Handler) GetAdminOperators() ([]*operator.Operator, error)

GetAdminOperators returns the running admin operators.

func (*Handler) GetAllStoresLimit

func (h *Handler) GetAllStoresLimit(limitType storelimit.Type) (map[uint64]config.StoreLimitConfig, error)

GetAllStoresLimit is used to get limit of all stores.

func (*Handler) GetHistory

func (h *Handler) GetHistory(start time.Time) ([]operator.OpHistory, error)

GetHistory returns finished operators' history since start.

func (*Handler) GetHistoryHotRegionIter

func (h *Handler) GetHistoryHotRegionIter(
	hotRegionTypes []string,
	startTime, endTime int64,
) storage.HotRegionStorageIterator

GetHistoryHotRegionIter return a iter which iter all qualified item .

func (*Handler) GetHotReadRegions

func (h *Handler) GetHotReadRegions() *statistics.StoreHotPeersInfos

GetHotReadRegions gets all hot read regions stats.

func (*Handler) GetHotRegionsReservedDays

func (h *Handler) GetHotRegionsReservedDays() uint64

GetHotRegionsReservedDays gets days hot region information is kept.

func (*Handler) GetHotRegionsWriteInterval

func (h *Handler) GetHotRegionsWriteInterval() time.Duration

GetHotRegionsWriteInterval gets interval for PD to store Hot Region information..

func (*Handler) GetHotWriteRegions

func (h *Handler) GetHotWriteRegions() *statistics.StoreHotPeersInfos

GetHotWriteRegions gets all hot write regions stats.

func (*Handler) GetLeaderOperators

func (h *Handler) GetLeaderOperators() ([]*operator.Operator, error)

GetLeaderOperators returns the running leader operators.

func (*Handler) GetOfflinePeer

func (h *Handler) GetOfflinePeer(typ statistics.RegionStatisticType) ([]*core.RegionInfo, error)

GetOfflinePeer gets the region with offline peer.

func (*Handler) GetOperator

func (h *Handler) GetOperator(regionID uint64) (*operator.Operator, error)

GetOperator returns the region operator.

func (*Handler) GetOperatorController

func (h *Handler) GetOperatorController() (*schedule.OperatorController, error)

GetOperatorController returns OperatorController.

func (*Handler) GetOperatorStatus

func (h *Handler) GetOperatorStatus(regionID uint64) (*schedule.OperatorWithStatus, error)

GetOperatorStatus returns the status of the region operator.

func (*Handler) GetOperators

func (h *Handler) GetOperators() ([]*operator.Operator, error)

GetOperators returns the running operators.

func (*Handler) GetOperatorsOfKind

func (h *Handler) GetOperatorsOfKind(mask operator.OpKind) ([]*operator.Operator, error)

GetOperatorsOfKind returns the running operators of the kind.

func (*Handler) GetPausedSchedulerDelayAt

func (h *Handler) GetPausedSchedulerDelayAt(name string) (int64, error)

GetPausedSchedulerDelayAt returns paused unix timestamp when a scheduler is paused

func (*Handler) GetPausedSchedulerDelayUntil

func (h *Handler) GetPausedSchedulerDelayUntil(name string) (int64, error)

GetPausedSchedulerDelayUntil returns resume unix timestamp when a scheduler is paused

func (*Handler) GetProgressByAction

func (h *Handler) GetProgressByAction(action string) (p, ls, cs float64, err error)

GetProgressByAction returns the progress details for a given action.

func (*Handler) GetProgressByID

func (h *Handler) GetProgressByID(storeID string) (action string, p, ls, cs float64, err error)

GetProgressByID returns the progress details for a given store ID.

func (*Handler) GetRaftCluster

func (h *Handler) GetRaftCluster() (*cluster.RaftCluster, error)

GetRaftCluster returns RaftCluster.

func (*Handler) GetRecords

func (h *Handler) GetRecords(from time.Time) ([]*operator.OpRecord, error)

GetRecords returns finished operators since start.

func (*Handler) GetRegionOperators

func (h *Handler) GetRegionOperators() ([]*operator.Operator, error)

GetRegionOperators returns the running region operators.

func (*Handler) GetRegionsByType

func (h *Handler) GetRegionsByType(typ statistics.RegionStatisticType) ([]*core.RegionInfo, error)

GetRegionsByType gets the region with specified type.

func (*Handler) GetScheduleConfig

func (h *Handler) GetScheduleConfig() *config.ScheduleConfig

GetScheduleConfig returns ScheduleConfig.

func (*Handler) GetSchedulerConfigHandler

func (h *Handler) GetSchedulerConfigHandler() (http.Handler, error)

GetSchedulerConfigHandler gets the handler of schedulers.

func (*Handler) GetSchedulers

func (h *Handler) GetSchedulers() ([]string, error)

GetSchedulers returns all names of schedulers.

func (*Handler) GetStoreLimitScene

func (h *Handler) GetStoreLimitScene(limitType storelimit.Type) *storelimit.Scene

GetStoreLimitScene returns the limit values for different scenes

func (*Handler) GetStores

func (h *Handler) GetStores() ([]*core.StoreInfo, error)

GetStores returns all stores in the cluster.

func (*Handler) GetStoresLoads

func (h *Handler) GetStoresLoads() map[uint64][]float64

GetStoresLoads gets all hot write stores stats.

func (*Handler) GetWaitingOperators

func (h *Handler) GetWaitingOperators() ([]*operator.Operator, error)

GetWaitingOperators returns the waiting operators.

func (*Handler) IsCheckerPaused

func (h *Handler) IsCheckerPaused(name string) (bool, error)

IsCheckerPaused returns if checker is paused

func (*Handler) IsLeader

func (h *Handler) IsLeader() bool

IsLeader return true if this server is leader

func (*Handler) IsSchedulerDisabled

func (h *Handler) IsSchedulerDisabled(name string) (bool, error)

IsSchedulerDisabled returns whether scheduler is disabled.

func (*Handler) IsSchedulerExisted

func (h *Handler) IsSchedulerExisted(name string) (bool, error)

IsSchedulerExisted returns whether scheduler is existed.

func (*Handler) IsSchedulerPaused

func (h *Handler) IsSchedulerPaused(name string) (bool, error)

IsSchedulerPaused returns whether scheduler is paused.

func (*Handler) PackHistoryHotReadRegions

func (h *Handler) PackHistoryHotReadRegions() ([]storage.HistoryHotRegion, error)

PackHistoryHotReadRegions get read hot region info in HistoryHotRegion form.

func (*Handler) PackHistoryHotWriteRegions

func (h *Handler) PackHistoryHotWriteRegions() ([]storage.HistoryHotRegion, error)

PackHistoryHotWriteRegions get write hot region info in HistoryHotRegion from

func (*Handler) PauseOrResumeChecker

func (h *Handler) PauseOrResumeChecker(name string, t int64) error

PauseOrResumeChecker pauses checker for delay seconds or resume checker t == 0 : resume checker. t > 0 : checker delays t seconds.

func (*Handler) PauseOrResumeScheduler

func (h *Handler) PauseOrResumeScheduler(name string, t int64) error

PauseOrResumeScheduler pauses a scheduler for delay seconds or resume a paused scheduler. t == 0 : resume scheduler. t > 0 : scheduler delays t seconds.

func (*Handler) PluginLoad

func (h *Handler) PluginLoad(pluginPath string) error

PluginLoad loads the plugin referenced by the pluginPath

func (*Handler) PluginUnload

func (h *Handler) PluginUnload(pluginPath string) error

PluginUnload unloads the plugin referenced by the pluginPath

func (*Handler) RemoveOperator

func (h *Handler) RemoveOperator(regionID uint64) error

RemoveOperator removes the region operator.

func (*Handler) RemoveScheduler

func (h *Handler) RemoveScheduler(name string) error

RemoveScheduler removes a scheduler by name.

func (*Handler) ResetTS

func (h *Handler) ResetTS(ts uint64, ignoreSmaller, skipUpperBoundCheck bool, _ uint32) error

ResetTS resets the ts with specified tso.

func (*Handler) SetAllStoresLimit

func (h *Handler) SetAllStoresLimit(ratePerMin float64, limitType storelimit.Type) error

SetAllStoresLimit is used to set limit of all stores.

func (*Handler) SetAllStoresLimitTTL

func (h *Handler) SetAllStoresLimitTTL(ratePerMin float64, limitType storelimit.Type, ttl time.Duration) error

SetAllStoresLimitTTL is used to set limit of all stores with ttl

func (*Handler) SetLabelStoresLimit

func (h *Handler) SetLabelStoresLimit(ratePerMin float64, limitType storelimit.Type, labels []*metapb.StoreLabel) error

SetLabelStoresLimit is used to set limit of label stores.

func (*Handler) SetStoreLimit

func (h *Handler) SetStoreLimit(storeID uint64, ratePerMin float64, limitType storelimit.Type) error

SetStoreLimit is used to set the limit of a store.

func (*Handler) SetStoreLimitScene

func (h *Handler) SetStoreLimitScene(scene *storelimit.Scene, limitType storelimit.Type)

SetStoreLimitScene sets the limit values for different scenes

func (*Handler) SetStoreLimitTTL

func (h *Handler) SetStoreLimitTTL(data string, value float64, ttl time.Duration) error

SetStoreLimitTTL set storeLimit with ttl

type HandlerBuilder

type HandlerBuilder func(context.Context, *Server) (http.Handler, apiutil.APIServiceGroup, error)

HandlerBuilder builds a server HTTP handler.

func CreateMockHandler

func CreateMockHandler(re *require.Assertions, ip string) HandlerBuilder

CreateMockHandler creates a mock handler for test.

type KeyspaceServer

type KeyspaceServer struct {
	*GrpcServer
}

KeyspaceServer wraps GrpcServer to provide keyspace service.

func (*KeyspaceServer) LoadKeyspace

LoadKeyspace load and return target keyspace metadata. Request must specify keyspace name. On Error, keyspaceMeta in response will be nil, error information will be encoded in response header with corresponding error type.

func (*KeyspaceServer) UpdateKeyspaceState

UpdateKeyspaceState updates the state of keyspace specified in the request.

func (*KeyspaceServer) WatchKeyspaces

WatchKeyspaces captures and sends keyspace metadata changes to the client via gRPC stream. Note: It sends all existing keyspaces as it's first package to the client.

type Server

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

Server is the pd server. It implements bs.Server nolint

func CreateServer

func CreateServer(ctx context.Context, cfg *config.Config, services []string, legacyServiceBuilders ...HandlerBuilder) (*Server, error)

CreateServer creates the UNINITIALIZED pd server with given configuration.

func MustWaitLeader

func MustWaitLeader(re *require.Assertions, svrs []*Server) *Server

MustWaitLeader return the leader until timeout.

func NewTestServer

NewTestServer creates a pd server for testing.

func (*Server) AddCloseCallback

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

AddCloseCallback adds a callback in the Close phase.

func (*Server) AddServiceLabel

func (s *Server) AddServiceLabel(serviceLabel string, accessPath apiutil.AccessPath)

AddServiceLabel is used to add the relationship between service label and api access path TODO: this function will be used for updating api rate limit config

func (*Server) AddServiceReadyCallback

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

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

func (*Server) AddStartCallback

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

AddStartCallback adds a callback in the startServer phase.

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 context of server.

func (*Server) DeleteLabelProperty

func (s *Server) DeleteLabelProperty(typ, labelKey, labelValue string) error

DeleteLabelProperty deletes a label property config.

func (*Server) GetAPIAccessServiceLabel

func (s *Server) GetAPIAccessServiceLabel(accessPath apiutil.AccessPath) string

GetAPIAccessServiceLabel returns service label by given access path TODO: this function will be used for updating api rate limit config

func (*Server) GetAddr

func (s *Server) GetAddr() string

GetAddr returns the server urls for clients.

func (*Server) GetAllocator

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

GetAllocator returns the ID allocator of server.

func (*Server) GetAuditBackend

func (s *Server) GetAuditBackend() []audit.Backend

GetAuditBackend returns audit backends

func (*Server) GetAuditConfig

func (s *Server) GetAuditConfig() *config.AuditConfig

GetAuditConfig gets the audit config information.

func (*Server) GetBasicCluster

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

GetBasicCluster returns the basic cluster of server.

func (*Server) GetClient

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

GetClient returns builtin etcd client.

func (*Server) GetClientScheme

func (s *Server) GetClientScheme() string

GetClientScheme returns the client URL scheme

func (*Server) GetCluster

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

GetCluster gets cluster.

func (*Server) GetClusterStatus

func (s *Server) GetClusterStatus() (*cluster.Status, error)

GetClusterStatus gets cluster status.

func (*Server) GetClusterVersion

func (s *Server) GetClusterVersion() semver.Version

GetClusterVersion returns the version of cluster.

func (*Server) GetConfig

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

GetConfig gets the config information.

func (*Server) GetControllerConfig

func (s *Server) GetControllerConfig() *rm_server.ControllerConfig

GetControllerConfig gets the resource manager controller config.

func (*Server) GetEndpoints

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

GetEndpoints returns the etcd endpoints for outer use.

func (*Server) GetExternalTS

func (s *Server) GetExternalTS() uint64

GetExternalTS returns external timestamp.

func (*Server) GetHBStreams

func (s *Server) GetHBStreams() *hbstream.HeartbeatStreams

GetHBStreams returns the heartbeat streams.

func (*Server) GetHTTPClient

func (s *Server) GetHTTPClient() *http.Client

GetHTTPClient returns builtin http client.

func (*Server) GetHandler

func (s *Server) GetHandler() *Handler

GetHandler returns the handler for API.

func (*Server) GetHistoryHotRegionStorage

func (s *Server) GetHistoryHotRegionStorage() *storage.HotRegionStorage

GetHistoryHotRegionStorage returns the backend storage of historyHotRegion.

func (*Server) GetKeyspaceGroupManager

func (s *Server) GetKeyspaceGroupManager() *keyspace.GroupManager

GetKeyspaceGroupManager returns the keyspace group manager of server.

func (*Server) GetKeyspaceManager

func (s *Server) GetKeyspaceManager() *keyspace.Manager

GetKeyspaceManager returns the keyspace manager of server.

func (*Server) GetLabelProperty

func (s *Server) GetLabelProperty() config.LabelPropertyConfig

GetLabelProperty returns the whole label property config.

func (*Server) GetLeader

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

GetLeader returns the leader of PD cluster(i.e the PD leader).

func (*Server) GetLeaderLease

func (s *Server) GetLeaderLease() int64

GetLeaderLease returns the leader lease.

func (*Server) GetLeaderListenUrls

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

GetLeaderListenUrls gets service endpoints from the leader in election group.

func (*Server) GetMaxResetTSGap

func (s *Server) GetMaxResetTSGap() time.Duration

GetMaxResetTSGap gets the max gap to reset the tso.

func (*Server) GetMember

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

GetMember returns the member of server.

func (*Server) GetMemberInfo

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

GetMemberInfo returns the server member information.

func (*Server) GetMembers

func (s *Server) GetMembers() ([]*pdpb.Member, error)

GetMembers returns PD server list.

func (*Server) GetMetaRegions

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

GetMetaRegions gets meta regions from cluster.

func (*Server) GetPDServerConfig

func (s *Server) GetPDServerConfig() *config.PDServerConfig

GetPDServerConfig gets the balance config information.

func (*Server) GetPersistOptions

func (s *Server) GetPersistOptions() *config.PersistOptions

GetPersistOptions returns the schedule option.

func (*Server) GetRaftCluster

func (s *Server) GetRaftCluster() *cluster.RaftCluster

GetRaftCluster gets Raft cluster. If cluster has not been bootstrapped, return nil.

func (*Server) GetRateLimitConfig

func (s *Server) GetRateLimitConfig() *config.RateLimitConfig

GetRateLimitConfig gets the rate limit config information.

func (*Server) GetRegions

func (s *Server) GetRegions() []*core.RegionInfo

GetRegions gets regions from cluster.

func (*Server) GetReplicationConfig

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

GetReplicationConfig get the replication config.

func (*Server) GetReplicationModeConfig

func (s *Server) GetReplicationModeConfig() *config.ReplicationModeConfig

GetReplicationModeConfig returns the replication mode config.

func (*Server) GetScheduleConfig

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

GetScheduleConfig gets the balance config information.

func (*Server) GetServerOption

func (s *Server) GetServerOption() *config.PersistOptions

GetServerOption gets the option of the server.

func (*Server) GetServiceAuditBackendLabels

func (s *Server) GetServiceAuditBackendLabels(serviceLabel string) *audit.BackendLabels

GetServiceAuditBackendLabels returns audit backend labels by serviceLabel

func (*Server) GetServiceLabels

func (s *Server) GetServiceLabels(serviceLabel string) []apiutil.AccessPath

GetServiceLabels returns ApiAccessPaths by given service label TODO: this function will be used for updating api rate limit config

func (*Server) GetServiceMiddlewareConfig

func (s *Server) GetServiceMiddlewareConfig() *config.ServiceMiddlewareConfig

GetServiceMiddlewareConfig gets the service middleware config information.

func (*Server) GetServiceMiddlewarePersistOptions

func (s *Server) GetServiceMiddlewarePersistOptions() *config.ServiceMiddlewarePersistOptions

GetServiceMiddlewarePersistOptions returns the service middleware persist option.

func (*Server) GetServicePrimaryAddr

func (s *Server) GetServicePrimaryAddr(ctx context.Context, serviceName string) (string, bool)

GetServicePrimaryAddr returns the primary address for a given service. Note: This function will only return primary address without judging if it's alive.

func (*Server) GetServiceRateLimiter

func (s *Server) GetServiceRateLimiter() *ratelimit.Limiter

GetServiceRateLimiter is used to get rate limiter

func (*Server) GetStorage

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

GetStorage returns the backend storage of server.

func (*Server) GetTLSConfig

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

GetTLSConfig get the security config.

func (*Server) GetTSOAllocatorManager

func (s *Server) GetTSOAllocatorManager() *tso.AllocatorManager

GetTSOAllocatorManager returns the manager of TSO Allocator.

func (*Server) GetTSOSaveInterval

func (s *Server) GetTSOSaveInterval() time.Duration

GetTSOSaveInterval returns TSO save interval.

func (*Server) GetTSOUpdatePhysicalInterval

func (s *Server) GetTSOUpdatePhysicalInterval() time.Duration

GetTSOUpdatePhysicalInterval returns TSO update physical interval.

func (*Server) IsAPIServiceMode

func (s *Server) IsAPIServiceMode() bool

IsAPIServiceMode return whether the server is in API service mode.

func (*Server) IsClosed

func (s *Server) IsClosed() bool

IsClosed checks whether server is closed or not.

func (*Server) IsInRateLimitAllowList

func (s *Server) IsInRateLimitAllowList(serviceLabel string) bool

IsInRateLimitAllowList returns whether given service label is in allow lost

func (*Server) IsLocalTSOEnabled

func (s *Server) IsLocalTSOEnabled() bool

IsLocalTSOEnabled returns if the local TSO is enabled.

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

func (s *Server) IsSnapshotRecovering(ctx context.Context) (bool, error)

IsSnapshotRecovering check whether recovering-mark marked

func (*Server) IsTTLConfigExist

func (s *Server) IsTTLConfigExist(key string) bool

IsTTLConfigExist returns true if the ttl config is existed for a given config.

func (*Server) LoopContext

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

LoopContext returns the loop context of server.

func (*Server) MarkSnapshotRecovering

func (s *Server) MarkSnapshotRecovering() error

MarkSnapshotRecovering mark pd that we're recovering tikv will get this state during BR EBS restore. we write this info into etcd for simplicity, the key only stays inside etcd temporary during BR EBS restore in which period the cluster is not able to serve request. and is deleted after BR EBS restore is done.

func (*Server) Name

func (s *Server) Name() string

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

func (*Server) PersistFile

func (s *Server) PersistFile(name string, data []byte) error

PersistFile saves a file in DataDir.

func (*Server) RecoverAllocID

func (s *Server) RecoverAllocID(ctx context.Context, id uint64) error

RecoverAllocID recover alloc id. set current base id to input id

func (*Server) ReplicateFileToMember

func (s *Server) ReplicateFileToMember(ctx context.Context, member *pdpb.Member, name string, data []byte) error

ReplicateFileToMember is used to synchronize state to a member. Each member will write `data` to a local file named `name`. For security reason, data should be in JSON format.

func (*Server) Run

func (s *Server) Run() error

Run runs the pd server.

func (*Server) SaveTTLConfig

func (s *Server) SaveTTLConfig(data map[string]interface{}, ttl time.Duration) error

SaveTTLConfig save ttl config

func (*Server) SetAuditConfig

func (s *Server) SetAuditConfig(cfg config.AuditConfig) error

SetAuditConfig sets the audit config.

func (*Server) SetClusterVersion

func (s *Server) SetClusterVersion(v string) error

SetClusterVersion sets the version of cluster.

func (*Server) SetEnableLocalTSO

func (s *Server) SetEnableLocalTSO(enableLocalTSO bool)

SetEnableLocalTSO sets enable-local-tso flag of Server. This function only for test.

func (*Server) SetExternalTS

func (s *Server) SetExternalTS(externalTS, globalTS uint64) error

SetExternalTS returns external timestamp.

func (*Server) SetLabelProperty

func (s *Server) SetLabelProperty(typ, labelKey, labelValue string) error

SetLabelProperty inserts a label property config.

func (*Server) SetLabelPropertyConfig

func (s *Server) SetLabelPropertyConfig(cfg config.LabelPropertyConfig) error

SetLabelPropertyConfig sets the label property config.

func (*Server) SetLogLevel

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

SetLogLevel sets log level.

func (*Server) SetPDServerConfig

func (s *Server) SetPDServerConfig(cfg config.PDServerConfig) error

SetPDServerConfig sets the server config.

func (*Server) SetRateLimitConfig

func (s *Server) SetRateLimitConfig(cfg config.RateLimitConfig) error

SetRateLimitConfig sets the rate limit config.

func (*Server) SetReplicationConfig

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

SetReplicationConfig sets the replication config.

func (*Server) SetReplicationModeConfig

func (s *Server) SetReplicationModeConfig(cfg config.ReplicationModeConfig) error

SetReplicationModeConfig sets the replication mode.

func (*Server) SetScheduleConfig

func (s *Server) SetScheduleConfig(cfg config.ScheduleConfig) error

SetScheduleConfig sets the balance config information.

func (*Server) SetServiceAuditBackendForHTTP

func (s *Server) SetServiceAuditBackendForHTTP(route *mux.Route, labels ...string)

SetServiceAuditBackendForHTTP is used to register service audit config for HTTP.

func (*Server) SetServiceAuditBackendLabels

func (s *Server) SetServiceAuditBackendLabels(serviceLabel string, labels []string)

SetServiceAuditBackendLabels is used to add audit backend labels for service by service label

func (*Server) SetStorage

func (s *Server) SetStorage(storage storage.Storage)

SetStorage changes the storage only for test purpose. When we use it, we should prevent calling GetStorage, otherwise, it may cause a data race problem.

func (*Server) StartTimestamp

func (s *Server) StartTimestamp() int64

StartTimestamp returns the start timestamp of this server

func (*Server) UnmarkSnapshotRecovering

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

UnmarkSnapshotRecovering unmark recovering mark

func (*Server) UpdateRateLimit

func (s *Server) UpdateRateLimit(cfg *config.RateLimitConfig, key string, value interface{}) error

UpdateRateLimit is used to update rate-limit config which will overwrite limiter-config

func (*Server) UpdateRateLimitConfig

func (s *Server) UpdateRateLimitConfig(key, label string, value ratelimit.DimensionConfig) error

UpdateRateLimitConfig is used to update rate-limit config which will reserve old limiter-config

func (*Server) UpdateServiceRateLimiter

func (s *Server) UpdateServiceRateLimiter(serviceLabel string, opts ...ratelimit.Option) ratelimit.UpdateStatus

UpdateServiceRateLimiter is used to update RateLimiter

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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