infosync

package
v1.1.0-beta.0...-71d1252 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: Apache-2.0 Imports: 56 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ServerInformationPath store server information such as IP, port and so on.
	ServerInformationPath = "/tidb/server/info"
	// ServerMinStartTSPath store the server min start timestamp.
	ServerMinStartTSPath = "/tidb/server/minstartts"
	// TiFlashTableSyncProgressPath store the tiflash table replica sync progress.
	TiFlashTableSyncProgressPath = "/tiflash/table/sync"

	// ReportInterval is interval of infoSyncerKeeper reporting min startTS.
	ReportInterval = 30 * time.Second
	// TopologyInformationPath means etcd path for storing topology info.
	TopologyInformationPath = "/topology/tidb"
	// TopologySessionTTL is ttl for topology, ant it's the ETCD session's TTL in seconds.
	TopologySessionTTL = 45
	// TopologyTimeToRefresh means time to refresh etcd.
	TopologyTimeToRefresh = 30 * time.Second
	// TopologyPrometheus means address of prometheus.
	TopologyPrometheus = "/topology/prometheus"
	// TopologyTiProxy means address of TiProxy.
	TopologyTiProxy = "/topology/tiproxy"

	// TopologyTiCDC means address of TiCDC.
	TopologyTiCDC = "/topology/ticdc"
	// TablePrometheusCacheExpiry is the expiry time for prometheus address cache.
	TablePrometheusCacheExpiry = 10 * time.Second
	// RequestRetryInterval is the sleep time before next retry for http request
	RequestRetryInterval = 200 * time.Millisecond
	// SyncBundlesMaxRetry is the max retry times for sync placement bundles
	SyncBundlesMaxRetry = 3
)

Variables

View Source
var (
	// ErrHTTPServiceError means we got a http response with a status code which is not '2xx'
	ErrHTTPServiceError = dbterror.ClassDomain.NewStd(errno.ErrHTTPServiceError)
)
View Source
var ErrPrometheusAddrIsNotSet = dbterror.ClassDomain.NewStd(errno.ErrPrometheusAddrIsNotSet)

ErrPrometheusAddrIsNotSet is the error that Prometheus address is not set in PD and etcd

View Source
var MockGlobalServerInfoManagerEntry = &MockGlobalServerInfoManager{
	mockServerPort: 4000,
}

MockGlobalServerInfoManagerEntry is a mock global ServerInfoManager entry.

Functions

func AddResourceGroup

func AddResourceGroup(ctx context.Context, group *rmpb.ResourceGroup) error

AddResourceGroup is used to create one specific resource group to resource manager.

func CalculateTiFlashProgress

func CalculateTiFlashProgress(tableID int64, replicaCount uint64, tiFlashStores map[int64]pdhttp.StoreInfo) (float64, error)

CalculateTiFlashProgress calculates TiFlash replica progress

func CheckBundle

func CheckBundle(bundle *placement.Bundle) error

CheckBundle check that the rules don't overlap without explicit Override Exported for testing reasons. Tries to be a simpler version of PDs prepareRulesForApply + checkApplyRules. And additionally checks for key overlaps.

func CleanTiFlashProgressCache

func CleanTiFlashProgressCache()

CleanTiFlashProgressCache clean progress cache

func CloseTiFlashManager

func CloseTiFlashManager(ctx context.Context)

CloseTiFlashManager closes TiFlash manager.

func ConfigureTiFlashPDForPartitions

func ConfigureTiFlashPDForPartitions(accel bool, definitions *[]model.PartitionDefinition, count uint64, locationLabels *[]string, tableID int64) error

ConfigureTiFlashPDForPartitions configures pd rule for all partition in partitioned tables.

func ConfigureTiFlashPDForTable

func ConfigureTiFlashPDForTable(id int64, count uint64, locationLabels *[]string) error

ConfigureTiFlashPDForTable configures pd rule for unpartitioned tables.

func DeleteInternalSession

func DeleteInternalSession(se any)

DeleteInternalSession is the entry function for delete an internal session from SessionManager.

func DeleteResourceGroup

func DeleteResourceGroup(ctx context.Context, name string) error

DeleteResourceGroup is used to delete one specific resource group from resource manager.

func DeleteTiFlashPlacementRules

