Skip to content

Commit 72f63d3

Browse files
author
Shlomi Noach
committed
safe access to applier/inspector hostnames for hooks
1 parent c749edc commit 72f63d3

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

go/base/context.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,28 @@ func (this *MigrationContext) RequiresBinlogFormatChange() bool {
236236
return this.OriginalBinlogFormat != "ROW"
237237
}
238238

239+
// GetApplierHostname is a safe access method to the applier hostname
240+
func (this *MigrationContext) GetApplierHostname() string {
241+
if this.ApplierConnectionConfig == nil {
242+
return ""
243+
}
244+
if this.ApplierConnectionConfig.ImpliedKey == nil {
245+
return ""
246+
}
247+
return this.ApplierConnectionConfig.ImpliedKey.Hostname
248+
}
249+
250+
// GetInspectorHostname is a safe access method to the inspector hostname
251+
func (this *MigrationContext) GetInspectorHostname() string {
252+
if this.InspectorConnectionConfig == nil {
253+
return ""
254+
}
255+
if this.InspectorConnectionConfig.ImpliedKey == nil {
256+
return ""
257+
}
258+
return this.InspectorConnectionConfig.ImpliedKey.Hostname
259+
}
260+
239261
// InspectorIsAlsoApplier is `true` when the both inspector and applier are the
240262
// same database instance. This would be true when running directly on master or when
241263
// testing on replica.

go/logic/hooks.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ func (this *HooksExecutor) applyEnvironmentVairables(extraVariables ...string) [
5959
env = append(env, fmt.Sprintf("GH_OST_ESTIMATED_ROWS=%d", estimatedRows))
6060
totalRowsCopied := this.migrationContext.GetTotalRowsCopied()
6161
env = append(env, fmt.Sprintf("GH_OST_COPIED_ROWS=%d", totalRowsCopied))
62-
env = append(env, fmt.Sprintf("GH_OST_MIGRATED_HOST=%s", this.migrationContext.ApplierConnectionConfig.ImpliedKey.Hostname))
63-
env = append(env, fmt.Sprintf("GH_OST_INSPECTED_HOST=%s", this.migrationContext.InspectorConnectionConfig.ImpliedKey.Hostname))
62+
env = append(env, fmt.Sprintf("GH_OST_MIGRATED_HOST=%s", this.migrationContext.GetApplierHostname()))
63+
env = append(env, fmt.Sprintf("GH_OST_INSPECTED_HOST=%s", this.migrationContext.GetInspectorHostname()))
6464
env = append(env, fmt.Sprintf("GH_OST_EXECUTING_HOST=%s", this.migrationContext.Hostname))
6565
env = append(env, fmt.Sprintf("GH_OST_HOOKS_HINT=%s", this.migrationContext.HooksHintMessage))
6666

0 commit comments

Comments
 (0)