Skip to content

Commit

Permalink
Merge remote-tracking branch 'pingcap/master' into on-missing-43686
Browse files Browse the repository at this point in the history
  • Loading branch information
mjonss committed May 14, 2023
2 parents 931f7e1 + d984e57 commit 3491479
Show file tree
Hide file tree
Showing 23 changed files with 227 additions and 72 deletions.
8 changes: 4 additions & 4 deletions DEPS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5983,8 +5983,8 @@ def go_deps():
name = "org_golang_x_crypto",
build_file_proto_mode = "disable_global",
importpath = "golang.org/x/crypto",
sum = "h1:pd9TJtTueMTVQXzk8E2XESSMQDj/U7OUu0PqJqPXQjQ=",
version = "v0.8.0",
sum = "h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g=",
version = "v0.9.0",
)
go_repository(
name = "org_golang_x_exp",
Expand Down Expand Up @@ -6033,8 +6033,8 @@ def go_deps():
name = "org_golang_x_net",
build_file_proto_mode = "disable_global",
importpath = "golang.org/x/net",
sum = "h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM=",
version = "v0.9.0",
sum = "h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=",
version = "v0.10.0",
)
go_repository(
name = "org_golang_x_oauth2",
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ enterprise-clear:
enterprise-docker: init-submodule enterprise-prepare
docker build -t "$(DOCKERPREFIX)tidb:latest" --build-arg 'GOPROXY=$(shell go env GOPROXY),' -f Dockerfile.enterprise .

enterprise-server-build: TIDB_EDITION=Enterprise
enterprise-server-build:
ifeq ($(TARGET), "")
CGO_ENABLED=1 $(GOBUILD) -tags enterprise $(RACE_FLAG) -ldflags '$(LDFLAGS) $(CHECK_FLAG) $(EXTENSION_FLAG)' -o bin/tidb-server tidb-server/main.go
Expand Down Expand Up @@ -460,6 +461,9 @@ bazel_build: bazel_ci_prepare
cp bazel-out/k8-fastbuild/bin/tidb-server/tidb-server_/tidb-server ./bin
cp bazel-out/k8-fastbuild/bin/cmd/importer/importer_/importer ./bin
cp bazel-out/k8-fastbuild/bin/tidb-server/tidb-server-check_/tidb-server-check ./bin
bazel $(BAZEL_GLOBAL_CONFIG) build $(BAZEL_CMD_CONFIG) \
//tidb-server:tidb-server --stamp --workspace_status_command=./build/print-enterprise-workspace-status.sh --define gotags=enterprise
./bazel-out/k8-fastbuild/bin/tidb-server/tidb-server_/tidb-server -V

bazel_fail_build: failpoint-enable bazel_ci_prepare
bazel $(BAZEL_GLOBAL_CONFIG) build $(BAZEL_CMD_CONFIG) \
Expand Down
42 changes: 42 additions & 0 deletions build/print-enterprise-workspace-status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash
#
# Copyright 2023 PingCAP, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This test is used to test compatible for BR restore.
# It will download backup data from internal file server.
# And make sure these backup data can restore through newly BR tools to newly cluster.

set -o errexit
set -o nounset
set -o pipefail

TiDB_RELEASE_VERSION=$(git describe --tags --dirty --always)
TiDB_BUILD_UTCTIME=$(date -u '+%Y-%m-%d %H:%M:%S')
TIDB_GIT_HASH=$(git rev-parse HEAD)
TIDB_GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
TIDB_EDITION=${TIDB_EDITION:-Enterprise}
TIDB_ENTERPRISE_EXTENSION_GIT_HASH=""
if [ -a "extension/enterprise/.git" ]; then
TIDB_ENTERPRISE_EXTENSION_GIT_HASH=$(cd extension/enterprise && git rev-parse HEAD)
fi

cat <<EOF
STABLE_TiDB_RELEASE_VERSION ${TiDB_RELEASE_VERSION}
STABLE_TiDB_BUILD_UTCTIME ${TiDB_BUILD_UTCTIME}
STABLE_TIDB_GIT_HASH ${TIDB_GIT_HASH}
STABLE_TIDB_GIT_BRANCH ${TIDB_GIT_BRANCH}
STABLE_TIDB_EDITION ${TIDB_EDITION}
STABLE_TIDB_ENTERPRISE_EXTENSION_GIT_HASH ${TIDB_ENTERPRISE_EXTENSION_GIT_HASH}
EOF
3 changes: 2 additions & 1 deletion ddl/metadatalocktest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ go_test(
"mdl_test.go",
],
flaky = True,
shard_count = 31,
shard_count = 32,
deps = [
"//config",
"//ddl",
"//errno",
"//server",
"//testkit",
"//testkit/testsetup",
"@com_github_pingcap_failpoint//:failpoint",
"@com_github_stretchr_testify//require",
"@org_uber_go_goleak//:goleak",
],
Expand Down
16 changes: 16 additions & 0 deletions ddl/metadatalocktest/mdl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"testing"
"time"

"github.com/pingcap/failpoint"
mysql "github.com/pingcap/tidb/errno"
"github.com/pingcap/tidb/server"
"github.com/pingcap/tidb/testkit"
Expand Down Expand Up @@ -1165,3 +1166,18 @@ func TestMDLPrepareFail(t *testing.T) {

tk2.MustExec("alter table test.t add column c int")
}

func TestMDLUpdateEtcdFail(t *testing.T) {
store := testkit.CreateMockStore(t)

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("create table t(a int);")

require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/ddl/mockUpdateMDLToETCDError", `3*return(true)`))
defer func() {
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/ddl/mockUpdateMDLToETCDError"))
}()

tk.MustExec("alter table test.t add column c int")
}
5 changes: 5 additions & 0 deletions ddl/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ func (s *MockSchemaSyncer) WatchGlobalSchemaVer(context.Context) {}

// UpdateSelfVersion implements SchemaSyncer.UpdateSelfVersion interface.
func (s *MockSchemaSyncer) UpdateSelfVersion(ctx context.Context, jobID int64, version int64) error {
failpoint.Inject("mockUpdateMDLToETCDError", func(val failpoint.Value) {
if val.(bool) {
failpoint.Return(errors.New("mock update mdl to etcd error"))
}
})
if variable.EnableMDL.Load() {
s.mdlSchemaVersions.Store(jobID, version)
} else {
Expand Down
2 changes: 1 addition & 1 deletion ddl/resourcegrouptest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ go_test(
srcs = ["resource_group_test.go"],
flaky = True,
race = "on",
shard_count = 4,
shard_count = 5,
deps = [
"//ddl/internal/callback",
"//ddl/resourcegroup",
Expand Down
45 changes: 33 additions & 12 deletions ddl/resourcegrouptest/resource_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,21 @@ func TestResourceGroupBasic(t *testing.T) {

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.Load(), groupInfo.ID)
require.Equal(t, uint64(4000), groupInfo.RURate)
require.Equal(t, int64(4000), groupInfo.BurstLimit)
re.Equal(true, groupInfo.ID != 0)
re.Equal("y", groupInfo.Name.L)
re.Equal(groupID.Load(), groupInfo.ID)
re.Equal(uint64(4000), groupInfo.RURate)
re.Equal(int64(4000), groupInfo.BurstLimit)
}
g = testResourceGroupNameFromIS(t, tk.Session(), "y")
checkFunc(g)
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.Load(), groupInfo.ID)
require.Equal(t, uint64(5000), groupInfo.RURate)
require.Equal(t, int64(-1), groupInfo.BurstLimit)
re.Equal(true, groupInfo.ID != 0)
re.Equal("y", groupInfo.Name.L)
re.Equal(groupID.Load(), groupInfo.ID)
re.Equal(uint64(5000), groupInfo.RURate)
re.Equal(int64(-1), groupInfo.BurstLimit)
}
g = testResourceGroupNameFromIS(t, tk.Session(), "y")
checkFunc(g)
Expand All @@ -142,8 +142,8 @@ func TestResourceGroupBasic(t *testing.T) {
tk.MustGetErrCode("create resource group x burstable, ru_per_sec=1000, burstable", mysql.ErrParse)
tk.MustContainErrMsg("create resource group x burstable, ru_per_sec=1000, burstable", "Dupliated options specified")
groups, err := infosync.ListResourceGroups(context.TODO())
require.Equal(t, 1, len(groups))
require.NoError(t, err)
re.Equal(1, len(groups))
re.NoError(err)

// Check information schema table information_schema.resource_groups
tk.MustExec("create resource group x RU_PER_SEC=1000 PRIORITY=LOW")
Expand Down Expand Up @@ -345,3 +345,24 @@ func TestNewResourceGroupFromOptions(t *testing.T) {
}
}
}

func TestBindHints(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
re := require.New(t)

tk.MustExec("drop resource group if exists rg1")
tk.MustExec("create resource group rg1 RU_PER_SEC=1000")

tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int, b int)")

tk.MustExec("create global binding for select * from t using select /*+ resource_group(rg1) */ * from t")
tk.MustQuery("select * from t")
re.Equal("rg1", tk.Session().GetSessionVars().StmtCtx.ResourceGroup)
re.Equal("", tk.Session().GetSessionVars().ResourceGroupName)
tk.MustQuery("select a, b from t")
re.Equal("", tk.Session().GetSessionVars().StmtCtx.ResourceGroup)
re.Equal("", tk.Session().GetSessionVars().ResourceGroupName)
}
1 change: 1 addition & 0 deletions domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,7 @@ func (do *Domain) mdlCheckLoop() {
logutil.BgLogger().Info("mdl gets lock, update to owner", zap.Int64("jobID", jobID), zap.Int64("version", ver))
err := do.ddl.SchemaSyncer().UpdateSelfVersion(context.Background(), jobID, ver)
if err != nil {
jobNeedToSync = true
logutil.BgLogger().Warn("update self version failed", zap.Error(err))
} else {
jobCache[jobID] = ver
Expand Down
36 changes: 24 additions & 12 deletions executor/cte.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,12 @@ func (e *CTEExec) Close() (err error) {
}

func (e *CTEExec) computeSeedPart(ctx context.Context) (err error) {
defer func() {
if r := recover(); r != nil && err == nil {
err = errors.Errorf("%v", r)
}
}()
failpoint.Inject("testCTESeedPanic", nil)
e.curIter = 0
e.iterInTbl.SetIter(e.curIter)
chks := make([]*chunk.Chunk, 0, 10)
Expand All @@ -240,50 +246,56 @@ func (e *CTEExec) computeSeedPart(ctx context.Context) (err error) {
}
chk := tryNewCacheChunk(e.seedExec)
if err = Next(ctx, e.seedExec, chk); err != nil {
return err
return
}
if chk.NumRows() == 0 {
break
}
if chk, err = e.tryDedupAndAdd(chk, e.iterInTbl, e.hashTbl); err != nil {
return err
return
}
chks = append(chks, chk)
}
// Initial resTbl is empty, so no need to deduplicate chk using resTbl.
// Just adding is ok.
for _, chk := range chks {
if err = e.resTbl.Add(chk); err != nil {
return err
return
}
}
e.curIter++
e.iterInTbl.SetIter(e.curIter)

return nil
return
}

func (e *CTEExec) computeRecursivePart(ctx context.Context) (err error) {
defer func() {
if r := recover(); r != nil && err == nil {
err = errors.Errorf("%v", r)
}
}()
failpoint.Inject("testCTERecursivePanic", nil)
if e.recursiveExec == nil || e.iterInTbl.NumChunks() == 0 {
return nil
return
}

if e.curIter > e.ctx.GetSessionVars().CTEMaxRecursionDepth {
return exeerrors.ErrCTEMaxRecursionDepth.GenWithStackByArgs(e.curIter)
}

if e.limitDone(e.resTbl) {
return nil
return
}

for {
chk := tryNewCacheChunk(e.recursiveExec)
if err = Next(ctx, e.recursiveExec, chk); err != nil {
return err
return
}
if chk.NumRows() == 0 {
if err = e.setupTblsForNewIteration(); err != nil {
return err
return
}
if e.limitDone(e.resTbl) {
break
Expand All @@ -300,18 +312,18 @@ func (e *CTEExec) computeRecursivePart(ctx context.Context) (err error) {
// Make sure iterInTbl is setup before Close/Open,
// because some executors will read iterInTbl in Open() (like IndexLookupJoin).
if err = e.recursiveExec.Close(); err != nil {
return err
return
}
if err = e.recursiveExec.Open(ctx); err != nil {
return err
return
}
} else {
if err = e.iterOutTbl.Add(chk); err != nil {
return err
return
}
}
}
return nil
return
}

// Get next chunk from resTbl for limit.
Expand Down
21 changes: 21 additions & 0 deletions executor/cte_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,3 +449,24 @@ func TestCTEsInView(t *testing.T) {
tk.MustExec("use test1;")
tk.MustQuery("select * from test.v;").Check(testkit.Rows("1"))
}

func TestCTEPanic(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test;")
tk.MustExec("create table t1(c1 int)")
tk.MustExec("insert into t1 values(1), (2), (3)")

fpPathPrefix := "github.com/pingcap/tidb/executor/"
fp := "testCTESeedPanic"
require.NoError(t, failpoint.Enable(fpPathPrefix+fp, fmt.Sprintf(`panic("%s")`, fp)))
err := tk.QueryToErr("with recursive cte1 as (select c1 from t1 union all select c1 + 1 from cte1 where c1 < 5) select t_alias_1.c1 from cte1 as t_alias_1 inner join cte1 as t_alias_2 on t_alias_1.c1 = t_alias_2.c1 order by c1")
require.Contains(t, err.Error(), fp)
require.NoError(t, failpoint.Disable(fpPathPrefix+fp))

fp = "testCTERecursivePanic"
require.NoError(t, failpoint.Enable(fpPathPrefix+fp, fmt.Sprintf(`panic("%s")`, fp)))
err = tk.QueryToErr("with recursive cte1 as (select c1 from t1 union all select c1 + 1 from cte1 where c1 < 5) select t_alias_1.c1 from cte1 as t_alias_1 inner join cte1 as t_alias_2 on t_alias_1.c1 = t_alias_2.c1 order by c1")
require.Contains(t, err.Error(), fp)
require.NoError(t, failpoint.Disable(fpPathPrefix+fp))
}
2 changes: 1 addition & 1 deletion extension/enterprise
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ require (
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.24.0
golang.org/x/exp v0.0.0-20221023144134-a1e5550cf13e
golang.org/x/net v0.9.0
golang.org/x/net v0.10.0
golang.org/x/oauth2 v0.7.0
golang.org/x/sync v0.2.0
golang.org/x/sys v0.8.0
Expand Down Expand Up @@ -268,7 +268,7 @@ require (
go.opentelemetry.io/otel/sdk/metric v0.20.0 // indirect
go.opentelemetry.io/otel/trace v0.20.0 // indirect
go.opentelemetry.io/proto/otlp v0.7.0 // indirect
golang.org/x/crypto v0.8.0 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/exp/typeparams v0.0.0-20230224173230-c95f2b4c22f2 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1115,8 +1115,8 @@ golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f/go.mod h1:IxCIyHEi3zRg3s0
golang.org/x/crypto v0.0.0-20220518034528-6f7dac969898/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/crypto v0.8.0 h1:pd9TJtTueMTVQXzk8E2XESSMQDj/U7OUu0PqJqPXQjQ=
golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE=
golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g=
golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand Down Expand Up @@ -1219,8 +1219,8 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM=
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down

0 comments on commit 3491479

Please sign in to comment.