func DeleteTiFlashPlacementRules(ctx context.Context, physicalTableIDs []int64) error

DeleteTiFlashPlacementRules is a helper function to delete TiFlash placement rules of given physical table IDs.

func DeleteTiFlashTableSyncProgress

func DeleteTiFlashTableSyncProgress(tableInfo *model.TableInfo) error

DeleteTiFlashTableSyncProgress is used to delete the tiflash table replica sync progress.

func GetAllLabelRules

func GetAllLabelRules(ctx context.Context) ([]*label.Rule, error)

GetAllLabelRules gets all label rules from PD.

func GetAllRuleBundles

func GetAllRuleBundles(ctx context.Context) ([]*placement.Bundle, error)

GetAllRuleBundles is used to get all rule bundles from PD It is used to load full rules from PD while fullload infoschema.

func GetAllServerInfo

func GetAllServerInfo(ctx context.Context) (map[string]*ServerInfo, error)

GetAllServerInfo gets all servers static information from etcd.

func GetEtcdClient

func GetEtcdClient() *clientv3.Client

GetEtcdClient is only used for test.

func GetLabelRules

func GetLabelRules(ctx context.Context, ruleIDs []string) (map[string]*label.Rule, error)

GetLabelRules gets the label rules according to the given IDs from PD.

func GetPDScheduleConfig

func GetPDScheduleConfig(ctx context.Context) (map[string]any, error)

GetPDScheduleConfig gets the schedule information from pd

func GetPrometheusAddr

func GetPrometheusAddr() (string, error)

GetPrometheusAddr gets prometheus Address

func GetResourceGroup

func GetResourceGroup(ctx context.Context, name string) (*rmpb.ResourceGroup, error)

GetResourceGroup is used to get one specific resource group from resource manager.

func GetRuleBundle

func GetRuleBundle(ctx context.Context, name string) (*placement.Bundle, error)

GetRuleBundle is used to get one specific rule bundle from PD.

func GetTiFlashGroupRules

func GetTiFlashGroupRules(ctx context.Context, group string) ([]*pdhttp.Rule, error)

GetTiFlashGroupRules to get all placement rule in a certain group.

func GetTiFlashProgressFromCache

func GetTiFlashProgressFromCache(tableID int64) (float64, bool)

GetTiFlashProgressFromCache gets tiflash replica progress from tiflashProgressCache

func GetTiFlashRegionCountFromPD

func GetTiFlashRegionCountFromPD(ctx context.Context, tableID int64, regionCount *int) error

GetTiFlashRegionCountFromPD is a helper function calling `/stats/region`.

func GetTiFlashStoresStat

func GetTiFlashStoresStat(ctx context.Context) (*pdhttp.StoresInfo, error)

GetTiFlashStoresStat gets the TiKV store information by accessing PD's api.

func GetTiProxyServerInfo

func GetTiProxyServerInfo(ctx context.Context) (map[string]*TiProxyServerInfo, error)

GetTiProxyServerInfo gets all TiProxy servers information from etcd.

func ListResourceGroups

func ListResourceGroups(ctx context.Context) ([]*rmpb.ResourceGroup, error)

ListResourceGroups is used to get all resource groups from resource manager.

func MakeNewRule

func MakeNewRule(id int64, count uint64, locationLabels []string) pd.Rule

MakeNewRule creates a pd rule for TiFlash.

func MakeRuleID

func MakeRuleID(id int64) string

MakeRuleID creates a rule ID for TiFlash with given TableID. This interface is exported for the module who wants to manipulate the TiFlash rule. The rule ID is in the format of "table-<TableID>-r". NOTE: PLEASE DO NOT write the rule ID manually, use this interface instead.

func ModifyResourceGroup

func ModifyResourceGroup(ctx context.Context, group *rmpb.ResourceGroup) error

ModifyResourceGroup is used to modify one specific resource group to resource manager.

func MustGetTiFlashProgress

func MustGetTiFlashProgress(tableID int64, replicaCount uint64, tiFlashStores *map[int64]pdhttp.StoreInfo) (float64, error)

MustGetTiFlashProgress gets tiflash replica progress from tiflashProgressCache, if cache not exist, it calculates progress from PD and TiFlash and inserts progress into cache.

func NewMockResourceManagerClient

func NewMockResourceManagerClient() pd.ResourceManagerClient

