Improve applier .ReadMigrationRangeValues()
func accuracy (#1164)
* Use a transaction in applier `ReadMigrationRangeValues` func * Private func names
This commit is contained in:
parent
1a473a4f66
commit
3c946e97d7
@ -438,15 +438,15 @@ func (this *Applier) ExecuteThrottleQuery() (int64, error) {
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadMigrationMinValues returns the minimum values to be iterated on rowcopy
|
// readMigrationMinValues returns the minimum values to be iterated on rowcopy
|
||||||
func (this *Applier) ReadMigrationMinValues(uniqueKey *sql.UniqueKey) error {
|
func (this *Applier) readMigrationMinValues(tx *gosql.Tx, uniqueKey *sql.UniqueKey) error {
|
||||||
this.migrationContext.Log.Debugf("Reading migration range according to key: %s", uniqueKey.Name)
|
this.migrationContext.Log.Debugf("Reading migration range according to key: %s", uniqueKey.Name)
|
||||||
query, err := sql.BuildUniqueKeyMinValuesPreparedQuery(this.migrationContext.DatabaseName, this.migrationContext.OriginalTableName, &uniqueKey.Columns)
|
query, err := sql.BuildUniqueKeyMinValuesPreparedQuery(this.migrationContext.DatabaseName, this.migrationContext.OriginalTableName, &uniqueKey.Columns)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
rows, err := this.db.Query(query)
|
rows, err := tx.Query(query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -463,15 +463,15 @@ func (this *Applier) ReadMigrationMinValues(uniqueKey *sql.UniqueKey) error {
|
|||||||
return rows.Err()
|
return rows.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadMigrationMaxValues returns the maximum values to be iterated on rowcopy
|
// readMigrationMaxValues returns the maximum values to be iterated on rowcopy
|
||||||
func (this *Applier) ReadMigrationMaxValues(uniqueKey *sql.UniqueKey) error {
|
func (this *Applier) readMigrationMaxValues(tx *gosql.Tx, uniqueKey *sql.UniqueKey) error {
|
||||||
this.migrationContext.Log.Debugf("Reading migration range according to key: %s", uniqueKey.Name)
|
this.migrationContext.Log.Debugf("Reading migration range according to key: %s", uniqueKey.Name)
|
||||||
query, err := sql.BuildUniqueKeyMaxValuesPreparedQuery(this.migrationContext.DatabaseName, this.migrationContext.OriginalTableName, &uniqueKey.Columns)
|
query, err := sql.BuildUniqueKeyMaxValuesPreparedQuery(this.migrationContext.DatabaseName, this.migrationContext.OriginalTableName, &uniqueKey.Columns)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
rows, err := this.db.Query(query)
|
rows, err := tx.Query(query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -510,13 +510,20 @@ func (this *Applier) ReadMigrationRangeValues() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := this.ReadMigrationMinValues(this.migrationContext.UniqueKey); err != nil {
|
tx, err := this.db.Begin()
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := this.ReadMigrationMaxValues(this.migrationContext.UniqueKey); err != nil {
|
defer tx.Rollback()
|
||||||
|
|
||||||
|
if err := this.readMigrationMinValues(tx, this.migrationContext.UniqueKey); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
if err := this.readMigrationMaxValues(tx, this.migrationContext.UniqueKey); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return tx.Commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
// CalculateNextIterationRangeEndValues reads the next-iteration-range-end unique key values,
|
// CalculateNextIterationRangeEndValues reads the next-iteration-range-end unique key values,
|
||||||
|
Loading…
Reference in New Issue
Block a user