diff --git a/go/base/context.go b/go/base/context.go index 2d9eaf7..9463266 100644 --- a/go/base/context.go +++ b/go/base/context.go @@ -8,7 +8,6 @@ package base import ( "encoding/json" "fmt" - "io/ioutil" "os" "regexp" "strings" @@ -221,14 +220,8 @@ func GetMigrationContext() *MigrationContext { return context } -// ToJSON exports this config to JSON string -func (this *MigrationContext) ToJSON() (string, error) { - b, err := json.Marshal(this) - return string(b), err -} - // DumpJSON exports this config to JSON string and writes it to file -func (this *MigrationContext) DumpJSON() (fileName string, err error) { +func (this *MigrationContext) ToJSON() (string, error) { if this.MigrationRangeMinValues != nil { this.EncodedRangeValues["MigrationRangeMinValues"], _ = this.MigrationRangeMinValues.ToBase64() } @@ -243,12 +236,9 @@ func (this *MigrationContext) DumpJSON() (fileName string, err error) { } jsonBytes, err := json.Marshal(this) if err != nil { - return fileName, err + return "", err } - fileName = fmt.Sprintf("%s/gh-ost.%s.%d.context.json", "/tmp", this.OriginalTableName, this.ElapsedTime()) - err = ioutil.WriteFile(fileName, jsonBytes, 0644) - - return fileName, err + return string(jsonBytes), nil } // GetGhostTableName generates the name of ghost table, based on original table name diff --git a/go/logic/applier.go b/go/logic/applier.go index afff578..3dfce2b 100644 --- a/go/logic/applier.go +++ b/go/logic/applier.go @@ -195,7 +195,7 @@ func (this *Applier) CreateChangelogTable() error { id bigint auto_increment, last_update timestamp not null DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, hint varchar(64) charset ascii not null, - value varchar(255) charset ascii not null, + value text charset ascii not null, primary key(id), unique key hint_uidx(hint) ) auto_increment=256 @@ -220,7 +220,7 @@ func (this *Applier) dropTable(tableName string) error { sql.EscapeName(this.migrationContext.DatabaseName), sql.EscapeName(tableName), ) - log.Infof("Droppping table %s.%s", + log.Infof("Dropping table %s.%s", sql.EscapeName(this.migrationContext.DatabaseName), sql.EscapeName(tableName), ) @@ -257,6 +257,8 @@ func (this *Applier) WriteChangelog(hint, value string) (string, error) { explicitId = 2 case "throttle": explicitId = 3 + case "context": + explicitId = 4 } query := fmt.Sprintf(` insert /* gh-ost */ into %s.%s diff --git a/go/logic/migrator.go b/go/logic/migrator.go index 7c55b80..0828199 100644 --- a/go/logic/migrator.go +++ b/go/logic/migrator.go @@ -128,13 +128,8 @@ func (this *Migrator) initiateContextDump() (err error) { go func() { contextDumpTick := time.Tick(contextDumpInterval) for range contextDumpTick { - if dumpFile, err := this.migrationContext.DumpJSON(); err == nil { - this.contextDumpFiles = append(this.contextDumpFiles, dumpFile) - if len(this.contextDumpFiles) > 2 { - oldDumpFile := this.contextDumpFiles[0] - this.contextDumpFiles = this.contextDumpFiles[1:] - os.Remove(oldDumpFile) - } + if jsonString, err := this.migrationContext.ToJSON(); err == nil { + this.applier.WriteChangelog("context", jsonString) } } }()