NewMockResourceManagerClient return a mock ResourceManagerClient for test usage.

func PutLabelRule

func PutLabelRule(ctx context.Context, rule *label.Rule) error

PutLabelRule synchronizes the label rule to PD.

func PutRuleBundles

func PutRuleBundles(ctx context.Context, bundles []*placement.Bundle) error

PutRuleBundles is used to post specific rule bundles to PD. an "empty" bundle means delete bundle if a bundle with such ID exists.

func PutRuleBundlesWithDefaultRetry

func PutRuleBundlesWithDefaultRetry(ctx context.Context, bundles []*placement.Bundle) (err error)

PutRuleBundlesWithDefaultRetry will retry for default times

func PutRuleBundlesWithRetry

func PutRuleBundlesWithRetry(ctx context.Context, bundles []*placement.Bundle, maxRetry int, interval time.Duration) (err error)

PutRuleBundlesWithRetry will retry for specified times when PutRuleBundles failed

func SetEtcdClient

func SetEtcdClient(etcdCli *clientv3.Client)

SetEtcdClient is only used for test.

func SetMockTiFlash

func SetMockTiFlash(tiflash *MockTiFlash)

SetMockTiFlash can only be used in tests to set MockTiFlash

func SetPDHttpCliForTest

func SetPDHttpCliForTest(cli pdhttp.Client) func()

SetPDHttpCliForTest sets the pdhttp.Client for testing. Please do not use it in the production environment.

func SetPDScheduleConfig

func SetPDScheduleConfig(ctx context.Context, config map[string]any) error

SetPDScheduleConfig sets the schedule information for pd

func SetTiFlashGroupConfig

func SetTiFlashGroupConfig(ctx context.Context) error

SetTiFlashGroupConfig is a helper function to set tiflash rule group config

func SetTiFlashPlacementRule

func SetTiFlashPlacementRule(ctx context.Context, rule pdhttp.Rule) error

SetTiFlashPlacementRule is a helper function to set placement rule. It is discouraged to use SetTiFlashPlacementRule directly, use `ConfigureTiFlashPDForTable`/`ConfigureTiFlashPDForPartitions` instead.

func StoreInternalSession

func StoreInternalSession(se any) bool

StoreInternalSession is the entry function for store an internal session to SessionManager. return whether the session is stored successfully.

func SyncTiFlashTableSchema

func SyncTiFlashTableSchema(ctx context.Context, tableID int64) error

SyncTiFlashTableSchema syncs TiFlash table schema.

func UpdateLabelRules

func UpdateLabelRules(ctx context.Context, patch *pdhttp.LabelRulePatch) error

UpdateLabelRules synchronizes the label rule to PD.

func UpdateServerLabel

func UpdateServerLabel(ctx context.Context, labels map[string]string) error

UpdateServerLabel updates the server label for global info syncer.

func UpdateTiFlashProgressCache

func UpdateTiFlashProgressCache(tableID int64, progress float64) error

UpdateTiFlashProgressCache updates tiflashProgressCache

Types

type InfoSyncer

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

InfoSyncer stores server info to etcd when the tidb-server starts and delete when tidb-server shuts down.

func GlobalInfoSyncerInit

func GlobalInfoSyncerInit(
	ctx context.Context,
	id string,
	serverIDGetter func() uint64,
	etcdCli, unprefixedEtcdCli *clientv3.Client,
	pdCli pd.Client, pdHTTPCli pdhttp.Client,
	codec tikv.Codec,
	skipRegisterToDashBoard bool,
) (*InfoSyncer, error)

GlobalInfoSyncerInit return a new InfoSyncer. It is exported for testing.

func (*InfoSyncer) Done

func (is *InfoSyncer) Done() <-chan struct{}

Done returns a channel that closes when the info syncer is no longer being refreshed.

func (*InfoSyncer) GetAllTiDBTopology

func (is *InfoSyncer) GetAllTiDBTopology(ctx context.Context) ([]*TopologyInfo, error)

GetAllTiDBTopology gets all tidb topology

func (*InfoSyncer) GetMinStartTS

func (is *InfoSyncer) GetMinStartTS() uint64

GetMinStartTS get min start timestamp. Export for testing.

func (*InfoSyncer) GetSessionManager

func (is *InfoSyncer) GetSessionManager() util2.SessionManager

