Skip to content

Commit

Permalink
restore: fix failed to restore due to no such policy (#42795)
Browse files Browse the repository at this point in the history
close #42796
  • Loading branch information
YuJuncen authored Apr 4, 2023
1 parent a991ae5 commit 8b60a36
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
5 changes: 5 additions & 0 deletions br/pkg/gluetidb/glue.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ func (gs *tidbSession) ExecuteInternal(ctx context.Context, sql string, args ...
if err != nil {
return errors.Trace(err)
}
defer func() {
// We need to manually clean the TxnCtx here.
// Or we may get stale information schema in the consequent calls.
gs.se.GetSessionVars().TxnCtx.InfoSchema = nil
}()
// 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
87 changes: 87 additions & 0 deletions br/pkg/gluetidb/glue_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// 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.

package gluetidb

import (
"context"
"testing"

"github.com/pingcap/tidb/br/pkg/glue"
"github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/testkit"
"github.com/pingcap/tidb/types"
"github.com/stretchr/testify/require"
)

func TestTheSessionIsoation(t *testing.T) {
req := require.New(t)
store, _, clean := testkit.CreateMockStoreAndDomain(t)
defer clean()
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,
}))
}

0 comments on commit 8b60a36

Please sign in to comment.