Skip to content

Commit

Permalink
This is an automated cherry-pick of #49579
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
  • Loading branch information
3pointer authored and ti-chi-bot committed Jan 2, 2024
1 parent 9c3d4e3 commit 138bdc0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
35 changes: 33 additions & 2 deletions br/pkg/restore/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2023,6 +2023,7 @@ func CheckNewCollationEnable(
g glue.Glue,
storage kv.Storage,
CheckRequirements bool,
<<<<<<< HEAD
) error {
if backupNewCollationEnable == "" {
if CheckRequirements {
Expand All @@ -2036,28 +2037,58 @@ func CheckNewCollationEnable(
return nil
}

=======
) (bool, error) {
>>>>>>> 49484b19661 (restore: correct new collation when "--check-requirements=false" (#49579))
se, err := g.CreateSession(storage)
if err != nil {
return errors.Trace(err)
return false, errors.Trace(err)
}

newCollationEnable, err := se.GetGlobalVariable(utils.GetTidbNewCollationEnabled())
if err != nil {
return errors.Trace(err)
return false, errors.Trace(err)
}
<<<<<<< HEAD

if !strings.EqualFold(backupNewCollationEnable, newCollationEnable) {
return errors.Annotatef(berrors.ErrUnknown,
"the config 'new_collations_enabled_on_first_bootstrap' not match, upstream:%v, downstream: %v",
backupNewCollationEnable, newCollationEnable)
}

=======
>>>>>>> 49484b19661 (restore: correct new collation when "--check-requirements=false" (#49579))
// collate.newCollationEnabled is set to 1 when the collate package is initialized,
// so we need to modify this value according to the config of the cluster
// before using the collate package.
enabled := newCollationEnable == "True"
// modify collate.newCollationEnabled according to the config of the cluster
collate.SetNewCollationEnabledForTest(enabled)
<<<<<<< HEAD
log.Info("set new_collation_enabled", zap.Bool("new_collation_enabled", enabled))
return nil
=======
log.Info(fmt.Sprintf("set %s", utils.TidbNewCollationEnabled), zap.Bool("new_collation_enabled", enabled))

if backupNewCollationEnable == "" {
if CheckRequirements {
return enabled, errors.Annotatef(berrors.ErrUnknown,
"the value '%s' not found in backupmeta. "+
"you can use \"SELECT VARIABLE_VALUE FROM mysql.tidb WHERE VARIABLE_NAME='%s';\" to manually check the config. "+
"if you ensure the value '%s' in backup cluster is as same as restore cluster, use --check-requirements=false to skip this check",
utils.TidbNewCollationEnabled, utils.TidbNewCollationEnabled, utils.TidbNewCollationEnabled)
}
log.Warn(fmt.Sprintf("the config '%s' is not in backupmeta", utils.TidbNewCollationEnabled))
return enabled, nil
}

if !strings.EqualFold(backupNewCollationEnable, newCollationEnable) {
return enabled, errors.Annotatef(berrors.ErrUnknown,
"the config '%s' not match, upstream:%v, downstream: %v",
utils.TidbNewCollationEnabled, backupNewCollationEnable, newCollationEnable)
}

return enabled, nil
>>>>>>> 49484b19661 (restore: correct new collation when "--check-requirements=false" (#49579))
}
10 changes: 8 additions & 2 deletions br/pkg/restore/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,19 +297,25 @@ func TestCheckNewCollationEnable(t *testing.T) {
CheckRequirements: true,
isErr: true,
},
{
backupMeta: &backuppb.BackupMeta{NewCollationsEnabled: ""},
newCollationEnableInCluster: "False",
CheckRequirements: false,
isErr: false,
},
}

for i, ca := range caseList {
g := &gluetidb.MockGlue{
GlobalVars: map[string]string{"new_collation_enabled": ca.newCollationEnableInCluster},
}
err := restore.CheckNewCollationEnable(ca.backupMeta.GetNewCollationsEnabled(), g, nil, ca.CheckRequirements)

enabled, err := restore.CheckNewCollationEnable(ca.backupMeta.GetNewCollationsEnabled(), g, nil, ca.CheckRequirements)
t.Logf("[%d] Got Error: %v\n", i, err)
if ca.isErr {
require.Error(t, err)
} else {
require.NoError(t, err)
}
require.Equal(t, ca.newCollationEnableInCluster == "True", enabled)
}
}
2 changes: 1 addition & 1 deletion br/pkg/task/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ func RunRestore(c context.Context, g glue.Glue, cmdName string, cfg *RestoreConf
return errors.Trace(versionErr)
}
}
if err = restore.CheckNewCollationEnable(backupMeta.GetNewCollationsEnabled(), g, mgr.GetStorage(), cfg.CheckRequirements); err != nil {
if _, err = restore.CheckNewCollationEnable(backupMeta.GetNewCollationsEnabled(), g, mgr.GetStorage(), cfg.CheckRequirements); err != nil {
return errors.Trace(err)
}

Expand Down

0 comments on commit 138bdc0

Please sign in to comment.