initial support for --resurrect flag

This commit is contained in:
Shlomi Noach 2016-12-20 22:33:44 +02:00
parent 4c6f42f2f1
commit c72851e1f6
3 changed files with 16 additions and 3 deletions

View File

@ -82,6 +82,7 @@ type MigrationContext struct {
SkipRenamedColumns bool
IsTungsten bool
DiscardForeignKeys bool
Resurrect bool
config ContextConfig
configMutex *sync.Mutex
@ -161,6 +162,7 @@ type MigrationContext struct {
UserCommandedUnpostponeFlag int64
CutOverCompleteFlag int64
InCutOverCriticalSectionFlag int64
IsResurrected bool
OriginalTableColumnsOnApplier *sql.ColumnList
OriginalTableColumns *sql.ColumnList

View File

@ -58,6 +58,7 @@ func main() {
flag.StringVar(&migrationContext.DatabaseName, "database", "", "database name (mandatory)")
flag.StringVar(&migrationContext.OriginalTableName, "table", "", "table name (mandatory)")
flag.StringVar(&migrationContext.AlterStatement, "alter", "", "alter statement (mandatory)")
flag.BoolVar(&migrationContext.CountTableRows, "exact-rowcount", false, "actually count table rows as opposed to estimate them (results in more accurate progress estimation)")
flag.BoolVar(&migrationContext.ConcurrentCountTableRows, "concurrent-rowcount", true, "(with --exact-rowcount), when true (default): count rows after row-copy begins, concurrently, and adjust row estimate later on; when false: first count rows, then start row copy")
flag.BoolVar(&migrationContext.AllowedRunningOnMaster, "allow-on-master", false, "allow this migration to run directly on master. Preferably it would run on a replica")
@ -68,6 +69,7 @@ func main() {
flag.BoolVar(&migrationContext.IsTungsten, "tungsten", false, "explicitly let gh-ost know that you are running on a tungsten-replication based topology (you are likely to also provide --assume-master-host)")
flag.BoolVar(&migrationContext.DiscardForeignKeys, "discard-foreign-keys", false, "DANGER! This flag will migrate a table that has foreign keys and will NOT create foreign keys on the ghost table, thus your altered table will have NO foreign keys. This is useful for intentional dropping of foreign keys")
flag.BoolVar(&migrationContext.SkipForeignKeyChecks, "skip-foreign-key-checks", false, "set to 'true' when you know for certain there are no foreign keys on your table, and wish to skip the time it takes for gh-ost to verify that")
flag.BoolVar(&migrationContext.Resurrect, "resurrect", false, "resume previously crashed migration")
executeFlag := flag.Bool("execute", false, "actually execute the alter & migrate the table. Default is noop: do some tests and exit")
flag.BoolVar(&migrationContext.TestOnReplica, "test-on-replica", false, "Have the migration run on a replica, not on the master. At the end of migration replication is stopped, and tables are swapped and immediately swap-revert. Replication remains stopped and you can compare the two tables for building trust")
@ -178,6 +180,12 @@ func main() {
if *cliMasterPassword != "" && migrationContext.AssumeMasterHostname == "" {
log.Fatalf("--master-password requires --assume-master-host")
}
if migrationContext.InitiallyDropGhostTable && migrationContext.Resurrect {
log.Fatalf("--initially-drop-ghost-table and --resurrect are mutually exclusive")
}
if migrationContext.InitiallyDropOldTable && migrationContext.Resurrect {
log.Fatalf("--initially-drop-old-table and --resurrect are mutually exclusive")
}
switch *cutOver {
case "atomic", "default", "":

View File

@ -1043,11 +1043,14 @@ func (this *Migrator) executeWriteFuncs() error {
case <-contextDumpTick:
{
this.migrationContext.SetStreamerBinlogCoordinates(this.eventsStreamer.GetCurrentBinlogCoordinates())
if !this.migrationContext.Resurrect || this.migrationContext.IsResurrected {
if jsonString, err := this.migrationContext.ToJSON(); err == nil {
this.applier.WriteChangelog("context", jsonString)
log.Debugf("Context dumped")
}
}
// If we're about to resurrect (resurrect requested) but haven't done so yet, do not wrtie resurrect info.
}
case applyEventFunc := <-this.applyEventsQueue:
{
if err := this.retryOperation(applyEventFunc); err != nil {