Skip to content

Commit 0f2a43d

Browse files
author
Shlomi Noach
authored
Merge pull request #222 from github/hooks-more-info
Hooks: more environment variables
2 parents 75d2253 + 4331593 commit 0f2a43d

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
#
44

5-
RELEASE_VERSION="1.0.16"
5+
RELEASE_VERSION="1.0.17"
66

77
function build {
88
osname=$1

doc/hooks.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,16 @@ The following variables are available on all hooks:
5858
- `GH_OST_DATABASE_NAME`
5959
- `GH_OST_TABLE_NAME`
6060
- `GH_OST_GHOST_TABLE_NAME`
61-
- `GH_OST_OLD_TABLE_NAME`
61+
- `GH_OST_OLD_TABLE_NAME` - the name the original table will be renamed to at the end of operation
6262
- `GH_OST_DDL`
63-
- `GH_OST_ELAPSED_SECONDS`
63+
- `GH_OST_ELAPSED_SECONDS` - total runtime
64+
- `GH_OST_ELAPSED_COPY_SECONDS` - row-copy time (excluding startup, row-count and postpone time)
65+
- `GH_OST_ESTIMATED_ROWS` - estimated total rows in table
66+
- `GH_OST_COPIED_ROWS` - number of rows copied by `gh-ost`
6467
- `GH_OST_MIGRATED_HOST`
6568
- `GH_OST_INSPECTED_HOST`
6669
- `GH_OST_EXECUTING_HOST`
67-
- `GH_OST_HOOKS_HINT`
70+
- `GH_OST_HOOKS_HINT` - copy of `--hooks-hint` value
6871

6972
The following variable are available on particular hooks:
7073

go/logic/hooks.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"os"
1212
"os/exec"
1313
"path/filepath"
14+
"sync/atomic"
1415

1516
"github.com/github/gh-ost/go/base"
1617
"github.com/outbrain/golib/log"
@@ -53,6 +54,11 @@ func (this *HooksExecutor) applyEnvironmentVairables(extraVariables ...string) [
5354
env = append(env, fmt.Sprintf("GH_OST_OLD_TABLE_NAME=%s", this.migrationContext.GetOldTableName()))
5455
env = append(env, fmt.Sprintf("GH_OST_DDL=%s", this.migrationContext.AlterStatement))
5556
env = append(env, fmt.Sprintf("GH_OST_ELAPSED_SECONDS=%f", this.migrationContext.ElapsedTime().Seconds()))
57+
env = append(env, fmt.Sprintf("GH_OST_ELAPSED_COPY_SECONDS=%f", this.migrationContext.ElapsedRowCopyTime().Seconds()))
58+
estimatedRows := atomic.LoadInt64(&this.migrationContext.RowsEstimate) + atomic.LoadInt64(&this.migrationContext.RowsDeltaEstimate)
59+
env = append(env, fmt.Sprintf("GH_OST_ESTIMATED_ROWS=%d", estimatedRows))
60+
totalRowsCopied := this.migrationContext.GetTotalRowsCopied()
61+
env = append(env, fmt.Sprintf("GH_OST_COPIED_ROWS=%d", totalRowsCopied))
5662
env = append(env, fmt.Sprintf("GH_OST_MIGRATED_HOST=%s", this.migrationContext.ApplierConnectionConfig.ImpliedKey.Hostname))
5763
env = append(env, fmt.Sprintf("GH_OST_INSPECTED_HOST=%s", this.migrationContext.InspectorConnectionConfig.ImpliedKey.Hostname))
5864
env = append(env, fmt.Sprintf("GH_OST_EXECUTING_HOST=%s", this.migrationContext.Hostname))

resources/hooks-sample/gh-ost-on-success-hook-2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
# Sample hook file for gh-ost-on-success
44

55
echo "$(date) gh-ost-on-success $GH_OST_DATABASE_NAME.$GH_OST_TABLE_NAME -- this message should show on the gh-ost log"
6+
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"

0 commit comments

Comments
 (0)