Skip to content

Commit 790f5e4

Browse files
timvaillancourtRainbowDashy
authored andcommitted
Improve applier .ReadMigrationRangeValues() func accuracy (github#1164)
* Use a transaction in applier `ReadMigrationRangeValues` func * Private func names
1 parent d4d1c88 commit 790f5e4

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

go/logic/applier.go

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

440-
// ReadMigrationMinValues returns the minimum values to be iterated on rowcopy
441-
func (this *Applier) ReadMigrationMinValues(uniqueKey *sql.UniqueKey) error {
440+
// readMigrationMinValues returns the minimum values to be iterated on rowcopy
441+
func (this *Applier) readMigrationMinValues(tx *gosql.Tx, uniqueKey *sql.UniqueKey) error {
442442
this.migrationContext.Log.Debugf("Reading migration range according to key: %s", uniqueKey.Name)
443443
query, err := sql.BuildUniqueKeyMinValuesPreparedQuery(this.migrationContext.DatabaseName, this.migrationContext.OriginalTableName, &uniqueKey.Columns)
444444
if err != nil {
445445
return err
446446
}
447-
rows, err := this.db.Query(query)
447+
448+
rows, err := tx.Query(query)
448449
if err != nil {
449450
return err
450451
}
@@ -461,14 +462,15 @@ func (this *Applier) ReadMigrationMinValues(uniqueKey *sql.UniqueKey) error {
461462
return err
462463
}
463464

464-
// ReadMigrationMaxValues returns the maximum values to be iterated on rowcopy
465-
func (this *Applier) ReadMigrationMaxValues(uniqueKey *sql.UniqueKey) error {
465+
// readMigrationMaxValues returns the maximum values to be iterated on rowcopy
466+
func (this *Applier) readMigrationMaxValues(tx *gosql.Tx, uniqueKey *sql.UniqueKey) error {
466467
this.migrationContext.Log.Debugf("Reading migration range according to key: %s", uniqueKey.Name)
467468
query, err := sql.BuildUniqueKeyMaxValuesPreparedQuery(this.migrationContext.DatabaseName, this.migrationContext.OriginalTableName, &uniqueKey.Columns)
468469
if err != nil {
469470
return err
470471
}
471-
rows, err := this.db.Query(query)
472+
473+
rows, err := tx.Query(query)
472474
if err != nil {
473475
return err
474476
}
@@ -507,13 +509,20 @@ func (this *Applier) ReadMigrationRangeValues() error {
507509
return err
508510
}
509511

510-
if err := this.ReadMigrationMinValues(this.migrationContext.UniqueKey); err != nil {
512+
tx, err := this.db.Begin()
513+
if err != nil {
511514
return err
512515
}
513-
if err := this.ReadMigrationMaxValues(this.migrationContext.UniqueKey); err != nil {
516+
defer tx.Rollback()
517+
518+
if err := this.readMigrationMinValues(tx, this.migrationContext.UniqueKey); err != nil {
514519
return err
515520
}
516-
return nil
521+
if err := this.readMigrationMaxValues(tx, this.migrationContext.UniqueKey); err != nil {
522+
return err
523+
}
524+
525+
return tx.Commit()
517526
}
518527

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

0 commit comments

Comments
 (0)