Skip to content

Commit

Permalink
style(dbbackup):format code style and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ylgeeker committed Oct 17, 2024
1 parent 2bb4939 commit ad9d3b7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ func (p *PhysicalRocksdbDumper) initConfig(mysqlVersion string) error {
p.dbbackupHome = filepath.Dir(cmdPath)
db, err := mysqlconn.InitConn(&p.cfg.Public)
if err != nil {
logger.Log.Errorf("can not connect to the mysql, host:%s, port:%d, errmsg:%s", p.cfg.Public.MysqlHost, p.cfg.Public.MysqlPort, err)
logger.Log.Errorf("can not connect to the mysql, host:%s, port:%d, errmsg:%s",
p.cfg.Public.MysqlHost, p.cfg.Public.MysqlPort, err)
return err
}

Expand All @@ -86,7 +87,8 @@ func (p *PhysicalRocksdbDumper) initConfig(mysqlVersion string) error {
p.storageEngine, err = mysqlconn.GetStorageEngine(db)

if err != nil {
logger.Log.Errorf("can not get the storage engine from the mysql, host:%s, port:%d, errmsg:%s", p.cfg.Public.MysqlHost, p.cfg.Public.MysqlPort, err)
logger.Log.Errorf("can not get the storage engine from the mysql, host:%s, port:%d, errmsg:%s",
p.cfg.Public.MysqlHost, p.cfg.Public.MysqlPort, err)
return err
}

Expand All @@ -96,7 +98,8 @@ func (p *PhysicalRocksdbDumper) initConfig(mysqlVersion string) error {
if p.mysqlRole == cst.RoleSlave || p.mysqlRole == cst.RoleRepeater {
p.masterHost, p.masterPort, err = mysqlconn.ShowMysqlSlaveStatus(db)
if err != nil {
logger.Log.Errorf("can not get the master host and port from the mysql, host:%s, port:%d, errmsg:%s", p.cfg.Public.MysqlHost, p.cfg.Public.MysqlPort, err)
logger.Log.Errorf("can not get the master host and port from the mysql, host:%s, port:%d, errmsg:%s",
p.cfg.Public.MysqlHost, p.cfg.Public.MysqlPort, err)
return err
}
}
Expand All @@ -114,11 +117,13 @@ func (p *PhysicalRocksdbDumper) Execute(enableTimeOut bool) error {
}()

if p.storageEngine != cst.StorageEngineRocksdb {
err := fmt.Errorf("unsupported engine:%s, host:%s, port:%d", p.storageEngine, p.cfg.Public.MysqlHost, p.cfg.Public.MysqlPort)
err := fmt.Errorf("unsupported engine:%s, host:%s, port:%d", p.storageEngine,
p.cfg.Public.MysqlHost, p.cfg.Public.MysqlPort)
logger.Log.Error(err)
return err
}

// pre-created checkpoint dir
_, err := os.Stat(p.checkpointDir)
if os.IsNotExist(err) {
logger.Log.Infof("the checkpoint does not exist, will create it. checkpoint:%s", p.checkpointDir)
Expand Down Expand Up @@ -150,7 +155,9 @@ func (p *PhysicalRocksdbDumper) Execute(enableTimeOut bool) error {
cmd = exec.Command("sh", "-c", backupCmd)
}

p.backupLogfile = fmt.Sprintf("dumper_%s_%s_%d_%d.log", p.storageEngine, cst.ToolMyrocksHotbackup, p.cfg.Public.MysqlPort, int(time.Now().Weekday()))
p.backupLogfile = fmt.Sprintf("dumper_%s_%s_%d_%d.log", p.storageEngine,
cst.ToolMyrocksHotbackup, p.cfg.Public.MysqlPort, int(time.Now().Weekday()))

p.backupLogfile = filepath.Join(p.dbbackupHome, "logs", p.backupLogfile)

outFile, err := os.Create(p.backupLogfile)
Expand All @@ -169,7 +176,8 @@ func (p *PhysicalRocksdbDumper) Execute(enableTimeOut bool) error {

err = cmd.Run()
if err != nil {
logger.Log.Errorf("can not run the rocksdb physical dumper command:%s, engine:%s, errmsg:%s", backupCmd, p.storageEngine, err)
logger.Log.Errorf("can not run the rocksdb physical dumper command:%s, engine:%s, errmsg:%s",
backupCmd, p.storageEngine, err)
return err
}

Expand Down Expand Up @@ -198,7 +206,8 @@ func (p *PhysicalRocksdbDumper) PrepareBackupMetaInfo(cnf *config.BackupConfig)

masterStatus, err := parseXtraBinlogInfo(qpressPath, xtrabackupBinlogInfoFileName, tmpFileName)
if err != nil {
logger.Log.Errorf("do not parse xtrabackup binlog file, file name:%s, errmsg:%s", xtrabackupBinlogInfoFileName, err)
logger.Log.Errorf("do not parse xtrabackup binlog file, file name:%s, errmsg:%s",
xtrabackupBinlogInfoFileName, err)
return nil, err
}

Expand All @@ -210,7 +219,8 @@ func (p *PhysicalRocksdbDumper) PrepareBackupMetaInfo(cnf *config.BackupConfig)
slaveStatus, err := parseXtraSlaveInfo(qpressPath, xtrabackupSlaveInfoFileName, tmpFileName)

if err != nil {
logger.Log.Errorf("do not parse xtrabackup slave information, xtrabackup file:%s, errmsg:%s", xtrabackupSlaveInfoFileName, err)
logger.Log.Errorf("do not parse xtrabackup slave information, xtrabackup file:%s, errmsg:%s",
xtrabackupSlaveInfoFileName, err)
return nil, err
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ func (p *PhysicalRocksdbLoader) decompress() error {
return errors.Wrap(err, errStr)
}

logger.Log.Infof("decompress success, command:%s, file name:%s, load dir:%s %s", binPath, file.FileName, p.cfg.PhysicalLoad.MysqlLoadDir, outStr)
logger.Log.Infof("decompress success, command:%s, file name:%s, load dir:%s %s",
binPath, file.FileName, p.cfg.PhysicalLoad.MysqlLoadDir, outStr)
}

return nil
Expand All @@ -90,7 +91,8 @@ func (p *PhysicalRocksdbLoader) decompress() error {
func (p *PhysicalRocksdbLoader) load() error {

if p.storageEngine != cst.StorageEngineRocksdb {
err := fmt.Errorf("unsupported engine:%s, host:%s, port:%d", p.storageEngine, p.cfg.Public.MysqlHost, p.cfg.Public.MysqlPort)
err := fmt.Errorf("unsupported engine:%s, host:%s, port:%d",
p.storageEngine, p.cfg.Public.MysqlHost, p.cfg.Public.MysqlPort)
return err
}

Expand All @@ -116,12 +118,14 @@ func (p *PhysicalRocksdbLoader) load() error {

err = cmd.Run()
if err != nil {
logger.Log.Errorf("can not run the rocksdb physical loader command:%s, engine:%s, errmsg:%s", loaderCmd, p.storageEngine, err)
logger.Log.Errorf("can not run the rocksdb physical loader command:%s, engine:%s, errmsg:%s",
loaderCmd, p.storageEngine, err)
return err
}

logger.Log.Infof("run load rocksdb success, command:%s", cmd.String())

// convert to root user and group to mysql.mysql, the mysql server was started by user mysql
cmutil.ExecCommand(false, "", "chown", "-R", "mysql.mysql", p.dataDir)
cmutil.ExecCommand(false, "", "chown", "-R", "mysql.mysql", p.innodbLogGroupHomeDir)
cmutil.ExecCommand(false, "", "chown", "-R", "mysql.mysql", p.innodbDataHomeDir)
Expand All @@ -139,6 +143,7 @@ func (p *PhysicalRocksdbLoader) initConfig(indexContent *dbareport.IndexContent)
return errors.New("rocksdb physical loader config missed")
}

// the user mysql and group mysql is required
_, err := user.Lookup("mysql")
if err != nil {
logger.Log.Errorf("can not lookup the user: mysql, errmsg:%s", err)
Expand All @@ -159,7 +164,9 @@ func (p *PhysicalRocksdbLoader) initConfig(indexContent *dbareport.IndexContent)
p.storageEngine = strings.ToLower(indexContent.StorageEngine)
p.indexContent = indexContent

p.loaderLogfile = filepath.Join(pwd, "logs", fmt.Sprintf("loader_%s_%s_%d_%d.log", p.storageEngine, cst.ToolMyrocksHotbackup, p.cfg.Public.MysqlPort, int(time.Now().Weekday())))
p.loaderLogfile = filepath.Join(pwd, "logs", fmt.Sprintf("loader_%s_%s_%d_%d.log",
p.storageEngine, cst.ToolMyrocksHotbackup, p.cfg.Public.MysqlPort, int(time.Now().Weekday())))

loaderLogDir := filepath.Dir(p.loaderLogfile)
err = os.MkdirAll(loaderLogDir, 0755)
if err != nil {
Expand Down

0 comments on commit ad9d3b7

Please sign in to comment.