GetSessionManager get the session manager.

func (*InfoSyncer) RemoveMinStartTS

func (is *InfoSyncer) RemoveMinStartTS()

RemoveMinStartTS removes self server min start timestamp from etcd.

func (*InfoSyncer) RemoveServerInfo

func (is *InfoSyncer) RemoveServerInfo()

RemoveServerInfo remove self server static information from etcd.

func (*InfoSyncer) ReportMinStartTS

func (is *InfoSyncer) ReportMinStartTS(store kv.Storage)

ReportMinStartTS reports self server min start timestamp to ETCD.

func (*InfoSyncer) Restart

func (is *InfoSyncer) Restart(ctx context.Context) error

Restart restart the info syncer with new session leaseID and store server info to etcd again.

func (*InfoSyncer) RestartTopology

func (is *InfoSyncer) RestartTopology(ctx context.Context) error

RestartTopology restart the topology syncer with new session leaseID and store server info to etcd again.

func (*InfoSyncer) SetSessionManager

func (is *InfoSyncer) SetSessionManager(manager util2.SessionManager)

SetSessionManager set the session manager for InfoSyncer.

func (*InfoSyncer) StoreServerInfo

func (is *InfoSyncer) StoreServerInfo(ctx context.Context) error

StoreServerInfo stores self server static information to etcd.

func (*InfoSyncer) StoreTopologyInfo

func (is *InfoSyncer) StoreTopologyInfo(ctx context.Context) error

StoreTopologyInfo stores the topology of tidb to etcd.

func (*InfoSyncer) TopologyDone

func (is *InfoSyncer) TopologyDone() <-chan struct{}

TopologyDone returns a channel that closes when the topology syncer is no longer being refreshed.

type LabelRuleManager

type LabelRuleManager interface {
	PutLabelRule(ctx context.Context, rule *label.Rule) error
	UpdateLabelRules(ctx context.Context, patch *pd.LabelRulePatch) error
	GetAllLabelRules(ctx context.Context) ([]*label.Rule, error)
	GetLabelRules(ctx context.Context, ruleIDs []string) (map[string]*label.Rule, error)
}

LabelRuleManager manages label rules

type MockGlobalServerInfoManager

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

MockGlobalServerInfoManager manages serverInfos in Distributed unit tests.

func (*MockGlobalServerInfoManager) Add

func (m *MockGlobalServerInfoManager) Add(id string, serverIDGetter func() uint64)

Add one mock ServerInfo.

func (*MockGlobalServerInfoManager) Close

func (m *MockGlobalServerInfoManager) Close()

Close reset MockGlobalServerInfoManager.

func (*MockGlobalServerInfoManager) Delete

func (m *MockGlobalServerInfoManager) Delete(idx int) error

Delete one mock ServerInfo by idx.

func (*MockGlobalServerInfoManager) DeleteByExecID

func (m *MockGlobalServerInfoManager) DeleteByExecID(execID string)

DeleteByExecID delete ServerInfo by execID.

func (*MockGlobalServerInfoManager) GetAllServerInfo

func (m *MockGlobalServerInfoManager) GetAllServerInfo() map[string]*ServerInfo

GetAllServerInfo return all serverInfo in a map.

type MockTiFlash

type MockTiFlash struct {
	syncutil.Mutex

	StatusAddr                  string
	StatusServer                *httptest.Server
	SyncStatus                  map[int]mockTiFlashTableInfo
	StoreInfo                   map[uint64]pd.MetaStore
	GlobalTiFlashPlacementRules map[string]*pd.Rule
	PdEnabled                   bool
	TiflashDelay                time.Duration
	StartTime                   time.Time
	NotAvailable                bool
	NetworkError                bool
	// contains filtered or unexported fields
}

MockTiFlash mocks a TiFlash, with necessary Pd support.

func GetMockTiFlash

func GetMockTiFlash() *MockTiFlash

GetMockTiFlash can only be used in tests to get MockTiFlash

func NewMockTiFlash

func NewMockTiFlash() *MockTiFlash

NewMockTiFlash creates a MockTiFlash with a mocked TiFlash server.

func (*MockTiFlash) AddStore

func (tiflash *MockTiFlash) AddStore(storeID uint64, address string)

AddStore is mock function for adding store info into MockTiFlash.

