Skip to content

Commit f1a76e6

Browse files
author
Shlomi Noach
authored
Merge pull request #415 from github/touch-postpone-flag-file
-postpone-cut-over-flag-file implies touching indicated file
2 parents bdd2897 + 4e6e454 commit f1a76e6

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

doc/command-line-flags.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ See also: [Sub-second replication lag throttling](subsecond-lag.md)
119119

120120
Typically `gh-ost` is used to migrate tables on a master. If you wish to only perform the migration in full on a replica, connect `gh-ost` to said replica and pass `--migrate-on-replica`. `gh-ost` will briefly connect to the master but other issue no changes on the master. Migration will be fully executed on the replica, while making sure to maintain a small replication lag.
121121

122+
### postpone-cut-over-flag-file
123+
124+
Indicate a file name, such that the final [cut-over](cut-over.md) step does not take place as long as the file exists.
125+
When this flag is set, `gh-ost` expects the file to exist on startup, or else tries to create it. `gh-ost` exits with error if the file does not exist and `gh-ost` is unable to create it.
126+
With this flag set, the migration will cut-over upon deletion of the file or upon `cut-over` [interactive command](interactive-commands.md).
127+
122128
### skip-foreign-key-checks
123129

124130
By default `gh-ost` verifies no foreign keys exist on the migrated table. On servers with large number of tables this check can take a long time. If you're absolutely certain no foreign keys exist (table does not referenece other table nor is referenced by other tables) and wish to save the check time, provide with `--skip-foreign-key-checks`.

go/base/utils.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ func FileExists(fileName string) bool {
3737
return false
3838
}
3939

40+
func TouchFile(fileName string) error {
41+
f, err := os.OpenFile(fileName, os.O_APPEND|os.O_CREATE, 0755)
42+
if err != nil {
43+
return (err)
44+
}
45+
defer f.Close()
46+
return nil
47+
}
48+
4049
// StringContainsAll returns true if `s` contains all non empty given `substrings`
4150
// The function returns `false` if no non-empty arguments are given.
4251
func StringContainsAll(s string, substrings ...string) bool {

go/logic/migrator.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,18 @@ func (this *Migrator) countTableRows() (err error) {
265265
return countRowsFunc()
266266
}
267267

268+
func (this *Migrator) createFlagFiles() (err error) {
269+
if this.migrationContext.PostponeCutOverFlagFile != "" {
270+
if !base.FileExists(this.migrationContext.PostponeCutOverFlagFile) {
271+
if err := base.TouchFile(this.migrationContext.PostponeCutOverFlagFile); err != nil {
272+
return log.Errorf("--postpone-cut-over-flag-file indicated by gh-ost is unable to create said file: %s", err.Error())
273+
}
274+
log.Infof("Created postpone-cut-over-flag-file: %s", this.migrationContext.PostponeCutOverFlagFile)
275+
}
276+
}
277+
return nil
278+
}
279+
268280
// Migrate executes the complete migration logic. This is *the* major gh-ost function.
269281
func (this *Migrator) Migrate() (err error) {
270282
log.Infof("Migrating %s.%s", sql.EscapeName(this.migrationContext.DatabaseName), sql.EscapeName(this.migrationContext.OriginalTableName))
@@ -296,6 +308,9 @@ func (this *Migrator) Migrate() (err error) {
296308
if err := this.initiateApplier(); err != nil {
297309
return err
298310
}
311+
if err := this.createFlagFiles(); err != nil {
312+
return err
313+
}
299314

300315
initialLag, _ := this.inspector.getReplicationLag()
301316
log.Infof("Waiting for ghost table to be migrated. Current lag is %+v", initialLag)

localtests/test.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ test_single() {
107107
--throttle-query='select timestampdiff(second, min(last_update), now()) < 5 from _gh_ost_test_ghc' \
108108
--serve-socket-file=/tmp/gh-ost.test.sock \
109109
--initially-drop-socket-file \
110-
--postpone-cut-over-flag-file=/tmp/gh-ost.test.postpone.flag \
111110
--test-on-replica \
112111
--default-retries=1 \
113112
--chunk-size=10 \

0 commit comments

Comments
 (0)