Skip to content

Commit

Permalink
ddl: disable raw mode resource group (#41050)
Browse files Browse the repository at this point in the history
close #41049
  • Loading branch information
BornChanger authored Feb 8, 2023
1 parent 8398f0f commit 3f0964f
Show file tree
Hide file tree
Showing 11 changed files with 4,851 additions and 4,969 deletions.
20 changes: 10 additions & 10 deletions DEPS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1018,8 +1018,8 @@ def go_deps():
name = "com_github_evanphx_json_patch",
build_file_proto_mode = "disable",
importpath = "github.com/evanphx/json-patch",
sum = "h1:4onqiflcdA9EOZ4RxV643DvftH5pOlLGNtQ5lPWQu84=",
version = "v4.12.0+incompatible",
sum = "h1:K1MDoo4AZ4wU0GIU/fPmtZg7VpzLjCxu+UwBD1FvwOc=",
version = "v4.1.0+incompatible",
)
go_repository(
name = "com_github_facebookgo_clock",
Expand Down Expand Up @@ -1709,8 +1709,8 @@ def go_deps():
name = "com_github_google_gofuzz",
build_file_proto_mode = "disable_global",
importpath = "github.com/google/gofuzz",
sum = "h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g=",
version = "v1.1.0",
sum = "h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw=",
version = "v1.0.0",
)
go_repository(
name = "com_github_google_licensecheck",
Expand Down Expand Up @@ -5622,8 +5622,8 @@ def go_deps():
name = "io_k8s_apimachinery",
build_file_proto_mode = "disable",
importpath = "k8s.io/apimachinery",
sum = "h1:1feANjElT7MvPqp0JT6F3Ss6TWDwmcjLypwoPpEf7zg=",
version = "v0.26.0",
sum = "h1:Jmdtdt1ZnoGfWWIIik61Z7nKYgO3J+swQJtPYsP9wHA=",
version = "v0.0.0-20190404173353-6a84e37a896d",
)
go_repository(
name = "io_k8s_client_go",
Expand Down Expand Up @@ -5651,8 +5651,8 @@ def go_deps():
name = "io_k8s_kube_openapi",
build_file_proto_mode = "disable",
importpath = "k8s.io/kube-openapi",
sum = "h1:+70TFaan3hfJzs+7VK2o+OGxg8HsuBr/5f6tVAjDu6E=",
version = "v0.0.0-20221012153701-172d655c2280",
sum = "h1:tHgpQvrWaYfrnC8G4N0Oszw5HHCsZxKilDi2R7HuCSM=",
version = "v0.0.0-20180629012420-d83b052f768a",
)
go_repository(
name = "io_k8s_sigs_json",
Expand Down Expand Up @@ -5680,8 +5680,8 @@ def go_deps():
name = "io_k8s_utils",
build_file_proto_mode = "disable",
importpath = "k8s.io/utils",
sum = "h1:0Smp/HP1OH4Rvhe+4B8nWGERtlqAGSftbSbbmm45oFs=",
version = "v0.0.0-20221107191617-1a15be271d1d",
sum = "h1:8r+l4bNWjRlsFYlQJnKJ2p7s1YQPj4XyXiJVqDHRx7c=",
version = "v0.0.0-20190308190857-21c4ce38f2a7",
)
go_repository(
name = "io_moul_zapgorm2",
Expand Down
1 change: 0 additions & 1 deletion ddl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ go_test(
"//config",
"//ddl/internal/callback",
"//ddl/placement",
"//ddl/resourcegroup",
"//ddl/schematracker",
"//ddl/testutil",
"//ddl/util",
Expand Down
45 changes: 19 additions & 26 deletions ddl/resource_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"testing"

"github.com/pingcap/tidb/ddl/internal/callback"
"github.com/pingcap/tidb/ddl/resourcegroup"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/domain/infosync"
mysql "github.com/pingcap/tidb/errno"
Expand Down Expand Up @@ -99,50 +98,50 @@ func TestResourceGroupBasic(t *testing.T) {
res = tk.MustQuery("show warnings")
res.Check(testkit.Rows("Note 8249 Unknown resource group 'not_exists'"))

tk.MustExec("create resource group y " +
"CPU='4000m' " +
"IO_READ_BANDWIDTH='1G' " +
"IO_WRITE_BANDWIDTH='300M'")
tk.MustExec("create resource group y RU_PER_SEC=4000")
checkFunc = func(groupInfo *model.ResourceGroupInfo) {
require.Equal(t, true, groupInfo.ID != 0)
require.Equal(t, "y", groupInfo.Name.L)
require.Equal(t, groupID, groupInfo.ID)
require.Equal(t, "4000m", groupInfo.CPULimiter)
require.Equal(t, "1G", groupInfo.IOReadBandwidth)
require.Equal(t, "300M", groupInfo.IOWriteBandwidth)
require.Equal(t, uint64(4000), groupInfo.RURate)
require.Equal(t, int64(0), groupInfo.BurstLimit)
}
g = testResourceGroupNameFromIS(t, tk.Session(), "y")
checkFunc(g)
tk.MustExec("alter resource group y " +
"CPU='8000m' " +
"IO_READ_BANDWIDTH='10G' " +
"IO_WRITE_BANDWIDTH='3000M'")
tk.MustExec("alter resource group y BURSTABLE RU_PER_SEC=5000")
checkFunc = func(groupInfo *model.ResourceGroupInfo) {
require.Equal(t, true, groupInfo.ID != 0)
require.Equal(t, "y", groupInfo.Name.L)
require.Equal(t, groupID, groupInfo.ID)
require.Equal(t, "8000m", groupInfo.CPULimiter)
require.Equal(t, "10G", groupInfo.IOReadBandwidth)
require.Equal(t, "3000M", groupInfo.IOWriteBandwidth)
require.Equal(t, uint64(5000), groupInfo.RURate)
require.Equal(t, int64(-1), groupInfo.BurstLimit)
}
g = testResourceGroupNameFromIS(t, tk.Session(), "y")
checkFunc(g)
tk.MustExec("drop resource group y")
g = testResourceGroupNameFromIS(t, tk.Session(), "y")
re.Nil(g)
tk.MustContainErrMsg("create resource group x RU_PER_SEC=1000, CPU='8000m';", resourcegroup.ErrInvalidResourceGroupDuplicatedMode.Error())

tk.MustGetErrCode("create resource group x ru_per_sec=1000 ru_per_sec=200", mysql.ErrParse)
tk.MustContainErrMsg("create resource group x ru_per_sec=1000 ru_per_sec=200, ru_per_sec=300", "Dupliated options specified")
tk.MustGetErrCode("create resource group x burstable, burstable", mysql.ErrParse)
tk.MustContainErrMsg("create resource group x burstable, burstable", "Dupliated options specified")
groups, err := infosync.ListResourceGroups(context.TODO())
require.Equal(t, 0, len(groups))
require.NoError(t, err)

// Check information schema table information_schema.resource_groups
tk.MustExec("create resource group x RU_PER_SEC=1000")
tk.MustQuery("select * from information_schema.resource_groups where name = 'x'").Check(testkit.Rows("x 1000 0 NO"))
tk.MustQuery("show create resource group x").Check(testkit.Rows("x CREATE RESOURCE GROUP `x` RU_PER_SEC=1000"))
tk.MustExec("alter resource group x RU_PER_SEC=2000 BURSTABLE")
tk.MustQuery("select * from information_schema.resource_groups where name = 'x'").Check(testkit.Rows("x 2000 0 YES"))
tk.MustExec("alter resource group x BURSTABLE RU_PER_SEC=3000")
tk.MustQuery("select * from information_schema.resource_groups where name = 'x'").Check(testkit.Rows("x 3000 0 YES"))
tk.MustQuery("show create resource group x").Check(testkit.Rows("x CREATE RESOURCE GROUP `x` RU_PER_SEC=3000 BURSTABLE"))

tk.MustExec("create resource group y RU_PER_SEC=2000")
tk.MustQuery("select * from information_schema.resource_groups where name = 'y'").Check(testkit.Rows("y 2000 0 NO"))
tk.MustQuery("show create resource group y").Check(testkit.Rows("y CREATE RESOURCE GROUP `y` RU_PER_SEC=2000"))
tk.MustExec("create resource group y BURSTABLE RU_PER_SEC=2000")
tk.MustQuery("select * from information_schema.resource_groups where name = 'y'").Check(testkit.Rows("y 2000 0 YES"))
tk.MustQuery("show create resource group y").Check(testkit.Rows("y CREATE RESOURCE GROUP `y` RU_PER_SEC=2000 BURSTABLE"))

tk.MustExec("alter resource group y RU_PER_SEC=4000 BURSTABLE")
tk.MustQuery("select * from information_schema.resource_groups where name = 'y'").Check(testkit.Rows("y 4000 0 YES"))
Expand All @@ -155,12 +154,6 @@ func TestResourceGroupBasic(t *testing.T) {
tk.MustGetErrCode("alter user user2 resource group nil_group", mysql.ErrResourceGroupNotExists)
tk.MustContainErrMsg("alter user user2 resource group nil_group", "Unknown resource group 'nil_group'")

tk.MustExec("create resource group z " +
"CPU='4000m' " +
"IO_READ_BANDWIDTH='1G' " +
"IO_WRITE_BANDWIDTH='300M'")
tk.MustQuery("show create resource group z").Check(testkit.Rows("z CREATE RESOURCE GROUP `z` CPU=\"4000m\" IO_READ_BANDWIDTH=\"1G\" IO_WRITE_BANDWIDTH=\"300M\""))

tk.MustExec("create resource group do_not_delete_rg ru_per_sec=100")
tk.MustExec("create user usr3 resource group do_not_delete_rg")
tk.MustQuery("select user_attributes from mysql.user where user = 'usr3'").Check(testkit.Rows(`{"resource_group": "do_not_delete_rg"}`))
Expand Down
1 change: 0 additions & 1 deletion ddl/resourcegroup/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ go_library(
"//parser/model",
"@com_github_pingcap_errors//:errors",
"@com_github_pingcap_kvproto//pkg/resource_manager",
"@io_k8s_apimachinery//pkg/api/resource",
],
)

Expand Down
56 changes: 2 additions & 54 deletions ddl/resourcegroup/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
package resourcegroup

import (
"github.com/pingcap/errors"
rmpb "github.com/pingcap/kvproto/pkg/resource_manager"
"github.com/pingcap/tidb/parser/model"
"k8s.io/apimachinery/pkg/api/resource"
)

// MaxGroupNameLength is max length of the name of a resource group
Expand All @@ -35,9 +33,7 @@ func NewGroupFromOptions(groupName string, options *model.ResourceGroupSettings)
group := &rmpb.ResourceGroup{
Name: groupName,
}
var isRUMode bool
if options.RURate > 0 {
isRUMode = true
group.Mode = rmpb.GroupMode_RUMode
group.RUSettings = &rmpb.GroupRequestUnitSettings{
RU: &rmpb.TokenBucket{
Expand All @@ -47,59 +43,11 @@ func NewGroupFromOptions(groupName string, options *model.ResourceGroupSettings)
},
},
}
}
if len(options.CPULimiter) > 0 || len(options.IOReadBandwidth) > 0 || len(options.IOWriteBandwidth) > 0 {
if isRUMode {
if len(options.CPULimiter) > 0 || len(options.IOReadBandwidth) > 0 || len(options.IOWriteBandwidth) > 0 {
return nil, ErrInvalidResourceGroupDuplicatedMode
}
parseF := func(s string, scale resource.Scale) (uint64, error) {
if len(s) == 0 {
return 0, nil
}
q, err := resource.ParseQuantity(s)
if err != nil {
return 0, err
}
return uint64(q.ScaledValue(scale)), nil
}
cpuRate, err := parseF(options.CPULimiter, resource.Milli)
if err != nil {
return nil, errors.Annotate(ErrInvalidResourceGroupFormat, err.Error())
}
ioReadRate, err := parseF(options.IOReadBandwidth, resource.Scale(0))
if err != nil {
return nil, errors.Annotate(ErrInvalidResourceGroupFormat, err.Error())
}
ioWriteRate, err := parseF(options.IOWriteBandwidth, resource.Scale(0))
if err != nil {
return nil, errors.Annotate(ErrInvalidResourceGroupFormat, err.Error())
}

group.Mode = rmpb.GroupMode_RawMode
group.RawResourceSettings = &rmpb.GroupRawResourceSettings{
Cpu: &rmpb.TokenBucket{
Settings: &rmpb.TokenLimitSettings{
FillRate: cpuRate,
BurstLimit: options.BurstLimit,
},
},
IoRead: &rmpb.TokenBucket{
Settings: &rmpb.TokenLimitSettings{
FillRate: ioReadRate,
BurstLimit: options.BurstLimit,
},
},
IoWrite: &rmpb.TokenBucket{
Settings: &rmpb.TokenLimitSettings{
FillRate: ioWriteRate,
BurstLimit: options.BurstLimit,
},
},
}
return group, nil
}
if isRUMode {
return group, nil
}
// Only support RU mode now
return nil, ErrUnknownResourceGroupMode
}
42 changes: 3 additions & 39 deletions ddl/resourcegroup/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,50 +73,14 @@ func TestNewResourceGroupFromOptions(t *testing.T) {
},
})

