cluster

package
v1.1.0-beta.0...-dd8df1a Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2025 License: Apache-2.0 Imports: 66 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultMinResolvedTSPersistenceInterval is the default value of min resolved ts persistence interval.
	// If interval in config is zero, it means not to persist resolved ts and check config with this DefaultMinResolvedTSPersistenceInterval
	DefaultMinResolvedTSPersistenceInterval = config.DefaultMinResolvedTSPersistenceInterval
)

Functions

func CheckHealth

func CheckHealth(client *http.Client, members []*pdpb.Member) map[uint64]*pdpb.Member

CheckHealth checks if members are healthy.

func GetMembers

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

GetMembers return a slice of Members.

func IsClientURL

func IsClientURL(addr string, etcdClient *clientv3.Client) bool

IsClientURL returns whether addr is a ClientUrl of any member.

Types

type RaftCluster

type RaftCluster struct {
	syncutil.RWMutex

	*core.BasicCluster // cached cluster info
	// 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 NewRaftCluster

func NewRaftCluster(
	ctx context.Context,
	member *member.EmbeddedEtcdMember,
	basicCluster *core.BasicCluster,
	storage storage.Storage,
	regionSyncer *syncer.RegionSyncer,
	etcdClient *clientv3.Client,
	httpClient *http.Client,
	tsoAllocator *tso.AllocatorManager,
) *RaftCluster

NewRaftCluster create a new cluster.

func (RaftCluster) AddPendingProcessedRegions

func (sc RaftCluster) AddPendingProcessedRegions(needCheckLen bool, regionIDs ...uint64)

AddPendingProcessedRegions adds regions to suspect list.

func (RaftCluster) AddScheduler

func (sc RaftCluster) AddScheduler(scheduler schedulers.Scheduler, args ...string) error

AddScheduler adds a scheduler.

func (RaftCluster) AddSchedulerHandler

func (sc RaftCluster) AddSchedulerHandler(scheduler schedulers.Scheduler, args ...string) error

AddSchedulerHandler adds a scheduler handler.

func (*RaftCluster) AddStoreLimit

func (c *RaftCluster) AddStoreLimit(store *metapb.Store)

AddStoreLimit add a store limit for a given store ID.

func (RaftCluster) AddSuspectKeyRange

func (sc RaftCluster) AddSuspectKeyRange(start, end []byte)

AddSuspectKeyRange adds the key range with the its ruleID as the key The instance of each keyRange is like following format: [2][]byte: start key/end key

func (*RaftCluster) AllocID

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

AllocID returns a global unique ID.

func (RaftCluster) BucketsStats

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

BucketsStats returns hot region's buckets stats.

func (*RaftCluster) BuryStore

func (c *RaftCluster) BuryStore(storeID uint64, forceBury bool) error

BuryStore marks a store as tombstone in cluster. If forceBury is false, the store should be offlined and emptied before calling this func.

func (*RaftCluster) CheckAndUpdateMinResolvedTS

func (c *RaftCluster) CheckAndUpdateMinResolvedTS() (uint64, bool)

CheckAndUpdateMinResolvedTS checks and updates the min resolved ts of the cluster. It only be called by the background job runMinResolvedTSJob. This is exported for testing purpose.

func (RaftCluster) ClearSuspectKeyRanges

func (sc RaftCluster) ClearSuspectKeyRanges()

ClearSuspectKeyRanges clears the suspect keyRanges, only for unit test

func (*RaftCluster) Context

func (c *RaftCluster) Context() context.Context

Context returns the context of RaftCluster.

func (*RaftCluster) DeleteStoreLabel

func (c *RaftCluster) DeleteStoreLabel(storeID uint64, labelKey string) error

DeleteStoreLabel updates a store's location labels

func (*RaftCluster) GetAllStoresLimit

func (c *RaftCluster) GetAllStoresLimit() map[uint64]sc.StoreLimitConfig

GetAllStoresLimit returns all store limit

func (*RaftCluster) GetBasicCluster

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

GetBasicCluster returns the basic cluster.

func (*RaftCluster) GetCheckerConfig

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

GetCheckerConfig returns the checker config.

func (*RaftCluster) GetClusterVersion

func (c *RaftCluster) GetClusterVersion() string

GetClusterVersion returns the current cluster version.

func (RaftCluster) GetCoordinator

func (sc RaftCluster) GetCoordinator() *schedule.Coordinator

GetCoordinator returns the coordinator.

func (*RaftCluster) GetEtcdClient

func (c *RaftCluster) GetEtcdClient() *clientv3.Client

GetEtcdClient returns the current etcd client

func (*RaftCluster) GetExternalTS

func (c *RaftCluster) GetExternalTS() uint64

GetExternalTS returns the external timestamp.

func (*RaftCluster) GetGlobalTSOAllocator

func (c *RaftCluster) GetGlobalTSOAllocator() tso.Allocator

GetGlobalTSOAllocator return global tso allocator It only is used for test.

func (*RaftCluster) GetHeartbeatStreams

func (c *RaftCluster) GetHeartbeatStreams() *hbstream.HeartbeatStreams

GetHeartbeatStreams returns the heartbeat streams.

func (RaftCluster) GetHotPeerStat

func (sc RaftCluster) GetHotPeerStat(rw utils.RWType, regionID, storeID uint64) *statistics.HotPeerStat

GetHotPeerStat returns hot peer stat with specified regionID and storeID.

func (RaftCluster) GetHotPeerStats

func (sc RaftCluster) 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.

func (RaftCluster) GetHotStat

func (sc RaftCluster) GetHotStat() *statistics.HotStat

GetHotStat gets hot stat.

func (RaftCluster) GetLabelStats

func (sc RaftCluster) GetLabelStats() *statistics.LabelStatistics

GetLabelStats gets label statistics.

func (RaftCluster) GetMergeChecker

func (sc RaftCluster) GetMergeChecker() *checker.MergeChecker

GetMergeChecker returns merge checker.

func (*RaftCluster) GetMetaCluster

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

GetMetaCluster gets meta cluster.

func (*RaftCluster) GetMinResolvedTS

func (c *RaftCluster) GetMinResolvedTS() uint64

GetMinResolvedTS returns the min resolved ts of the cluster.

func (*RaftCluster) GetMinResolvedTSByStoreIDs

func (c *RaftCluster) GetMinResolvedTSByStoreIDs(ids []uint64) (uint64, map[uint64]uint64)

GetMinResolvedTSByStoreIDs returns the min_resolved_ts for each store and returns the min_resolved_ts for all given store lists.

func (RaftCluster) GetOperatorController

func (sc RaftCluster) GetOperatorController() *operator.Controller

GetOperatorController returns the operator controller.

func (*RaftCluster) GetOpts

func (c *RaftCluster) GetOpts() sc.ConfProvider

GetOpts returns cluster's configuration. There is no need a lock since it won't changed.

func (*RaftCluster) GetPDServerConfig

func (c *RaftCluster) GetPDServerConfig() *config.PDServerConfig

GetPDServerConfig returns pd server configurations.

func (RaftCluster) GetPausedSchedulerDelayAt

func (sc RaftCluster) GetPausedSchedulerDelayAt(name string) (int64, error)

GetPausedSchedulerDelayAt returns DelayAt of a paused scheduler

func (RaftCluster) GetPausedSchedulerDelayUntil

func (sc RaftCluster) GetPausedSchedulerDelayUntil(name string) (int64, error)

GetPausedSchedulerDelayUntil returns DelayUntil of a paused scheduler

func (RaftCluster) GetPendingProcessedRegions

func (sc RaftCluster) GetPendingProcessedRegions() []uint64

GetPendingProcessedRegions gets all suspect regions.

func (*RaftCluster) GetProgressByAction

func (c *RaftCluster) GetProgressByAction(action string) (process, ls, cs float64, err error)

GetProgressByAction returns the progress details for a given action.

func (*RaftCluster) GetProgressByID

func (c *RaftCluster) GetProgressByID(storeID string) (action string, process, ls, cs float64, err error)

GetProgressByID returns the progress details for a given store ID.

func (*RaftCluster) GetRegionLabeler

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

GetRegionLabeler returns the region labeler.

func (RaftCluster) GetRegionScatterer

func (sc RaftCluster) GetRegionScatterer() *scatter.RegionScatterer

GetRegionScatterer returns the region scatter.

func (RaftCluster) GetRegionSplitter

func (sc RaftCluster) GetRegionSplitter() *splitter.RegionSplitter

GetRegionSplitter returns the region splitter

func (RaftCluster) GetRegionStats

func (sc RaftCluster) GetRegionStats() *statistics.RegionStatistics

GetRegionStats gets region statistics.

func (*RaftCluster) GetRegionStatsByRange

func (c *RaftCluster) GetRegionStatsByRange(startKey, endKey []byte) *statistics.RegionStats

GetRegionStatsByRange returns region statistics from cluster.

func (RaftCluster) GetRegionStatsByType

func (sc RaftCluster) GetRegionStatsByType(typ statistics.RegionStatisticType) []*core.RegionInfo

GetRegionStatsByType gets the status of the region by types.

func (*RaftCluster) GetRegionStatsCount

func (c *RaftCluster) GetRegionStatsCount(startKey, endKey []byte) *statistics.RegionStats

GetRegionStatsCount returns the number of regions in the range.

func (*RaftCluster) GetRegionSyncer

func (c *RaftCluster) GetRegionSyncer() *syncer.RegionSyncer

GetRegionSyncer returns the region syncer.

func (*RaftCluster) GetReplicationConfig

func (c *RaftCluster) GetReplicationConfig() *sc.ReplicationConfig

GetReplicationConfig returns replication configurations.

func (*RaftCluster) GetReplicationMode

func (c *RaftCluster) GetReplicationMode() *replication.ModeManager

GetReplicationMode returns the ReplicationMode.

func (RaftCluster) GetRuleChecker

func (sc RaftCluster) GetRuleChecker() *checker.RuleChecker

GetRuleChecker returns rule checker.

func (*RaftCluster) GetRuleManager

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

GetRuleManager returns the rule manager reference.

func (*RaftCluster) GetScheduleConfig

func (c *RaftCluster) GetScheduleConfig() *sc.ScheduleConfig

GetScheduleConfig returns scheduling configurations.

func (*RaftCluster) GetSchedulerConfig

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

GetSchedulerConfig returns the scheduler config.

func (RaftCluster) GetSchedulerHandlers

func (sc RaftCluster) GetSchedulerHandlers() map[string]http.Handler

GetSchedulerHandlers gets all scheduler handlers.

func (RaftCluster) GetSchedulers

func (sc RaftCluster) GetSchedulers() []string

GetSchedulers gets all schedulers.

func (*RaftCluster) GetSharedConfig

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

GetSharedConfig returns the shared config.

func (*RaftCluster) GetStorage

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

GetStorage returns the storage.

func (*RaftCluster) GetStoreConfig

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

GetStoreConfig returns the store config.

func (*RaftCluster) GetStoreLimitByType

func (c *RaftCluster) GetStoreLimitByType(storeID uint64, typ storelimit.Type) float64

GetStoreLimitByType returns the store limit for a given store ID and type.

func (*RaftCluster) GetStoreMinResolvedTS

func (c *RaftCluster) GetStoreMinResolvedTS(storeID uint64) uint64

GetStoreMinResolvedTS returns the min resolved ts of the store.

func (RaftCluster) GetStoresLoads

func (sc RaftCluster) GetStoresLoads() map[uint64][]float64

GetStoresLoads returns load stats of all stores.

func (RaftCluster) GetStoresStats

func (sc RaftCluster) 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 (*RaftCluster) GetUnsafeRecoveryController

func (c *RaftCluster) GetUnsafeRecoveryController() *unsaferecovery.Controller

GetUnsafeRecoveryController returns the unsafe recovery controller.

func (*RaftCluster) HandleAskBatchSplit

func (c *RaftCluster) HandleAskBatchSplit(request *pdpb.AskBatchSplitRequest) (*pdpb.AskBatchSplitResponse, error)

HandleAskBatchSplit handles the batch split request.

func (*RaftCluster) HandleAskSplit

func (c *RaftCluster) HandleAskSplit(request *pdpb.AskSplitRequest) (*pdpb.AskSplitResponse, error)

HandleAskSplit handles the split request.

func (*RaftCluster) HandleBatchReportSplit

func (*RaftCluster) HandleBatchReportSplit(request *pdpb.ReportBatchSplitRequest) (*pdpb.ReportBatchSplitResponse, error)

HandleBatchReportSplit handles the batch report split request.

func (*RaftCluster) HandleRegionHeartbeat

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

HandleRegionHeartbeat processes RegionInfo reports from client.

func (*RaftCluster) HandleReportBuckets

func (c *RaftCluster) HandleReportBuckets(b *metapb.Buckets) error

HandleReportBuckets processes buckets reports from client

func (*RaftCluster) HandleReportSplit

func (*RaftCluster) HandleReportSplit(request *pdpb.ReportSplitRequest) (*pdpb.ReportSplitResponse, error)

HandleReportSplit handles the report split request.

func (*RaftCluster) HandleStoreHeartbeat

func (c *RaftCluster) HandleStoreHeartbeat(heartbeat *pdpb.StoreHeartbeatRequest, resp *pdpb.StoreHeartbeatResponse) error

HandleStoreHeartbeat updates the store status.

func (*RaftCluster) InitCluster

func (c *RaftCluster) InitCluster(
	id id.Allocator,
	opt sc.ConfProvider,
	hbstreams *hbstream.HeartbeatStreams,
	keyspaceGroupManager *keyspace.GroupManager) error

InitCluster initializes the raft cluster.

func (RaftCluster) IsPrepared

func (sc RaftCluster) IsPrepared() bool

IsPrepared return true if the prepare checker is ready.

func (RaftCluster) IsRegionHot

func (sc RaftCluster) IsRegionHot(region *core.RegionInfo) bool

IsRegionHot checks if a region is in hot state.

func (*RaftCluster) IsRunning

func (c *RaftCluster) IsRunning() bool

IsRunning return if the cluster is running.

func (RaftCluster) IsSchedulingControllerRunning

func (sc RaftCluster) IsSchedulingControllerRunning() bool

IsSchedulingControllerRunning returns whether the scheduling controller is running. Only for test purpose.

func (*RaftCluster) IsSchedulingHalted

func (c *RaftCluster) IsSchedulingHalted() bool

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

  • The `HaltScheduling` persist option is set to true.
  • Online unsafe recovery is running.

func (*RaftCluster) IsServiceIndependent

func (c *RaftCluster) IsServiceIndependent(name string) bool

IsServiceIndependent returns whether the service is independent.

func (*RaftCluster) LoadClusterInfo

func (c *RaftCluster) LoadClusterInfo() (*RaftCluster, error)

LoadClusterInfo loads cluster related info.

func (*RaftCluster) LoadClusterStatus

func (c *RaftCluster) LoadClusterStatus() (*Status, error)

LoadClusterStatus loads the cluster status.

func (*RaftCluster) NeedAwakenAllRegionsInStore

func (c *RaftCluster) NeedAwakenAllRegionsInStore(storeID uint64) (needAwaken bool, slowStoreIDs []uint64)

NeedAwakenAllRegionsInStore checks whether we should do AwakenRegions operation.

func (*RaftCluster) OnStoreVersionChange

func (c *RaftCluster) OnStoreVersionChange()

OnStoreVersionChange changes the version of the cluster when needed.

func (RaftCluster) PauseOrResumeChecker

func (sc RaftCluster) PauseOrResumeChecker(name string, t int64) error

PauseOrResumeChecker pauses or resumes checker.

func (RaftCluster) PauseOrResumeScheduler

func (sc RaftCluster) PauseOrResumeScheduler(name string, t int64) error

PauseOrResumeScheduler pauses or resumes a scheduler.

func (RaftCluster) PopOneSuspectKeyRange

func (sc RaftCluster) PopOneSuspectKeyRange() ([2][]byte, bool)

PopOneSuspectKeyRange gets one suspect keyRange group. it would return value and true if pop success, or return empty [][2][]byte and false if suspectKeyRanges couldn't pop keyRange group.

func (*RaftCluster) PutMetaCluster

func (c *RaftCluster) PutMetaCluster(meta *metapb.Cluster) error

PutMetaCluster puts meta cluster.

func (*RaftCluster) PutMetaStore

func (c *RaftCluster) PutMetaStore(store *metapb.Store) error

PutMetaStore puts a store.

func (*RaftCluster) ReadyToServe

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

ReadyToServe change store's node state to Serving.

func (RaftCluster) RemovePendingProcessedRegion

func (sc RaftCluster) RemovePendingProcessedRegion(id uint64)

RemovePendingProcessedRegion removes region from pending processed regions.

func (RaftCluster) RemoveScheduler

func (sc RaftCluster) RemoveScheduler(name string) error

RemoveScheduler removes a scheduler.

func (RaftCluster) RemoveSchedulerHandler

func (sc RaftCluster) RemoveSchedulerHandler(name string) error

RemoveSchedulerHandler removes a scheduler handler.

func (*RaftCluster) RemoveStore

func (c *RaftCluster) RemoveStore(storeID uint64, physicallyDestroyed bool) error

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

func (*RaftCluster) RemoveStoreLimit

func (c *RaftCluster) RemoveStoreLimit(storeID uint64)

RemoveStoreLimit remove a store limit for a given store ID.

func (*RaftCluster) RemoveTombStoneRecords

func (c *RaftCluster) RemoveTombStoneRecords() error

RemoveTombStoneRecords removes the tombStone Records.

func (*RaftCluster) SetAllStoresLimit

func (c *RaftCluster) SetAllStoresLimit(typ storelimit.Type, ratePerMin float64) error

SetAllStoresLimit sets all store limit for a given type and rate.

func (*RaftCluster) SetAllStoresLimitTTL

func (c *RaftCluster) SetAllStoresLimitTTL(typ storelimit.Type, ratePerMin float64, ttl time.Duration) error

SetAllStoresLimitTTL sets all store limit for a given type and rate with ttl.

func (*RaftCluster) SetExternalTS

func (c *RaftCluster) SetExternalTS(timestamp uint64) error

SetExternalTS sets the external timestamp.

func (*RaftCluster) SetMinResolvedTS

func (c *RaftCluster) SetMinResolvedTS(storeID, minResolvedTS uint64) error

SetMinResolvedTS sets up a store with min resolved ts.

func (*RaftCluster) SetPDServerConfig

func (c *RaftCluster) SetPDServerConfig(cfg *config.PDServerConfig)

SetPDServerConfig sets the PD configuration.

func (RaftCluster) SetPrepared

func (sc RaftCluster) SetPrepared()

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

func (*RaftCluster) SetScheduleConfig

func (c *RaftCluster) SetScheduleConfig(cfg *sc.ScheduleConfig)

SetScheduleConfig sets the PD scheduling configuration.

func (*RaftCluster) SetServiceIndependent

func (c *RaftCluster) SetServiceIndependent(name string)

SetServiceIndependent sets the service to be independent.

func (*RaftCluster) SetStoreLimit

func (c *RaftCluster) SetStoreLimit(storeID uint64, typ storelimit.Type, ratePerMin float64) error

SetStoreLimit sets a store limit for a given type and rate.

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

func (c *RaftCluster) Start(s Server, bootstrap bool) (err error)

Start starts a cluster.

func (*RaftCluster) Stop

func (c *RaftCluster) Stop()

Stop stops the cluster.

func (*RaftCluster) UnsetServiceIndependent

func (c *RaftCluster) UnsetServiceIndependent(name string)

UnsetServiceIndependent unsets the service to be independent.

func (*RaftCluster) UpStore

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

UpStore up a store from offline

func (RaftCluster) UpdateRegionsLabelLevelStats

func (sc RaftCluster) UpdateRegionsLabelLevelStats(regions []*core.RegionInfo)

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

func (*RaftCluster) UpdateStoreLabels

func (c *RaftCluster) UpdateStoreLabels(storeID uint64, labels []*metapb.StoreLabel, force bool) error

UpdateStoreLabels updates a store's location labels If 'force' is true, the origin labels will be overwritten with the new one forcibly.

func (*RaftCluster) Wait

func (c *RaftCluster) Wait()

Wait blocks until the cluster is stopped. Only for test purpose.

type Server

type Server interface {
	GetAllocator() id.Allocator
	GetConfig() *config.Config
	GetPersistOptions() *config.PersistOptions
	GetStorage() storage.Storage
	GetHBStreams() *hbstream.HeartbeatStreams
	GetRaftCluster() *RaftCluster
	GetBasicCluster() *core.BasicCluster
	GetMembers() ([]*pdpb.Member, error)
	ReplicateFileToMember(ctx context.Context, member *pdpb.Member, name string, data []byte) error
	GetKeyspaceGroupManager() *keyspace.GroupManager
	IsKeyspaceGroupEnabled() bool
	GetSafePointV2Manager() *gc.SafePointV2Manager
}

Server is the interface for cluster.

type Status

type Status struct {
	RaftBootstrapTime time.Time `json:"raft_bootstrap_time,omitempty"`
	IsInitialized     bool      `json:"is_initialized"`
	ReplicationStatus string    `json:"replication_status"`
}

Status saves some state information. NOTE: - This type is exported by HTTP API. Please pay more attention when modifying it. - Need to sync with client/http/types.go#ClusterStatus

Jump to

Keyboard shortcuts

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