From 4011cc397d5581a2b2896fa1f331ff851e2f9882 Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Fri, 16 Apr 2021 13:35:01 +0800 Subject: [PATCH 1/2] fix the data race problem Signed-off-by: Ryan Leung --- server/config/persist_options.go | 5 +++++ server/server.go | 12 +++--------- server/statistics/store_collection.go | 3 ++- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/server/config/persist_options.go b/server/config/persist_options.go index b112315d70e..63a1b75f8c3 100644 --- a/server/config/persist_options.go +++ b/server/config/persist_options.go @@ -495,6 +495,11 @@ func (o *PersistOptions) GetHotRegionCacheHitsThreshold() int { return int(o.GetScheduleConfig().HotRegionCacheHitsThreshold) } +// GetStoresLimit gets the stores' limit. +func (o *PersistOptions) GetStoresLimit() map[uint64]StoreLimitConfig { + return o.GetScheduleConfig().StoreLimit +} + // GetSchedulers gets the scheduler configurations. func (o *PersistOptions) GetSchedulers() SchedulerConfigs { return o.GetScheduleConfig().Schedulers diff --git a/server/server.go b/server/server.go index 97d2df8c0ac..7c475af1cb0 100644 --- a/server/server.go +++ b/server/server.go @@ -785,9 +785,7 @@ func (s *Server) GetConfig() *config.Config { // GetScheduleConfig gets the balance config information. func (s *Server) GetScheduleConfig() *config.ScheduleConfig { - cfg := &config.ScheduleConfig{} - *cfg = *s.persistOptions.GetScheduleConfig() - return cfg + return s.persistOptions.GetScheduleConfig().Clone() } // SetScheduleConfig sets the balance config information. @@ -815,9 +813,7 @@ func (s *Server) SetScheduleConfig(cfg config.ScheduleConfig) error { // GetReplicationConfig get the replication config. func (s *Server) GetReplicationConfig() *config.ReplicationConfig { - cfg := &config.ReplicationConfig{} - *cfg = *s.persistOptions.GetReplicationConfig() - return cfg + return s.persistOptions.GetReplicationConfig().Clone() } // SetReplicationConfig sets the replication config. @@ -905,9 +901,7 @@ func (s *Server) SetReplicationConfig(cfg config.ReplicationConfig) error { // GetPDServerConfig gets the balance config information. func (s *Server) GetPDServerConfig() *config.PDServerConfig { - cfg := &config.PDServerConfig{} - *cfg = *s.persistOptions.GetPDServerConfig() - return cfg + return s.persistOptions.GetPDServerConfig().Clone() } // SetPDServerConfig sets the server config. diff --git a/server/statistics/store_collection.go b/server/statistics/store_collection.go index 6813ad055e7..c7d289c8506 100644 --- a/server/statistics/store_collection.go +++ b/server/statistics/store_collection.go @@ -187,7 +187,8 @@ func (s *storeStatistics) Collect() { placementStatusGauge.WithLabelValues(labelType, name).Set(float64(value)) } - for storeID, limit := range s.opt.GetScheduleConfig().StoreLimit { + storesLimit := s.opt.GetStoresLimit() + for storeID, limit := range storesLimit { id := strconv.FormatUint(storeID, 10) StoreLimitGauge.WithLabelValues(id, "add-peer").Set(limit.AddPeer) StoreLimitGauge.WithLabelValues(id, "remove-peer").Set(limit.RemovePeer) From 9fe36373261cf8b3caa47a4125665286b31dfd66 Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Fri, 16 Apr 2021 14:46:15 +0800 Subject: [PATCH 2/2] address the comment Signed-off-by: Ryan Leung --- server/statistics/store_collection.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/statistics/store_collection.go b/server/statistics/store_collection.go index c7d289c8506..d24f68295aa 100644 --- a/server/statistics/store_collection.go +++ b/server/statistics/store_collection.go @@ -187,8 +187,7 @@ func (s *storeStatistics) Collect() { placementStatusGauge.WithLabelValues(labelType, name).Set(float64(value)) } - storesLimit := s.opt.GetStoresLimit() - for storeID, limit := range storesLimit { + for storeID, limit := range s.opt.GetStoresLimit() { id := strconv.FormatUint(storeID, 10) StoreLimitGauge.WithLabelValues(id, "add-peer").Set(limit.AddPeer) StoreLimitGauge.WithLabelValues(id, "remove-peer").Set(limit.RemovePeer)