tests = append(tests, TestCase{
name: "normal case: native case 1",
input: &model.ResourceGroupSettings{
CPULimiter: "8000m",
IOReadBandwidth: "3000M",
IOWriteBandwidth: "1500M",
},
output: &rmpb.ResourceGroup{
Name: groupName,
Mode: rmpb.GroupMode_RawMode,
RawResourceSettings: &rmpb.GroupRawResourceSettings{
Cpu: &rmpb.TokenBucket{Settings: &rmpb.TokenLimitSettings{FillRate: 8000}},
IoRead: &rmpb.TokenBucket{Settings: &rmpb.TokenLimitSettings{FillRate: 3000000000}},
IoWrite: &rmpb.TokenBucket{Settings: &rmpb.TokenLimitSettings{FillRate: 1500000000}},
},
},
})

tests = append(tests, TestCase{
name: "normal case: native case 2",
input: &model.ResourceGroupSettings{
CPULimiter: "8",
IOReadBandwidth: "3000Mi",
IOWriteBandwidth: "3000Mi",
},
output: &rmpb.ResourceGroup{
Name: groupName,
Mode: rmpb.GroupMode_RawMode,
RawResourceSettings: &rmpb.GroupRawResourceSettings{
Cpu: &rmpb.TokenBucket{Settings: &rmpb.TokenLimitSettings{FillRate: 8000}},
IoRead: &rmpb.TokenBucket{Settings: &rmpb.TokenLimitSettings{FillRate: 3145728000}},
IoWrite: &rmpb.TokenBucket{Settings: &rmpb.TokenLimitSettings{FillRate: 3145728000}},
},
},
})