func (*MockTiFlash) CheckPlacementRule

func (tiflash *MockTiFlash) CheckPlacementRule(rule pd.Rule) bool

CheckPlacementRule find if a given rule precisely matches already set rules.

func (*MockTiFlash) CleanPlacementRules

func (tiflash *MockTiFlash) CleanPlacementRules()

CleanPlacementRules cleans all placement rules.

func (*MockTiFlash) GetPlacementRule

func (tiflash *MockTiFlash) GetPlacementRule(ruleName string) (*pd.Rule, bool)

GetPlacementRule find a rule by name.

func (*MockTiFlash) GetRuleGroupIndex

func (tiflash *MockTiFlash) GetRuleGroupIndex() int

GetRuleGroupIndex gets the group index of tiflash

func (*MockTiFlash) GetTableSyncStatus

func (tiflash *MockTiFlash) GetTableSyncStatus(tableID int) (*mockTiFlashTableInfo, bool)

GetTableSyncStatus returns table sync status by given tableID.

func (*MockTiFlash) HandleDeletePlacementRule

func (tiflash *MockTiFlash) HandleDeletePlacementRule(_ string, ruleID string)

HandleDeletePlacementRule is mock function for DeleteTiFlashPlacementRule.

func (*MockTiFlash) HandleGetGroupRules

func (tiflash *MockTiFlash) HandleGetGroupRules(_ string) ([]*pd.Rule, error)

HandleGetGroupRules is mock function for GetTiFlashGroupRules.

func (*MockTiFlash) HandleGetPDRegionRecordStats

func (*MockTiFlash) HandleGetPDRegionRecordStats(int64) pd.RegionStats

HandleGetPDRegionRecordStats is mock function for GetRegionCountFromPD. It currently always returns 1 Region for convenience.

func (*MockTiFlash) HandleGetStoresStat

func (tiflash *MockTiFlash) HandleGetStoresStat() *pd.StoresInfo

HandleGetStoresStat is mock function for GetStoresStat. It returns address of our mocked TiFlash server.

func (*MockTiFlash) HandlePostAccelerateSchedule

func (tiflash *MockTiFlash) HandlePostAccelerateSchedule(endKey string) error

HandlePostAccelerateSchedule is mock function for PostAccelerateSchedule

func (*MockTiFlash) HandleSetPlacementRule

func (tiflash *MockTiFlash) HandleSetPlacementRule(rule *pd.Rule) error

HandleSetPlacementRule is mock function for SetTiFlashPlacementRule.

func (*MockTiFlash) HandleSetPlacementRuleBatch

func (tiflash *MockTiFlash) HandleSetPlacementRuleBatch(rules []*pd.Rule) error

HandleSetPlacementRuleBatch is mock function for batch SetTiFlashPlacementRule.

func (*MockTiFlash) PdSwitch

func (tiflash *MockTiFlash) PdSwitch(enabled bool)

PdSwitch controls if pd is enabled.

func (*MockTiFlash) PlacementRulesLen

func (tiflash *MockTiFlash) PlacementRulesLen() int

PlacementRulesLen gets length of all currently set placement rules.

func (*MockTiFlash) ResetSyncStatus

func (tiflash *MockTiFlash) ResetSyncStatus(tableID int, canAvailable bool)

ResetSyncStatus is mock function for reset sync status.

func (*MockTiFlash) SetNetworkError

func (tiflash *MockTiFlash) SetNetworkError(e bool)

SetNetworkError sets network error state.

func (*MockTiFlash) SetRuleGroupIndex

func (tiflash *MockTiFlash) SetRuleGroupIndex(groupIndex int)

SetRuleGroupIndex sets the group index of tiflash

type MockTiFlashError

type MockTiFlashError struct {
	Message string
}

MockTiFlashError represents MockTiFlash error

func (*MockTiFlashError) Error

func (me *MockTiFlashError) Error() string

type PDLabelManager

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

PDLabelManager manages rules with pd

func (*PDLabelManager) GetAllLabelRules

func (lm *PDLabelManager) GetAllLabelRules(ctx context.Context) ([]*label.Rule, error)

GetAllLabelRules implements GetAllLabelRules

func (*PDLabelManager) GetLabelRules

func (lm *PDLabelManager) GetLabelRules(ctx context.Context, ruleIDs []string) (map[string]*label.Rule, error)

