From fff67a0fcc40639a8311a859d08bdc2bf2af4f3c Mon Sep 17 00:00:00 2001 From: JmPotato Date: Thu, 6 Apr 2023 11:13:44 +0800 Subject: [PATCH 1/2] Unify the TSO ServiceConfig and ConfigProvider interfaces Signed-off-by: JmPotato --- pkg/tso/allocator_manager.go | 24 +++++++----------------- pkg/tso/config.go | 6 ++++++ 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/pkg/tso/allocator_manager.go b/pkg/tso/allocator_manager.go index 8709f0d7645..07411d8e84a 100644 --- a/pkg/tso/allocator_manager.go +++ b/pkg/tso/allocator_manager.go @@ -143,16 +143,6 @@ type ElectionMember interface { PrecheckLeader() error } -// ConfigProvider is used to provide TSO configuration. -type ConfigProvider interface { - IsLocalTSOEnabled() bool - GetLeaderLease() int64 - GetTSOSaveInterval() time.Duration - GetTSOUpdatePhysicalInterval() time.Duration - GetMaxResetTSGap() time.Duration - GetTLSConfig() *grpcutil.TLSConfig -} - // AllocatorManager is used to manage the TSO Allocators a PD server holds. // It is in charge of maintaining TSO allocators' leadership, checking election // priority, and forwarding TSO allocation requests to correct TSO Allocators. @@ -207,7 +197,7 @@ func NewAllocatorManager( member ElectionMember, rootPath string, storage endpoint.TSOStorage, - configProvider ConfigProvider, + cfg TSOConfig, startGlobalLeaderLoop bool, ) *AllocatorManager { ctx, cancel := context.WithCancel(ctx) @@ -218,12 +208,12 @@ func NewAllocatorManager( member: member, rootPath: rootPath, storage: storage, - enableLocalTSO: configProvider.IsLocalTSOEnabled(), - saveInterval: configProvider.GetTSOSaveInterval(), - updatePhysicalInterval: configProvider.GetTSOUpdatePhysicalInterval(), - leaderLease: configProvider.GetLeaderLease(), - maxResetTSGap: configProvider.GetMaxResetTSGap, - securityConfig: configProvider.GetTLSConfig(), + enableLocalTSO: cfg.IsLocalTSOEnabled(), + saveInterval: cfg.GetTSOSaveInterval(), + updatePhysicalInterval: cfg.GetTSOUpdatePhysicalInterval(), + leaderLease: cfg.GetLeaderLease(), + maxResetTSGap: cfg.GetMaxResetTSGap, + securityConfig: cfg.GetTLSConfig(), } am.mu.allocatorGroups = make(map[string]*allocatorGroup) am.mu.clusterDCLocations = make(map[string]*DCLocationInfo) diff --git a/pkg/tso/config.go b/pkg/tso/config.go index dae60715fb9..cde29eb2f28 100644 --- a/pkg/tso/config.go +++ b/pkg/tso/config.go @@ -30,6 +30,12 @@ type ServiceConfig interface { GetListenAddr() string // GetAdvertiseListenAddr returns the AdvertiseListenAddr GetAdvertiseListenAddr() string + // TSO-related configuration + TSOConfig +} + +// TSOConfig is used to provide TSO configuration. +type TSOConfig interface { // GetLeaderLease returns the leader lease. GetLeaderLease() int64 // IsLocalTSOEnabled returns if the local TSO is enabled. From ef324a899dd1354c2101e7d95da5862f6f609755 Mon Sep 17 00:00:00 2001 From: JmPotato Date: Thu, 6 Apr 2023 11:28:53 +0800 Subject: [PATCH 2/2] Make the lint happy Signed-off-by: JmPotato --- pkg/tso/allocator_manager.go | 2 +- pkg/tso/config.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/tso/allocator_manager.go b/pkg/tso/allocator_manager.go index 07411d8e84a..362ff6763b4 100644 --- a/pkg/tso/allocator_manager.go +++ b/pkg/tso/allocator_manager.go @@ -197,7 +197,7 @@ func NewAllocatorManager( member ElectionMember, rootPath string, storage endpoint.TSOStorage, - cfg TSOConfig, + cfg Config, startGlobalLeaderLoop bool, ) *AllocatorManager { ctx, cancel := context.WithCancel(ctx) diff --git a/pkg/tso/config.go b/pkg/tso/config.go index cde29eb2f28..598f76004b1 100644 --- a/pkg/tso/config.go +++ b/pkg/tso/config.go @@ -31,11 +31,11 @@ type ServiceConfig interface { // GetAdvertiseListenAddr returns the AdvertiseListenAddr GetAdvertiseListenAddr() string // TSO-related configuration - TSOConfig + Config } -// TSOConfig is used to provide TSO configuration. -type TSOConfig interface { +// Config is used to provide TSO configuration. +type Config interface { // GetLeaderLease returns the leader lease. GetLeaderLease() int64 // IsLocalTSOEnabled returns if the local TSO is enabled.