@@ -98,20 +98,26 @@ func NewMockDomain() *Domain {
98
98
// Domain represents a storage space. Different domains can use the same database name.
99
99
// Multiple domains can be used in parallel without synchronization.
100
100
type Domain struct {
101
- store kv.Storage
102
- infoCache * infoschema.InfoCache
103
- privHandle * privileges.Handle
104
- bindHandle atomic.Pointer [bindinfo.BindHandle ]
105
- statsHandle unsafe.Pointer
106
- statsLease time.Duration
107
- ddl ddl.DDL
108
- info * infosync.InfoSyncer
109
- globalCfgSyncer * globalconfigsync.GlobalConfigSyncer
110
- m sync.Mutex
111
- SchemaValidator SchemaValidator
112
- sysSessionPool * sessionPool
113
- exit chan struct {}
114
- etcdClient * clientv3.Client
101
+ store kv.Storage
102
+ infoCache * infoschema.InfoCache
103
+ privHandle * privileges.Handle
104
+ bindHandle atomic.Pointer [bindinfo.BindHandle ]
105
+ statsHandle unsafe.Pointer
106
+ statsLease time.Duration
107
+ ddl ddl.DDL
108
+ info * infosync.InfoSyncer
109
+ globalCfgSyncer * globalconfigsync.GlobalConfigSyncer
110
+ m sync.Mutex
111
+ SchemaValidator SchemaValidator
112
+ sysSessionPool * sessionPool
113
+ exit chan struct {}
114
+ // `etcdClient` must be used when keyspace is not set, or when the logic to each etcd path needs to be separated by keyspace.
115
+ etcdClient * clientv3.Client
116
+ // `unprefixedEtcdCli` will never set the etcd namespace prefix by keyspace.
117
+ // It is only used in storeMinStartTS and RemoveMinStartTS now.
118
+ // It must be used when the etcd path isn't needed to separate by keyspace.
119
+ // See keyspace RFC: https://github.com/pingcap/tidb/pull/39685
120
+ unprefixedEtcdCli * clientv3.Client
115
121
sysVarCache sysVarCache // replaces GlobalVariableCache
116
122
slowQuery * topNSlowQueries
117
123
expensiveQueryHandle * expensivequery.Handle
@@ -881,6 +887,10 @@ func (do *Domain) Close() {
881
887
terror .Log (errors .Trace (do .etcdClient .Close ()))
882
888
}
883
889
890
+ if do .unprefixedEtcdCli != nil {
891
+ terror .Log (errors .Trace (do .unprefixedEtcdCli .Close ()))
892
+ }
893
+
884
894
do .slowQuery .Close ()
885
895
if do .cancel != nil {
886
896
do .cancel ()
@@ -927,6 +937,27 @@ func NewDomain(store kv.Storage, ddlLease time.Duration, statsLease time.Duratio
927
937
928
938
const serverIDForStandalone = 1 // serverID for standalone deployment.
929
939
940
+ func newEtcdCli (addrs []string , ebd kv.EtcdBackend ) (* clientv3.Client , error ) {
941
+ cfg := config .GetGlobalConfig ()
942
+ etcdLogCfg := zap .NewProductionConfig ()
943
+ etcdLogCfg .Level = zap .NewAtomicLevelAt (zap .ErrorLevel )
944
+ cli , err := clientv3 .New (clientv3.Config {
945
+ LogConfig : & etcdLogCfg ,
946
+ Endpoints : addrs ,
947
+ AutoSyncInterval : 30 * time .Second ,
948
+ DialTimeout : 5 * time .Second ,
949
+ DialOptions : []grpc.DialOption {
950
+ grpc .WithBackoffMaxDelay (time .Second * 3 ),
951
+ grpc .WithKeepaliveParams (keepalive.ClientParameters {
952
+ Time : time .Duration (cfg .TiKVClient .GrpcKeepAliveTime ) * time .Second ,
953
+ Timeout : time .Duration (cfg .TiKVClient .GrpcKeepAliveTimeout ) * time .Second ,
954
+ }),
955
+ },
956
+ TLS : ebd .TLSConfig (),
957
+ })
958
+ return cli , err
959
+ }
960
+
930
961
// Init initializes a domain.
931
962
func (do * Domain ) Init (
932
963
ddlLease time.Duration ,
@@ -942,32 +973,20 @@ func (do *Domain) Init(
942
973
return err
943
974
}
944
975
if addrs != nil {
945
- cfg := config .GetGlobalConfig ()
946
- // silence etcd warn log, when domain closed, it won't randomly print warn log
947
- // see details at the issue https://github.com/pingcap/tidb/issues/15479
948
- etcdLogCfg := zap .NewProductionConfig ()
949
- etcdLogCfg .Level = zap .NewAtomicLevelAt (zap .ErrorLevel )
950
- cli , err := clientv3 .New (clientv3.Config {
951
- LogConfig : & etcdLogCfg ,
952
- Endpoints : addrs ,
953
- AutoSyncInterval : 30 * time .Second ,
954
- DialTimeout : 5 * time .Second ,
955
- DialOptions : []grpc.DialOption {
956
- grpc .WithBackoffMaxDelay (time .Second * 3 ),
957
- grpc .WithKeepaliveParams (keepalive.ClientParameters {
958
- Time : time .Duration (cfg .TiKVClient .GrpcKeepAliveTime ) * time .Second ,
959
- Timeout : time .Duration (cfg .TiKVClient .GrpcKeepAliveTimeout ) * time .Second ,
960
- }),
961
- },
962
- TLS : ebd .TLSConfig (),
963
- })
976
+ cli , err := newEtcdCli (addrs , ebd )
964
977
if err != nil {
965
978
return errors .Trace (err )
966
979
}
967
980
968
981
etcd .SetEtcdCliByNamespace (cli , keyspace .MakeKeyspaceEtcdNamespace (do .store .GetCodec ()))
969
982
970
983
do .etcdClient = cli
984
+
985
+ unprefixedEtcdCli , err := newEtcdCli (addrs , ebd )
986
+ if err != nil {
987
+ return errors .Trace (err )
988
+ }
989
+ do .unprefixedEtcdCli = unprefixedEtcdCli
971
990
}
972
991
}
973
992
@@ -1029,7 +1048,7 @@ func (do *Domain) Init(
1029
1048
1030
1049
// step 1: prepare the info/schema syncer which domain reload needed.
1031
1050
skipRegisterToDashboard := config .GetGlobalConfig ().SkipRegisterToDashboard
1032
- do .info , err = infosync .GlobalInfoSyncerInit (ctx , do .ddl .GetID (), do .ServerID , do .etcdClient , skipRegisterToDashboard )
1051
+ do .info , err = infosync .GlobalInfoSyncerInit (ctx , do .ddl .GetID (), do .ServerID , do .etcdClient , do . unprefixedEtcdCli , skipRegisterToDashboard )
1033
1052
if err != nil {
1034
1053
return err
1035
1054
}
0 commit comments