From 8a7ba0a8e4eaa640a6c51d3b0bb6d86888e06127 Mon Sep 17 00:00:00 2001 From: JmPotato Date: Wed, 7 Aug 2024 20:14:56 +0800 Subject: [PATCH] Implement the switch group action Signed-off-by: JmPotato --- DEPS.bzl | 322 +++++++++++++++++- go.mod | 2 +- go.sum | 4 +- pkg/ddl/resourcegroup/group.go | 5 +- pkg/domain/resourcegroup/runaway.go | 127 +++++-- pkg/domain/runaway.go | 6 +- pkg/executor/adapter.go | 6 +- pkg/executor/infoschema_reader.go | 7 +- .../internal/querywatch/query_watch.go | 7 +- pkg/session/bootstrap.go | 16 +- 10 files changed, 432 insertions(+), 70 deletions(-) diff --git a/DEPS.bzl b/DEPS.bzl index 8823c4f3c9a06e..5bf436905ca671 100644 --- a/DEPS.bzl +++ b/DEPS.bzl @@ -329,6 +329,32 @@ def go_deps(): "https://storage.googleapis.com/pingcapmirror/gomod/github.com/Antonboom/testifylint/com_github_antonboom_testifylint-v1.3.0.zip", ], ) + go_repository( + name = "com_github_apache_arrow_go_v10", + build_file_proto_mode = "disable_global", + importpath = "github.com/apache/arrow/go/v10", + sha256 = "16a5e19ef7d1e4c0a5139c84aa7ba467425fabc90380ad7a18929907dec0a9e7", + strip_prefix = "github.com/apache/arrow/go/v10@v10.0.1", + urls = [ + "http://bazel-cache.pingcap.net:8080/gomod/github.com/apache/arrow/go/v10/com_github_apache_arrow_go_v10-v10.0.1.zip", + "http://ats.apps.svc/gomod/github.com/apache/arrow/go/v10/com_github_apache_arrow_go_v10-v10.0.1.zip", + "https://cache.hawkingrei.com/gomod/github.com/apache/arrow/go/v10/com_github_apache_arrow_go_v10-v10.0.1.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/github.com/apache/arrow/go/v10/com_github_apache_arrow_go_v10-v10.0.1.zip", + ], + ) + go_repository( + name = "com_github_apache_arrow_go_v11", + build_file_proto_mode = "disable_global", + importpath = "github.com/apache/arrow/go/v11", + sha256 = "d5275ec213d31234d54ca13fff78d07ba1837d78664c13b76363d2f75718ae4f", + strip_prefix = "github.com/apache/arrow/go/v11@v11.0.0", + urls = [ + "http://bazel-cache.pingcap.net:8080/gomod/github.com/apache/arrow/go/v11/com_github_apache_arrow_go_v11-v11.0.0.zip", + "http://ats.apps.svc/gomod/github.com/apache/arrow/go/v11/com_github_apache_arrow_go_v11-v11.0.0.zip", + "https://cache.hawkingrei.com/gomod/github.com/apache/arrow/go/v11/com_github_apache_arrow_go_v11-v11.0.0.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/github.com/apache/arrow/go/v11/com_github_apache_arrow_go_v11-v11.0.0.zip", + ], + ) go_repository( name = "com_github_apache_arrow_go_v12", build_file_proto_mode = "disable_global", @@ -875,6 +901,19 @@ def go_deps(): "https://storage.googleapis.com/pingcapmirror/gomod/github.com/census-instrumentation/opencensus-proto/com_github_census_instrumentation_opencensus_proto-v0.4.1.zip", ], ) + go_repository( + name = "com_github_cespare_xxhash", + build_file_proto_mode = "disable_global", + importpath = "github.com/cespare/xxhash", + sha256 = "fe98c56670b21631f7fd3305a29a3b17e86a6cce3876a2119460717a18538e2e", + strip_prefix = "github.com/cespare/xxhash@v1.1.0", + urls = [ + "http://bazel-cache.pingcap.net:8080/gomod/github.com/cespare/xxhash/com_github_cespare_xxhash-v1.1.0.zip", + "http://ats.apps.svc/gomod/github.com/cespare/xxhash/com_github_cespare_xxhash-v1.1.0.zip", + "https://cache.hawkingrei.com/gomod/github.com/cespare/xxhash/com_github_cespare_xxhash-v1.1.0.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/github.com/cespare/xxhash/com_github_cespare_xxhash-v1.1.0.zip", + ], + ) go_repository( name = "com_github_cespare_xxhash_v2", build_file_proto_mode = "disable_global", @@ -1100,13 +1139,13 @@ def go_deps(): name = "com_github_cncf_udpa_go", build_file_proto_mode = "disable_global", importpath = "github.com/cncf/udpa/go", - sha256 = "a449fa94e58117a79c17577e39f72f695c4876f74cbd9142d512278192ca90aa", - strip_prefix = "github.com/cncf/udpa/go@v0.0.0-20210930031921-04548b0d99d4", + sha256 = "8fe1585f25d40a5e3cd4243a92143d71ae4ee92e915e7192e72387047539438e", + strip_prefix = "github.com/cncf/udpa/go@v0.0.0-20220112060539-c52dc94e7fbe", urls = [ - "http://bazel-cache.pingcap.net:8080/gomod/github.com/cncf/udpa/go/com_github_cncf_udpa_go-v0.0.0-20210930031921-04548b0d99d4.zip", - "http://ats.apps.svc/gomod/github.com/cncf/udpa/go/com_github_cncf_udpa_go-v0.0.0-20210930031921-04548b0d99d4.zip", - "https://cache.hawkingrei.com/gomod/github.com/cncf/udpa/go/com_github_cncf_udpa_go-v0.0.0-20210930031921-04548b0d99d4.zip", - "https://storage.googleapis.com/pingcapmirror/gomod/github.com/cncf/udpa/go/com_github_cncf_udpa_go-v0.0.0-20210930031921-04548b0d99d4.zip", + "http://bazel-cache.pingcap.net:8080/gomod/github.com/cncf/udpa/go/com_github_cncf_udpa_go-v0.0.0-20220112060539-c52dc94e7fbe.zip", + "http://ats.apps.svc/gomod/github.com/cncf/udpa/go/com_github_cncf_udpa_go-v0.0.0-20220112060539-c52dc94e7fbe.zip", + "https://cache.hawkingrei.com/gomod/github.com/cncf/udpa/go/com_github_cncf_udpa_go-v0.0.0-20220112060539-c52dc94e7fbe.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/github.com/cncf/udpa/go/com_github_cncf_udpa_go-v0.0.0-20220112060539-c52dc94e7fbe.zip", ], ) go_repository( @@ -3423,6 +3462,32 @@ def go_deps(): "https://storage.googleapis.com/pingcapmirror/gomod/github.com/googleapis/gax-go/v2/com_github_googleapis_gax_go_v2-v2.12.2.zip", ], ) + go_repository( + name = "com_github_googleapis_go_type_adapters", + build_file_proto_mode = "disable_global", + importpath = "github.com/googleapis/go-type-adapters", + sha256 = "34319a3a8572d65bfc0cee5108e585348e102b7d293ddbeea5c44c7077c22742", + strip_prefix = "github.com/googleapis/go-type-adapters@v1.0.0", + urls = [ + "http://bazel-cache.pingcap.net:8080/gomod/github.com/googleapis/go-type-adapters/com_github_googleapis_go_type_adapters-v1.0.0.zip", + "http://ats.apps.svc/gomod/github.com/googleapis/go-type-adapters/com_github_googleapis_go_type_adapters-v1.0.0.zip", + "https://cache.hawkingrei.com/gomod/github.com/googleapis/go-type-adapters/com_github_googleapis_go_type_adapters-v1.0.0.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/github.com/googleapis/go-type-adapters/com_github_googleapis_go_type_adapters-v1.0.0.zip", + ], + ) + go_repository( + name = "com_github_googleapis_google_cloud_go_testing", + build_file_proto_mode = "disable_global", + importpath = "github.com/googleapis/google-cloud-go-testing", + sha256 = "af70a872c8b0107e2fc7b32a9562e15be885793454df61dc6aae3c774387ca7d", + strip_prefix = "github.com/googleapis/google-cloud-go-testing@v0.0.0-20200911160855-bcd43fbb19e8", + urls = [ + "http://bazel-cache.pingcap.net:8080/gomod/github.com/googleapis/google-cloud-go-testing/com_github_googleapis_google_cloud_go_testing-v0.0.0-20200911160855-bcd43fbb19e8.zip", + "http://ats.apps.svc/gomod/github.com/googleapis/google-cloud-go-testing/com_github_googleapis_google_cloud_go_testing-v0.0.0-20200911160855-bcd43fbb19e8.zip", + "https://cache.hawkingrei.com/gomod/github.com/googleapis/google-cloud-go-testing/com_github_googleapis_google_cloud_go_testing-v0.0.0-20200911160855-bcd43fbb19e8.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/github.com/googleapis/google-cloud-go-testing/com_github_googleapis_google_cloud_go_testing-v0.0.0-20200911160855-bcd43fbb19e8.zip", + ], + ) go_repository( name = "com_github_gophercloud_gophercloud", build_file_proto_mode = "disable_global", @@ -3935,6 +4000,19 @@ def go_deps(): "https://storage.googleapis.com/pingcapmirror/gomod/github.com/hydrogen18/memlistener/com_github_hydrogen18_memlistener-v1.0.0.zip", ], ) + go_repository( + name = "com_github_iancoleman_strcase", + build_file_proto_mode = "disable_global", + importpath = "github.com/iancoleman/strcase", + sha256 = "cb5027fec91d36426f0978a6c42ab52d8735fa3e1711be0127feda70a9a9fd05", + strip_prefix = "github.com/iancoleman/strcase@v0.2.0", + urls = [ + "http://bazel-cache.pingcap.net:8080/gomod/github.com/iancoleman/strcase/com_github_iancoleman_strcase-v0.2.0.zip", + "http://ats.apps.svc/gomod/github.com/iancoleman/strcase/com_github_iancoleman_strcase-v0.2.0.zip", + "https://cache.hawkingrei.com/gomod/github.com/iancoleman/strcase/com_github_iancoleman_strcase-v0.2.0.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/github.com/iancoleman/strcase/com_github_iancoleman_strcase-v0.2.0.zip", + ], + ) go_repository( name = "com_github_ianlancetaylor_demangle", build_file_proto_mode = "disable_global", @@ -4641,6 +4719,19 @@ def go_deps(): "https://storage.googleapis.com/pingcapmirror/gomod/github.com/konsorten/go-windows-terminal-sequences/com_github_konsorten_go_windows_terminal_sequences-v1.0.1.zip", ], ) + go_repository( + name = "com_github_kr_fs", + build_file_proto_mode = "disable_global", + importpath = "github.com/kr/fs", + sha256 = "d376bd98e81aea34585fc3b04bab76363e9e87cde69383964e57e9779f2af81e", + strip_prefix = "github.com/kr/fs@v0.1.0", + urls = [ + "http://bazel-cache.pingcap.net:8080/gomod/github.com/kr/fs/com_github_kr_fs-v0.1.0.zip", + "http://ats.apps.svc/gomod/github.com/kr/fs/com_github_kr_fs-v0.1.0.zip", + "https://cache.hawkingrei.com/gomod/github.com/kr/fs/com_github_kr_fs-v0.1.0.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/github.com/kr/fs/com_github_kr_fs-v0.1.0.zip", + ], + ) go_repository( name = "com_github_kr_pretty", build_file_proto_mode = "disable_global", @@ -4953,6 +5044,32 @@ def go_deps(): "https://storage.googleapis.com/pingcapmirror/gomod/github.com/lufia/plan9stats/com_github_lufia_plan9stats-v0.0.0-20230326075908-cb1d2100619a.zip", ], ) + go_repository( + name = "com_github_lyft_protoc_gen_star", + build_file_proto_mode = "disable_global", + importpath = "github.com/lyft/protoc-gen-star", + sha256 = "f186c05b58627f1e2c591a70f65ac23d9f2eb7cef2cecf18be11b256f67e42f4", + strip_prefix = "github.com/lyft/protoc-gen-star@v0.6.1", + urls = [ + "http://bazel-cache.pingcap.net:8080/gomod/github.com/lyft/protoc-gen-star/com_github_lyft_protoc_gen_star-v0.6.1.zip", + "http://ats.apps.svc/gomod/github.com/lyft/protoc-gen-star/com_github_lyft_protoc_gen_star-v0.6.1.zip", + "https://cache.hawkingrei.com/gomod/github.com/lyft/protoc-gen-star/com_github_lyft_protoc_gen_star-v0.6.1.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/github.com/lyft/protoc-gen-star/com_github_lyft_protoc_gen_star-v0.6.1.zip", + ], + ) + go_repository( + name = "com_github_lyft_protoc_gen_star_v2", + build_file_proto_mode = "disable_global", + importpath = "github.com/lyft/protoc-gen-star/v2", + sha256 = "470b1555254cdc780f840700144c2cf6ca9966b1260972a90c825b00b901e3fe", + strip_prefix = "github.com/lyft/protoc-gen-star/v2@v2.0.3", + urls = [ + "http://bazel-cache.pingcap.net:8080/gomod/github.com/lyft/protoc-gen-star/v2/com_github_lyft_protoc_gen_star_v2-v2.0.3.zip", + "http://ats.apps.svc/gomod/github.com/lyft/protoc-gen-star/v2/com_github_lyft_protoc_gen_star_v2-v2.0.3.zip", + "https://cache.hawkingrei.com/gomod/github.com/lyft/protoc-gen-star/v2/com_github_lyft_protoc_gen_star_v2-v2.0.3.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/github.com/lyft/protoc-gen-star/v2/com_github_lyft_protoc_gen_star_v2-v2.0.3.zip", + ], + ) go_repository( name = "com_github_macabu_inamedparam", build_file_proto_mode = "disable_global", @@ -5616,6 +5733,19 @@ def go_deps(): "https://storage.googleapis.com/pingcapmirror/gomod/github.com/olekukonko/tablewriter/com_github_olekukonko_tablewriter-v0.0.5.zip", ], ) + go_repository( + name = "com_github_oneofone_xxhash", + build_file_proto_mode = "disable_global", + importpath = "github.com/OneOfOne/xxhash", + sha256 = "b4a7d4dd033e96312c06b43d42a6425e00837c0254741bcd569c9a0909b26f9d", + strip_prefix = "github.com/OneOfOne/xxhash@v1.2.2", + urls = [ + "http://bazel-cache.pingcap.net:8080/gomod/github.com/OneOfOne/xxhash/com_github_oneofone_xxhash-v1.2.2.zip", + "http://ats.apps.svc/gomod/github.com/OneOfOne/xxhash/com_github_oneofone_xxhash-v1.2.2.zip", + "https://cache.hawkingrei.com/gomod/github.com/OneOfOne/xxhash/com_github_oneofone_xxhash-v1.2.2.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/github.com/OneOfOne/xxhash/com_github_oneofone_xxhash-v1.2.2.zip", + ], + ) go_repository( name = "com_github_onsi_ginkgo", build_file_proto_mode = "disable_global", @@ -5984,13 +6114,13 @@ def go_deps(): name = "com_github_pingcap_kvproto", build_file_proto_mode = "disable_global", importpath = "github.com/pingcap/kvproto", - sha256 = "b1af34db24f2650cd2a687fa9c58bd746eb3ca76e08afe5dbe2ac569ce54b597", - strip_prefix = "github.com/pingcap/kvproto@v0.0.0-20240716095229-5f7ffec83ea7", + sha256 = "6771bc6ceac87e9f82c728d552003081ee634864727795a8d2f7a3fa53c067df", + strip_prefix = "github.com/JmPotato/kvproto@v0.0.0-20240807105224-7e7a2da7bfcd", urls = [ - "http://bazel-cache.pingcap.net:8080/gomod/github.com/pingcap/kvproto/com_github_pingcap_kvproto-v0.0.0-20240716095229-5f7ffec83ea7.zip", - "http://ats.apps.svc/gomod/github.com/pingcap/kvproto/com_github_pingcap_kvproto-v0.0.0-20240716095229-5f7ffec83ea7.zip", - "https://cache.hawkingrei.com/gomod/github.com/pingcap/kvproto/com_github_pingcap_kvproto-v0.0.0-20240716095229-5f7ffec83ea7.zip", - "https://storage.googleapis.com/pingcapmirror/gomod/github.com/pingcap/kvproto/com_github_pingcap_kvproto-v0.0.0-20240716095229-5f7ffec83ea7.zip", + "http://bazel-cache.pingcap.net:8080/gomod/github.com/JmPotato/kvproto/com_github_jmpotato_kvproto-v0.0.0-20240807105224-7e7a2da7bfcd.zip", + "http://ats.apps.svc/gomod/github.com/JmPotato/kvproto/com_github_jmpotato_kvproto-v0.0.0-20240807105224-7e7a2da7bfcd.zip", + "https://cache.hawkingrei.com/gomod/github.com/JmPotato/kvproto/com_github_jmpotato_kvproto-v0.0.0-20240807105224-7e7a2da7bfcd.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/github.com/JmPotato/kvproto/com_github_jmpotato_kvproto-v0.0.0-20240807105224-7e7a2da7bfcd.zip", ], ) go_repository( @@ -6084,6 +6214,19 @@ def go_deps(): "https://storage.googleapis.com/pingcapmirror/gomod/github.com/pkg/profile/com_github_pkg_profile-v1.2.1.zip", ], ) + go_repository( + name = "com_github_pkg_sftp", + build_file_proto_mode = "disable_global", + importpath = "github.com/pkg/sftp", + sha256 = "8709c6556ed68fc9a9c25b4950e2dc70e688b5ec03f751c511feb4d44ff34904", + strip_prefix = "github.com/pkg/sftp@v1.13.1", + urls = [ + "http://bazel-cache.pingcap.net:8080/gomod/github.com/pkg/sftp/com_github_pkg_sftp-v1.13.1.zip", + "http://ats.apps.svc/gomod/github.com/pkg/sftp/com_github_pkg_sftp-v1.13.1.zip", + "https://cache.hawkingrei.com/gomod/github.com/pkg/sftp/com_github_pkg_sftp-v1.13.1.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/github.com/pkg/sftp/com_github_pkg_sftp-v1.13.1.zip", + ], + ) go_repository( name = "com_github_pkg_xattr", build_file_proto_mode = "disable_global", @@ -6877,6 +7020,19 @@ def go_deps(): "https://storage.googleapis.com/pingcapmirror/gomod/github.com/sourcegraph/go-diff/com_github_sourcegraph_go_diff-v0.7.0.zip", ], ) + go_repository( + name = "com_github_spaolacci_murmur3", + build_file_proto_mode = "disable_global", + importpath = "github.com/spaolacci/murmur3", + sha256 = "7fca345fffeb6d4ef1ffb8a9130a715f6b6e71c0e0dcc5eacf73995601b69766", + strip_prefix = "github.com/spaolacci/murmur3@v0.0.0-20180118202830-f09979ecbc72", + urls = [ + "http://bazel-cache.pingcap.net:8080/gomod/github.com/spaolacci/murmur3/com_github_spaolacci_murmur3-v0.0.0-20180118202830-f09979ecbc72.zip", + "http://ats.apps.svc/gomod/github.com/spaolacci/murmur3/com_github_spaolacci_murmur3-v0.0.0-20180118202830-f09979ecbc72.zip", + "https://cache.hawkingrei.com/gomod/github.com/spaolacci/murmur3/com_github_spaolacci_murmur3-v0.0.0-20180118202830-f09979ecbc72.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/github.com/spaolacci/murmur3/com_github_spaolacci_murmur3-v0.0.0-20180118202830-f09979ecbc72.zip", + ], + ) go_repository( name = "com_github_spf13_afero", build_file_proto_mode = "disable_global", @@ -7865,6 +8021,19 @@ def go_deps(): "https://storage.googleapis.com/pingcapmirror/gomod/cloud.google.com/go/apigeeregistry/com_google_cloud_go_apigeeregistry-v0.8.3.zip", ], ) + go_repository( + name = "com_google_cloud_go_apikeys", + build_file_proto_mode = "disable_global", + importpath = "cloud.google.com/go/apikeys", + sha256 = "511ba83f3837459a9e553026ecf556ebec9007403054635d90f065f7d735ddbe", + strip_prefix = "cloud.google.com/go/apikeys@v0.6.0", + urls = [ + "http://bazel-cache.pingcap.net:8080/gomod/cloud.google.com/go/apikeys/com_google_cloud_go_apikeys-v0.6.0.zip", + "http://ats.apps.svc/gomod/cloud.google.com/go/apikeys/com_google_cloud_go_apikeys-v0.6.0.zip", + "https://cache.hawkingrei.com/gomod/cloud.google.com/go/apikeys/com_google_cloud_go_apikeys-v0.6.0.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/cloud.google.com/go/apikeys/com_google_cloud_go_apikeys-v0.6.0.zip", + ], + ) go_repository( name = "com_google_cloud_go_appengine", build_file_proto_mode = "disable_global", @@ -8229,6 +8398,19 @@ def go_deps(): "https://storage.googleapis.com/pingcapmirror/gomod/cloud.google.com/go/dataplex/com_google_cloud_go_dataplex-v1.14.2.zip", ], ) + go_repository( + name = "com_google_cloud_go_dataproc", + build_file_proto_mode = "disable_global", + importpath = "cloud.google.com/go/dataproc", + sha256 = "f4adc94c30406a2bd04b62f2a0c8c33ddb605ffda53024b034e5c136407f0c73", + strip_prefix = "cloud.google.com/go/dataproc@v1.12.0", + urls = [ + "http://bazel-cache.pingcap.net:8080/gomod/cloud.google.com/go/dataproc/com_google_cloud_go_dataproc-v1.12.0.zip", + "http://ats.apps.svc/gomod/cloud.google.com/go/dataproc/com_google_cloud_go_dataproc-v1.12.0.zip", + "https://cache.hawkingrei.com/gomod/cloud.google.com/go/dataproc/com_google_cloud_go_dataproc-v1.12.0.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/cloud.google.com/go/dataproc/com_google_cloud_go_dataproc-v1.12.0.zip", + ], + ) go_repository( name = "com_google_cloud_go_dataproc_v2", build_file_proto_mode = "disable_global", @@ -8437,6 +8619,19 @@ def go_deps(): "https://storage.googleapis.com/pingcapmirror/gomod/cloud.google.com/go/functions/com_google_cloud_go_functions-v1.16.0.zip", ], ) + go_repository( + name = "com_google_cloud_go_gaming", + build_file_proto_mode = "disable_global", + importpath = "cloud.google.com/go/gaming", + sha256 = "d7864d1a76ccd83a8a3047e861ccd1d5f2d23cc4c4894e52722d8995c15b3a9f", + strip_prefix = "cloud.google.com/go/gaming@v1.10.1", + urls = [ + "http://bazel-cache.pingcap.net:8080/gomod/cloud.google.com/go/gaming/com_google_cloud_go_gaming-v1.10.1.zip", + "http://ats.apps.svc/gomod/cloud.google.com/go/gaming/com_google_cloud_go_gaming-v1.10.1.zip", + "https://cache.hawkingrei.com/gomod/cloud.google.com/go/gaming/com_google_cloud_go_gaming-v1.10.1.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/cloud.google.com/go/gaming/com_google_cloud_go_gaming-v1.10.1.zip", + ], + ) go_repository( name = "com_google_cloud_go_gkebackup", build_file_proto_mode = "disable_global", @@ -8489,6 +8684,19 @@ def go_deps(): "https://storage.googleapis.com/pingcapmirror/gomod/cloud.google.com/go/gkemulticloud/com_google_cloud_go_gkemulticloud-v1.1.1.zip", ], ) + go_repository( + name = "com_google_cloud_go_grafeas", + build_file_proto_mode = "disable_global", + importpath = "cloud.google.com/go/grafeas", + sha256 = "e6a8e9872cc3306558dd60fe8bb5eed6afe6cca0d18bbd4136cc25e906d6a512", + strip_prefix = "cloud.google.com/go/grafeas@v0.3.0", + urls = [ + "http://bazel-cache.pingcap.net:8080/gomod/cloud.google.com/go/grafeas/com_google_cloud_go_grafeas-v0.3.0.zip", + "http://ats.apps.svc/gomod/cloud.google.com/go/grafeas/com_google_cloud_go_grafeas-v0.3.0.zip", + "https://cache.hawkingrei.com/gomod/cloud.google.com/go/grafeas/com_google_cloud_go_grafeas-v0.3.0.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/cloud.google.com/go/grafeas/com_google_cloud_go_grafeas-v0.3.0.zip", + ], + ) go_repository( name = "com_google_cloud_go_gsuiteaddons", build_file_proto_mode = "disable_global", @@ -8879,6 +9087,19 @@ def go_deps(): "https://storage.googleapis.com/pingcapmirror/gomod/cloud.google.com/go/pubsublite/com_google_cloud_go_pubsublite-v1.8.1.zip", ], ) + go_repository( + name = "com_google_cloud_go_recaptchaenterprise", + build_file_proto_mode = "disable_global", + importpath = "cloud.google.com/go/recaptchaenterprise", + sha256 = "81b75b9d1cb2b24878ee83f540e2e50ad9669f916ddaf76112d3c88ee71e7e3b", + strip_prefix = "cloud.google.com/go/recaptchaenterprise@v1.3.1", + urls = [ + "http://bazel-cache.pingcap.net:8080/gomod/cloud.google.com/go/recaptchaenterprise/com_google_cloud_go_recaptchaenterprise-v1.3.1.zip", + "http://ats.apps.svc/gomod/cloud.google.com/go/recaptchaenterprise/com_google_cloud_go_recaptchaenterprise-v1.3.1.zip", + "https://cache.hawkingrei.com/gomod/cloud.google.com/go/recaptchaenterprise/com_google_cloud_go_recaptchaenterprise-v1.3.1.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/cloud.google.com/go/recaptchaenterprise/com_google_cloud_go_recaptchaenterprise-v1.3.1.zip", + ], + ) go_repository( name = "com_google_cloud_go_recaptchaenterprise_v2", build_file_proto_mode = "disable_global", @@ -9035,6 +9256,19 @@ def go_deps(): "https://storage.googleapis.com/pingcapmirror/gomod/cloud.google.com/go/securitycenter/com_google_cloud_go_securitycenter-v1.24.4.zip", ], ) + go_repository( + name = "com_google_cloud_go_servicecontrol", + build_file_proto_mode = "disable_global", + importpath = "cloud.google.com/go/servicecontrol", + sha256 = "499ce8763d315e0ffdf3705549a507051a27eff9b8dec9debe43bca8d130fabb", + strip_prefix = "cloud.google.com/go/servicecontrol@v1.11.1", + urls = [ + "http://bazel-cache.pingcap.net:8080/gomod/cloud.google.com/go/servicecontrol/com_google_cloud_go_servicecontrol-v1.11.1.zip", + "http://ats.apps.svc/gomod/cloud.google.com/go/servicecontrol/com_google_cloud_go_servicecontrol-v1.11.1.zip", + "https://cache.hawkingrei.com/gomod/cloud.google.com/go/servicecontrol/com_google_cloud_go_servicecontrol-v1.11.1.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/cloud.google.com/go/servicecontrol/com_google_cloud_go_servicecontrol-v1.11.1.zip", + ], + ) go_repository( name = "com_google_cloud_go_servicedirectory", build_file_proto_mode = "disable_global", @@ -9048,6 +9282,32 @@ def go_deps(): "https://storage.googleapis.com/pingcapmirror/gomod/cloud.google.com/go/servicedirectory/com_google_cloud_go_servicedirectory-v1.11.4.zip", ], ) + go_repository( + name = "com_google_cloud_go_servicemanagement", + build_file_proto_mode = "disable_global", + importpath = "cloud.google.com/go/servicemanagement", + sha256 = "2e02a723d1c226c2ecba4e47892b96052efb941be2910fd7afc38197f5bc6083", + strip_prefix = "cloud.google.com/go/servicemanagement@v1.8.0", + urls = [ + "http://bazel-cache.pingcap.net:8080/gomod/cloud.google.com/go/servicemanagement/com_google_cloud_go_servicemanagement-v1.8.0.zip", + "http://ats.apps.svc/gomod/cloud.google.com/go/servicemanagement/com_google_cloud_go_servicemanagement-v1.8.0.zip", + "https://cache.hawkingrei.com/gomod/cloud.google.com/go/servicemanagement/com_google_cloud_go_servicemanagement-v1.8.0.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/cloud.google.com/go/servicemanagement/com_google_cloud_go_servicemanagement-v1.8.0.zip", + ], + ) + go_repository( + name = "com_google_cloud_go_serviceusage", + build_file_proto_mode = "disable_global", + importpath = "cloud.google.com/go/serviceusage", + sha256 = "377bad0176bbec558ddb55b1fe10318e2c034c9e87536aba1ba8216b57548f3f", + strip_prefix = "cloud.google.com/go/serviceusage@v1.6.0", + urls = [ + "http://bazel-cache.pingcap.net:8080/gomod/cloud.google.com/go/serviceusage/com_google_cloud_go_serviceusage-v1.6.0.zip", + "http://ats.apps.svc/gomod/cloud.google.com/go/serviceusage/com_google_cloud_go_serviceusage-v1.6.0.zip", + "https://cache.hawkingrei.com/gomod/cloud.google.com/go/serviceusage/com_google_cloud_go_serviceusage-v1.6.0.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/cloud.google.com/go/serviceusage/com_google_cloud_go_serviceusage-v1.6.0.zip", + ], + ) go_repository( name = "com_google_cloud_go_shell", build_file_proto_mode = "disable_global", @@ -9204,6 +9464,19 @@ def go_deps(): "https://storage.googleapis.com/pingcapmirror/gomod/cloud.google.com/go/videointelligence/com_google_cloud_go_videointelligence-v1.11.5.zip", ], ) + go_repository( + name = "com_google_cloud_go_vision", + build_file_proto_mode = "disable_global", + importpath = "cloud.google.com/go/vision", + sha256 = "1fa3845639ba185f74abee6693a53dde3409c040fe77a9de5f866efa216e5849", + strip_prefix = "cloud.google.com/go/vision@v1.2.0", + urls = [ + "http://bazel-cache.pingcap.net:8080/gomod/cloud.google.com/go/vision/com_google_cloud_go_vision-v1.2.0.zip", + "http://ats.apps.svc/gomod/cloud.google.com/go/vision/com_google_cloud_go_vision-v1.2.0.zip", + "https://cache.hawkingrei.com/gomod/cloud.google.com/go/vision/com_google_cloud_go_vision-v1.2.0.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/cloud.google.com/go/vision/com_google_cloud_go_vision-v1.2.0.zip", + ], + ) go_repository( name = "com_google_cloud_go_vision_v2", build_file_proto_mode = "disable_global", @@ -10218,6 +10491,19 @@ def go_deps(): "https://storage.googleapis.com/pingcapmirror/gomod/google.golang.org/grpc/org_golang_google_grpc-v1.63.2.zip", ], ) + go_repository( + name = "org_golang_google_grpc_cmd_protoc_gen_go_grpc", + build_file_proto_mode = "disable_global", + importpath = "google.golang.org/grpc/cmd/protoc-gen-go-grpc", + sha256 = "13877d86cbfa30bde4d62fef2bc58dd56377dcb502c16cf78197f6934193009a", + strip_prefix = "google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.1.0", + urls = [ + "http://bazel-cache.pingcap.net:8080/gomod/google.golang.org/grpc/cmd/protoc-gen-go-grpc/org_golang_google_grpc_cmd_protoc_gen_go_grpc-v1.1.0.zip", + "http://ats.apps.svc/gomod/google.golang.org/grpc/cmd/protoc-gen-go-grpc/org_golang_google_grpc_cmd_protoc_gen_go_grpc-v1.1.0.zip", + "https://cache.hawkingrei.com/gomod/google.golang.org/grpc/cmd/protoc-gen-go-grpc/org_golang_google_grpc_cmd_protoc_gen_go_grpc-v1.1.0.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/google.golang.org/grpc/cmd/protoc-gen-go-grpc/org_golang_google_grpc_cmd_protoc_gen_go_grpc-v1.1.0.zip", + ], + ) go_repository( name = "org_golang_google_grpc_examples", build_file_proto_mode = "disable_global", @@ -10300,13 +10586,13 @@ def go_deps(): name = "org_golang_x_lint", build_file_proto_mode = "disable_global", importpath = "golang.org/x/lint", - sha256 = "4620205ccd1fd5c5ced7ccbc264217f407c53924e847f4219e48c04c7480b294", - strip_prefix = "golang.org/x/lint@v0.0.0-20201208152925-83fdc39ff7b5", + sha256 = "0a4a5ebd2b1d79e7f480cbf5a54b45a257ae1ec9d11f01688efc5c35268d4603", + strip_prefix = "golang.org/x/lint@v0.0.0-20210508222113-6edffad5e616", urls = [ - "http://bazel-cache.pingcap.net:8080/gomod/golang.org/x/lint/org_golang_x_lint-v0.0.0-20201208152925-83fdc39ff7b5.zip", - "http://ats.apps.svc/gomod/golang.org/x/lint/org_golang_x_lint-v0.0.0-20201208152925-83fdc39ff7b5.zip", - "https://cache.hawkingrei.com/gomod/golang.org/x/lint/org_golang_x_lint-v0.0.0-20201208152925-83fdc39ff7b5.zip", - "https://storage.googleapis.com/pingcapmirror/gomod/golang.org/x/lint/org_golang_x_lint-v0.0.0-20201208152925-83fdc39ff7b5.zip", + "http://bazel-cache.pingcap.net:8080/gomod/golang.org/x/lint/org_golang_x_lint-v0.0.0-20210508222113-6edffad5e616.zip", + "http://ats.apps.svc/gomod/golang.org/x/lint/org_golang_x_lint-v0.0.0-20210508222113-6edffad5e616.zip", + "https://cache.hawkingrei.com/gomod/golang.org/x/lint/org_golang_x_lint-v0.0.0-20210508222113-6edffad5e616.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/golang.org/x/lint/org_golang_x_lint-v0.0.0-20210508222113-6edffad5e616.zip", ], ) go_repository( diff --git a/go.mod b/go.mod index f3e352f8dc807d..59fab9aae753fa 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,7 @@ module github.com/pingcap/tidb go 1.21 -replace github.com/pingcap/kvproto => github.com/JmPotato/kvproto v0.0.0-20240730032855-30010ef5dc20 +replace github.com/pingcap/kvproto => github.com/JmPotato/kvproto v0.0.0-20240807105224-7e7a2da7bfcd require ( cloud.google.com/go/storage v1.38.0 diff --git a/go.sum b/go.sum index 3b7908de34c0f6..608ebb5c396fb1 100644 --- a/go.sum +++ b/go.sum @@ -845,8 +845,8 @@ github.com/DataDog/zstd v1.5.5 h1:oWf5W7GtOLgp6bciQYDmhHHjdhYkALu6S/5Ni9ZgSvQ= github.com/DataDog/zstd v1.5.5/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= github.com/HdrHistogram/hdrhistogram-go v1.1.2 h1:5IcZpTvzydCQeHzK4Ef/D5rrSqwxob0t8PQPMybUNFM= github.com/HdrHistogram/hdrhistogram-go v1.1.2/go.mod h1:yDgFjdqOqDEKOvasDdhWNXYg9BVp4O+o5f6V/ehm6Oo= -github.com/JmPotato/kvproto v0.0.0-20240730032855-30010ef5dc20 h1:Hxu4QP2WeowrYaqta923Stz3ZVY55QGAzOTzy6QekFI= -github.com/JmPotato/kvproto v0.0.0-20240730032855-30010ef5dc20/go.mod h1:rXxWk2UnwfUhLXha1jxRWPADw9eMZGWEWCg92Tgmb/8= +github.com/JmPotato/kvproto v0.0.0-20240807105224-7e7a2da7bfcd h1:y9cKHOkSUX2wiMt7J5IeKNl4aSCuyIF2Y0ah/MuYVhc= +github.com/JmPotato/kvproto v0.0.0-20240807105224-7e7a2da7bfcd/go.mod h1:rXxWk2UnwfUhLXha1jxRWPADw9eMZGWEWCg92Tgmb/8= github.com/JohnCGriffin/overflow v0.0.0-20211019200055-46fa312c352c h1:RGWPOewvKIROun94nF7v2cua9qP+thov/7M50KEoeSU= github.com/JohnCGriffin/overflow v0.0.0-20211019200055-46fa312c352c/go.mod h1:X0CRv0ky0k6m906ixxpzmDRLvX58TFUKS2eePweuyxk= github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI= diff --git a/pkg/ddl/resourcegroup/group.go b/pkg/ddl/resourcegroup/group.go index 9e904bfcd2ea09..6903cb1e3f20ca 100644 --- a/pkg/ddl/resourcegroup/group.go +++ b/pkg/ddl/resourcegroup/group.go @@ -51,10 +51,7 @@ func NewGroupFromOptions(groupName string, options *model.ResourceGroupSettings) } // Update the action settings. runaway.Action = rmpb.RunawayAction(options.Runaway.Action.Type) - runaway.ActionV2 = &rmpb.RunawayActionV2{ - Type: runaway.Action, - SwitchGroupName: options.Runaway.Action.SwitchGroupName, - } + runaway.SwitchGroupName = options.Runaway.Action.SwitchGroupName // Update the watch settings. if options.Runaway.WatchType != model.WatchNone { runaway.Watch = &rmpb.RunawayWatch{} diff --git a/pkg/domain/resourcegroup/runaway.go b/pkg/domain/resourcegroup/runaway.go index f19adec9568eaf..7ee8e1787f3b75 100644 --- a/pkg/domain/resourcegroup/runaway.go +++ b/pkg/domain/resourcegroup/runaway.go @@ -16,6 +16,7 @@ package resourcegroup import ( "context" + "fmt" "strings" "sync" "sync/atomic" @@ -111,12 +112,13 @@ type QuarantineRecord struct { ID int64 ResourceGroupName string // startTime and endTime are in UTC. - StartTime time.Time - EndTime time.Time - Watch rmpb.RunawayWatchType - WatchText string - Source string - Action rmpb.RunawayAction + StartTime time.Time + EndTime time.Time + Watch rmpb.RunawayWatchType + WatchText string + Source string + action rmpb.RunawayAction + switchGroupName string } // GetRecordKey is used to get the key in ttl cache. @@ -124,6 +126,36 @@ func (r *QuarantineRecord) GetRecordKey() string { return r.ResourceGroupName + "/" + r.WatchText } +// GetAction returns the runaway action type. +func (r *QuarantineRecord) GetAction() rmpb.RunawayAction { + return r.action +} + +// GetSwitchGroupName returns the switch group name if the action type is `SWITCH_GROUP`. +func (r *QuarantineRecord) GetSwitchGroupName() string { + if r.action == rmpb.RunawayAction_SwitchGroup { + return r.switchGroupName + } + return "" +} + +// GetActionString returns the action string. +func (r *QuarantineRecord) GetActionString() string { + if r == nil { + return rmpb.RunawayAction_NoneAction.String() + } + if r.action == rmpb.RunawayAction_SwitchGroup { + return fmt.Sprintf("%s(%s)", r.action.String(), r.switchGroupName) + } + return r.action.String() +} + +// SetAction sets the runaway action fields. +func (r *QuarantineRecord) SetAction(action rmpb.RunawayAction, switchGroupName string) { + r.action = action + r.switchGroupName = switchGroupName +} + func writeInsert(builder *strings.Builder, tableName string) { builder.WriteString("insert into ") builder.WriteString(tableName) @@ -135,7 +167,7 @@ func (r *QuarantineRecord) GenInsertionStmt() (string, []any) { var builder strings.Builder params := make([]any, 0, 6) writeInsert(&builder, RunawayWatchTableName) - builder.WriteString("(null, %?, %?, %?, %?, %?, %?, %?)") + builder.WriteString("(null, %?, %?, %?, %?, %?, %?, %?, %?)") params = append(params, r.ResourceGroupName) params = append(params, r.StartTime) if r.EndTime.Equal(NullTime) { @@ -146,7 +178,8 @@ func (r *QuarantineRecord) GenInsertionStmt() (string, []any) { params = append(params, r.Watch) params = append(params, r.WatchText) params = append(params, r.Source) - params = append(params, r.Action) + params = append(params, r.GetAction()) + params = append(params, r.GetSwitchGroupName()) return builder.String(), params } @@ -155,7 +188,7 @@ func (r *QuarantineRecord) GenInsertionDoneStmt() (string, []any) { var builder strings.Builder params := make([]any, 0, 9) writeInsert(&builder, RunawayWatchDoneTableName) - builder.WriteString("(null, %?, %?, %?, %?, %?, %?, %?, %?, %?)") + builder.WriteString("(null, %?, %?, %?, %?, %?, %?, %?, %?, %?, %?)") params = append(params, r.ID) params = append(params, r.ResourceGroupName) params = append(params, r.StartTime) @@ -167,7 +200,8 @@ func (r *QuarantineRecord) GenInsertionDoneStmt() (string, []any) { params = append(params, r.Watch) params = append(params, r.WatchText) params = append(params, r.Source) - params = append(params, r.Action) + params = append(params, r.GetAction()) + params = append(params, r.GetSwitchGroupName()) params = append(params, time.Now().UTC()) return builder.String(), params } @@ -276,7 +310,11 @@ func (rm *RunawayManager) DeriveChecker(resourceGroupName, originalSQL, sqlDiges return newRunawayChecker(rm, resourceGroupName, group.RunawaySettings, originalSQL, sqlDigest, planDigest, startTime) } -func (rm *RunawayManager) markQuarantine(resourceGroupName, convict string, watchType rmpb.RunawayWatchType, action rmpb.RunawayAction, ttl time.Duration, now *time.Time) { +func (rm *RunawayManager) markQuarantine( + resourceGroupName, convict string, + watchType rmpb.RunawayWatchType, action rmpb.RunawayAction, switchGroupName string, + ttl time.Duration, now *time.Time, +) { var endTime time.Time if ttl > 0 { endTime = now.UTC().Add(ttl) @@ -288,7 +326,8 @@ func (rm *RunawayManager) markQuarantine(resourceGroupName, convict string, watc Watch: watchType, WatchText: convict, Source: rm.serverID, - Action: action, + action: action, + switchGroupName: switchGroupName, } // Add record without ID into watch list in this TiDB right now. rm.addWatchList(record, ttl, false) @@ -399,7 +438,7 @@ func (rm *RunawayManager) getWatchFromWatchList(key string) *QuarantineRecord { return nil } -func (rm *RunawayManager) markRunaway(resourceGroupName, originalSQL, planDigest string, action string, matchType RunawayMatchType, now *time.Time) { +func (rm *RunawayManager) markRunaway(resourceGroupName, originalSQL, planDigest, actionStr string, matchType RunawayMatchType, now *time.Time) { source := rm.serverID if !rm.syncerInitialized.Load() { rm.logOnce.Do(func() { @@ -412,7 +451,7 @@ func (rm *RunawayManager) markRunaway(resourceGroupName, originalSQL, planDigest ResourceGroupName: resourceGroupName, Time: *now, Match: matchType.String(), - Action: action, + Action: actionStr, SQLText: originalSQL, PlanDigest: planDigest, Source: source, @@ -443,12 +482,12 @@ func (rm *RunawayManager) StaleQuarantineRecordChan() <-chan *QuarantineRecord { } // examineWatchList check whether the query is in watch list. -func (rm *RunawayManager) examineWatchList(resourceGroupName string, convict string) (bool, rmpb.RunawayAction) { +func (rm *RunawayManager) examineWatchList(resourceGroupName, convict string) (bool, rmpb.RunawayAction, string) { item := rm.getWatchFromWatchList(resourceGroupName + "/" + convict) if item == nil { - return false, 0 + return false, 0, "" } - return true, item.Action + return true, item.GetAction(), item.GetSwitchGroupName() } // Stop stops the watchList which is a ttlcache. @@ -470,11 +509,15 @@ type RunawayChecker struct { planDigest string deadline time.Time - setting *rmpb.RunawaySettings + // settings is used as the fallback runaway settings if there is no other specification. + setting *rmpb.RunawaySettings markedByRule atomic.Bool markedByWatch bool - watchAction rmpb.RunawayAction + // action is the specified action for the runaway query. + // If it's not given, the action defined in `groupSettings` will be used. + action rmpb.RunawayAction + switchGroupName string } func newRunawayChecker(manager *RunawayManager, resourceGroupName string, setting *rmpb.RunawaySettings, originalSQL, sqlDigest, planDigest string, startTime time.Time) *RunawayChecker { @@ -495,34 +538,39 @@ func newRunawayChecker(manager *RunawayManager, resourceGroupName string, settin } // BeforeExecutor checks whether query is in watch list before executing and after compiling. -func (r *RunawayChecker) BeforeExecutor() error { +func (r *RunawayChecker) BeforeExecutor() (string, error) { if r == nil { - return nil + return "", nil } for _, convict := range r.getConvictIdentifiers() { - watched, action := r.manager.examineWatchList(r.resourceGroupName, convict) + watched, action, switchGroupName := r.manager.examineWatchList(r.resourceGroupName, convict) if watched { + // Fallback to use the resource group runaway setting. if action == rmpb.RunawayAction_NoneAction && r.setting != nil { action = r.setting.Action + switchGroupName = r.setting.SwitchGroupName } r.markedByWatch = true now := time.Now() - r.watchAction = action - r.markRunaway(RunawayMatchTypeWatch, action, &now) + r.action = action + r.switchGroupName = switchGroupName + r.markRunaway(RunawayMatchTypeWatch, action, switchGroupName, &now) // If no match action, it will do nothing. switch action { case rmpb.RunawayAction_Kill: - return exeerrors.ErrResourceGroupQueryRunawayQuarantine + return "", exeerrors.ErrResourceGroupQueryRunawayQuarantine case rmpb.RunawayAction_CoolDown: // This action should be done in BeforeCopRequest. - return nil + return "", nil case rmpb.RunawayAction_DryRun: - return nil + return "", nil + case rmpb.RunawayAction_SwitchGroup: + return switchGroupName, nil default: } } } - return nil + return "", nil } // BeforeCopRequest checks runaway and modifies the request if necessary before sending coprocessor request. @@ -534,7 +582,7 @@ func (r *RunawayChecker) BeforeCopRequest(req *tikvrpc.Request) error { if !marked { // note: now we don't check whether query is in watch list again. if r.markedByWatch { - if r.watchAction == rmpb.RunawayAction_CoolDown { + if r.action == rmpb.RunawayAction_CoolDown { req.ResourceControlContext.OverridePriority = 1 // set priority to lowest } } @@ -552,7 +600,7 @@ func (r *RunawayChecker) BeforeCopRequest(req *tikvrpc.Request) error { } // execution time exceeds the threshold, mark the query as runaway if r.markedByRule.CompareAndSwap(false, true) { - r.markRunaway(RunawayMatchTypeIdentify, r.setting.Action, &now) + r.markRunaway(RunawayMatchTypeIdentify, r.setting.Action, r.setting.SwitchGroupName, &now) if !r.markedByWatch { r.markQuarantine(&now) } @@ -580,7 +628,7 @@ func (r *RunawayChecker) CheckCopRespError(err error) error { if !r.markedByRule.Load() { now := time.Now() if r.deadline.Before(now) && r.markedByRule.CompareAndSwap(false, true) { - r.markRunaway(RunawayMatchTypeIdentify, r.setting.Action, &now) + r.markRunaway(RunawayMatchTypeIdentify, r.setting.Action, r.setting.SwitchGroupName, &now) if !r.markedByWatch { r.markQuarantine(&now) } @@ -601,11 +649,22 @@ func (r *RunawayChecker) markQuarantine(now *time.Time) { } ttl := time.Duration(r.setting.Watch.LastingDurationMs) * time.Millisecond - r.manager.markQuarantine(r.resourceGroupName, r.getSettingConvictIdentifier(), r.setting.Watch.Type, r.setting.Action, ttl, now) + r.manager.markQuarantine( + r.resourceGroupName, r.getSettingConvictIdentifier(), + r.setting.Watch.Type, r.setting.Action, r.setting.SwitchGroupName, + ttl, now, + ) } -func (r *RunawayChecker) markRunaway(matchType RunawayMatchType, action rmpb.RunawayAction, now *time.Time) { - actionStr := strings.ToLower(rmpb.RunawayAction_name[int32(action)]) +func (r *RunawayChecker) markRunaway(matchType RunawayMatchType, action rmpb.RunawayAction, switchGroupName string, now *time.Time) { + var actionStr string + switch action { + case rmpb.RunawayAction_NoneAction, rmpb.RunawayAction_DryRun, rmpb.RunawayAction_CoolDown, rmpb.RunawayAction_Kill: + actionStr = action.String() + case rmpb.RunawayAction_SwitchGroup: + actionStr = fmt.Sprintf("%s(%s)", action.String(), switchGroupName) + } + actionStr = strings.ToLower(actionStr) metrics.RunawayCheckerCounter.WithLabelValues(r.resourceGroupName, matchType.String(), actionStr).Inc() r.manager.markRunaway(r.resourceGroupName, r.originalSQL, r.planDigest, actionStr, matchType, now) } diff --git a/pkg/domain/runaway.go b/pkg/domain/runaway.go index ae5d50724a047a..f04007fade6d20 100644 --- a/pkg/domain/runaway.go +++ b/pkg/domain/runaway.go @@ -566,8 +566,9 @@ func getRunawayWatchRecord(exec sqlexec.RestrictedSQLExecutor, reader *SystemTab Watch: rmpb.RunawayWatchType(r.GetInt64(4)), WatchText: r.GetString(5), Source: r.GetString(6), - Action: rmpb.RunawayAction(r.GetInt64(7)), } + // TODO: initialize the switch group name from the system table also. + qr.SetAction(rmpb.RunawayAction(r.GetInt64(7)), "") // If a TiDB write record slow, it will occur that the record which has earlier start time is inserted later than others. // So we start the scan a little earlier. if push { @@ -606,8 +607,9 @@ func getRunawayWatchDoneRecord(exec sqlexec.RestrictedSQLExecutor, reader *Syste Watch: rmpb.RunawayWatchType(r.GetInt64(5)), WatchText: r.GetString(6), Source: r.GetString(7), - Action: rmpb.RunawayAction(r.GetInt64(8)), } + // TODO: initialize the switch group name from the system table also. + qr.SetAction(rmpb.RunawayAction(r.GetInt64(8)), "") // Ditto as getRunawayWatchRecord. if push { reader.CheckPoint = now.Add(-3 * runawayWatchSyncInterval) diff --git a/pkg/executor/adapter.go b/pkg/executor/adapter.go index 5ea9fdcafb178d..0c5f3be4a818a8 100644 --- a/pkg/executor/adapter.go +++ b/pkg/executor/adapter.go @@ -547,9 +547,13 @@ func (a *ExecStmt) Exec(ctx context.Context) (_ sqlexec.RecordSet, err error) { _, planDigest := GetPlanDigest(stmtCtx) _, sqlDigest := stmtCtx.SQLDigest() stmtCtx.RunawayChecker = rm.DeriveChecker(stmtCtx.ResourceGroupName, stmtCtx.OriginalSQL, sqlDigest.String(), planDigest.String(), sessionVars.StartTime) - if err := stmtCtx.RunawayChecker.BeforeExecutor(); err != nil { + switchGroupName, err := stmtCtx.RunawayChecker.BeforeExecutor() + if err != nil { return nil, err } + if len(switchGroupName) > 0 { + stmtCtx.ResourceGroupName = switchGroupName + } } ctx = a.observeStmtBeginForTopSQL(ctx) diff --git a/pkg/executor/infoschema_reader.go b/pkg/executor/infoschema_reader.go index 2bf96b2ae6631b..08fb425a617319 100644 --- a/pkg/executor/infoschema_reader.go +++ b/pkg/executor/infoschema_reader.go @@ -3614,7 +3614,6 @@ func (e *memtableRetriever) setDataFromRunawayWatches(sctx sessionctx.Context) e watches := do.GetRunawayWatchList() rows := make([][]types.Datum, 0, len(watches)) for _, watch := range watches { - action := watch.Action row := types.MakeDatums( watch.ID, watch.ResourceGroupName, @@ -3623,7 +3622,7 @@ func (e *memtableRetriever) setDataFromRunawayWatches(sctx sessionctx.Context) e rmpb.RunawayWatchType_name[int32(watch.Watch)], watch.WatchText, watch.Source, - rmpb.RunawayAction_name[int32(action)], + watch.GetActionString(), ) if watch.EndTime.Equal(resourcegroup.NullTime) { row[3].SetString("UNLIMITED", mysql.DefaultCollationName) @@ -3665,12 +3664,12 @@ func (e *memtableRetriever) setDataFromResourceGroups() error { } dur := time.Duration(setting.Rule.ExecElapsedTimeMs) * time.Millisecond fmt.Fprintf(limitBuilder, "EXEC_ELAPSED='%s'", dur.String()) - actionType := model.RunawayActionType(setting.ActionV2.GetType()) + actionType := model.RunawayActionType(setting.Action) switch actionType { case model.RunawayActionDryRun, model.RunawayActionCooldown, model.RunawayActionKill: fmt.Fprintf(limitBuilder, ", ACTION=%s", actionType.String()) case model.RunawayActionSwitchGroup: - fmt.Fprintf(limitBuilder, ", ACTION=%s(%s)", actionType.String(), setting.ActionV2.GetSwitchGroupName()) + fmt.Fprintf(limitBuilder, ", ACTION=%s(%s)", actionType.String(), setting.SwitchGroupName) default: } if setting.Watch != nil { diff --git a/pkg/executor/internal/querywatch/query_watch.go b/pkg/executor/internal/querywatch/query_watch.go index 07b19104399e54..179ba401bc6970 100644 --- a/pkg/executor/internal/querywatch/query_watch.go +++ b/pkg/executor/internal/querywatch/query_watch.go @@ -60,7 +60,7 @@ func setWatchOption(ctx context.Context, record.ResourceGroupName = resourceGroupOption.GroupNameStr.L } case ast.QueryWatchAction: - record.Action = rmpb.RunawayAction(op.ActionOption.Type) + record.SetAction(rmpb.RunawayAction(op.ActionOption.Type), op.ActionOption.SwitchGroupName.String()) case ast.QueryWatchType: textOption := op.TextOption expr, err := plannerutil.RewriteAstExprWithPlanCtx(sctx.GetPlanCtx(), textOption.PatternExpr, nil, nil, false) @@ -144,12 +144,13 @@ func validateWatchRecord(record *resourcegroup.QuarantineRecord, client *rmclien if rg == nil { return infoschema.ErrResourceGroupNotExists.GenWithStackByArgs(record.ResourceGroupName) } - if record.Action == rmpb.RunawayAction_NoneAction { + if record.GetAction() == rmpb.RunawayAction_NoneAction { if rg.RunawaySettings == nil { return errors.Errorf("must set runaway config for resource group `%s`", record.ResourceGroupName) } - record.Action = rg.RunawaySettings.Action + record.SetAction(rg.RunawaySettings.Action, rg.RunawaySettings.SwitchGroupName) } + // TODO: validate the switch group. if record.Watch == rmpb.RunawayWatchType_NoneWatch { return errors.Errorf("must specify watch type") } diff --git a/pkg/session/bootstrap.go b/pkg/session/bootstrap.go index adaae4cdb5f91e..d99a4dccdc9eeb 100644 --- a/pkg/session/bootstrap.go +++ b/pkg/session/bootstrap.go @@ -641,6 +641,7 @@ const ( watch_text TEXT NOT NULL, source varchar(512) NOT NULL, action bigint(10), + switch_group_name VARCHAR(32) DEFAULT '', INDEX sql_index(resource_group_name,watch_text(700)) COMMENT "accelerate the speed when select quarantined query", INDEX time_index(end_time) COMMENT "accelerate the speed when querying with active watch" ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;` @@ -656,6 +657,7 @@ const ( watch_text TEXT NOT NULL, source varchar(512) NOT NULL, action bigint(10), + switch_group_name VARCHAR(32) DEFAULT '', done_time TIMESTAMP(6) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;` @@ -1110,11 +1112,14 @@ const ( // version211 add column `summary` to `mysql.tidb_background_subtask_history`. version211 = 211 + + // version212 add column `switch_group_name` to `mysql.tidb_runaway_watch` and `mysql.tidb_runaway_watch_done`. + version212 = 212 ) // currentBootstrapVersion is defined as a variable, so we can modify its value for testing. // please make sure this is the largest version -var currentBootstrapVersion int64 = version211 +var currentBootstrapVersion int64 = version212 // DDL owner key's expired time is ManagerSessionTTL seconds, we should wait the time and give more time to have a chance to finish it. var internalSQLTimeout = owner.ManagerSessionTTL + 15 @@ -1281,6 +1286,7 @@ var ( upgradeToVer209, upgradeToVer210, upgradeToVer211, + upgradeToVer212, } ) @@ -3078,6 +3084,14 @@ func upgradeToVer211(s sessiontypes.Session, ver int64) { doReentrantDDL(s, "ALTER TABLE mysql.tidb_background_subtask_history ADD COLUMN `summary` JSON", infoschema.ErrColumnExists) } +func upgradeToVer212(s sessiontypes.Session, ver int64) { + if ver >= version211 { + return + } + doReentrantDDL(s, "ALTER TABLE mysql.tidb_runaway_watch ADD COLUMN `switch_group_name` VARCHAR(32) DEFAULT '' AFTER `action`;", infoschema.ErrColumnExists) + doReentrantDDL(s, "ALTER TABLE mysql.tidb_runaway_watch_done ADD COLUMN `switch_group_name` VARCHAR(32) DEFAULT '' AFTER `action`;", infoschema.ErrColumnExists) +} + // initGlobalVariableIfNotExists initialize a global variable with specific val if it does not exist. func initGlobalVariableIfNotExists(s sessiontypes.Session, name string, val any) { ctx := kv.WithInternalSourceType(context.Background(), kv.InternalTxnBootstrap)