@@ -25,13 +25,15 @@ import (
2525 "sync"
2626 "time"
2727
28+ "github.com/XiaoMi/Gaea/core/errors"
2829 "github.com/XiaoMi/Gaea/log"
2930 "github.com/XiaoMi/Gaea/models"
3031 "github.com/XiaoMi/Gaea/mysql"
3132 "github.com/XiaoMi/Gaea/parser"
3233 "github.com/XiaoMi/Gaea/stats"
3334 "github.com/XiaoMi/Gaea/stats/prometheus"
3435 "github.com/XiaoMi/Gaea/util"
36+ "github.com/XiaoMi/Gaea/util/sync2"
3537)
3638
3739// LoadAndCreateManager load namespace config, and create manager
@@ -126,10 +128,11 @@ func loadAllNamespace(cfg *models.Proxy) (map[string]*models.Namespace, error) {
126128
127129// Manager contains namespace manager and user manager
128130type Manager struct {
129- switchIndex util.BoolIndex
130- namespaces [2 ]* NamespaceManager
131- users [2 ]* UserManager
132- statistics * StatisticManager
131+ reloadPrepared sync2.AtomicBool
132+ switchIndex util.BoolIndex
133+ namespaces [2 ]* NamespaceManager
134+ users [2 ]* UserManager
135+ statistics * StatisticManager
133136}
134137
135138// NewManager return empty Manager
@@ -196,12 +199,19 @@ func (m *Manager) ReloadNamespacePrepare(namespaceConfig *models.Namespace) erro
196199 newUserManager := CloneUserManager (currentUserManager )
197200 newUserManager .RebuildNamespaceUsers (namespaceConfig )
198201 m .users [other ] = newUserManager
202+ m .reloadPrepared .Set (true )
199203
200204 return nil
201205}
202206
203207// ReloadNamespaceCommit commit config
204208func (m * Manager ) ReloadNamespaceCommit (name string ) error {
209+ if ! m .reloadPrepared .CompareAndSwap (true , false ) {
210+ err := errors .ErrNamespaceNotPrepared
211+ log .Warn ("commit namespace error, namespace: %s, err: %v" , err )
212+ return err
213+ }
214+
205215 current , _ , index := m .switchIndex .Get ()
206216
207217 currentNamespace := m .namespaces [current ].GetNamespace (name )
@@ -836,6 +846,6 @@ func (s *StatisticManager) recordConnectPoolInuseCount(namespace string, slice s
836846
837847//record wait queue length
838848func (s * StatisticManager ) recordConnectPoolWaitCount (namespace string , slice string , addr string , count int64 ) {
839- statsKey := []string {s .clusterName , namespace , slice , addr }
849+ statsKey := []string {s .clusterName , namespace , slice , addr }
840850 s .backendConnectPoolWaitCounts .Set (statsKey , count )
841851}
0 commit comments