Skip to content

Commit 5edcb9e

Browse files
Add .ServerInfo() method
1 parent 20337e7 commit 5edcb9e

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

go/logic/applier.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ func NewApplier(migrationContext *base.MigrationContext) *Applier {
7272
}
7373
}
7474

75+
func (this *Applier) ServerInfo() *mysql.ServerInfo {
76+
return this.migrationContext.ApplierServerInfo
77+
}
78+
7579
func (this *Applier) InitDBConnections() (err error) {
7680
applierUri := this.connectionConfig.GetDBUri(this.migrationContext.DatabaseName)
7781
if this.db, _, err = mysql.GetDB(this.migrationContext.Uuid, applierUri); err != nil {
@@ -85,7 +89,7 @@ func (this *Applier) InitDBConnections() (err error) {
8589
return err
8690
}
8791
this.singletonDB.SetMaxOpenConns(1)
88-
if err = base.ValidateConnection(this.migrationContext.ApplierServerInfo, this.connectionConfig, this.migrationContext, this.name); err != nil {
92+
if err = base.ValidateConnection(this.ServerInfo(), this.connectionConfig, this.migrationContext, this.name); err != nil {
8993
return err
9094
}
9195
if !this.migrationContext.AliyunRDS && !this.migrationContext.GoogleCloudPlatform && !this.migrationContext.AzureMySQL {
@@ -99,7 +103,7 @@ func (this *Applier) InitDBConnections() (err error) {
99103
return err
100104
}
101105
this.migrationContext.Log.Infof("Applier initiated on %+v, version %+v (%+v)", this.connectionConfig.ImpliedKey,
102-
this.migrationContext.ApplierServerInfo.Version, this.migrationContext.ApplierServerInfo.VersionComment)
106+
this.ServerInfo().Version, this.ServerInfo().VersionComment)
103107
return nil
104108
}
105109

@@ -224,7 +228,7 @@ func (this *Applier) CreateGhostTable() error {
224228
}
225229
defer tx.Rollback()
226230

227-
sessionQuery := fmt.Sprintf(`SET SESSION time_zone = '%s'`, this.migrationContext.ApplierServerInfo.TimeZone)
231+
sessionQuery := fmt.Sprintf(`SET SESSION time_zone = '%s'`, this.ServerInfo().TimeZone)
228232
sessionQuery = fmt.Sprintf("%s, %s", sessionQuery, this.generateSqlModeQuery())
229233

230234
if _, err := tx.Exec(sessionQuery); err != nil {
@@ -265,7 +269,7 @@ func (this *Applier) AlterGhost() error {
265269
}
266270
defer tx.Rollback()
267271

268-
sessionQuery := fmt.Sprintf(`SET SESSION time_zone = '%s'`, this.migrationContext.ApplierServerInfo.TimeZone)
272+
sessionQuery := fmt.Sprintf(`SET SESSION time_zone = '%s'`, this.ServerInfo().TimeZone)
269273
sessionQuery = fmt.Sprintf("%s, %s", sessionQuery, this.generateSqlModeQuery())
270274

271275
if _, err := tx.Exec(sessionQuery); err != nil {
@@ -625,7 +629,7 @@ func (this *Applier) ApplyIterationInsertQuery() (chunkSize int64, rowsAffected
625629
}
626630
defer tx.Rollback()
627631

628-
sessionQuery := fmt.Sprintf(`SET SESSION time_zone = '%s'`, this.migrationContext.ApplierServerInfo.TimeZone)
632+
sessionQuery := fmt.Sprintf(`SET SESSION time_zone = '%s'`, this.ServerInfo().TimeZone)
629633
sessionQuery = fmt.Sprintf("%s, %s", sessionQuery, this.generateSqlModeQuery())
630634

631635
if _, err := tx.Exec(sessionQuery); err != nil {

go/logic/inspect.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ func NewInspector(migrationContext *base.MigrationContext) *Inspector {
4242
}
4343
}
4444

45+
func (this *Inspector) ServerInfo() *mysql.ServerInfo {
46+
return this.migrationContext.InspectorServerInfo
47+
}
48+
4549
func (this *Inspector) InitDBConnections() (err error) {
4650
inspectorUri := this.connectionConfig.GetDBUri(this.migrationContext.DatabaseName)
4751
if this.db, _, err = mysql.GetDB(this.migrationContext.Uuid, inspectorUri); err != nil {
@@ -76,7 +80,7 @@ func (this *Inspector) InitDBConnections() (err error) {
7680
return err
7781
}
7882
this.migrationContext.Log.Infof("Inspector initiated on %+v, version %+v (%+v)", this.connectionConfig.ImpliedKey,
79-
this.migrationContext.InspectorServerInfo.Version, this.migrationContext.InspectorServerInfo.VersionComment)
83+
this.ServerInfo().Version, this.ServerInfo().VersionComment)
8084
return nil
8185
}
8286

@@ -188,7 +192,7 @@ func (this *Inspector) inspectOriginalAndGhostTables() (err error) {
188192
column := this.migrationContext.SharedColumns.Columns()[i]
189193
mappedColumn := this.migrationContext.MappedSharedColumns.Columns()[i]
190194
if column.Name == mappedColumn.Name && column.Type == sql.DateTimeColumnType && mappedColumn.Type == sql.TimestampColumnType {
191-
this.migrationContext.MappedSharedColumns.SetConvertDatetimeToTimestamp(column.Name, this.migrationContext.InspectorServerInfo.TimeZone)
195+
this.migrationContext.MappedSharedColumns.SetConvertDatetimeToTimestamp(column.Name, this.ServerInfo().TimeZone)
192196
}
193197
if column.Name == mappedColumn.Name && column.Type == sql.EnumColumnType && mappedColumn.Charset != "" {
194198
this.migrationContext.MappedSharedColumns.SetEnumToTextConversion(column.Name)
@@ -218,7 +222,7 @@ func (this *Inspector) validateConnection() error {
218222
return fmt.Errorf("MySQL replication length limited to 32 characters. See https://dev.mysql.com/doc/refman/5.7/en/assigning-passwords.html")
219223
}
220224

221-
return base.ValidateConnection(this.migrationContext.InspectorServerInfo, this.connectionConfig, this.migrationContext, this.name)
225+
return base.ValidateConnection(this.ServerInfo(), this.connectionConfig, this.migrationContext, this.name)
222226
}
223227

224228
// validateGrants verifies the user by which we're executing has necessary grants
@@ -316,7 +320,7 @@ func (this *Inspector) applyBinlogFormat() error {
316320
if this.migrationContext.RequiresBinlogFormatChange() {
317321
if !this.migrationContext.SwitchToRowBinlogFormat {
318322
return fmt.Errorf("Existing binlog_format is %s. Am not switching it to ROW unless you specify --switch-to-rbr",
319-
this.migrationContext.InspectorServerInfo.BinlogFormat)
323+
this.ServerInfo().BinlogFormat)
320324
}
321325
if _, err := sqlutils.ExecNoPrepare(this.db, `set global binlog_format='ROW'`); err != nil {
322326
return err
@@ -341,8 +345,7 @@ func (this *Inspector) applyBinlogFormat() error {
341345

342346
// validateBinlogs checks that binary log configuration is good to go
343347
func (this *Inspector) validateBinlogs() error {
344-
inspectorServerInfo := this.migrationContext.InspectorServerInfo
345-
if !inspectorServerInfo.LogBin {
348+
if !this.ServerInfo().LogBin {
346349
return fmt.Errorf("%s must have binary logs enabled", this.connectionConfig.Key.String())
347350
}
348351

@@ -360,13 +363,13 @@ func (this *Inspector) validateBinlogs() error {
360363
return err
361364
}
362365
if countReplicas > 0 {
363-
return fmt.Errorf("%s has %s binlog_format, but I'm too scared to change it to ROW because it has replicas. Bailing out", this.connectionConfig.Key.String(), inspectorServerInfo.BinlogFormat)
366+
return fmt.Errorf("%s has %s binlog_format, but I'm too scared to change it to ROW because it has replicas. Bailing out", this.connectionConfig.Key.String(), this.ServerInfo().BinlogFormat)
364367
}
365-
this.migrationContext.Log.Infof("%s has %s binlog_format. I will change it to ROW, and will NOT change it back, even in the event of failure.", this.connectionConfig.Key.String(), inspectorServerInfo.BinlogFormat)
368+
this.migrationContext.Log.Infof("%s has %s binlog_format. I will change it to ROW, and will NOT change it back, even in the event of failure.", this.connectionConfig.Key.String(), this.ServerInfo().BinlogFormat)
366369
}
367370

368-
if inspectorServerInfo.BinlogRowImage != "FULL" {
369-
return fmt.Errorf("%s has '%s' binlog_row_image, and only 'FULL' is supported. This operation cannot proceed. You may `set global binlog_row_image='full'` and try again", this.connectionConfig.Key.String(), inspectorServerInfo.BinlogRowImage)
371+
if this.ServerInfo().BinlogRowImage != "FULL" {
372+
return fmt.Errorf("%s has '%s' binlog_row_image, and only 'FULL' is supported. This operation cannot proceed. You may `set global binlog_row_image='full'` and try again", this.connectionConfig.Key.String(), this.ServerInfo().BinlogRowImage)
370373
}
371374

372375
this.migrationContext.Log.Infof("binary logs validated on %s", this.connectionConfig.Key.String())
@@ -375,7 +378,7 @@ func (this *Inspector) validateBinlogs() error {
375378

376379
// validateLogSlaveUpdates checks that binary log log_slave_updates is set. This test is not required when migrating on replica or when migrating directly on master
377380
func (this *Inspector) validateLogSlaveUpdates() error {
378-
if this.migrationContext.InspectorServerInfo.LogSlaveUpdates {
381+
if this.ServerInfo().LogSlaveUpdates {
379382
this.migrationContext.Log.Infof("log_slave_updates validated on %s", this.connectionConfig.Key.String())
380383
return nil
381384
}

0 commit comments

Comments
 (0)