Created
July 23, 2018 19:22
-
-
Save shuhaowu/5c48465040bda9d4143363f06c600c59 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"sync" | |
"github.com/Shopify/ghostferry" | |
"github.com/Shopify/ghostferry/copydb" | |
"github.com/sirupsen/logrus" | |
) | |
func main() { | |
var err error | |
logrus.SetLevel(logrus.DebugLevel) | |
ferry := &ghostferry.Ferry{ | |
Config: &ghostferry.Config{ | |
Source: ghostferry.DatabaseConfig{ | |
Host: "localhost", | |
Port: uint16(29291), | |
User: "root", | |
Pass: "", | |
}, | |
Target: ghostferry.DatabaseConfig{ | |
Host: "localhost", | |
Port: uint16(29292), | |
User: "root", | |
Pass: "", | |
}, | |
TableFilter: ©db.StaticTableFilter{ | |
Dbs: []string{"abc"}, | |
Tables: []string{}, | |
TablesIsBlacklist: true, | |
}, | |
AutomaticCutover: true, | |
}, | |
} | |
err = ferry.ValidateConfig() | |
if err != nil { | |
panic(err) | |
} | |
err = ferry.Initialize() | |
if err != nil { | |
panic(err) | |
} | |
err = ferry.Start() | |
if err != nil { | |
panic(err) | |
} | |
wg := &sync.WaitGroup{} | |
wg.Add(1) | |
go func() { | |
defer wg.Done() | |
ferry.Run() | |
}() | |
ferry.WaitUntilRowCopyIsComplete() | |
logrus.Warn("setting source read_only = 1") | |
_, err = ferry.SourceDB.Exec("FLUSH TABLES WITH READ LOCK; SET GLOBAL read_only = 1;") | |
if err != nil { | |
panic(err) | |
} | |
ferry.FlushBinlogAndStopStreaming() | |
wg.Wait() | |
logrus.Warn("setting source read_only = 0") | |
_, err = ferry.SourceDB.Exec("SET GLOBAL read_only = 0") | |
if err != nil { | |
panic(err) | |
} | |
verifier := &ghostferry.ChecksumTableVerifier{ | |
Tables: ferry.Tables.AsSlice(), | |
SourceDB: ferry.SourceDB, | |
TargetDB: ferry.TargetDB, | |
} | |
result, err := verifier.Verify() | |
if err != nil { | |
panic(err) | |
} | |
logrus.Infof("Verification match: %v, Message: %s", result.DataCorrect, result.Message) | |
logrus.Info("completed ghostferry run") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment