Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config: remove config dependency for tso #5771

Merged
merged 2 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 23 additions & 3 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ const (
defaultDRWaitStoreTimeout = time.Minute

defaultTSOSaveInterval = time.Duration(defaultLeaderLease) * time.Second
// DefaultTSOUpdatePhysicalInterval is the default value of the config `TSOUpdatePhysicalInterval`.
DefaultTSOUpdatePhysicalInterval = 50 * time.Millisecond
// defaultTSOUpdatePhysicalInterval is the default value of the config `TSOUpdatePhysicalInterval`.
defaultTSOUpdatePhysicalInterval = 50 * time.Millisecond
maxTSOUpdatePhysicalInterval = 10 * time.Second
minTSOUpdatePhysicalInterval = 1 * time.Millisecond

Expand Down Expand Up @@ -550,7 +550,7 @@ func (c *Config) Adjust(meta *toml.MetaData, reloading bool) error {

adjustDuration(&c.TSOSaveInterval, defaultTSOSaveInterval)

adjustDuration(&c.TSOUpdatePhysicalInterval, DefaultTSOUpdatePhysicalInterval)
adjustDuration(&c.TSOUpdatePhysicalInterval, defaultTSOUpdatePhysicalInterval)

if c.TSOUpdatePhysicalInterval.Duration > maxTSOUpdatePhysicalInterval {
c.TSOUpdatePhysicalInterval.Duration = maxTSOUpdatePhysicalInterval
Expand Down Expand Up @@ -1296,6 +1296,26 @@ func (c *Config) GetConfigFile() string {
return c.configFile
}

// IsLocalTSOEnabled returns if the local TSO is enabled.
func (c *Config) IsLocalTSOEnabled() bool {
return c.EnableLocalTSO
}

// GetTSOUpdatePhysicalInterval returns TSO update physical interval.
func (c *Config) GetTSOUpdatePhysicalInterval() time.Duration {
return c.TSOUpdatePhysicalInterval.Duration
}

// GetTSOSaveInterval returns TSO save interval.
func (c *Config) GetTSOSaveInterval() time.Duration {
return c.TSOSaveInterval.Duration
}

// GetTLSConfig returns the TLS config.
func (c *Config) GetTLSConfig() *grpcutil.TLSConfig {
return &c.Security.TLSConfig
}

// GenEmbedEtcdConfig generates a configuration for embedded etcd.
func (c *Config) GenEmbedEtcdConfig() (*embed.Config, error) {
cfg := embed.NewConfig()
Expand Down
2 changes: 1 addition & 1 deletion server/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ leader-schedule-limit = 0
re.Equal(uint64(0), cfg.Schedule.MaxMergeRegionKeys)
re.Equal("http://127.0.0.1:9090", cfg.PDServerCfg.MetricStorage)

re.Equal(DefaultTSOUpdatePhysicalInterval, cfg.TSOUpdatePhysicalInterval.Duration)
re.Equal(defaultTSOUpdatePhysicalInterval, cfg.TSOUpdatePhysicalInterval.Duration)

// Check undefined config fields
cfgData = `
Expand Down
15 changes: 8 additions & 7 deletions server/tso/allocator_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"github.com/tikv/pd/pkg/utils/etcdutil"
"github.com/tikv/pd/pkg/utils/grpcutil"
"github.com/tikv/pd/pkg/utils/syncutil"
"github.com/tikv/pd/server/config"
"github.com/tikv/pd/server/member"
"go.etcd.io/etcd/clientv3"
"go.uber.org/zap"
Expand All @@ -51,6 +50,8 @@ const (
leaderTickInterval = 50 * time.Millisecond
localTSOAllocatorEtcdPrefix = "lta"
localTSOSuffixEtcdPrefix = "lts"
// The value should be the same as the variable defined in server's config.
defaultTSOUpdatePhysicalInterval = 50 * time.Millisecond
)

var (
Expand Down Expand Up @@ -133,17 +134,17 @@ type AllocatorManager struct {
func NewAllocatorManager(
m *member.Member,
rootPath string,
cfg *config.Config,
cfg config,
maxResetTSGap func() time.Duration,
) *AllocatorManager {
allocatorManager := &AllocatorManager{
enableLocalTSO: cfg.EnableLocalTSO,
enableLocalTSO: cfg.IsLocalTSOEnabled(),
member: m,
rootPath: rootPath,
saveInterval: cfg.TSOSaveInterval.Duration,
updatePhysicalInterval: cfg.TSOUpdatePhysicalInterval.Duration,
saveInterval: cfg.GetTSOSaveInterval(),
updatePhysicalInterval: cfg.GetTSOUpdatePhysicalInterval(),
maxResetTSGap: maxResetTSGap,
securityConfig: &cfg.Security.TLSConfig,
securityConfig: cfg.GetTLSConfig(),
}
allocatorManager.mu.allocatorGroups = make(map[string]*allocatorGroup)
allocatorManager.mu.clusterDCLocations = make(map[string]*DCLocationInfo)
Expand Down Expand Up @@ -312,7 +313,7 @@ func CalSuffixBits(maxSuffix int32) int {
func (am *AllocatorManager) SetUpAllocator(parentCtx context.Context, dcLocation string, leadership *election.Leadership) {
am.mu.Lock()
defer am.mu.Unlock()
if am.updatePhysicalInterval != config.DefaultTSOUpdatePhysicalInterval {
if am.updatePhysicalInterval != defaultTSOUpdatePhysicalInterval {
log.Warn("tso update physical interval is non-default",
zap.Duration("update-physical-interval", am.updatePhysicalInterval))
}
Expand Down
28 changes: 28 additions & 0 deletions server/tso/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2022 TiKV Project Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package tso

import (
"time"

"github.com/tikv/pd/pkg/utils/grpcutil"
)

type config interface {
IsLocalTSOEnabled() bool
GetTSOSaveInterval() time.Duration
GetTSOUpdatePhysicalInterval() time.Duration
GetTLSConfig() *grpcutil.TLSConfig
}