Skip to content

Commit

Permalink
add native mode
Browse files Browse the repository at this point in the history
Signed-off-by: nolouch <nolouch@gmail.com>
  • Loading branch information
nolouch committed Dec 28, 2022
1 parent 62d0397 commit 8fa8e45
Show file tree
Hide file tree
Showing 15 changed files with 226 additions and 71 deletions.
101 changes: 85 additions & 16 deletions DEPS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ def go_deps():
sum = "h1:BUAU3CGlLvorLI26FmByPp2eC2qla6E1Tw+scpcg/to=",
version = "v0.0.0-20180808171621-7fddfc383310",
)
go_repository(
name = "com_github_armon_go_socks5",
build_file_proto_mode = "disable",
importpath = "github.com/armon/go-socks5",
sum = "h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=",
version = "v0.0.0-20160902184237-e75332964ef5",
)

go_repository(
name = "com_github_ashanbrown_forbidigo",
build_file_proto_mode = "disable",
Expand Down Expand Up @@ -864,6 +872,14 @@ def go_deps():
sum = "h1:G/bYguwHIzWq9ZoyUQqrjTmJbbYn3j3CKKpKinvZLFk=",
version = "v1.0.0",
)
go_repository(
name = "com_github_elazarl_goproxy",
build_file_proto_mode = "disable",
importpath = "github.com/elazarl/goproxy",
sum = "h1:yUdfgN0XgIJw7foRItutHYUIhlcKzcSf5vDpdhQAKTc=",
version = "v0.0.0-20180725130230-947c36da3153",
)

go_repository(
name = "com_github_emirpasic_gods",
build_file_proto_mode = "disable",
Expand Down Expand Up @@ -919,8 +935,8 @@ def go_deps():
name = "com_github_evanphx_json_patch",
build_file_proto_mode = "disable",
importpath = "github.com/evanphx/json-patch",
sum = "h1:K1MDoo4AZ4wU0GIU/fPmtZg7VpzLjCxu+UwBD1FvwOc=",
version = "v4.1.0+incompatible",
sum = "h1:4onqiflcdA9EOZ4RxV643DvftH5pOlLGNtQ5lPWQu84=",
version = "v4.12.0+incompatible",
)
go_repository(
name = "com_github_facebookgo_clock",
Expand Down Expand Up @@ -1153,6 +1169,14 @@ def go_deps():
sum = "h1:otpy5pqBCBZ1ng9RQ0dPu4PN7ba75Y/aA+UpowDyNVA=",
version = "v0.5.1",
)
go_repository(
name = "com_github_go_logr_logr",
build_file_proto_mode = "disable",
importpath = "github.com/go-logr/logr",
sum = "h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=",
version = "v1.2.3",
)

go_repository(
name = "com_github_go_martini_martini",
build_file_proto_mode = "disable_global",
Expand Down Expand Up @@ -1473,6 +1497,14 @@ def go_deps():
sum = "h1:xf4v41cLI2Z6FxbKm+8Bu+m8ifhj15JuZ9sa0jZCMUU=",
version = "v1.1.2",
)
go_repository(
name = "com_github_google_gnostic",
build_file_proto_mode = "disable",
importpath = "github.com/google/gnostic",
sum = "h1:FhTMOKj2VhjpouxvWJAV1TL304uMlb9zcDqkl6cEI54=",
version = "v0.5.7-v3refs",
)

go_repository(
name = "com_github_google_go_cmp",
build_file_proto_mode = "disable_global",
Expand All @@ -1491,8 +1523,8 @@ def go_deps():
name = "com_github_google_gofuzz",
build_file_proto_mode = "disable_global",
importpath = "github.com/google/gofuzz",
sum = "h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw=",
version = "v1.0.0",
sum = "h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g=",
version = "v1.1.0",
)
go_repository(
name = "com_github_google_martian",
Expand Down Expand Up @@ -2563,6 +2595,13 @@ def go_deps():
sum = "h1:FVzMWA5RllMAKIdUSC8mdWo3XtwoecrH79BY70sEEpE=",
version = "v1.0.1",
)
go_repository(
name = "com_github_moby_spdystream",
build_file_proto_mode = "disable",
importpath = "github.com/moby/spdystream",
sum = "h1:cjW1zVyyoiM0T7b6UoySUFqzXMoqRckQtXwGPiBhOM8=",
version = "v0.2.0",
)