GetLabelRules implements GetLabelRules

func (*PDLabelManager) PutLabelRule

func (lm *PDLabelManager) PutLabelRule(ctx context.Context, rule *label.Rule) error

PutLabelRule implements PutLabelRule

func (*PDLabelManager) UpdateLabelRules

func (lm *PDLabelManager) UpdateLabelRules(ctx context.Context, patch *pd.LabelRulePatch) error

UpdateLabelRules implements UpdateLabelRules

type PDPlacementManager

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

PDPlacementManager manages placement with pd

func (*PDPlacementManager) GetAllRuleBundles

func (m *PDPlacementManager) GetAllRuleBundles(ctx context.Context) ([]*placement.Bundle, error)

GetAllRuleBundles is used to get all rule bundles from PD. It is used to load full rules from PD while fullload infoschema.

func (*PDPlacementManager) GetRuleBundle

func (m *PDPlacementManager) GetRuleBundle(ctx context.Context, name string) (*placement.Bundle, error)

GetRuleBundle is used to get one specific rule bundle from PD.

func (*PDPlacementManager) PutRuleBundles

func (m *PDPlacementManager) PutRuleBundles(ctx context.Context, bundles []*placement.Bundle) error

PutRuleBundles is used to post specific rule bundles to PD.

type PDScheduleManager

type PDScheduleManager struct {
	pd.Client
}

PDScheduleManager manages schedule with pd

type PlacementManager

type PlacementManager interface {
	// GetRuleBundle is used to get one specific rule bundle from PD.
	GetRuleBundle(ctx context.Context, name string) (*placement.Bundle, error)
	// GetAllRuleBundles is used to get all rule bundles from PD. It is used to load full rules from PD while fullload infoschema.
	GetAllRuleBundles(ctx context.Context) ([]*placement.Bundle, error)
	// PutRuleBundles is used to post specific rule bundles to PD.
	PutRuleBundles(ctx context.Context, bundles []*placement.Bundle) error
}

PlacementManager manages placement settings

type PlacementScheduleState

type PlacementScheduleState int

PlacementScheduleState is the returned third-valued state from GetReplicationState(). For convenience, the string of PD is deserialized into an enum first.

const (
	// PlacementScheduleStatePending corresponds to "PENDING" from PD.
	PlacementScheduleStatePending PlacementScheduleState = iota
	// PlacementScheduleStateInProgress corresponds to "INPROGRESS" from PD.
	PlacementScheduleStateInProgress
	// PlacementScheduleStateScheduled corresponds to "REPLICATED" from PD.
	PlacementScheduleStateScheduled
)

func GetReplicationState

func GetReplicationState(ctx context.Context, startKey []byte, endKey []byte) (PlacementScheduleState, error)

GetReplicationState is used to check if regions in the given keyranges are replicated from PD.

func (PlacementScheduleState) String

func (t PlacementScheduleState) String() string

type ScheduleManager

type ScheduleManager interface {
	GetScheduleConfig(ctx context.Context) (map[string]any, error)
	SetScheduleConfig(ctx context.Context, config map[string]any) error
}

ScheduleManager manages schedule configs

type ServerInfo

type ServerInfo struct {
	ServerVersionInfo
	ID             string            `json:"ddl_id"`
	IP             string            `json:"ip"`
	Port           uint              `json:"listening_port"`
	StatusPort     uint              `json:"status_port"`
	Lease          string            `json:"lease"`
	StartTimestamp int64             `json:"start_timestamp"`
	Labels         map[string]string `json:"labels"`
	// ServerID is a function, to always retrieve latest serverID from `Domain`,
	// which will be changed on occasions such as connection to PD is restored after broken.
	ServerIDGetter func() uint64 `json:"-"`

	// JSONServerID is `serverID` for json marshal/unmarshal ONLY.
	JSONServerID uint64 `json:"server_id"`
}

ServerInfo is server static information. It will not be updated when tidb-server running. So please only put static information in ServerInfo struct.

func GetServerInfo

func GetServerInfo() (*ServerInfo, error)

GetServerInfo gets self server static information.

func GetServerInfoByID

func GetServerInfoByID(ctx context.Context, id string) (*ServerInfo, error)

GetServerInfoByID gets specified server static information from etcd.

