doc/hooks.md
gh-ost supports hooks: external processes which gh-ost executes at particular points of interest.
Use cases include:
gh-ost postpones cut-over (at your demand), thus ready to complete (at your leisure)--test-on-replica, but who cannot have gh-ost issue a STOP SLAVE, would use a hook to command RDS to stop replicationgh-ost defines certain points of interest (event types), and executes hooks at those points.
Notes:
gh-ost will invoke relevant hooks sequentially and synchronously
gh-ost. Thus, you are able to force gh-ost to fail migration on your conditions.
All hooks are expected to reside in a single directory. This directory is indicated by --hooks-path. When not provided, no hooks are executed.
gh-ost will dynamically search for hooks in said directory. You may add and remove hooks to/from this directory as gh-ost makes progress (though likely you don't want to). Hook files are expected to be executable processes.
In an effort to simplify code and to standardize usage, gh-ost expects hooks in explicit naming conventions. As an example, the onStartup hook expects processes named gh-ost-on-startup*. It will match and accept files named:
gh-ost-on-startupgh-ost-on-startup--send-notification-mailgh-ost-on-startup12345The full list of supported hooks is best found in code: hooks.go. Documentation will always be a bit behind. At this time, though, the following are recognized:
gh-ost-on-startupgh-ost-on-validatedgh-ost-on-rowcount-completegh-ost-on-before-row-copygh-ost-on-statusgh-ost-on-interactive-commandgh-ost-on-row-copy-completegh-ost-on-stop-replicationgh-ost-on-start-replicationgh-ost-on-begin-postponedgh-ost-on-before-cut-overgh-ost-on-successgh-ost-on-failuregh-ost-on-batch-copy-retrygh-ost will set environment variables per hook invocation. Hooks are then able to read those variables, indicating schema name, table name, alter statement, migrated host name etc. Some variables are available on all hooks, and some are available on relevant hooks.
The following variables are available on all hooks:
GH_OST_DATABASE_NAMEGH_OST_TABLE_NAMEGH_OST_GHOST_TABLE_NAMEGH_OST_OLD_TABLE_NAME - the name the original table will be renamed to at the end of operationGH_OST_DDLGH_OST_ELAPSED_SECONDS - total runtimeGH_OST_ELAPSED_COPY_SECONDS - row-copy time (excluding startup, row-count and postpone time)GH_OST_ESTIMATED_ROWS - estimated total rows in tableGH_OST_COPIED_ROWS - number of rows copied by gh-ostGH_OST_INSPECTED_LAG - lag in seconds (floating point) of inspected serverGH_OST_HEARTBEAT_LAG - lag in seconds (floating point) of heartbeatGH_OST_PROGRESS - progress pct ([0..100], floating point) of migrationGH_OST_ETA_SECONDS - estimated duration until migration finishes in secondsGH_OST_MIGRATED_HOSTGH_OST_INSPECTED_HOSTGH_OST_EXECUTING_HOSTGH_OST_HOOKS_HINT - copy of --hooks-hint valueGH_OST_HOOKS_HINT_OWNER - copy of --hooks-hint-owner valueGH_OST_HOOKS_HINT_TOKEN - copy of --hooks-hint-token valueGH_OST_DRY_RUN - whether or not the gh-ost run is a dry runGH_OST_REVERT - whether or not gh-ost is running in revert modeThe following variable are available on particular hooks:
GH_OST_INSTANT_DDL is only available in gh-ost-on-success. The value is true if instant DDL was successful, and false if it was not.GH_OST_COMMAND is only available in gh-ost-on-interactive-commandGH_OST_STATUS is only available in gh-ost-on-statusGH_OST_LAST_BATCH_COPY_ERROR is only available in gh-ost-on-batch-copy-retrySee sample hooks, as bash implementation samples.