Skip to content

Commit 9c0c993

Browse files
committed
Add GH_OST_INSTANT_DDL env var for hook
1 parent 8bc63f0 commit 9c0c993

3 files changed

Lines changed: 8 additions & 5 deletions

File tree

doc/hooks.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ The following variables are available on all hooks:
8181

8282
The following variable are available on particular hooks:
8383

84+
- `GH_OST_INSTANT_DDL` is only available in `gh-ost-on-success`. The value is true if instant DDL was successful.
8485
- `GH_OST_COMMAND` is only available in `gh-ost-on-interactive-command`
8586
- `GH_OST_STATUS` is only available in `gh-ost-on-status`
8687
- `GH_OST_LAST_BATCH_COPY_ERROR` is only available in `gh-ost-on-batch-copy-retry`

go/logic/hooks.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,9 @@ func (this *HooksExecutor) onInteractiveCommand(command string) error {
148148
return this.executeHooks(onInteractiveCommand, v)
149149
}
150150

151-
func (this *HooksExecutor) onSuccess() error {
152-
return this.executeHooks(onSuccess)
151+
func (this *HooksExecutor) onSuccess(instantDDL bool) error {
152+
v := fmt.Sprintf("GH_OST_INSTANT_DDL=%t", instantDDL)
153+
return this.executeHooks(onSuccess, v)
153154
}
154155

155156
func (this *HooksExecutor) onFailure() error {

go/logic/migrator.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,13 +478,14 @@ func (this *Migrator) Migrate() (err error) {
478478
if this.migrationContext.AttemptInstantDDL {
479479
if this.migrationContext.Noop {
480480
this.migrationContext.Log.Debugf("Noop operation; not really attempting instant DDL")
481+
return this.hooksExecutor.onSuccess(true)
481482
} else {
482483
this.migrationContext.Log.Infof("Attempting to execute alter with ALGORITHM=INSTANT")
483484
if err := this.applier.AttemptInstantDDL(); err == nil {
484485
if err := this.finalCleanup(); err != nil {
485486
return nil
486487
}
487-
if err := this.hooksExecutor.onSuccess(); err != nil {
488+
if err := this.hooksExecutor.onSuccess(true); err != nil {
488489
return err
489490
}
490491
this.migrationContext.Log.Infof("Success! table %s.%s migrated instantly", sql.EscapeName(this.migrationContext.DatabaseName), sql.EscapeName(this.migrationContext.OriginalTableName))
@@ -620,7 +621,7 @@ func (this *Migrator) Migrate() (err error) {
620621
if err := this.finalCleanup(); err != nil {
621622
return nil
622623
}
623-
if err := this.hooksExecutor.onSuccess(); err != nil {
624+
if err := this.hooksExecutor.onSuccess(false); err != nil {
624625
return err
625626
}
626627
this.migrationContext.Log.Infof("Done migrating %s.%s", sql.EscapeName(this.migrationContext.DatabaseName), sql.EscapeName(this.migrationContext.OriginalTableName))
@@ -734,7 +735,7 @@ func (this *Migrator) Revert() error {
734735
if err := this.finalCleanup(); err != nil {
735736
return nil
736737
}
737-
if err := this.hooksExecutor.onSuccess(); err != nil {
738+
if err := this.hooksExecutor.onSuccess(false); err != nil {
738739
return err
739740
}
740741
this.migrationContext.Log.Infof("Done reverting %s.%s", sql.EscapeName(this.migrationContext.DatabaseName), sql.EscapeName(this.migrationContext.OriginalTableName))

0 commit comments

Comments
 (0)