Skip to content

Commit

Permalink
brie: add integration test for br (pingcap#18797)
Browse files Browse the repository at this point in the history
  • Loading branch information
3pointer committed Jul 28, 2020
1 parent f29d4ce commit 06ba57d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 9 deletions.
7 changes: 0 additions & 7 deletions executor/brie.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"sync/atomic"
"time"

"github.com/pingcap/br/pkg/backup"
"github.com/pingcap/br/pkg/glue"
"github.com/pingcap/br/pkg/storage"
"github.com/pingcap/br/pkg/task"
Expand Down Expand Up @@ -250,8 +249,6 @@ func (b *executorBuilder) buildBRIE(s *ast.BRIEStmt, schema *expression.Schema)
switch s.Kind {
case ast.BRIEKindBackup:
e.backupCfg = &task.BackupConfig{Config: cfg}
// TODO adapt new backup config in br.
e.backupCfg.GCTTL = backup.DefaultBRGCSafePointTTL

for _, opt := range s.Options {
switch opt.Tp {
Expand Down Expand Up @@ -280,10 +277,6 @@ func (b *executorBuilder) buildBRIE(s *ast.BRIEStmt, schema *expression.Schema)

case ast.BRIEKindRestore:
e.restoreCfg = &task.RestoreConfig{Config: cfg}
// TODO adapt new restore config in br. now give these with default value
e.restoreCfg.SwitchModeInterval = backup.DefaultBRGCSafePointTTL
e.restoreCfg.CheckRequirements = false
e.restoreCfg.RemoveTiFlash = true
for _, opt := range s.Options {
switch opt.Tp {
case ast.BRIEOptionOnline:
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ require (
github.com/gorilla/mux v1.7.3
github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4
github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334
github.com/klauspost/cpuid v1.2.0
github.com/klauspost/cpuid v1.2.1
github.com/ngaut/pools v0.0.0-20180318154953-b7bc8c42aac7
github.com/ngaut/sync2 v0.0.0-20141008032647-7a24ed77b2ef
github.com/opentracing/basictracer-go v1.0.0
github.com/opentracing/opentracing-go v1.1.0
github.com/pingcap/br v0.0.0-20200716021245-f1df51c11469
github.com/pingcap/br v0.0.0-20200727110227-c6c8b7734bfa
github.com/pingcap/check v0.0.0-20200212061837-5e12011dc712
github.com/pingcap/errors v0.11.5-0.20190809092503-95897b64e011
github.com/pingcap/failpoint v0.0.0-20200603062251-b230c36c413c
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o
github.com/klauspost/cpuid v0.0.0-20170728055534-ae7887de9fa5/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/klauspost/cpuid v1.2.0 h1:NMpwD2G9JSFOE1/TJjGSo5zG7Yb2bTe7eq1jH+irmeE=
github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/klauspost/cpuid v1.2.1 h1:vJi+O/nMdFt0vqm8NZBI6wzALWdA2X+egi0ogNyrC/w=
github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
Expand Down Expand Up @@ -379,6 +381,8 @@ github.com/pingcap/br v0.0.0-20200623060633-439a1c2b2bfd h1:vEoTsslkTbSiMMAY8XHs
github.com/pingcap/br v0.0.0-20200623060633-439a1c2b2bfd/go.mod h1:NGee2H9vXLunFIBXGb3uFsWRpw3BBo822sY4dyXepqo=
github.com/pingcap/br v0.0.0-20200716021245-f1df51c11469 h1:sp6f6H8j9Iqt1rVzA1XOs4oCEumb9S3lL3L5UqLpKWo=
github.com/pingcap/br v0.0.0-20200716021245-f1df51c11469/go.mod h1:Ft2Vuvj6XJkbjQvflDOesJTy+9bui0saz0UonIgipAw=
github.com/pingcap/br v0.0.0-20200727110227-c6c8b7734bfa h1:hCJf4QukVo9KYJJU084pF136m6QT4QuTSjnIhmNdsCE=
github.com/pingcap/br v0.0.0-20200727110227-c6c8b7734bfa/go.mod h1:JVsPK6Ibo2RBkTC2l1bzcRBVuHte/tJRERgay5gsBb8=
github.com/pingcap/check v0.0.0-20190102082844-67f458068fc8/go.mod h1:B1+S9LNcuMyLH/4HMTViQOJevkGiik3wW2AN9zb2fNQ=
github.com/pingcap/check v0.0.0-20191107115940-caf2b9e6ccf4/go.mod h1:PYMCGwN0JHjoqGr3HrZoD+b8Tgx8bKnArhSq8YVzUMc=
github.com/pingcap/check v0.0.0-20191216031241-8a5a85928f12/go.mod h1:PYMCGwN0JHjoqGr3HrZoD+b8Tgx8bKnArhSq8YVzUMc=
Expand Down Expand Up @@ -429,6 +433,7 @@ github.com/pingcap/tidb v1.1.0-beta.0.20200424154252-5ede18f10eed/go.mod h1:m2VD
github.com/pingcap/tidb v1.1.0-beta.0.20200509133407-a9dc72cf2558/go.mod h1:cXNbVSQAkwwmjFQmEnEPI00Z2/Y/KOhouttUPERiInE=
github.com/pingcap/tidb v1.1.0-beta.0.20200606093724-b5b4da0e6a90/go.mod h1:aaBBi3OJmYjENWY31YYOY8K6UoZZYgjZVZH56D0QIdE=
github.com/pingcap/tidb v1.1.0-beta.0.20200715100003-b4da443a3c4c/go.mod h1:TplKBs1sevRvK11aT7ro0ntTCalyh1fMaWACp03dQf4=
github.com/pingcap/tidb v1.1.0-beta.0.20200716023258-b10faca6ff89/go.mod h1:hDlQ5BJ4rLLCOUlvXqW3skyYEjyymzeTA3eXpNEDx38=
github.com/pingcap/tidb-tools v4.0.0-beta.1.0.20200306084441-875bd09aa3d5+incompatible/go.mod h1:XGdcy9+yqlDSEMTpOXnwf3hiTeqrV6MN/u1se9N8yIM=
github.com/pingcap/tidb-tools v4.0.0-rc.1.0.20200421113014-507d2bb3a15e+incompatible/go.mod h1:XGdcy9+yqlDSEMTpOXnwf3hiTeqrV6MN/u1se9N8yIM=
github.com/pingcap/tidb-tools v4.0.0-rc.1.0.20200514040632-f76b3e428e19+incompatible h1:/JKsYjsa5Ug8v5CN4zIbJGIqsvgBUkGwaP/rEScVvWM=
Expand Down
40 changes: 40 additions & 0 deletions session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"context"
"flag"
"fmt"
"os"
"path"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -69,6 +71,7 @@ var _ = Suite(&testSchemaSuite{})
var _ = Suite(&testIsolationSuite{})
var _ = SerialSuites(&testSchemaSerialSuite{})
var _ = SerialSuites(&testSessionSerialSuite{})
var _ = SerialSuites(&testBackupRestoreSuite{})

type testSessionSuiteBase struct {
cluster *mocktikv.Cluster
Expand All @@ -94,6 +97,10 @@ type testSessionSerialSuite struct {
testSessionSuiteBase
}

type testBackupRestoreSuite struct {
testSessionSuiteBase
}

func clearStorage(store kv.Storage) error {
txn, err := store.Begin()
if err != nil {
Expand Down Expand Up @@ -3214,3 +3221,36 @@ func (s *testSessionSuite2) TestPerStmtTaskID(c *C) {

c.Assert(taskID1 != taskID2, IsTrue)
}

func (s *testBackupRestoreSuite) TestBackupAndRestore(c *C) {
// only run BR SQL integration test with tikv store.
if *withTiKV {
cfg := config.GetGlobalConfig()
cfg.Store = "tikv"
cfg.Path = s.pdAddr
config.StoreGlobalConfig(cfg)
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("create database if not exists br")
tk.MustExec("use br")
tk.MustExec("create table t1(v int)")
tk.MustExec("insert into t1 values (1)")
tk.MustExec("insert into t1 values (2)")
tk.MustExec("insert into t1 values (3)")

tk.MustQuery("select count(*) from t1").Check(testkit.Rows("3"))

tmpDir := path.Join(os.TempDir(), "bk1")
os.RemoveAll(tmpDir)
// backup database to tmp dir
tk.MustQuery("backup database br to 'local://" + tmpDir + "'")

// remove database for recovery
tk.MustExec("drop database br")

// restore database with backup data
tk.MustQuery("restore database br from 'local://" + tmpDir + "'")
tk.MustExec("use br")
tk.MustQuery("select count(*) from t1").Check(testkit.Rows("3"))
tk.MustExec("drop database br")
}
}

0 comments on commit 06ba57d

Please sign in to comment.