exporting to changelog table, not to file
This commit is contained in:
parent
75b6f9edf2
commit
6999b4e8bf
@ -8,7 +8,6 @@ package base
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
@ -221,14 +220,8 @@ func GetMigrationContext() *MigrationContext {
|
|||||||
return context
|
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
|
// 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 {
|
if this.MigrationRangeMinValues != nil {
|
||||||
this.EncodedRangeValues["MigrationRangeMinValues"], _ = this.MigrationRangeMinValues.ToBase64()
|
this.EncodedRangeValues["MigrationRangeMinValues"], _ = this.MigrationRangeMinValues.ToBase64()
|
||||||
}
|
}
|
||||||
@ -243,12 +236,9 @@ func (this *MigrationContext) DumpJSON() (fileName string, err error) {
|
|||||||
}
|
}
|
||||||
jsonBytes, err := json.Marshal(this)
|
jsonBytes, err := json.Marshal(this)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fileName, err
|
return "", err
|
||||||
}
|
}
|
||||||
fileName = fmt.Sprintf("%s/gh-ost.%s.%d.context.json", "/tmp", this.OriginalTableName, this.ElapsedTime())
|
return string(jsonBytes), nil
|
||||||
err = ioutil.WriteFile(fileName, jsonBytes, 0644)
|
|
||||||
|
|
||||||
return fileName, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetGhostTableName generates the name of ghost table, based on original table name
|
// GetGhostTableName generates the name of ghost table, based on original table name
|
||||||
|
@ -195,7 +195,7 @@ func (this *Applier) CreateChangelogTable() error {
|
|||||||
id bigint auto_increment,
|
id bigint auto_increment,
|
||||||
last_update timestamp not null DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
last_update timestamp not null DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
hint varchar(64) charset ascii not null,
|
hint varchar(64) charset ascii not null,
|
||||||
value varchar(255) charset ascii not null,
|
value text charset ascii not null,
|
||||||
primary key(id),
|
primary key(id),
|
||||||
unique key hint_uidx(hint)
|
unique key hint_uidx(hint)
|
||||||
) auto_increment=256
|
) auto_increment=256
|
||||||
@ -220,7 +220,7 @@ func (this *Applier) dropTable(tableName string) error {
|
|||||||
sql.EscapeName(this.migrationContext.DatabaseName),
|
sql.EscapeName(this.migrationContext.DatabaseName),
|
||||||
sql.EscapeName(tableName),
|
sql.EscapeName(tableName),
|
||||||
)
|
)
|
||||||
log.Infof("Droppping table %s.%s",
|
log.Infof("Dropping table %s.%s",
|
||||||
sql.EscapeName(this.migrationContext.DatabaseName),
|
sql.EscapeName(this.migrationContext.DatabaseName),
|
||||||
sql.EscapeName(tableName),
|
sql.EscapeName(tableName),
|
||||||
)
|
)
|
||||||
@ -257,6 +257,8 @@ func (this *Applier) WriteChangelog(hint, value string) (string, error) {
|
|||||||
explicitId = 2
|
explicitId = 2
|
||||||
case "throttle":
|
case "throttle":
|
||||||
explicitId = 3
|
explicitId = 3
|
||||||
|
case "context":
|
||||||
|
explicitId = 4
|
||||||
}
|
}
|
||||||
query := fmt.Sprintf(`
|
query := fmt.Sprintf(`
|
||||||
insert /* gh-ost */ into %s.%s
|
insert /* gh-ost */ into %s.%s
|
||||||
|
@ -128,13 +128,8 @@ func (this *Migrator) initiateContextDump() (err error) {
|
|||||||
go func() {
|
go func() {
|
||||||
contextDumpTick := time.Tick(contextDumpInterval)
|
contextDumpTick := time.Tick(contextDumpInterval)
|
||||||
for range contextDumpTick {
|
for range contextDumpTick {
|
||||||
if dumpFile, err := this.migrationContext.DumpJSON(); err == nil {
|
if jsonString, err := this.migrationContext.ToJSON(); err == nil {
|
||||||
this.contextDumpFiles = append(this.contextDumpFiles, dumpFile)
|
this.applier.WriteChangelog("context", jsonString)
|
||||||
if len(this.contextDumpFiles) > 2 {
|
|
||||||
oldDumpFile := this.contextDumpFiles[0]
|
|
||||||
this.contextDumpFiles = this.contextDumpFiles[1:]
|
|
||||||
os.Remove(oldDumpFile)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
Loading…
Reference in New Issue
Block a user