go_repository(
name = "com_github_modern_go_concurrent",
Expand Down Expand Up @@ -2615,6 +2654,14 @@ def go_deps():
sum = "h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU=",
version = "v0.0.0-20190716064945-2f068394615f",
)
go_repository(
name = "com_github_mxk_go_flowrate",
build_file_proto_mode = "disable",
importpath = "github.com/mxk/go-flowrate",
sum = "h1:y5//uYreIhSUg3J1GEMiLbxo1LJaP8RfCpH6pymGZus=",
version = "v0.0.0-20140419014527-cca7078d478f",
)

go_repository(
name = "com_github_nakabonne_nestif",
build_file_proto_mode = "disable",
Expand Down Expand Up @@ -2743,15 +2790,15 @@ def go_deps():
name = "com_github_onsi_ginkgo_v2",
build_file_proto_mode = "disable_global",
importpath = "github.com/onsi/ginkgo/v2",
sum = "h1:CcuG/HvWNkkaqCUpJifQY8z7qEMBJya6aLPx6ftGyjQ=",
version = "v2.0.0",
sum = "h1:+Ig9nvqgS5OBSACXNk15PLdp0U9XPYROt9CFzVdFGIs=",
version = "v2.4.0",
)
go_repository(
name = "com_github_onsi_gomega",
build_file_proto_mode = "disable_global",
importpath = "github.com/onsi/gomega",
sum = "h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=",
version = "v1.18.1",
sum = "h1:/oxKu9c2HVap+F3PfKort2Hw5DEU+HGlW8n+tguWsys=",
version = "v1.23.0",
)
go_repository(
name = "com_github_openpeedeep_depguard",
Expand Down Expand Up @@ -4176,8 +4223,8 @@ def go_deps():
name = "io_k8s_apimachinery",
build_file_proto_mode = "disable",
importpath = "k8s.io/apimachinery",
sum = "h1:Jmdtdt1ZnoGfWWIIik61Z7nKYgO3J+swQJtPYsP9wHA=",
version = "v0.0.0-20190404173353-6a84e37a896d",
sum = "h1:1feANjElT7MvPqp0JT6F3Ss6TWDwmcjLypwoPpEf7zg=",
version = "v0.26.0",
)
go_repository(
name = "io_k8s_client_go",
Expand All @@ -4193,27 +4240,49 @@ def go_deps():
sum = "h1:0VPpR+sizsiivjIfIAQH/rl8tan6jvWkS7lU+0di3lE=",
version = "v0.3.0",
)
go_repository(
name = "io_k8s_klog_v2",
build_file_proto_mode = "disable",
importpath = "k8s.io/klog/v2",
sum = "h1:atnLQ121W371wYYFawwYx1aEY2eUfs4l3J72wtgAwV4=",
version = "v2.80.1",
)

go_repository(
name = "io_k8s_kube_openapi",
build_file_proto_mode = "disable",
importpath = "k8s.io/kube-openapi",
sum = "h1:tHgpQvrWaYfrnC8G4N0Oszw5HHCsZxKilDi2R7HuCSM=",
version = "v0.0.0-20180629012420-d83b052f768a",
sum = "h1:+70TFaan3hfJzs+7VK2o+OGxg8HsuBr/5f6tVAjDu6E=",
version = "v0.0.0-20221012153701-172d655c2280",
)
go_repository(
name = "io_k8s_sigs_json",
build_file_proto_mode = "disable",
importpath = "sigs.k8s.io/json",
sum = "h1:iXTIw73aPyC+oRdyqqvVJuloN1p0AC/kzH07hu3NE+k=",
version = "v0.0.0-20220713155537-f223a00ba0e2",
)
go_repository(
name = "io_k8s_sigs_structured_merge_diff_v4",
build_file_proto_mode = "disable",
importpath = "sigs.k8s.io/structured-merge-diff/v4",
sum = "h1:PRbqxJClWWYMNV1dhaG4NsibJbArud9kFxnAMREiWFE=",
version = "v4.2.3",
)

