Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Merge master to release 3.1 #203

Merged
merged 58 commits into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
7cf307c
restore: fix alter auto increment id for no-primary-key table (#139)
5kbpers Jan 10, 2020
191fdce
*: use oracle package to manipulate ts and test gc safe point (#121)
overvenus Jan 15, 2020
2aa1322
cmd: convert version command to flags (#144)
overvenus Jan 16, 2020
0c1dea4
*: add changelog and github templates (#143)
overvenus Jan 16, 2020
0a43d2a
restore: merge tidb-tools/pkg/restore-util (#146)
overvenus Jan 22, 2020
3863a3a
Fixed handling for a dbName that do not exist in the backup being res…
Feb 1, 2020
6b65080
validate: fix debug meta test ci (#153)
3pointer Feb 5, 2020
0dfe82d
*: extracts runBackup/runRestore in cmd into pkg/task (#156)
kennytm Feb 10, 2020
8c97452
restore: fix restore summary log (#150)
3pointer Feb 13, 2020
008ec45
restore: enhance error handling (#152)
5kbpers Feb 13, 2020
1e1fc97
Incremental BR: support DDL (#155)
5kbpers Feb 20, 2020
4492b8f
Reduce TiDB dependencies (#158)
kennytm Feb 22, 2020
3c9d42f
go.mod: update tidb (#168)
overvenus Feb 23, 2020
028963d
BR support TLS (#161)
3pointer Feb 27, 2020
e462f80
upgrade golangci and prepare for go 1.14 (#171)
overvenus Feb 28, 2020
4657932
backup: add raw backup command (#101)
3pointer Mar 4, 2020
0a1a044
restore: speed up retry on not leader (#179)
overvenus Mar 5, 2020
09fb715
conn, restore: paginate scan regions (#165)
overvenus Mar 5, 2020
82b5016
Batch restore (#167)
overvenus Mar 6, 2020
3fc9ee2
README, docker: add quick start (#181)
overvenus Mar 7, 2020
237fe5b
*: update tidb dependency build with go1.14 (#176)
3pointer Mar 10, 2020
0672ab3
*: add license header (#182)
overvenus Mar 11, 2020
9caa6de
conn: support not shutting down the storage when closing the connecti…
kennytm Mar 11, 2020
7d59284
conn: use GetDomain to avoid some TiDB breaking changes (#186)
overvenus Mar 11, 2020
0e25496
fix check safepoint & unhide experimental features (#175)
5kbpers Mar 11, 2020
3419d8a
support backupts (#172)
3pointer Mar 12, 2020
e476c82
*: update pd deps to v4 (#184)
kennytm Mar 12, 2020
9c2bf9d
restore: support online restore (#114)
disksing Mar 13, 2020
512855d
metrics: add grafana scripts (#140)
WangXiangUSTC Mar 15, 2020
6b88e51
filter out all TiFlash nodes when retrieving lists of stores from PD …
kennytm Mar 16, 2020
156f003
Create integration test for S3 storage (#174)
kennytm Mar 16, 2020
bbedfc8
Fix summary log (#191)
3pointer Mar 16, 2020
c3d26d9
Implement Raw Restore (#104)
MyonKeminta Mar 17, 2020
962c837
Merge branch 'master' into cherry-pick-3.1.0-rc
3pointer Mar 17, 2020
8236091
update dep
3pointer Mar 17, 2020
6268cde
restore: remove tiflash replica before restore (#194)
5kbpers Mar 18, 2020
4ea6c1c
summary: put summary log at last (#197)
3pointer Mar 19, 2020
2669204
*: abstract the progress channel (updateCh) into the glue package (#196)
kennytm Mar 20, 2020
a211bae
Merge branch 'master' into cherry-pick-3.1.0-rc
3pointer Mar 20, 2020
f9f6e19
*: refline logs (#189)
TennyZhuang Mar 20, 2020
9b96206
adapt pd/tidb related 3.1 changes
3pointer Mar 23, 2020
e168a60
tests: disable TLS test (#204)
overvenus Mar 24, 2020
4bc66c3
*: add S3 quick start and few enhancement of log (#202)
overvenus Mar 25, 2020
2f083c8
restore: add error field to `DownloadResponse` (#195)
5kbpers Mar 25, 2020
1f27b57
restore: populate restore cancel error (#207)
overvenus Mar 25, 2020
ae7688a
enhance usability of br (#208)
3pointer Mar 25, 2020
8638d9a
task: do not run checksum if restore failed (#209)
kennytm Mar 26, 2020
f112da7
fix incremental bug in llroad test (#199)
3pointer Mar 26, 2020
953ddf0
Merge branch 'master' into cherry-pick-3.1.0-rc
3pointer Mar 30, 2020
8fbedbf
add skip create sqls (#211)
3pointer Mar 30, 2020
f031777
Revert "tests: disable TLS test (#204)" (#218)
kennytm Mar 31, 2020
f7dc2db
doc: add `minio` to dependence list. (#221)
YuJuncen Apr 1, 2020
01de3f5
move waiting reject stores in import file (#222)
3pointer Apr 1, 2020
de4857c
Merge branch 'master' into cherry-pick-3.1.0-rc
3pointer Apr 2, 2020
3341f40
Max index length (#220)
3pointer Apr 2, 2020
7de169d
glue: create schema/table directly with info (#216)
kennytm Apr 2, 2020
ab69f59
Merge branch 'master' into cherry-pick-3.1.0-rc
3pointer Apr 2, 2020
14b4241
update deps
3pointer Apr 2, 2020
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
10 changes: 10 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
codecov:
require_ci_to_pass: yes

coverage:
status:
project:
default:
# Allow the coverage to drop by 3%
threshold: 3%
patch: off
1 change: 1 addition & 0 deletions .dockerignore
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ backupmeta
*.ngo
*.coverprofile
coverage.txt
docker/data/
docker/logs/
4 changes: 2 additions & 2 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ Apache License
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright {}
Copyright [yyyy] [name of copyright owner]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -198,4 +198,4 @@ Apache License
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
24 changes: 17 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,28 @@ LDFLAGS += -X "$(BR_PKG)/pkg/utils.BRBuildTS=$(shell date -u '+%Y-%m-%d %I:%M:%S
LDFLAGS += -X "$(BR_PKG)/pkg/utils.BRGitHash=$(shell git rev-parse HEAD)"
LDFLAGS += -X "$(BR_PKG)/pkg/utils.BRGitBranch=$(shell git rev-parse --abbrev-ref HEAD)"

all: check test build
ifeq ("$(WITH_RACE)", "1")
RACEFLAG = -race
endif

release:
GO111MODULE=on go build -ldflags '$(LDFLAGS)' -o bin/br
all: check test build

build:
GO111MODULE=on go build -ldflags '$(LDFLAGS)' -race -o bin/br
GO111MODULE=on go build -ldflags '$(LDFLAGS)' ${RACEFLAG} -o bin/br

build_for_integration_test:
GO111MODULE=on go test -c -cover -covermode=count \
-coverpkg=$(BR_PKG)/... \
-o bin/br.test
# build key locker
GO111MODULE=on go build -race -o bin/locker tests/br_key_locked/*.go
GO111MODULE=on go build ${RACEFLAG} -o bin/locker tests/br_key_locked/*.go
# build gc
GO111MODULE=on go build -race -o bin/gc tests/br_z_gc_safepoint/*.go
GO111MODULE=on go build ${RACEFLAG} -o bin/gc tests/br_z_gc_safepoint/*.go
# build rawkv client
GO111MODULE=on go build ${RACEFLAG} -o bin/rawkv tests/br_rawkv/*.go

test:
GO111MODULE=on go test -race -tags leak ./...
GO111MODULE=on go test ${RACEFLAG} -tags leak ./...

testcover:
GO111MODULE=on retool do overalls \
Expand All @@ -46,6 +49,7 @@ integration_test: build build_for_integration_test
@which bin/pd-server
@which bin/pd-ctl
@which bin/go-ycsb
@which bin/minio
@which bin/br
tests/run.sh

Expand All @@ -71,6 +75,12 @@ static:
--disable interfacer \
--disable goimports \
--disable gofmt \
--disable wsl \
--disable funlen \
--disable whitespace \
--disable gocognit \
--disable godox \
--disable gomnd \
$$($(PACKAGE_DIRECTORIES))

lint:
Expand Down
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,55 @@ Notice BR supports building with Go version `Go >= 1.13`

When BR is built successfully, you can find binary in the `bin` directory.

## Quick start

```sh
# Start TiDB cluster
docker-compose -f docker-compose.yaml rm -s -v && \
docker-compose -f docker-compose.yaml build && \
docker-compose -f docker-compose.yaml up --remove-orphans

# Attach to control container to run BR
docker exec -it br_control_1 bash

# Load testing data to TiDB
go-ycsb load mysql -p workload=core \
-p mysql.host=tidb -p mysql.port=4000 -p mysql.user=root \
-p recordcount=100000 -p threadcount=100

# How many rows do we get? 100000 rows.
mysql -uroot -htidb -P4000 -E -e "SELECT COUNT(*) FROM test.usertable"

# Build BR and backup!
make build && \
bin/br backup full --pd pd0:2379 --storage "local:///data/backup/full" \
--log-file "/logs/br_backup.log"

# Let's drop database.
mysql -uroot -htidb -P4000 -E -e "DROP DATABASE test; SHOW DATABASES;"

# Restore!
bin/br restore full --pd pd0:2379 --storage "local:///data/backup/full" \
--log-file "/logs/br_restore.log"

# How many rows do we get again? Expected to be 100000 rows.
mysql -uroot -htidb -P4000 -E -e "SELECT COUNT(*) FROM test.usertable"

# Test S3 compatible storage (MinIO).
# Create a bucket to save backup by mc (a MinIO Client).
mc config host add minio $S3_ENDPOINT $MINIO_ACCESS_KEY $MINIO_SECRET_KEY && \
mc mb minio/mybucket

# Backup to S3 compatible storage.
bin/br backup full --pd pd0:2379 --storage "s3://mybucket/full" \
--s3.endpoint="$S3_ENDPOINT"

# Drop database and restore!
mysql -uroot -htidb -P4000 -E -e "DROP DATABASE test; SHOW DATABASES;" && \
bin/br restore full --pd pd0:2379 --storage "s3://mybucket/full" \
--s3.endpoint="$S3_ENDPOINT"
```

## Contributing

Contributions are welcomed and greatly appreciated. See [CONTRIBUTING](./CONTRIBUTING.md)
Expand Down
36 changes: 33 additions & 3 deletions cmd/backup.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// Copyright 2020 PingCAP, Inc. Licensed under Apache-2.0.

package cmd

import (
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/session"
"github.com/spf13/cobra"

"github.com/pingcap/br/pkg/gluetikv"
"github.com/pingcap/br/pkg/summary"
"github.com/pingcap/br/pkg/task"
"github.com/pingcap/br/pkg/utils"
Expand All @@ -13,16 +16,27 @@ import (
func runBackupCommand(command *cobra.Command, cmdName string) error {
cfg := task.BackupConfig{Config: task.Config{LogProgress: HasLogFile()}}
if err := cfg.ParseFromFlags(command.Flags()); err != nil {
command.SilenceUsage = false
return err
}
return task.RunBackup(GetDefaultContext(), cmdName, &cfg)
return task.RunBackup(GetDefaultContext(), tidbGlue, cmdName, &cfg)
}

func runBackupRawCommand(command *cobra.Command, cmdName string) error {
cfg := task.RawKvConfig{Config: task.Config{LogProgress: HasLogFile()}}
if err := cfg.ParseFromFlags(command.Flags()); err != nil {
command.SilenceUsage = false
return err
}
return task.RunBackupRaw(GetDefaultContext(), gluetikv.Glue{}, cmdName, &cfg)
}

// NewBackupCommand return a full backup subcommand.
func NewBackupCommand() *cobra.Command {
command := &cobra.Command{
Use: "backup",
Short: "backup a TiDB cluster",
Use: "backup",
Short: "backup a TiDB/TiKV cluster",
SilenceUsage: true,
PersistentPreRunE: func(c *cobra.Command, args []string) error {
if err := Init(c); err != nil {
return err
Expand All @@ -43,6 +57,7 @@ func NewBackupCommand() *cobra.Command {
newFullBackupCommand(),
newDbBackupCommand(),
newTableBackupCommand(),
newRawBackupCommand(),
)

task.DefineBackupFlags(command.PersistentFlags())
Expand Down Expand Up @@ -87,3 +102,18 @@ func newTableBackupCommand() *cobra.Command {
task.DefineTableFlags(command)
return command
}

// newRawBackupCommand return a raw kv range backup subcommand.
func newRawBackupCommand() *cobra.Command {
// TODO: remove experimental tag if it's stable
command := &cobra.Command{
Use: "raw",
Short: "(experimental) backup a raw kv range from TiKV cluster",
RunE: func(command *cobra.Command, _ []string) error {
return runBackupRawCommand(command, "Raw backup")
},
}

task.DefineRawBackupFlags(command)
return command
}
46 changes: 35 additions & 11 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
// Copyright 2020 PingCAP, Inc. Licensed under Apache-2.0.

package cmd

import (
"context"
"net/http"
"net/http/pprof"
"os"
"path/filepath"
"sync"
"sync/atomic"
"time"

"github.com/pingcap/log"
"github.com/pingcap/tidb/util/logutil"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"go.uber.org/zap"

"github.com/pingcap/br/pkg/gluetidb"
"github.com/pingcap/br/pkg/summary"
"github.com/pingcap/br/pkg/task"
"github.com/pingcap/br/pkg/utils"
)

var (
initOnce = sync.Once{}
defaultContext context.Context
hasLogFile uint64
initOnce = sync.Once{}
defaultContext context.Context
hasLogFile uint64
tidbGlue = gluetidb.Glue{}
envLogToTermKey = "BR_LOG_TO_TERM"
)

const (
Expand All @@ -37,6 +46,10 @@ const (
flagVersionShort = "V"
)

func timestampLogFileName() string {
return filepath.Join(os.TempDir(), "br.log."+time.Now().Format(time.RFC3339))
}

// AddFlags adds flags to the given cmd.
func AddFlags(cmd *cobra.Command) {
cmd.Version = utils.BRInfo()
Expand All @@ -45,8 +58,8 @@ func AddFlags(cmd *cobra.Command) {

cmd.PersistentFlags().StringP(FlagLogLevel, "L", "info",
"Set the log level")
cmd.PersistentFlags().String(FlagLogFile, "",
"Set the log file path. If not set, logs will output to stdout")
cmd.PersistentFlags().String(FlagLogFile, timestampLogFileName(),
"Set the log file path. If not set, logs will output to temp file")
cmd.PersistentFlags().String(FlagStatusAddr, "",
"Set the HTTP listening address for the status report service. Set to empty string to disable")
task.DefineCommonFlags(cmd.PersistentFlags())
Expand All @@ -69,8 +82,15 @@ func Init(cmd *cobra.Command) (err error) {
if err != nil {
return
}
_, outputLogToTerm := os.LookupEnv(envLogToTermKey)
if outputLogToTerm {
// Log to term if env `BR_LOG_TO_TERM` is set.
conf.File.Filename = ""
}
if len(conf.File.Filename) != 0 {
atomic.StoreUint64(&hasLogFile, 1)
summary.InitCollector(true)
cmd.Printf("Detial BR log in %s\n", conf.File.Filename)
}
lg, p, e := log.InitLogger(conf)
if e != nil {
Expand All @@ -84,16 +104,20 @@ func Init(cmd *cobra.Command) (err error) {
err = e
return
}
tidbLogCfg := logutil.LogConfig{}
if len(slowLogFilename) != 0 {
slowCfg := logutil.LogConfig{SlowQueryFile: slowLogFilename}
e = logutil.InitLogger(&slowCfg)
if e != nil {
err = e
return
}
tidbLogCfg.SlowQueryFile = slowLogFilename
} else {
// Hack! Discard slow log by setting log level to PanicLevel
logutil.SlowQueryLogger.SetLevel(logrus.PanicLevel)
// Disable annoying TiDB Log.
// TODO: some error logs outputs randomly, we need to fix them in TiDB.
tidbLogCfg.Level = "fatal"
}
e = logutil.InitLogger(&tidbLogCfg)
if e != nil {
err = e
return
}

// Initialize the pprof server.
Expand Down
Loading