MCPcopy
hub / github.com/github/gh-ost / cutOverTwoStep

Method cutOverTwoStep

go/logic/migrator.go:956–985  ·  view source on GitHub ↗

cutOverTwoStep will lock down the original table, execute what's left of last DML entries, and **non-atomically** swap original->old, then new->original. There is a point in time where the "original" table does not exist and queries are non-blocked and failing.

()

Source from the content-addressed store, hash-verified

954// There is a point in time where the "original" table does not exist and queries are non-blocked
955// and failing.
956func (mgtr *Migrator) cutOverTwoStep() (err error) {
957 atomic.StoreInt64(&mgtr.migrationContext.InCutOverCriticalSectionFlag, 1)
958 defer atomic.StoreInt64(&mgtr.migrationContext.InCutOverCriticalSectionFlag, 0)
959 atomic.StoreInt64(&mgtr.migrationContext.AllEventsUpToLockProcessedInjectedFlag, 0)
960
961 if err := mgtr.retryOperation(mgtr.applier.LockOriginalTable); err != nil {
962 return err
963 }
964
965 if err := mgtr.retryOperation(mgtr.waitForEventsUpToLock); err != nil {
966 return err
967 }
968 // If we need to create triggers we need to do it here (only create part)
969 if mgtr.migrationContext.IncludeTriggers && len(mgtr.migrationContext.Triggers) > 0 {
970 if err := mgtr.retryOperation(mgtr.applier.CreateTriggersOnGhost); err != nil {
971 return err
972 }
973 }
974 if err := mgtr.retryOperation(mgtr.applier.SwapTablesQuickAndBumpy); err != nil {
975 return err
976 }
977 if err := mgtr.retryOperation(mgtr.applier.UnlockTables); err != nil {
978 return err
979 }
980
981 lockAndRenameDuration := mgtr.migrationContext.RenameTablesEndTime.Sub(mgtr.migrationContext.LockTablesStartTime)
982 renameDuration := mgtr.migrationContext.RenameTablesEndTime.Sub(mgtr.migrationContext.RenameTablesStartTime)
983 mgtr.migrationContext.Log.Debugf("Lock & rename duration: %s (rename only: %s). During mgtr time, queries on %s were locked or failing", lockAndRenameDuration, renameDuration, sql.EscapeName(mgtr.migrationContext.OriginalTableName))
984 return nil
985}
986
987// atomicCutOver
988func (mgtr *Migrator) atomicCutOver() (err error) {

Callers 1

cutOverMethod · 0.95

Calls 3

retryOperationMethod · 0.95
EscapeNameFunction · 0.92
DebugfMethod · 0.65

Tested by

no test coverage detected