go_repository(
name = "io_k8s_sigs_yaml",
build_file_proto_mode = "disable_global",
importpath = "sigs.k8s.io/yaml",
sum = "h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=",
version = "v1.2.0",
sum = "h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=",
version = "v1.3.0",
)
go_repository(
name = "io_k8s_utils",
build_file_proto_mode = "disable",
importpath = "k8s.io/utils",
sum = "h1:8r+l4bNWjRlsFYlQJnKJ2p7s1YQPj4XyXiJVqDHRx7c=",
version = "v0.0.0-20190308190857-21c4ce38f2a7",
sum = "h1:0Smp/HP1OH4Rvhe+4B8nWGERtlqAGSftbSbbmm45oFs=",
version = "v0.0.0-20221107191617-1a15be271d1d",
)

go_repository(
Expand Down
5 changes: 2 additions & 3 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3023,7 +3023,7 @@ func SetDirectPlacementOpt(placementSettings *model.PlacementSettings, placement
return nil
}

// SetDirectResourceGroupUnit tries to make the PlacementSettings assignments generic for Schema/Table/Partition
// SetDirectResourceGroupUnit tries to set the ResourceGroupSettings.
func SetDirectResourceGroupUnit(resourceGroupSettings *model.ResourceGroupSettings, typ ast.ResourceUnitType, stringVal string, uintVal uint64) error {
switch typ {
case ast.ResourceRRURate:
Expand Down Expand Up @@ -7637,7 +7637,7 @@ func (d *ddl) DropResourceGroup(ctx sessionctx.Context, stmt *ast.DropResourceGr
// Check group existence.
group, ok := is.ResourceGroupByName(groupName)
if !ok {
err = infoschema.ErrPlacementPolicyNotExists.GenWithStackByArgs(groupName)
err = infoschema.ErrResourceGroupNotExists.GenWithStackByArgs(groupName)
if stmt.IfExists {
ctx.GetSessionVars().StmtCtx.AppendNote(err)
return nil
Expand Down Expand Up @@ -7670,7 +7670,6 @@ func buildResourceGroup(oldGroup *model.ResourceGroupInfo, options []*ast.Resour

// AlterResourceGroup implements the DDL interface.
func (d *ddl) AlterResourceGroup(ctx sessionctx.Context, stmt *ast.AlterResourceGroupStmt) (err error) {
// groupInfo := &model.ResourceGroupInfo{ResourceGroupSettings: &model.ResourceGroupSettings{}}
groupName := stmt.ResourceGroupName
is := d.GetInfoSchemaWithInterceptor(ctx)
// Check group existence.
Expand Down
11 changes: 6 additions & 5 deletions ddl/resource_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ func onAlterResourceGroup(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, _
newGroup := *oldGroup
newGroup.ResourceGroupSettings = alterGroupInfo.ResourceGroupSettings

// TODO: check the policy validation

// TODO: check the group validation
err = t.UpdateResourceGroup(&newGroup)
if err != nil {
return ver, errors.Trace(err)
Expand All @@ -113,7 +112,6 @@ func onAlterResourceGroup(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, _
// Finish this job.
job.FinishDBJob(model.JobStateDone, model.StatePublic, ver, nil)
return ver, nil

}

func checkResourceGroupExist(t *meta.Meta, job *model.Job, groupID int64) (*model.ResourceGroupInfo, error) {
Expand Down Expand Up @@ -167,12 +165,15 @@ func onDropResourceGroup(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, _
if err != nil {
return ver, errors.Trace(err)
}
infosync.DeleteResourceGroup(context.TODO(), groupInfo.Name.L)
err = infosync.DeleteResourceGroup(context.TODO(), groupInfo.Name.L)
if err != nil {
return ver, errors.Trace(err)
}
ver, err = updateSchemaVersion(d, t, job)
if err != nil {
return ver, errors.Trace(err)
}
// Finish this job. By now policy don't consider the binlog sync.
// Finish this job. By now resource group don't consider the binlog sync.
job.FinishDBJob(model.JobStateDone, model.StateNone, ver, nil)
default:
err = dbterror.ErrInvalidDDLState.GenWithStackByArgs("resource_group", groupInfo.State)
Expand Down
58 changes: 43 additions & 15 deletions ddl/resource_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package ddl_test

import (
"runtime/debug"
"testing"

"github.com/pingcap/tidb/ddl"
Expand All @@ -29,19 +28,15 @@ import (

func TestResourceGroup(t *testing.T) {
store, dom := testkit.CreateMockStoreAndDomain(t)
// clearAllBundles(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
re := require.New(t)

hook := &ddl.TestDDLCallback{Do: dom}
var groupID int64
onJobUpdatedExportedFunc := func(job *model.Job) {
debug.PrintStack()
if groupID != 0 {
return
}
// job.SchemaID will be assigned when the policy is created.
if job.SchemaName == "x" && job.Type == model.ActionCreateResourceGroup && job.SchemaID != 0 {
// job.SchemaID will be assigned when the group is created.
if (job.SchemaName == "x" || job.SchemaName == "y") && job.Type == model.ActionCreateResourceGroup && job.SchemaID != 0 {
groupID = job.SchemaID
return
}
Expand All @@ -59,24 +54,58 @@ func TestResourceGroup(t *testing.T) {
require.Equal(t, uint64(1000), groupInfo.RRURate)
require.Equal(t, uint64(2000), groupInfo.WRURate)
}
// Check the group is correctly reloaded in the information schema.
g := testResourceGroupNameFromIS(t, tk.Session(), "x")
checkFunc(g)

tk.MustGetErrCode("create resource group x "+
"RRU_PER_SEC=1000 "+
"WRU_PER_SEC=2000", mysql.ErrResourceGroupExists)
// Check the policy is correctly reloaded in the information schema.
g := testResourceGroupNameFromIS(t, tk.Session(), "x")
checkFunc(g)

tk.MustExec("alter resource group x " +
"RRU_PER_SEC=2000 " +
"WRU_PER_SEC=3000")
g = testResourceGroupNameFromIS(t, tk.Session(), "x")
require.Equal(t, uint64(2000), g.RRURate)
require.Equal(t, uint64(3000), g.WRURate)
re.Equal(uint64(2000), g.RRURate)
re.Equal(uint64(3000), g.WRURate)

tk.MustExec("drop resource group x")
g = testResourceGroupNameFromIS(t, tk.Session(), "x")
require.Nil(t, g)
re.Nil(g)

tk.MustExec("create resource group y " +
"CPU='4000m' " +
"IO_READ_BANDWIDTH='1G' " +
"IO_WRITE_BANDWIDTH='300M'")
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)
}
g = testResourceGroupNameFromIS(t, tk.Session(), "y")
checkFunc(g)
tk.MustExec("alter resource group y " +
"CPU='8000m' " +
"IO_READ_BANDWIDTH='10G' " +
"IO_WRITE_BANDWIDTH='3000M'")
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)
}
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 RRU_PER_SEC=1000, CPU='8000m';", "Only one of RUMode and NativeMode can be set")
// TODO: privilege check & constraint syntax check.
}

Expand All @@ -86,6 +115,5 @@ func testResourceGroupNameFromIS(t *testing.T, ctx sessionctx.Context, name stri
err := dom.Reload()
require.NoError(t, err)
g, _ := dom.InfoSchema().ResourceGroupByName(model.NewCIStr(name))
//require.Equal(t, true, ok)
return g
}
1 change: 1 addition & 0 deletions domain/infosync/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ go_library(
"@com_github_tikv_pd_client//:client",
"@io_etcd_go_etcd_client_v3//:client",
"@io_etcd_go_etcd_client_v3//concurrency",
"@io_k8s_apimachinery//pkg/api/resource",
"@org_uber_go_zap//:zap",
],
)
Expand Down
Loading

0 comments on commit 8fa8e45

Please sign in to comment.