Skip to content

Commit

Permalink
enable tx for ob by default
Browse files Browse the repository at this point in the history
  • Loading branch information
whhe committed Nov 15, 2023
1 parent a3a64eb commit 45b57c1
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions session/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,11 +490,6 @@ func (s *session) checkOptions() error {
return fmt.Errorf("con:%d %v", s.sessionVars.ConnectionID, err)
}

if s.opt.tranBatch > 1 {
s.ddlDB, _ = gorm.Open("mysql", fmt.Sprintf("%s&autocommit=1", addr))
s.ddlDB.LogMode(false)
}

// 禁用日志记录器,不显示任何日志
db.LogMode(false)

Expand All @@ -513,13 +508,13 @@ func (s *session) checkOptions() error {
if s.inc.BackupHost == "" || s.inc.BackupPort == 0 || s.inc.BackupUser == "" {
return errors.New(s.getErrorMessage(ER_INVALID_BACKUP_HOST_INFO))
}
addr = fmt.Sprintf("%s:%s@tcp(%s:%d)/?charset=%s&parseTime=True&loc=Local&autocommit=1",
backupAddr := fmt.Sprintf("%s:%s@tcp(%s:%d)/?charset=%s&parseTime=True&loc=Local&autocommit=1",
s.inc.BackupUser, s.inc.BackupPassword, s.inc.BackupHost, s.inc.BackupPort,
s.inc.DefaultCharset)
if s.inc.BackupTLS != "" {
addr += "&tls=" + s.inc.BackupTLS
}
backupdb, err := gorm.Open("mysql", addr)
backupdb, err := gorm.Open("mysql", backupAddr)

if err != nil {
return fmt.Errorf("con:%d %v", s.sessionVars.ConnectionID, err)
Expand Down Expand Up @@ -552,6 +547,16 @@ func (s *session) checkOptions() error {
s.appendErrorMsg("TiDB暂不支持备份功能.")
}

if s.opt.Backup && s.needTransactionMark() && s.opt.tranBatch <= 1 {
s.opt.tranBatch = 50
log.Infof("enable transaction with batch size %d to backup with transaction mark", 50)
}

if s.opt.tranBatch > 1 {
s.ddlDB, _ = gorm.Open("mysql", fmt.Sprintf("%s&autocommit=1", addr))
s.ddlDB.LogMode(false)
}

return nil
}

Expand Down

0 comments on commit 45b57c1

Please sign in to comment.