Skip to content

Commit 3c946e9

Browse files
Improve applier .ReadMigrationRangeValues() func accuracy (#1164)
* Use a transaction in applier `ReadMigrationRangeValues` func * Private func names
1 parent 1a473a4 commit 3c946e9

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

go/logic/applier.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -438,15 +438,15 @@ func (this *Applier) ExecuteThrottleQuery() (int64, error) {
438438
return result, nil
439439
}
440440

441-
// ReadMigrationMinValues returns the minimum values to be iterated on rowcopy
442-
func (this *Applier) ReadMigrationMinValues(uniqueKey *sql.UniqueKey) error {
441+
// readMigrationMinValues returns the minimum values to be iterated on rowcopy
442+
func (this *Applier) readMigrationMinValues(tx *gosql.Tx, uniqueKey *sql.UniqueKey) error {
443443
this.migrationContext.Log.Debugf("Reading migration range according to key: %s", uniqueKey.Name)
444444
query, err := sql.BuildUniqueKeyMinValuesPreparedQuery(this.migrationContext.DatabaseName, this.migrationContext.OriginalTableName, &uniqueKey.Columns)
445445
if err != nil {
446446
return err
447447
}
448448

449-
rows, err := this.db.Query(query)
449+
rows, err := tx.Query(query)
450450
if err != nil {
451451
return err
452452
}
@@ -463,15 +463,15 @@ func (this *Applier) ReadMigrationMinValues(uniqueKey *sql.UniqueKey) error {
463463
return rows.Err()
464464
}
465465

466-
// ReadMigrationMaxValues returns the maximum values to be iterated on rowcopy
467-
func (this *Applier) ReadMigrationMaxValues(uniqueKey *sql.UniqueKey) error {
466+
// readMigrationMaxValues returns the maximum values to be iterated on rowcopy
467+
func (this *Applier) readMigrationMaxValues(tx *gosql.Tx, uniqueKey *sql.UniqueKey) error {
468468
this.migrationContext.Log.Debugf("Reading migration range according to key: %s", uniqueKey.Name)
469469
query, err := sql.BuildUniqueKeyMaxValuesPreparedQuery(this.migrationContext.DatabaseName, this.migrationContext.OriginalTableName, &uniqueKey.Columns)
470470
if err != nil {
471471
return err
472472
}
473473

474-
rows, err := this.db.Query(query)
474+
rows, err := tx.Query(query)
475475
if err != nil {
476476
return err
477477
}
@@ -510,13 +510,20 @@ func (this *Applier) ReadMigrationRangeValues() error {
510510
return err
511511
}
512512

513-
if err := this.ReadMigrationMinValues(this.migrationContext.UniqueKey); err != nil {
513+
tx, err := this.db.Begin()
514+
if err != nil {
514515
return err
515516
}
516-
if err := this.ReadMigrationMaxValues(this.migrationContext.UniqueKey); err != nil {
517+
defer tx.Rollback()
518+
519+
if err := this.readMigrationMinValues(tx, this.migrationContext.UniqueKey); err != nil {
517520
return err
518521
}
519-
return nil
522+
if err := this.readMigrationMaxValues(tx, this.migrationContext.UniqueKey); err != nil {
523+
return err
524+
}
525+
526+
return tx.Commit()
520527
}
521528

522529
// CalculateNextIterationRangeEndValues reads the next-iteration-range-end unique key values,

0 commit comments

Comments
 (0)