From 171cad2a98a909541da04112d1278194a9ff94be Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Wed, 21 Dec 2016 09:23:00 +0200 Subject: [PATCH] sanity checks for resurrection --- go/cmd/gh-ost/main.go | 10 ++++++---- go/logic/applier.go | 13 +++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/go/cmd/gh-ost/main.go b/go/cmd/gh-ost/main.go index c9109c7..b498e90 100644 --- a/go/cmd/gh-ost/main.go +++ b/go/cmd/gh-ost/main.go @@ -180,11 +180,13 @@ 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.Resurrect && migrationContext.InitiallyDropGhostTable { + migrationContext.InitiallyDropGhostTable = false + log.Warningf("--resurrect given, implicitly disabling --initially-drop-ghost-table") } - if migrationContext.InitiallyDropOldTable && migrationContext.Resurrect { - log.Fatalf("--initially-drop-old-table and --resurrect are mutually exclusive") + if migrationContext.Resurrect && migrationContext.InitiallyDropOldTable { + migrationContext.InitiallyDropOldTable = false + log.Warningf("--resurrect given, implicitly disabling --initially-drop-old-table") } switch *cutOver { diff --git a/go/logic/applier.go b/go/logic/applier.go index 3dfce2b..0d322f6 100644 --- a/go/logic/applier.go +++ b/go/logic/applier.go @@ -128,6 +128,19 @@ func (this *Applier) tableExists(tableName string) (tableFound bool) { // ValidateOrDropExistingTables verifies ghost and changelog tables do not exist, // or attempts to drop them if instructed to. func (this *Applier) ValidateOrDropExistingTables() error { + if this.migrationContext.Resurrect { + ghostTableExists := this.tableExists(this.migrationContext.GetGhostTableName()) + if !ghostTableExists { + return fmt.Errorf("--ressurect requested, but ghost table %s doesn't exist. Panicking.", this.migrationContext.GetGhostTableName()) + } + changelogTableExists := this.tableExists(this.migrationContext.GetChangelogTableName()) + if !changelogTableExists { + return fmt.Errorf("--ressurect requested, but changelog table %s doesn't exist. Panicking.", this.migrationContext.GetChangelogTableName()) + } + return nil + } + // Normal mode (no resurrection) + if this.migrationContext.InitiallyDropGhostTable { if err := this.DropGhostTable(); err != nil { return err