diff --git a/DEPS.bzl b/DEPS.bzl index 64b86db81c126..ccc74d30966da 100644 --- a/DEPS.bzl +++ b/DEPS.bzl @@ -3342,8 +3342,8 @@ def go_deps(): name = "com_github_pingcap_kvproto", build_file_proto_mode = "disable_global", importpath = "github.com/pingcap/kvproto", - sum = "h1:oYUK4V5PMlyIooU/+pPkKrJ3vELwcuuCNyKKlqSQa5c=", - version = "v0.0.0-20230131104319-a7c51106dfe7", + sum = "h1:ZiCJcEzmmF5xNgt8GIXekd3WQXI/22kzYQnrHi3Fc/4=", + version = "v0.0.0-20230201112839-2b853bed8125", ) go_repository( name = "com_github_pingcap_log", @@ -4055,23 +4055,23 @@ def go_deps(): name = "com_github_tikv_client_go_v2", build_file_proto_mode = "disable_global", importpath = "github.com/tikv/client-go/v2", - sum = "h1:2BmijiUk1Hcv0z58DVk4ypwaNmgutzLc2YJm0SHPEWE=", - version = "v2.0.5-0.20230120021435-f89383775234", + sum = "h1:j2s6Gechj46t1GWxE0vZEPBqgp7sc7mb3v0srBmf5Tw=", + version = "v2.0.5-0.20230202101145-8fd09cd88cce", ) go_repository( name = "com_github_tikv_pd", build_file_proto_mode = "disable", importpath = "github.com/tikv/pd", - sum = "h1:ef+kODGby/rmF9fabJzqRM15NcGufkTRftROdy7jvAk=", - version = "v1.1.0-beta.0.20230201064005-6ca9a3398f15", + sum = "h1:iY/RztOIZ2nTbINUiLGsSv3SUGoEiub1GN0SKVKHJYg=", + version = "v1.1.0-beta.0.20230202094356-18df271ce57f", ) go_repository( name = "com_github_tikv_pd_client", build_file_proto_mode = "disable_global", importpath = "github.com/tikv/pd/client", - sum = "h1:KK5bx0KLcpYUCnuQ06THPYT6QdAMfvwAtRQ0saVGD7k=", - version = "v0.0.0-20230119115149-5c518d079b93", + sum = "h1:xHPPej9Z8IrYdyLED4byOGtGm/7yhxyRUf4m93CpDyg=", + version = "v0.0.0-20230202094356-18df271ce57f", ) go_repository( name = "com_github_timakin_bodyclose", diff --git a/domain/globalconfigsync/globalconfig.go b/domain/globalconfigsync/globalconfig.go index 020e5dde8491c..35b4447189884 100644 --- a/domain/globalconfigsync/globalconfig.go +++ b/domain/globalconfigsync/globalconfig.go @@ -22,9 +22,6 @@ import ( "go.uber.org/zap" ) -// GlobalConfigPath as Etcd prefix -const GlobalConfigPath = "/global/config/" - // GlobalConfigSyncer is used to sync pd global config. type GlobalConfigSyncer struct { pd pd.Client @@ -44,7 +41,7 @@ func (s *GlobalConfigSyncer) StoreGlobalConfig(ctx context.Context, item pd.Glob if s.pd == nil { return nil } - err := s.pd.StoreGlobalConfig(ctx, GlobalConfigPath, []pd.GlobalConfigItem{item}) + err := s.pd.StoreGlobalConfig(ctx, "", []pd.GlobalConfigItem{item}) if err != nil { return err } diff --git a/domain/globalconfigsync/globalconfig_test.go b/domain/globalconfigsync/globalconfig_test.go index 455b79f2276b4..2d97b7c9e2b9f 100644 --- a/domain/globalconfigsync/globalconfig_test.go +++ b/domain/globalconfigsync/globalconfig_test.go @@ -16,7 +16,6 @@ package globalconfigsync_test import ( "context" - "path" "runtime" "testing" "time" @@ -59,10 +58,10 @@ func TestGlobalConfigSyncer(t *testing.T) { syncer.Notify(pd.GlobalConfigItem{Name: "a", Value: "b"}) err = syncer.StoreGlobalConfig(context.Background(), <-syncer.NotifyCh) require.NoError(t, err) - items, revision, err := client.LoadGlobalConfig(context.Background(), globalconfigsync.GlobalConfigPath) + items, revision, err := client.LoadGlobalConfig(context.Background(), []string{"a"}, "") require.NoError(t, err) require.Equal(t, 1, len(items)) - require.Equal(t, path.Join(globalconfigsync.GlobalConfigPath, "a"), items[0].Name) + require.Equal(t, "/global/config/a", items[0].Name) require.Equal(t, int64(0), revision) require.Equal(t, "b", items[0].Value) } @@ -97,15 +96,15 @@ func TestStoreGlobalConfig(t *testing.T) { client := store.(kv.StorageWithPD).GetPDClient() // enable top sql will be translated to enable_resource_metering - items, _, err := client.LoadGlobalConfig(context.Background(), globalconfigsync.GlobalConfigPath) + items, _, err := client.LoadGlobalConfig(context.Background(), []string{"enable_resource_metering", "source_id"}, "") require.NoError(t, err) if len(items) == 2 && items[0].Value == "" { continue } require.Len(t, items, 2) - require.Equal(t, items[0].Name, path.Join(globalconfigsync.GlobalConfigPath, "enable_resource_metering")) + require.Equal(t, items[0].Name, "/global/config/enable_resource_metering") require.Equal(t, items[0].Value, "true") - require.Equal(t, items[1].Name, path.Join(globalconfigsync.GlobalConfigPath, "source_id")) + require.Equal(t, items[1].Name, "/global/config/source_id") require.Equal(t, items[1].Value, "2") return } diff --git a/go.mod b/go.mod index 94def97907765..302a89ad94138 100644 --- a/go.mod +++ b/go.mod @@ -71,7 +71,7 @@ require ( github.com/pingcap/errors v0.11.5-0.20221009092201-b66cddb77c32 github.com/pingcap/failpoint v0.0.0-20220423142525-ae43b7f4e5c3 github.com/pingcap/fn v0.0.0-20200306044125-d5540d389059 - github.com/pingcap/kvproto v0.0.0-20230131104319-a7c51106dfe7 + github.com/pingcap/kvproto v0.0.0-20230201112839-2b853bed8125 github.com/pingcap/log v1.1.1-0.20221116035753-734d527bc87c github.com/pingcap/sysutil v0.0.0-20220114020952-ea68d2dbf5b4 github.com/pingcap/tidb/parser v0.0.0-20211011031125-9b13dc409c5e @@ -92,9 +92,9 @@ require ( github.com/stretchr/testify v1.8.1 github.com/tdakkota/asciicheck v0.1.1 github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2 - github.com/tikv/client-go/v2 v2.0.5-0.20230120021435-f89383775234 - github.com/tikv/pd v1.1.0-beta.0.20230201064005-6ca9a3398f15 - github.com/tikv/pd/client v0.0.0-20230119115149-5c518d079b93 + github.com/tikv/client-go/v2 v2.0.5-0.20230202101145-8fd09cd88cce + github.com/tikv/pd v1.1.0-beta.0.20230202094356-18df271ce57f + github.com/tikv/pd/client v0.0.0-20230202094356-18df271ce57f github.com/timakin/bodyclose v0.0.0-20210704033933-f49887972144 github.com/twmb/murmur3 v1.1.3 github.com/uber/jaeger-client-go v2.22.1+incompatible diff --git a/go.sum b/go.sum index c5964185fa6c5..05c043c3a2bb8 100644 --- a/go.sum +++ b/go.sum @@ -1143,9 +1143,8 @@ github.com/pingcap/fn v0.0.0-20200306044125-d5540d389059/go.mod h1:fMRU1BA1y+r89 github.com/pingcap/goleveldb v0.0.0-20191226122134-f82aafb29989 h1:surzm05a8C9dN8dIUmo4Be2+pMRb6f55i+UIYrluu2E= github.com/pingcap/goleveldb v0.0.0-20191226122134-f82aafb29989/go.mod h1:O17XtbryoCJhkKGbT62+L2OlrniwqiGLSqrmdHCMzZw= github.com/pingcap/kvproto v0.0.0-20191211054548-3c6b38ea5107/go.mod h1:WWLmULLO7l8IOcQG+t+ItJ3fEcrL5FxF0Wu+HrMy26w= -github.com/pingcap/kvproto v0.0.0-20230119031034-25f1909b7934/go.mod h1:+on3Lfk/fb1lXkud3XvskJumhSIEEgN2TTbMObUlrxE= -github.com/pingcap/kvproto v0.0.0-20230131104319-a7c51106dfe7 h1:oYUK4V5PMlyIooU/+pPkKrJ3vELwcuuCNyKKlqSQa5c= -github.com/pingcap/kvproto v0.0.0-20230131104319-a7c51106dfe7/go.mod h1:+on3Lfk/fb1lXkud3XvskJumhSIEEgN2TTbMObUlrxE= +github.com/pingcap/kvproto v0.0.0-20230201112839-2b853bed8125 h1:ZiCJcEzmmF5xNgt8GIXekd3WQXI/22kzYQnrHi3Fc/4= +github.com/pingcap/kvproto v0.0.0-20230201112839-2b853bed8125/go.mod h1:+on3Lfk/fb1lXkud3XvskJumhSIEEgN2TTbMObUlrxE= github.com/pingcap/log v0.0.0-20191012051959-b742a5d432e9/go.mod h1:4rbK1p9ILyIfb6hU7OG2CiWSqMXnp3JMbiaVJ6mvoY8= github.com/pingcap/log v0.0.0-20210625125904-98ed8e2eb1c7/go.mod h1:8AanEdAHATuRurdGxZXBz0At+9avep+ub7U1AGYLIMM= github.com/pingcap/log v1.1.0/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4= @@ -1308,12 +1307,12 @@ github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2 h1:mbAskLJ0oJf github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2/go.mod h1:2PfKggNGDuadAa0LElHrByyrz4JPZ9fFx6Gs7nx7ZZU= github.com/tiancaiamao/gp v0.0.0-20221230034425-4025bc8a4d4a h1:J/YdBZ46WKpXsxsW93SG+q0F8KI+yFrcIDT4c/RNoc4= github.com/tiancaiamao/gp v0.0.0-20221230034425-4025bc8a4d4a/go.mod h1:h4xBhSNtOeEosLJ4P7JyKXX7Cabg7AVkWCK5gV2vOrM= -github.com/tikv/client-go/v2 v2.0.5-0.20230120021435-f89383775234 h1:2BmijiUk1Hcv0z58DVk4ypwaNmgutzLc2YJm0SHPEWE= -github.com/tikv/client-go/v2 v2.0.5-0.20230120021435-f89383775234/go.mod h1:jc7J2EbNeVvU6eXmB50wAGrTPyJwdi+0ENccMXMFSpw= -github.com/tikv/pd v1.1.0-beta.0.20230201064005-6ca9a3398f15 h1:ef+kODGby/rmF9fabJzqRM15NcGufkTRftROdy7jvAk= -github.com/tikv/pd v1.1.0-beta.0.20230201064005-6ca9a3398f15/go.mod h1:UnfZJ+ykNsVbQgo/CZ3NFyHnLJ/pQGlBD0M/WgxFHMQ= -github.com/tikv/pd/client v0.0.0-20230119115149-5c518d079b93 h1:KK5bx0KLcpYUCnuQ06THPYT6QdAMfvwAtRQ0saVGD7k= -github.com/tikv/pd/client v0.0.0-20230119115149-5c518d079b93/go.mod h1:NrbwVp9afaCmJjJEwFNtEQWfCChAW1ndnwjteHHS+d0= +github.com/tikv/client-go/v2 v2.0.5-0.20230202101145-8fd09cd88cce h1:j2s6Gechj46t1GWxE0vZEPBqgp7sc7mb3v0srBmf5Tw= +github.com/tikv/client-go/v2 v2.0.5-0.20230202101145-8fd09cd88cce/go.mod h1:DtwnMX8PDLcbXn2T4AyiCFPjmzTr1F4MQzJQpQhJeLM= +github.com/tikv/pd v1.1.0-beta.0.20230202094356-18df271ce57f h1:iY/RztOIZ2nTbINUiLGsSv3SUGoEiub1GN0SKVKHJYg= +github.com/tikv/pd v1.1.0-beta.0.20230202094356-18df271ce57f/go.mod h1:jb9oq6rN4U0U3FZdvqWlpi9rZzFJxiOlvZ3aj5BTpg8= +github.com/tikv/pd/client v0.0.0-20230202094356-18df271ce57f h1:xHPPej9Z8IrYdyLED4byOGtGm/7yhxyRUf4m93CpDyg= +github.com/tikv/pd/client v0.0.0-20230202094356-18df271ce57f/go.mod h1:0fdKmj9cafPLsHAeVAcgB50Uj018WGfMC1tgvzWXXQQ= github.com/timakin/bodyclose v0.0.0-20210704033933-f49887972144 h1:kl4KhGNsJIbDHS9/4U9yQo1UcPQM0kOMJHn29EoH/Ro= github.com/timakin/bodyclose v0.0.0-20210704033933-f49887972144/go.mod h1:Qimiffbc6q9tBWlVV6x0P9sat/ao1xEkREYPPj9hphk= github.com/tklauser/go-sysconf v0.3.9/go.mod h1:11DU/5sG7UexIrp/O6g35hrWzu0JxlwQ3LSFUzyeuhs= diff --git a/store/mockstore/unistore/pd.go b/store/mockstore/unistore/pd.go index 380707cc166a7..d72247ef8b44f 100644 --- a/store/mockstore/unistore/pd.go +++ b/store/mockstore/unistore/pd.go @@ -18,8 +18,6 @@ import ( "context" "errors" "math" - "path" - "strings" "sync" "sync/atomic" @@ -50,11 +48,13 @@ func newPDClient(pd *us.MockPD) *pdClient { } } -func (c *pdClient) LoadGlobalConfig(ctx context.Context, configPath string) ([]pd.GlobalConfigItem, int64, error) { - ret := make([]pd.GlobalConfigItem, 0) - for k, v := range c.globalConfig { - if strings.HasPrefix(k, configPath) { - ret = append(ret, pd.GlobalConfigItem{Name: k, Value: v}) +func (c *pdClient) LoadGlobalConfig(ctx context.Context, names []string, configPath string) ([]pd.GlobalConfigItem, int64, error) { + ret := make([]pd.GlobalConfigItem, len(names)) + for i, name := range names { + if r, ok := c.globalConfig["/global/config/"+name]; ok { + ret[i] = pd.GlobalConfigItem{Name: "/global/config/" + name, Value: r, EventType: pdpb.EventType_PUT} + } else { + ret[i] = pd.GlobalConfigItem{Name: "/global/config/" + name, Value: ""} } } return ret, 0, nil @@ -62,7 +62,7 @@ func (c *pdClient) LoadGlobalConfig(ctx context.Context, configPath string) ([]p func (c *pdClient) StoreGlobalConfig(ctx context.Context, configPath string, items []pd.GlobalConfigItem) error { for _, item := range items { - c.globalConfig[path.Join(configPath, item.Name)] = item.Value + c.globalConfig["/global/config/"+item.Name] = item.Value } return nil } diff --git a/store/mockstore/unistore/pd_test.go b/store/mockstore/unistore/pd_test.go index a75533c83533e..4cfbfd094e396 100644 --- a/store/mockstore/unistore/pd_test.go +++ b/store/mockstore/unistore/pd_test.go @@ -34,15 +34,39 @@ func SetUpSuite() *GlobalConfigTestSuite { return s } -func TestLoadAndStore(t *testing.T) { +func TestLoad(t *testing.T) { s := SetUpSuite() - - err := s.client.StoreGlobalConfig(context.Background(), "/global/config", []pd.GlobalConfigItem{{Name: "NewObject", Value: "ok"}}) + err := s.client.StoreGlobalConfig(context.Background(), "", []pd.GlobalConfigItem{{Name: "LoadOkGlobalConfig", Value: "ok"}}) require.Equal(t, nil, err) + res, _, err := s.client.LoadGlobalConfig(context.Background(), []string{"LoadOkGlobalConfig", "LoadErrGlobalConfig"}, "") + require.Equal(t, err, nil) + for _, j := range res { + println(j.Name) + switch j.Name { + case "/global/config/LoadOkGlobalConfig": + require.Equal(t, "ok", j.Value) + case "/global/config/LoadErrGlobalConfig": + require.Equal(t, "", j.Value) + default: + require.Equal(t, true, false) + } + } + s.TearDownSuite() +} - res, _, err := s.client.LoadGlobalConfig(context.Background(), "/global/config") - require.Equal(t, nil, err) - require.Equal(t, 1, len(res)) +func TestStore(t *testing.T) { + s := SetUpSuite() + + res, _, err := s.client.LoadGlobalConfig(context.Background(), []string{"NewObject"}, "") + require.Equal(t, err, nil) + require.Equal(t, res[0].Value, "") + + err = s.client.StoreGlobalConfig(context.Background(), "", []pd.GlobalConfigItem{{Name: "NewObject", Value: "ok"}}) + require.Equal(t, err, nil) + + res, _, err = s.client.LoadGlobalConfig(context.Background(), []string{"NewObject"}, "") + require.Equal(t, err, nil) + require.Equal(t, res[0].Value, "ok") s.TearDownSuite() }