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: introduce the dc-location config #2925

Merged
merged 7 commits into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/tikv/pd/pkg/metricutil"
"github.com/tikv/pd/pkg/typeutil"
"github.com/tikv/pd/server/schedule/storelimit"
"github.com/tikv/pd/server/tso"
"github.com/tikv/pd/server/versioninfo"

"github.com/BurntSushi/toml"
Expand Down Expand Up @@ -82,8 +83,8 @@ type Config struct {
LogFileDeprecated string `toml:"log-file" json:"log-file,omitempty"`
LogLevelDeprecated string `toml:"log-level" json:"log-level,omitempty"`

// TsoSaveInterval is the interval to save timestamp.
TsoSaveInterval typeutil.Duration `toml:"tso-save-interval" json:"tso-save-interval"`
// Tso service related configuration.
Tso TsoConfig `toml:"tso" json:"tso"`
JmPotato marked this conversation as resolved.
Show resolved Hide resolved
JmPotato marked this conversation as resolved.
Show resolved Hide resolved

Metric metricutil.MetricConfig `toml:"metric" json:"metric"`

Expand Down Expand Up @@ -492,7 +493,9 @@ func (c *Config) Adjust(meta *toml.MetaData) error {

adjustInt64(&c.LeaderLease, defaultLeaderLease)

adjustDuration(&c.TsoSaveInterval, time.Duration(defaultLeaderLease)*time.Second)
if err := c.Tso.adjust(); err != nil {
return err
}

if c.nextRetryDelay == 0 {
c.nextRetryDelay = defaultNextRetryDelay
Expand Down Expand Up @@ -1319,3 +1322,32 @@ func (c *DRAutoSyncReplicationConfig) adjust(meta *configMetaData) {
c.WaitSyncTimeout = typeutil.Duration{Duration: defaultDRWaitSyncTimeout}
}
}

// TsoConfig is the configuration for Tso service.
type TsoConfig struct {
// TsoSaveInterval is the interval to save timestamp.
TsoSaveInterval typeutil.Duration `toml:"tso-save-interval" json:"tso-save-interval"`
// EnableLocalTso is used to enable the Local TSO Allocator feature,
// which allows the PD server to generate local Tso for certain DC-level transactions.
// To make this feature meaningful, user has to set the dc-location configuration for
// each PD server.
EnableLocalTso bool `toml:"enable-local-tso" json:"enable-local-tso"`
// DCLocation indicates that which data center a PD server is in. According to it,
// the PD cluster can elect a TSO allocator to generate local Tso for
// DC-level transactions.
DCLocation string `toml:"dc-location" json:"dc-location"`
}
JmPotato marked this conversation as resolved.
Show resolved Hide resolved

// Validate is used to validate if some Tso configurations are right.
func (c *TsoConfig) Validate() error {
if c.DCLocation == tso.GlobalDCLocation {
errMsg := fmt.Sprintf("dc-location %s is the PD reserved label to represent the PD leader, please try another one.", tso.GlobalDCLocation)
return errors.New(errMsg)
}
return nil
}

func (c *TsoConfig) adjust() error {
adjustDuration(&c.TsoSaveInterval, time.Duration(defaultLeaderLease)*time.Second)
return c.Validate()
}
2 changes: 1 addition & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func (s *Server) startServer(ctx context.Context) error {
s.member.SetMemberGitHash(s.member.ID(), versioninfo.PDGitHash)
s.idAllocator = id.NewAllocatorImpl(s.client, s.rootPath, s.member.MemberValue())
s.tsoAllocatorManager = tso.NewAllocatorManager(
s.member.Etcd(), s.client, s.rootPath, s.cfg.TsoSaveInterval.Duration,
s.member.Etcd(), s.client, s.rootPath, s.cfg.Tso.TsoSaveInterval.Duration,
func() time.Duration { return s.persistOptions.GetMaxResetTSGap() },
)
kvBase := kv.NewEtcdKVBase(s.client, s.rootPath)
Expand Down
6 changes: 4 additions & 2 deletions server/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ func NewTestSingleConfig(c *check.C) *config.Config {

InitialClusterState: embed.ClusterStateFlagNew,

LeaderLease: 1,
TsoSaveInterval: typeutil.NewDuration(200 * time.Millisecond),
LeaderLease: 1,
Tso: config.TsoConfig{
TsoSaveInterval: typeutil.NewDuration(200 * time.Millisecond),
},
}

cfg.AdvertiseClientUrls = cfg.ClientUrls
Expand Down
2 changes: 1 addition & 1 deletion tools/pd-simulator/simulator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (sc *SimConfig) Adjust() error {
adjustInt64(&sc.StoreIOMBPerSecond, defaultStoreIOMBPerSecond)
adjustString(&sc.StoreVersion, defaultStoreVersion)
adjustInt64(&sc.ServerConfig.LeaderLease, defaultLeaderLease)
adjustDuration(&sc.ServerConfig.TsoSaveInterval, defaultTsoSaveInterval)
adjustDuration(&sc.ServerConfig.Tso.TsoSaveInterval, defaultTsoSaveInterval)
adjustDuration(&sc.ServerConfig.TickInterval, defaultTickInterval)
adjustDuration(&sc.ServerConfig.ElectionInterval, defaultElectionInterval)
adjustDuration(&sc.ServerConfig.LeaderPriorityCheckInterval, defaultLeaderPriorityCheckInterval)
Expand Down