func (*ServerInfo) Marshal

func (info *ServerInfo) Marshal() ([]byte, error)

Marshal `ServerInfo` into bytes.

func (*ServerInfo) Unmarshal

func (info *ServerInfo) Unmarshal(v []byte) error

Unmarshal `ServerInfo` from bytes.

type ServerVersionInfo

type ServerVersionInfo struct {
	Version string `json:"version"`
	GitHash string `json:"git_hash"`
}

ServerVersionInfo is the server version and git_hash.

type TiCDCInfo

type TiCDCInfo struct {
	ID             string `json:"id"`
	Address        string `json:"address"`
	Version        string `json:"version"`
	GitHash        string `json:"git-hash"`
	DeployPath     string `json:"deploy-path"`
	StartTimestamp int64  `json:"start-timestamp"`
	ClusterID      string `json:"cluster-id"`
}

TiCDCInfo is the server info for TiCDC.

func GetTiCDCServerInfo

func GetTiCDCServerInfo(ctx context.Context) ([]*TiCDCInfo, error)

GetTiCDCServerInfo gets all TiCDC servers information from etcd.

type TiFlashReplicaManager

type TiFlashReplicaManager interface {
	// SetTiFlashGroupConfig sets the group index of the tiflash placement rule
	SetTiFlashGroupConfig(ctx context.Context) error
	// SetPlacementRule is a helper function to set placement rule.
	SetPlacementRule(ctx context.Context, rule *pd.Rule) error
	// SetPlacementRuleBatch is a helper function to set a batch of placement rules.
	SetPlacementRuleBatch(ctx context.Context, rules []*pd.Rule) error
	// DeletePlacementRule is to delete placement rule for certain group.
	DeletePlacementRule(ctx context.Context, group string, ruleID string) error
	// GetGroupRules to get all placement rule in a certain group.
	GetGroupRules(ctx context.Context, group string) ([]*pd.Rule, error)
	// PostAccelerateScheduleBatch sends `regions/accelerate-schedule/batch` request.
	PostAccelerateScheduleBatch(ctx context.Context, tableIDs []int64) error
	// GetRegionCountFromPD is a helper function calling `/stats/region`.
	GetRegionCountFromPD(ctx context.Context, tableID int64, regionCount *int) error
	// GetStoresStat gets the TiKV store information by accessing PD's api.
	GetStoresStat(ctx context.Context) (*pd.StoresInfo, error)
	// CalculateTiFlashProgress calculates TiFlash replica progress
	CalculateTiFlashProgress(tableID int64, replicaCount uint64, TiFlashStores map[int64]pd.StoreInfo) (float64, error)
	// UpdateTiFlashProgressCache updates tiflashProgressCache
	UpdateTiFlashProgressCache(tableID int64, progress float64)
	// GetTiFlashProgressFromCache gets tiflash replica progress from tiflashProgressCache
	GetTiFlashProgressFromCache(tableID int64) (float64, bool)
	// DeleteTiFlashProgressFromCache delete tiflash replica progress from tiflashProgressCache
	DeleteTiFlashProgressFromCache(tableID int64)
	// CleanTiFlashProgressCache clean progress cache
	CleanTiFlashProgressCache()
	// SyncTiFlashTableSchema syncs the table's schema to TiFlash.
	SyncTiFlashTableSchema(tableID int64, storesStat []pd.StoreInfo) error
	// Close is to close TiFlashReplicaManager
	Close(ctx context.Context)
}

TiFlashReplicaManager manages placement settings and replica progress for TiFlash.

type TiFlashReplicaManagerCtx

type TiFlashReplicaManagerCtx struct {
	sync.RWMutex // protect tiflashProgressCache
	// contains filtered or unexported fields
}

TiFlashReplicaManagerCtx manages placement with pd and replica progress for TiFlash.

func (*TiFlashReplicaManagerCtx) CalculateTiFlashProgress

func (m *TiFlashReplicaManagerCtx) CalculateTiFlashProgress(tableID int64, replicaCount uint64, tiFlashStores map[int64]pd.StoreInfo) (float64, error)

CalculateTiFlashProgress calculates TiFlash replica progress.

func (*TiFlashReplicaManagerCtx) CleanTiFlashProgressCache

func (m *TiFlashReplicaManagerCtx) CleanTiFlashProgressCache()

