From a58e80387e9470e26cda599b4112b0426c2fb4f3 Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Fri, 2 Sep 2016 10:48:29 +0200 Subject: [PATCH] More environment variables in hooks --- build.sh | 2 +- go/logic/hooks.go | 6 ++++++ resources/hooks-sample/gh-ost-on-success-hook-2 | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 158530f..77146c3 100755 --- a/build.sh +++ b/build.sh @@ -2,7 +2,7 @@ # # -RELEASE_VERSION="1.0.16" +RELEASE_VERSION="1.0.17" function build { osname=$1 diff --git a/go/logic/hooks.go b/go/logic/hooks.go index d0522e5..d288218 100644 --- a/go/logic/hooks.go +++ b/go/logic/hooks.go @@ -11,6 +11,7 @@ import ( "os" "os/exec" "path/filepath" + "sync/atomic" "github.com/github/gh-ost/go/base" "github.com/outbrain/golib/log" @@ -53,6 +54,11 @@ func (this *HooksExecutor) applyEnvironmentVairables(extraVariables ...string) [ env = append(env, fmt.Sprintf("GH_OST_OLD_TABLE_NAME=%s", this.migrationContext.GetOldTableName())) env = append(env, fmt.Sprintf("GH_OST_DDL=%s", this.migrationContext.AlterStatement)) env = append(env, fmt.Sprintf("GH_OST_ELAPSED_SECONDS=%f", this.migrationContext.ElapsedTime().Seconds())) + env = append(env, fmt.Sprintf("GH_OST_ELAPSED_COPY_SECONDS=%f", this.migrationContext.ElapsedRowCopyTime().Seconds())) + estimatedRows := atomic.LoadInt64(&this.migrationContext.RowsEstimate) + atomic.LoadInt64(&this.migrationContext.RowsDeltaEstimate) + 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_EXECUTING_HOST=%s", this.migrationContext.Hostname)) diff --git a/resources/hooks-sample/gh-ost-on-success-hook-2 b/resources/hooks-sample/gh-ost-on-success-hook-2 index 29cba49..66417e6 100755 --- a/resources/hooks-sample/gh-ost-on-success-hook-2 +++ b/resources/hooks-sample/gh-ost-on-success-hook-2 @@ -3,3 +3,4 @@ # Sample hook file for gh-ost-on-success echo "$(date) gh-ost-on-success $GH_OST_DATABASE_NAME.$GH_OST_TABLE_NAME -- this message should show on the gh-ost log" +echo "$(date) gh-ost-on-success copied $GH_OST_COPIED_ROWS rows in $GH_OST_ELAPSED_COPY_SECONDS seconds. Total runtime was $GH_OST_ELAPSED_SECONDS seconds"