Skip to content

Add move-tables environment variables to hooks#1711

Merged
danieljoos merged 1 commit into
feature-move-tablesfrom
danieljoos-move-tables-hooks-env
Jun 16, 2026
Merged

Add move-tables environment variables to hooks#1711
danieljoos merged 1 commit into
feature-move-tablesfrom
danieljoos-move-tables-hooks-env

Conversation

@danieljoos

Copy link
Copy Markdown
Contributor

A Pull Request should be associated with an Issue.

We wish to have discussions in Issues. A single issue may be targeted by multiple PRs.
If you're offering a new feature or fixing anything, we'd like to know beforehand in Issues,
and potentially we'll be able to point development in a particular direction.

Related issue (internal): https://github.com/github/database-infrastructure/issues/8211
Related issue (public): #1681

Further notes in https://github.com/github/gh-ost/blob/master/.github/CONTRIBUTING.md
Thank you! We are open to PRs, but please understand if for technical reasons we are unable to accept each and any PR

Description

This PR exposes move-tables information as environment variables to the hooks scripts:

  • GH_OST_TARGET_HOST: the target host, meaning the primary hosts that is written to. For move tables, that will be the primary host of the other cluster.
  • GH_OST_MOVE_TABLES: holds "true" if gh-ost is operating in move-tables mode.
  • GH_OST_TARGET_DATABASE_NAME: the target database name, meaning the schema/database name on the target cluster.
  • GH_OST_TARGET_TABLE_NAME: similarly, the target table name, meaning the name of table written to.
  • GH_OST_DRAIN_GTID: for the on-success hook in move-tables mode, this environment variable holds the last GTID written to the old table, before it was renamed.

In case this PR introduced Go code changes:

  • contributed code is using same conventions as original code
  • script/cibuild returns with no formatting errors, build errors or unit test errors.

Copilot AI review requested due to automatic review settings June 15, 2026 14:47
@danieljoos danieljoos requested a review from meiji163 as a code owner June 15, 2026 14:47
@danieljoos danieljoos added the feature-move-tables PRs that are associated with the new move-tables feature label Jun 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends gh-ost’s hook execution contract to better support move-tables mode by exporting additional move-tables context as environment variables and by passing a “drain GTID” marker to the on-success hook.

Changes:

  • Add move-tables-related environment variables for hook scripts (target host/db/table + move-tables mode flag).
  • Add a move-tables-specific on-success hook path that passes GH_OST_DRAIN_GTID.
  • Add MigrationContext.GetTargetHostname() to consistently surface the “target” host across modes.
Show a summary per file
File Description
go/logic/migrator.go Switch move-tables cutover to invoke move-tables-specific on-success hook method with drain GTID.
go/logic/hooks.go Add new composite + executor hook method; extend hook env var set for move-tables context.
go/logic/hooks_test.go Add tests validating new env vars and drain GTID behavior.
go/base/hooks.go Extend exported base.Hooks interface with move-tables on-success callback.
go/base/context.go Add GetTargetHostname() helper for safe target host retrieval.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 5/5 changed files
  • Comments generated: 4

Comment thread go/base/hooks.go
Comment thread go/logic/hooks.go Outdated
Comment thread go/base/context.go
Comment thread go/logic/hooks.go
Comment thread go/base/hooks.go Outdated
OnBeforeCutOver() error
OnInteractiveCommand(command string) error
OnSuccess(instantDDL bool) error
OnSuccessMoveTables(drainGTID string) error

@zacharysierakowski zacharysierakowski Jun 15, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs:

Don't introduce new hook types. The existing on-row-copy-complete, on-before-cut-over, and on-success hooks fire at exactly the protocol boundaries needed (P2, T0, T5).

Should we be using OnSuccess instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah. probably best not to introduce a new interface method here.
It does call the on-success hook though. just with different env variables.
I'll work on it tomorrow

@danieljoos danieljoos force-pushed the danieljoos-move-tables-hooks-env branch from 7ebd36b to 1533e8a Compare June 16, 2026 09:12
@danieljoos danieljoos requested a review from Copilot June 16, 2026 09:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

  • Files reviewed: 5/5 changed files
  • Comments generated: 4

Comment thread go/logic/hooks.go Outdated
Comment thread go/base/context.go Outdated
Comment thread doc/hooks.md Outdated
Comment thread go/logic/migrator.go
@danieljoos danieljoos force-pushed the danieljoos-move-tables-hooks-env branch from 1533e8a to b60e605 Compare June 16, 2026 09:35
@danieljoos danieljoos merged commit 755ac75 into feature-move-tables Jun 16, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature-move-tables PRs that are associated with the new move-tables feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants