Skip to content

Commit

Permalink
fix race
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <rleungx@gmail.com>
  • Loading branch information
rleungx committed Nov 22, 2023
1 parent 709b68c commit 24983ba
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions pkg/mcs/scheduling/server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,15 @@ type PersistConfig struct {
}

// NewPersistConfig creates a new PersistConfig instance.
func NewPersistConfig(cfg *Config) *PersistConfig {
func NewPersistConfig(cfg *Config, ttl *cache.TTLString) *PersistConfig {
o := &PersistConfig{}
o.SetClusterVersion(&cfg.ClusterVersion)
o.schedule.Store(&cfg.Schedule)
o.replication.Store(&cfg.Replication)
// storeConfig will be fetched from TiKV by PD API server,
// so we just set an empty value here first.
o.storeConfig.Store(&sc.StoreConfig{})
o.ttl = nil
o.ttl = ttl
return o
}

Expand Down
4 changes: 0 additions & 4 deletions pkg/mcs/scheduling/server/config/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (

"github.com/coreos/go-semver/semver"
"github.com/pingcap/log"
"github.com/tikv/pd/pkg/cache"
sc "github.com/tikv/pd/pkg/schedule/config"
"github.com/tikv/pd/pkg/schedule/schedulers"
"github.com/tikv/pd/pkg/storage"
Expand Down Expand Up @@ -155,9 +154,6 @@ func (cw *Watcher) initializeConfigWatcher() error {

func (cw *Watcher) initializeTTLConfigWatcher() error {
putFn := func(kv *mvccpb.KeyValue) error {
if cw.ttl == nil {
cw.ttl = cache.NewStringTTL(cw.ctx, time.Second*5, time.Minute*5)
}
key := string(kv.Key)[len(sc.TTLConfigPrefix)+1:]
value := string(kv.Value)
leaseID := kv.Lease
Expand Down
3 changes: 2 additions & 1 deletion pkg/mcs/scheduling/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/pingcap/sysutil"
"github.com/spf13/cobra"
bs "github.com/tikv/pd/pkg/basicserver"
"github.com/tikv/pd/pkg/cache"
"github.com/tikv/pd/pkg/core"
"github.com/tikv/pd/pkg/errs"
"github.com/tikv/pd/pkg/mcs/discovery"
Expand Down Expand Up @@ -534,7 +535,7 @@ func CreateServer(ctx context.Context, cfg *config.Config) *Server {
BaseServer: server.NewBaseServer(ctx),
DiagnosticsServer: sysutil.NewDiagnosticsServer(cfg.Log.File.Filename),
cfg: cfg,
persistConfig: config.NewPersistConfig(cfg),
persistConfig: config.NewPersistConfig(cfg, cache.NewStringTTL(ctx, time.Second*5, time.Minute*5)),
checkMembershipCh: make(chan struct{}, 1),
}
return svr
Expand Down
5 changes: 3 additions & 2 deletions tests/integrations/mcs/scheduling/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"github.com/tikv/pd/pkg/cache"
"github.com/tikv/pd/pkg/core"
"github.com/tikv/pd/pkg/mcs/scheduling/server/config"
sc "github.com/tikv/pd/pkg/schedule/config"
Expand Down Expand Up @@ -84,7 +85,7 @@ func (suite *configTestSuite) TestConfigWatch() {
suite.ctx,
suite.pdLeaderServer.GetEtcdClient(),
suite.cluster.GetCluster().GetId(),
config.NewPersistConfig(config.NewConfig()),
config.NewPersistConfig(config.NewConfig(), cache.NewStringTTL(suite.ctx, time.Second*5, time.Minute*5)),
endpoint.NewStorageEndpoint(kv.NewMemoryKV(), nil),
)
re.NoError(err)
Expand Down Expand Up @@ -144,7 +145,7 @@ func (suite *configTestSuite) TestSchedulerConfigWatch() {
suite.ctx,
suite.pdLeaderServer.GetEtcdClient(),
suite.cluster.GetCluster().GetId(),
config.NewPersistConfig(config.NewConfig()),
config.NewPersistConfig(config.NewConfig(), cache.NewStringTTL(suite.ctx, time.Second*5, time.Minute*5)),
storage,
)
re.NoError(err)
Expand Down

0 comments on commit 24983ba

Please sign in to comment.