Skip to content

Commit c11c611

Browse files
author
Shlomi Noach
authored
Merge pull request #260 from github/hooks-nil-check
safe access to applier/inspector hostnames for hooks
2 parents c399119 + 72f63d3 commit c11c611

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
@@ -238,6 +238,28 @@ func (this *MigrationContext) RequiresBinlogFormatChange() bool {
238238
return this.OriginalBinlogFormat != "ROW"
239239
}
240240

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