Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

syncer: add detect server version for upstream and downstream database #1673

Merged
merged 5 commits into from
May 13, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions syncer/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2468,6 +2468,8 @@ func (s *Syncer) createDBs(ctx context.Context) error {
return err
}
s.ddlDBConn = ddlDBConns[0]
printServerVersion(s.tctx, s.fromDB.BaseDB, "upstream")
printServerVersion(s.tctx, s.toDB, "downstream")

return nil
}
Expand Down
17 changes: 17 additions & 0 deletions syncer/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ import (
"os"
"strconv"

dcontext "github.com/pingcap/dumpling/v4/context"
"github.com/pingcap/dumpling/v4/export"
dlog "github.com/pingcap/dumpling/v4/log"
"github.com/pingcap/parser/ast"
"github.com/pingcap/tidb-tools/pkg/filter"
"go.uber.org/zap"

"github.com/pingcap/dm/dm/config"
"github.com/pingcap/dm/pkg/conn"
tcontext "github.com/pingcap/dm/pkg/context"
"github.com/pingcap/dm/pkg/terror"
)

Expand Down Expand Up @@ -126,3 +132,14 @@ func recordSourceTbls(sourceTbls map[string]map[string]struct{}, stmt ast.StmtNo
sourceTbls[schema][name] = struct{}{}
}
}

func printServerVersion(tctx *tcontext.Context, db *conn.BaseDB, scope string) {
logger := dlog.NewAppLogger(tctx.Logger.With(zap.String("scope", scope)))
versionInfo, err := export.SelectVersion(db.DB)
if err != nil {
logger.Warn("fail to get version info", zap.Error(err))
return
}
dctx := dcontext.NewContext(tctx.Ctx, logger)
export.ParseServerInfo(dctx, versionInfo)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems GetFlavor and (*SourceConfig).AdjustFlavor could be replaced by this function 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these two are different functions and we don't need to change them for now.

}