Skip to content

Commit

Permalink
check newcollacitonEnable in br
Browse files Browse the repository at this point in the history
Signed-off-by: joccau <zak.zhao@pingcap.com>
  • Loading branch information
joccau committed Mar 28, 2022
1 parent bc90aa9 commit 0cc7d82
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
4 changes: 3 additions & 1 deletion br/pkg/task/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,11 @@ func RunBackup(c context.Context, g glue.Glue, cmdName string, cfg *BackupConfig
if err != nil {
return errors.Trace(err)
}
newCollationEnable, err := se.GetGlobalVariables("new_collation_enabled")
newCollationEnable, err := se.GetGlobalVariables(tidbNewCollationEnabled)
if err != nil {
return errors.Trace(err)
}
log.Info("get newCollationEnable for check during restore", zap.String("newCollationEnable", newCollationEnable))

client, err := backup.NewBackupClient(ctx, mgr)
if err != nil {
Expand Down Expand Up @@ -360,6 +361,7 @@ func RunBackup(c context.Context, g glue.Glue, cmdName string, cfg *BackupConfig
m.ClusterId = req.ClusterId
m.ClusterVersion = clusterVersion
m.BrVersion = brVersion
m.NewCollationsEnabled = newCollationEnable
})

log.Info("get placement policies", zap.Int("count", len(policies)))
Expand Down
2 changes: 2 additions & 0 deletions br/pkg/task/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ const (
crypterAES128KeyLen = 16
crypterAES192KeyLen = 24
crypterAES256KeyLen = 32

tidbNewCollationEnabled = "new_collation_enabled"
)

// TLSConfig is the common configuration for TLS connection.
Expand Down
42 changes: 42 additions & 0 deletions br/pkg/task/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package task

import (
"context"
"strings"
"time"

"github.com/opentracing/opentracing-go"
Expand All @@ -21,6 +22,7 @@ import (
"github.com/pingcap/tidb/br/pkg/utils"
"github.com/pingcap/tidb/br/pkg/version"
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/kv"
"github.com/spf13/pflag"
"go.uber.org/multierr"
"go.uber.org/zap"
Expand Down Expand Up @@ -265,6 +267,42 @@ func CheckRestoreDBAndTable(client *restore.Client, cfg *RestoreConfig) error {
return nil
}

func CheckNewCollationEnable(
backupNewCollationEnable string,
g glue.Glue,
storage kv.Storage,
CheckRequirements bool,
) error {
if backupNewCollationEnable == "" {
if CheckRequirements {
return errors.Annotatef(berrors.ErrUnknown,
"NewCollactionEnable not found in backupmeta. "+
"if you ensure the newCollactionEnable config is same as restore cluster, "+
"use --check-requirements=false to skip")
} else {
log.Warn("no NewCollactionEnable in backup")
return nil
}
}

se, err := g.CreateSession(storage)
if err != nil {
return errors.Trace(err)
}

newCollationEnable, err := se.GetGlobalVariables(tidbNewCollationEnabled)
if err != nil {
return errors.Trace(err)
}

if strings.ToLower(backupNewCollationEnable) != strings.ToLower(newCollationEnable) {
return errors.Annotatef(berrors.ErrUnknown,
"newCollationEnable not match, upstream:%v, downstream: %v",
backupNewCollationEnable, newCollationEnable)
}
return nil
}

func isFullRestore(cmdName string) bool {
return cmdName == FullRestoreCmd
}
Expand Down Expand Up @@ -315,6 +353,10 @@ func RunRestore(c context.Context, g glue.Glue, cmdName string, cfg *RestoreConf
return errors.Trace(versionErr)
}
}
if err = CheckNewCollationEnable(backupMeta.GetNewCollationsEnabled(), g, mgr.GetStorage(), cfg.CheckRequirements); err != nil {
return errors.Trace(err)
}

reader := metautil.NewMetaReader(backupMeta, s, &cfg.CipherInfo)
if err = client.InitBackupMeta(c, backupMeta, u, s, reader); err != nil {
return errors.Trace(err)
Expand Down
1 change: 1 addition & 0 deletions br/pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func CheckClusterVersion(ctx context.Context, client pd.Client, checker VerCheck
if err := checkTiFlashVersion(s); err != nil {
return errors.Trace(err)
}
continue
}

tikvVersionString := removeVAndHash(s.Version)
Expand Down

0 comments on commit 0cc7d82

Please sign in to comment.