From 72f63d30420c56d1155ca3cf9dfecc196cdffcc2 Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Tue, 4 Oct 2016 21:18:44 +0200 Subject: [PATCH] safe access to applier/inspector hostnames for hooks --- go/base/context.go | 22 ++++++++++++++++++++++ go/logic/hooks.go | 4 ++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/go/base/context.go b/go/base/context.go index 41aa915cb..b5809a2bc 100644 --- a/go/base/context.go +++ b/go/base/context.go @@ -236,6 +236,28 @@ func (this *MigrationContext) RequiresBinlogFormatChange() bool { return this.OriginalBinlogFormat != "ROW" } +// GetApplierHostname is a safe access method to the applier hostname +func (this *MigrationContext) GetApplierHostname() string { + if this.ApplierConnectionConfig == nil { + return "" + } + if this.ApplierConnectionConfig.ImpliedKey == nil { + return "" + } + return this.ApplierConnectionConfig.ImpliedKey.Hostname +} + +// GetInspectorHostname is a safe access method to the inspector hostname +func (this *MigrationContext) GetInspectorHostname() string { + if this.InspectorConnectionConfig == nil { + return "" + } + if this.InspectorConnectionConfig.ImpliedKey == nil { + return "" + } + return this.InspectorConnectionConfig.ImpliedKey.Hostname +} + // InspectorIsAlsoApplier is `true` when the both inspector and applier are the // same database instance. This would be true when running directly on master or when // testing on replica. diff --git a/go/logic/hooks.go b/go/logic/hooks.go index d28821876..25d745af2 100644 --- a/go/logic/hooks.go +++ b/go/logic/hooks.go @@ -59,8 +59,8 @@ func (this *HooksExecutor) applyEnvironmentVairables(extraVariables ...string) [ env = append(env, fmt.Sprintf("GH_OST_ESTIMATED_ROWS=%d", estimatedRows)) totalRowsCopied := this.migrationContext.GetTotalRowsCopied() env = append(env, fmt.Sprintf("GH_OST_COPIED_ROWS=%d", totalRowsCopied)) - env = append(env, fmt.Sprintf("GH_OST_MIGRATED_HOST=%s", this.migrationContext.ApplierConnectionConfig.ImpliedKey.Hostname)) - env = append(env, fmt.Sprintf("GH_OST_INSPECTED_HOST=%s", this.migrationContext.InspectorConnectionConfig.ImpliedKey.Hostname)) + env = append(env, fmt.Sprintf("GH_OST_MIGRATED_HOST=%s", this.migrationContext.GetApplierHostname())) + env = append(env, fmt.Sprintf("GH_OST_INSPECTED_HOST=%s", this.migrationContext.GetInspectorHostname())) env = append(env, fmt.Sprintf("GH_OST_EXECUTING_HOST=%s", this.migrationContext.Hostname)) env = append(env, fmt.Sprintf("GH_OST_HOOKS_HINT=%s", this.migrationContext.HooksHintMessage))