tests = append(tests, TestCase{
name: "error case: native case 1",
input: &model.ResourceGroupSettings{
CPULimiter: "8",
IOReadBandwidth: "3000MB/s",
IOWriteBandwidth: "3000Mi",
},
err: ErrInvalidResourceGroupFormat,
err: ErrUnknownResourceGroupMode,
})

tests = append(tests, TestCase{
Expand All @@ -126,7 +90,7 @@ func TestNewResourceGroupFromOptions(t *testing.T) {
IOReadBandwidth: "3000Mi",
IOWriteBandwidth: "3000Mi",
},
err: ErrInvalidResourceGroupFormat,
err: ErrUnknownResourceGroupMode,
})

tests = append(tests, TestCase{
Expand All @@ -136,7 +100,7 @@ func TestNewResourceGroupFromOptions(t *testing.T) {
IOReadBandwidth: "3000G",
IOWriteBandwidth: "3000MB",
},
err: ErrInvalidResourceGroupFormat,
err: ErrUnknownResourceGroupMode,
})

tests = append(tests, TestCase{
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ require (
google.golang.org/grpc v1.52.3
gopkg.in/yaml.v2 v2.4.0
honnef.co/go/tools v0.4.0
k8s.io/apimachinery v0.26.0
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0
sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67
)
Expand Down Expand Up @@ -218,6 +217,7 @@ require (
github.com/ngaut/sync2 v0.0.0-20141008032647-7a24ed77b2ef // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/onsi/gomega v1.23.0 // indirect
github.com/petermattis/goid v0.0.0-20211229010228-4d14c490ee36 // indirect
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
github.com/pingcap/check v0.0.0-20200212061837-5e12011dc712 // indirect
Expand Down Expand Up @@ -265,7 +265,6 @@ require (
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230202175211-008b39050e57 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
Expand Down
5 changes: 1 addition & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@ github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g=
github.com/google/licensecheck v0.3.1 h1:QoxgoDkaeC4nFrtGN1jV7IPmDCHFNIVh54e5hSt6sPs=
github.com/google/licensecheck v0.3.1/go.mod h1:ORkR35t/JjW+emNKtfJDII0zlciG9JgbT7SmsohlHmY=
github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no=
Expand Down Expand Up @@ -724,6 +723,7 @@ github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.23.0 h1:/oxKu9c2HVap+F3PfKort2Hw5DEU+HGlW8n+tguWsys=
github.com/onsi/gomega v1.23.0/go.mod h1:Z/NWtiqwBrwUt4/2loMmHL63EDLnYHmVbuBpDr2vQAg=
github.com/opentracing-contrib/go-stdlib v0.0.0-20170113013457-1de4cc2120e7/go.mod h1:PLldrQSroqzH70Xl+1DQcGnefIbqsKR7UDaiux3zV+w=
github.com/opentracing/basictracer-go v1.0.0 h1:YyUAhaEfjoWXclZVJ9sGoNct7j4TVk7lZWlQw5UXuoo=
github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74=
Expand Down Expand Up @@ -1505,7 +1505,6 @@ gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMy
gopkg.in/fsnotify/fsnotify.v1 v1.3.1/go.mod h1:Fyux9zXlo4rWoMSIzpn9fDAYjalPqJ/K1qJ27s+7ltE=
gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE=
gopkg.in/go-playground/validator.v8 v8.18.2/go.mod h1:RX2a/7Ha8BgOhfk7j780h4/u/RRjR0eouCJSH80/M2Y=
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/ini.v1 v1.66.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
Expand Down Expand Up @@ -1547,8 +1546,6 @@ honnef.co/go/tools v0.4.0 h1:lyXVV1c8wUBJRKqI8JgIpT8TW1VDagfYYaxbKa/HoL8=
honnef.co/go/tools v0.4.0/go.mod h1:36ZgoUOrqOk1GxwHhyryEkq8FQWkUO2xGuSMhUCcdvA=
k8s.io/api v0.0.0-20190409021203-6e4e0e4f393b/go.mod h1:iuAfoD4hCxJ8Onx9kaTIt30j7jUFS00AXQi6QMi99vA=
k8s.io/apimachinery v0.0.0-20190404173353-6a84e37a896d/go.mod h1:ccL7Eh7zubPUSh9A3USN90/OzHNSVN6zxzde07TDCL0=
k8s.io/apimachinery v0.26.0 h1:1feANjElT7MvPqp0JT6F3Ss6TWDwmcjLypwoPpEf7zg=
k8s.io/apimachinery v0.26.0/go.mod h1:tnPmbONNJ7ByJNz9+n9kMjNP8ON+1qoAIIC70lztu74=
k8s.io/client-go v11.0.1-0.20190409021438-1a26190bd76a+incompatible/go.mod h1:7vJpHMYJwNQCWgzmNV+VYUl1zCObLyodBc8nIyt8L5s=
k8s.io/klog v0.3.0/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
k8s.io/kube-openapi v0.0.0-20180629012420-d83b052f768a/go.mod h1:BXM9ceUBTj2QnfH2MK1odQs778ajze1RxcmP6S8RVVc=
Expand Down
Loading

0 comments on commit 3f0964f

Please sign in to comment.