Skip to content

Commit aca288e

Browse files
author
Shlomi Noach
committed
-postpone-cut-over-flag-file implies touching indicated file
1 parent d016760 commit aca288e

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

go/base/utils.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ func FileExists(fileName string) bool {
3333
return false
3434
}
3535

36+
func TouchFile(fileName string) error {
37+
f, err := os.OpenFile(fileName, os.O_APPEND|os.O_CREATE, 0755)
38+
if err != nil {
39+
return (err)
40+
}
41+
defer f.Close()
42+
return nil
43+
}
44+
3645
// StringContainsAll returns true if `s` contains all non empty given `substrings`
3746
// The function returns `false` if no non-empty arguments are given.
3847
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
@@ -281,6 +281,18 @@ func (this *Migrator) countTableRows() (err error) {
281281
return countRowsFunc()
282282
}
283283

284+
func (this *Migrator) createFlagFiles() (err error) {
285+
if this.migrationContext.PostponeCutOverFlagFile != "" {
286+
if !base.FileExists(this.migrationContext.PostponeCutOverFlagFile) {
287+
if err := base.TouchFile(this.migrationContext.PostponeCutOverFlagFile); err != nil {
288+
return err
289+
}
290+
log.Infof("Created postpone-cut-over-flag-file: %s", this.migrationContext.PostponeCutOverFlagFile)
291+
}
292+
}
293+
return nil
294+
}
295+
284296
// Migrate executes the complete migration logic. This is *the* major gh-ost function.
285297
func (this *Migrator) Migrate() (err error) {
286298
log.Infof("Migrating %s.%s", sql.EscapeName(this.migrationContext.DatabaseName), sql.EscapeName(this.migrationContext.OriginalTableName))
@@ -312,6 +324,9 @@ func (this *Migrator) Migrate() (err error) {
312324
if err := this.initiateApplier(); err != nil {
313325
return err
314326
}
327+
if err := this.createFlagFiles(); err != nil {
328+
return err
329+
}
315330

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

0 commit comments

Comments
 (0)