Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

brie: add integration test for br #18797

Merged
merged 7 commits into from
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
github.com/opentracing/basictracer-go v1.0.0
github.com/opentracing/opentracing-go v1.1.0
github.com/pingcap/badger v1.5.1-0.20200604041313-19c397305fcc
github.com/pingcap/br v0.0.0-20200723130425-d904ae3349a1
github.com/pingcap/br v0.0.0-20200727092753-a475692725db
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
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,8 @@ github.com/pingcap/br v0.0.0-20200521085655-53201addd4ad/go.mod h1:SlSUHWY7QUooo
github.com/pingcap/br v0.0.0-20200610051721-b057d65ff579/go.mod h1:Gq6o66nDReG0fMxqSdl8JHLZhMnxKhVxtHxqubUWAyg=
github.com/pingcap/br v0.0.0-20200617120402-56e151ad8b67 h1:8yXYPX4gQ5WVz67dL3SiAEbF8CQyi0CBhT1rnuTksx8=
github.com/pingcap/br v0.0.0-20200617120402-56e151ad8b67/go.mod h1:/3QzpDG7YTPrDsrg8i1lwdYUrplJ0jVD+9pxhh19+k4=
github.com/pingcap/br v0.0.0-20200723130425-d904ae3349a1 h1:DMUbZLROeb3U29lzE1yQJ/iWX9sXIK8l/7yqRimEU7I=
github.com/pingcap/br v0.0.0-20200723130425-d904ae3349a1/go.mod h1:4iTqZAMbEPmjBggYixqIg2FwIHBQtyImTM/QYlpTBGk=
github.com/pingcap/br v0.0.0-20200727092753-a475692725db h1:LoS2dSe764tdHEnspPGpeMVDTP0vJHCqUlZ6zxhnuO8=
github.com/pingcap/br v0.0.0-20200727092753-a475692725db/go.mod h1:4iTqZAMbEPmjBggYixqIg2FwIHBQtyImTM/QYlpTBGk=
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
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 @@ -70,6 +72,7 @@ var _ = Suite(&testSchemaSuite{})
var _ = Suite(&testIsolationSuite{})
var _ = SerialSuites(&testSchemaSerialSuite{})
var _ = SerialSuites(&testSessionSerialSuite{})
var _ = SerialSuites(&testBackupRestoreSuite{})

type testSessionSuiteBase struct {
cluster cluster.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 @@ -3219,3 +3226,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")
}
}