Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into add-index-checkpo…
Browse files Browse the repository at this point in the history
…int-v2
  • Loading branch information
tangenta committed Apr 11, 2023
2 parents 87987c6 + 84084c9 commit 92dc8b5
Show file tree
Hide file tree
Showing 136 changed files with 15,088 additions and 12,487 deletions.
613 changes: 318 additions & 295 deletions DEPS.bzl

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Makefile
Expand Up @@ -334,8 +334,9 @@ mock_s3iface:
@mockgen -package mock github.com/aws/aws-sdk-go/service/s3/s3iface S3API > br/pkg/mock/s3iface.go

mock_lightning:
@mockgen -package mock -mock_names AbstractBackend=MockBackend github.com/pingcap/tidb/br/pkg/lightning/backend AbstractBackend,EngineWriter,TargetInfoGetter > br/pkg/mock/backend.go
@mockgen -package mock github.com/pingcap/tidb/br/pkg/lightning/backend Backend,EngineWriter,TargetInfoGetter,ChunkFlushStatus > br/pkg/mock/backend.go
@mockgen -package mock github.com/pingcap/tidb/br/pkg/lightning/backend/encode Encoder,EncodingBuilder,Rows,Row > br/pkg/mock/encode.go
@mockgen -package mocklocal github.com/pingcap/tidb/br/pkg/lightning/backend/local DiskUsage > br/pkg/mock/mocklocal/local.go

# There is no FreeBSD environment for GitHub actions. So cross-compile on Linux
# but that doesn't work with CGO_ENABLED=1, so disable cgo. The reason to have
Expand Down
2 changes: 2 additions & 0 deletions br/pkg/gluetidb/BUILD.bazel
Expand Up @@ -33,12 +33,14 @@ go_test(
embed = [":gluetidb"],
flaky = True,
deps = [
"//br/pkg/glue",
"//ddl",
"//kv",
"//meta",
"//parser/model",
"//sessionctx",
"//testkit",
"//types",
"@com_github_pingcap_failpoint//:failpoint",
"@com_github_stretchr_testify//require",
],
Expand Down
6 changes: 6 additions & 0 deletions br/pkg/gluetidb/glue.go
Expand Up @@ -176,6 +176,12 @@ func (gs *tidbSession) ExecuteInternal(ctx context.Context, sql string, args ...
if err != nil {
return errors.Trace(err)
}
defer func() {
vars := gs.se.GetSessionVars()
vars.TxnCtxMu.Lock()
vars.TxnCtx.InfoSchema = nil
vars.TxnCtxMu.Unlock()
}()
// Some of SQLs (like ADMIN RECOVER INDEX) may lazily take effect
// when we polling the result set.
// At least call `next` once for triggering theirs side effect.
Expand Down
62 changes: 62 additions & 0 deletions br/pkg/gluetidb/glue_test.go
Expand Up @@ -20,12 +20,14 @@ import (
"testing"

"github.com/pingcap/failpoint"
"github.com/pingcap/tidb/br/pkg/glue"
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/meta"
"github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/testkit"
"github.com/pingcap/tidb/types"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -206,3 +208,63 @@ func TestSplitBatchCreateTableFailWithEntryTooLarge(t *testing.T) {

require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/ddl/RestoreBatchCreateTableEntryTooLarge"))
}

func TestTheSessionIsoation(t *testing.T) {
req := require.New(t)
store, _ := testkit.CreateMockStoreAndDomain(t)
ctx := context.Background()

g := Glue{}
session, err := g.CreateSession(store)
req.NoError(err)

req.NoError(session.ExecuteInternal(ctx, "use test;"))
infos := []*model.TableInfo{}
infos = append(infos, &model.TableInfo{
Name: model.NewCIStr("tables_1"),
Columns: []*model.ColumnInfo{
{Name: model.NewCIStr("foo"), FieldType: *types.NewFieldType(types.KindBinaryLiteral), State: model.StatePublic},
},
})
infos = append(infos, &model.TableInfo{
Name: model.NewCIStr("tables_2"),
PlacementPolicyRef: &model.PolicyRefInfo{
Name: model.NewCIStr("threereplication"),
},
Columns: []*model.ColumnInfo{
{Name: model.NewCIStr("foo"), FieldType: *types.NewFieldType(types.KindBinaryLiteral), State: model.StatePublic},
},
})
infos = append(infos, &model.TableInfo{
Name: model.NewCIStr("tables_3"),
PlacementPolicyRef: &model.PolicyRefInfo{
Name: model.NewCIStr("fivereplication"),
},
Columns: []*model.ColumnInfo{
{Name: model.NewCIStr("foo"), FieldType: *types.NewFieldType(types.KindBinaryLiteral), State: model.StatePublic},
},
})
polices := []*model.PolicyInfo{
{
PlacementSettings: &model.PlacementSettings{
Followers: 4,
},
Name: model.NewCIStr("fivereplication"),
},
{
PlacementSettings: &model.PlacementSettings{
Followers: 2,
},
Name: model.NewCIStr("threereplication"),
},
}
for _, pinfo := range polices {
before := session.(*tidbSession).se.GetInfoSchema().SchemaMetaVersion()
req.NoError(session.CreatePlacementPolicy(ctx, pinfo))
after := session.(*tidbSession).se.GetInfoSchema().SchemaMetaVersion()
req.Greater(after, before)
}
req.NoError(session.(glue.BatchCreateTableSession).CreateTables(ctx, map[string][]*model.TableInfo{
"test": infos,
}))
}
1 change: 0 additions & 1 deletion br/pkg/lightning/backend/BUILD.bazel
Expand Up @@ -16,7 +16,6 @@ go_library(
"@com_github_google_uuid//:uuid",
"@com_github_pingcap_errors//:errors",
"@com_github_pingcap_failpoint//:failpoint",
"@org_golang_x_exp//slices",
"@org_uber_go_zap//:zap",
],
)
Expand Down

0 comments on commit 92dc8b5

Please sign in to comment.