CleanTiFlashProgressCache clean progress cache

func (*TiFlashReplicaManagerCtx) Close

Close is called to close TiFlashReplicaManagerCtx.

func (*TiFlashReplicaManagerCtx) DeletePlacementRule

func (m *TiFlashReplicaManagerCtx) DeletePlacementRule(ctx context.Context, group string, ruleID string) error

DeletePlacementRule is to delete placement rule for certain group.

func (*TiFlashReplicaManagerCtx) DeleteTiFlashProgressFromCache

func (m *TiFlashReplicaManagerCtx) DeleteTiFlashProgressFromCache(tableID int64)

DeleteTiFlashProgressFromCache delete tiflash replica progress from tiflashProgressCache

func (*TiFlashReplicaManagerCtx) GetGroupRules

func (m *TiFlashReplicaManagerCtx) GetGroupRules(ctx context.Context, group string) ([]*pd.Rule, error)

GetGroupRules to get all placement rule in a certain group.

func (*TiFlashReplicaManagerCtx) GetRegionCountFromPD

func (m *TiFlashReplicaManagerCtx) GetRegionCountFromPD(ctx context.Context, tableID int64, regionCount *int) error

GetRegionCountFromPD is a helper function calling `/stats/region`.

func (*TiFlashReplicaManagerCtx) GetStoresStat

func (m *TiFlashReplicaManagerCtx) GetStoresStat(ctx context.Context) (*pd.StoresInfo, error)

GetStoresStat gets the TiKV store information by accessing PD's api.

func (*TiFlashReplicaManagerCtx) GetTiFlashProgressFromCache

func (m *TiFlashReplicaManagerCtx) GetTiFlashProgressFromCache(tableID int64) (float64, bool)

GetTiFlashProgressFromCache gets tiflash replica progress from tiflashProgressCache

func (*TiFlashReplicaManagerCtx) PostAccelerateScheduleBatch

func (m *TiFlashReplicaManagerCtx) PostAccelerateScheduleBatch(ctx context.Context, tableIDs []int64) error

PostAccelerateScheduleBatch sends `regions/batch-accelerate-schedule` request.

func (*TiFlashReplicaManagerCtx) SetPlacementRule

func (m *TiFlashReplicaManagerCtx) SetPlacementRule(ctx context.Context, rule *pd.Rule) error

SetPlacementRule is a helper function to set placement rule.

func (*TiFlashReplicaManagerCtx) SetPlacementRuleBatch

func (m *TiFlashReplicaManagerCtx) SetPlacementRuleBatch(ctx context.Context, rules []*pd.Rule) error

SetPlacementRuleBatch is a helper function to set a batch of placement rules.

func (*TiFlashReplicaManagerCtx) SetTiFlashGroupConfig

func (m *TiFlashReplicaManagerCtx) SetTiFlashGroupConfig(ctx context.Context) error

SetTiFlashGroupConfig sets the tiflash's rule group config

func (*TiFlashReplicaManagerCtx) SyncTiFlashTableSchema

func (m *TiFlashReplicaManagerCtx) SyncTiFlashTableSchema(tableID int64, tiFlashStores []pd.StoreInfo) error

SyncTiFlashTableSchema syncs the table's schema to TiFlash.

func (*TiFlashReplicaManagerCtx) UpdateTiFlashProgressCache

func (m *TiFlashReplicaManagerCtx) UpdateTiFlashProgressCache(tableID int64, progress float64)

UpdateTiFlashProgressCache updates tiflashProgressCache

type TiProxyServerInfo

type TiProxyServerInfo struct {
	Version        string `json:"version"`
	GitHash        string `json:"git_hash"`
	IP             string `json:"ip"`
	Port           string `json:"port"`
	StatusPort     string `json:"status_port"`
	StartTimestamp int64  `json:"start_timestamp"`
}

TiProxyServerInfo is the server info for TiProxy.

type TopologyInfo

type TopologyInfo struct {
	ServerVersionInfo
	IP             string            `json:"ip"`
	StatusPort     uint              `json:"status_port"`
	DeployPath     string            `json:"deploy_path"`
	StartTimestamp int64             `json:"start_timestamp"`
	Labels         map[string]string `json:"labels"`
}

TopologyInfo is the topology info

Jump to

Keyboard shortcuts

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