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

Commit 9b76002

Browse files
3pointer5kbpersovervenuskennytmdisksing
authored
Merge master to release 3.1 (#203)
* restore: fix alter auto increment id for no-primary-key table (#139) * restore: fix alter auto increment id for no-primary-key table Signed-off-by: 5kbpers <tangminghua@pingcap.com> * add integration test Signed-off-by: 5kbpers <tangminghua@pingcap.com> * address comments Signed-off-by: 5kbpers <tangminghua@pingcap.com> * *: use oracle package to manipulate ts and test gc safe point (#121) Signed-off-by: Neil Shen <overvenus@gmail.com> * cmd: convert version command to flags (#144) * cmd: convert version command to flags Signed-off-by: Neil Shen <overvenus@gmail.com> * address comments Signed-off-by: Neil Shen <overvenus@gmail.com> * *: add changelog and github templates (#143) Signed-off-by: Neil Shen <overvenus@gmail.com> * restore: merge tidb-tools/pkg/restore-util (#146) * restore-util: Implement split/scatter (#274) * implement split/scatter Signed-off-by: 5kbpers <tangminghua@pingcap.com> * init test Signed-off-by: 5kbpers <tangminghua@pingcap.com> * redesign output/input of the lib Signed-off-by: 5kbpers <tangminghua@pingcap.com> * update dependency Signed-off-by: 5kbpers <tangminghua@pingcap.com> * add commments and more tests Signed-off-by: 5kbpers <tangminghua@pingcap.com> * add ScanRegions interface to Client Signed-off-by: 5kbpers <tangminghua@pingcap.com> * fix potential data race Signed-off-by: 5kbpers <tangminghua@pingcap.com> * address comments Signed-off-by: 5kbpers <tangminghua@pingcap.com> * address comments Signed-off-by: 5kbpers <tangminghua@pingcap.com> * Apply suggestions from code review Co-Authored-By: kennytm <kennytm@gmail.com> * Update pkg/restore-util/client.go Co-Authored-By: kennytm <kennytm@gmail.com> * address comments Signed-off-by: 5kbpers <tangminghua@pingcap.com> * address comments Signed-off-by: 5kbpers <tangminghua@pingcap.com> * address comments Signed-off-by: 5kbpers <tangminghua@pingcap.com> * update dependency Signed-off-by: 5kbpers <tangminghua@pingcap.com> * resolve conflicts Signed-off-by: 5kbpers <tangminghua@pingcap.com> * fix prefix rewrite Signed-off-by: 5kbpers <tangminghua@pingcap.com> * add RewriteRule/skip failed scatter region/retry the SplitRegion Signed-off-by: 5kbpers <tangminghua@pingcap.com> * fix test Signed-off-by: 5kbpers <tangminghua@pingcap.com> * check if region has peer Signed-off-by: 5kbpers <tangminghua@pingcap.com> * more logs Signed-off-by: 5kbpers <tangminghua@pingcap.com> * restore-util: add split retry interval (#277) * reset dependencies to release-3.1 * add split retry interval Signed-off-by: 5kbpers <tangminghua@pingcap.com> * fix go.sum Signed-off-by: 5kbpers <tangminghua@pingcap.com> * restore-util: wait for scatter region sequentially (#279) * wait for scatter region sequentially Signed-off-by: 5kbpers <tangminghua@pingcap.com> * address comments Signed-off-by: 5kbpers <tangminghua@pingcap.com> * restore-util: add on split hook (#281) * restore-util: add on split hook Signed-off-by: Neil Shen <overvenus@gmail.com> * Nil check onSplit Co-Authored-By: kennytm <kennytm@gmail.com> * restore-util: fix returned new region is nil (#283) * restore-util: fix returned new region is nil Signed-off-by: 5kbpers <tangminghua@pingcap.com> * more logs Signed-off-by: 5kbpers <tangminghua@pingcap.com> * *: gofmt Signed-off-by: 5kbpers <tangminghua@pingcap.com> * Apply suggestions from code review Co-Authored-By: kennytm <kennytm@gmail.com> * fix log Signed-off-by: 5kbpers <tangminghua@pingcap.com> * restore-util: call onSplit on splitByRewriteRules (#285) Signed-off-by: Neil Shen <overvenus@gmail.com> * restore-util: fix overlapped error message (#293) * restore-util: fix overlapped error message Signed-off-by: 5kbpers <tangminghua@pingcap.com> * fix log message Signed-off-by: 5kbpers <tangminghua@pingcap.com> * reduce error trace Signed-off-by: 5kbpers <tangminghua@pingcap.com> * fix test Signed-off-by: 5kbpers <tangminghua@pingcap.com> * address comments Signed-off-by: 5kbpers <tangminghua@pingcap.com> * address comments Signed-off-by: 5kbpers <tangminghua@pingcap.com> * restore-util: log warning when cannot find matched rewrite rule (#299) * restore-util: add method to set placement rules and store labels (#301) * restore-util: add method to set placement rules and store labels Signed-off-by: disksing <i@disksing.com> * minor fix Signed-off-by: disksing <i@disksing.com> * address comment Signed-off-by: disksing <i@disksing.com> * add GetPlacementRules Signed-off-by: disksing <i@disksing.com> * fix test Signed-off-by: disksing <i@disksing.com> * restore-util: support batch split (#300) * restore-util: support batch split Signed-off-by: 5kbpers <tangminghua@pingcap.com> * go fmt Signed-off-by: 5kbpers <tangminghua@pingcap.com> * Apply suggestions from code review Co-Authored-By: kennytm <kennytm@gmail.com> * address commits Signed-off-by: 5kbpers <tangminghua@pingcap.com> * Update pkg/restore-util/split.go Co-Authored-By: kennytm <kennytm@gmail.com> * add onSplit callback Signed-off-by: 5kbpers <tangminghua@pingcap.com> * fix test Signed-off-by: 5kbpers <tangminghua@pingcap.com> * address comments Signed-off-by: 5kbpers <tangminghua@pingcap.com> * restore-util: add upper bound time for waiting for scatter (#305) * restore: fix scatter regions failed Signed-off-by: 5kbpers <tangminghua@pingcap.com> * add log Signed-off-by: 5kbpers <tangminghua@pingcap.com> * stop waiting for scatter after 3min Signed-off-by: 5kbpers <tangminghua@pingcap.com> * address comments Signed-off-by: 5kbpers <tangminghua@pingcap.com> * restore-util: fix wrong url (#306) Signed-off-by: disksing <i@disksing.com> * restore-util: add warning about unmatched table id (#313) * restore-util: support table partition Signed-off-by: 5kbpers <tangminghua@pingcap.com> * fix log Signed-off-by: 5kbpers <tangminghua@pingcap.com> * warn table id does not match Signed-off-by: 5kbpers <tangminghua@pingcap.com> * add unit tests Signed-off-by: 5kbpers <tangminghua@pingcap.com> * Apply suggestions from code review Co-Authored-By: Neil Shen <overvenus@gmail.com> * fix compile error Signed-off-by: 5kbpers <tangminghua@pingcap.com> * address comments Signed-off-by: 5kbpers <tangminghua@pingcap.com> * address comments Signed-off-by: 5kbpers <tangminghua@pingcap.com> * fix test Signed-off-by: 5kbpers <tangminghua@pingcap.com> Co-authored-by: Ian <ArGregoryIan@gmail.com> Co-authored-by: Neil Shen <overvenus@gmail.com> * *: prune tidb-tools Signed-off-by: Neil Shen <overvenus@gmail.com> * restore: address linters suggestions Signed-off-by: Neil Shen <overvenus@gmail.com> * restore: merge restoreutil into restore Signed-off-by: Neil Shen <overvenus@gmail.com> * address comment Signed-off-by: Neil Shen <overvenus@gmail.com> Co-authored-by: 5kbpers <20279863+5kbpers@users.noreply.github.com> Co-authored-by: kennytm <kennytm@gmail.com> Co-authored-by: disksing <i@disksing.com> Co-authored-by: Ian <ArGregoryIan@gmail.com> * Fixed handling for a dbName that do not exist in the backup being restored (#148) * Fixed handling for a dbName that do not exist in the backup being restored * Fixed handling for a dbName that do not exist in the backup being restored * validate: fix debug meta test ci (#153) * validate: fix debug meta test ci * *: extracts runBackup/runRestore in cmd into pkg/task (#156) * *: extracts runBackup/runRestore in cmd into pkg/task Defines a "Config" structure to store the parsed flags. Use the "black-white-list" structure to define what tables/databases to backup/restore. * go.mod: update tidb to v4.0.0-beta * restore: fix restore summary log (#150) Co-authored-by: kennytm <kennytm@gmail.com> * restore: enhance error handling (#152) * restore: enhance error handling Signed-off-by: 5kbpers <tangminghua@pingcap.com> * unit test Signed-off-by: 5kbpers <tangminghua@pingcap.com> * address comments Signed-off-by: 5kbpers <tangminghua@pingcap.com> * fix region epoch error Signed-off-by: 5kbpers <tangminghua@pingcap.com> * address comments Signed-off-by: 5kbpers <tangminghua@pingcap.com> * remove `Restore*` Signed-off-by: 5kbpers <tangminghua@pingcap.com> * address lint Signed-off-by: 5kbpers <tangminghua@pingcap.com> * add debug log Signed-off-by: 5kbpers <tangminghua@pingcap.com> * Apply suggestions from code review Co-Authored-By: kennytm <kennytm@gmail.com> * Update pkg/restore/import.go Co-Authored-By: kennytm <kennytm@gmail.com> * fix retry error Signed-off-by: 5kbpers <tangminghua@pingcap.com> * handle RegionNotFound error Signed-off-by: 5kbpers <tangminghua@pingcap.com> Co-authored-by: Neil Shen <overvenus@gmail.com> Co-authored-by: kennytm <kennytm@gmail.com> * Incremental BR: support DDL (#155) * support backup&restore ddl Signed-off-by: 5kbpers <tangminghua@pingcap.com> * integration tests Signed-off-by: 5kbpers <tangminghua@pingcap.com> * update kvproto Signed-off-by: 5kbpers <tangminghua@pingcap.com> * fix integration tests Signed-off-by: 5kbpers <tangminghua@pingcap.com> * reduce cyclomatic complexity of `runRestore` Signed-off-by: 5kbpers <tangminghua@pingcap.com> * fix test Signed-off-by: 5kbpers <tangminghua@pingcap.com> * add unit test Signed-off-by: 5kbpers <tangminghua@pingcap.com> * fix tests Signed-off-by: 5kbpers <tangminghua@pingcap.com> * disable fast checksum in incremental br Signed-off-by: 5kbpers <tangminghua@pingcap.com> * fix no valid key error Signed-off-by: 5kbpers <tangminghua@pingcap.com> * address lint Signed-off-by: 5kbpers <tangminghua@pingcap.com> * address comments Signed-off-by: 5kbpers <tangminghua@pingcap.com> * Reduce TiDB dependencies (#158) * utils: exclude mock_cluster outside of unit test * utils: remove unused ResultSetToStringSlice() * *: abstract away dependencies of tidb/session into a Glue interface * *: fix hound lint * util,mock: move utils.MockCluster to mock.Cluster * restore: fix test build failure Co-authored-by: 3pointer <qdlc2010@gmail.com> * go.mod: update tidb (#168) Signed-off-by: Neil Shen <overvenus@gmail.com> * BR support TLS (#161) * *: support tls * move tikv.driver to glue * fix comments * upgrade golangci and prepare for go 1.14 (#171) Signed-off-by: Neil Shen <overvenus@gmail.com> * backup: add raw backup command (#101) * backup: add raw backup command * restore: speed up retry on not leader (#179) * tests: stable cluster start up Signed-off-by: Neil Shen <overvenus@gmail.com> * tests: fix unbound var Signed-off-by: Neil Shen <overvenus@gmail.com> * restore: speed retry on not leader Signed-off-by: Neil Shen <overvenus@gmail.com> * address comments Signed-off-by: Neil Shen <overvenus@gmail.com> * tests: add --cacert flag Signed-off-by: Neil Shen <overvenus@gmail.com> * make codecov green Signed-off-by: Neil Shen <overvenus@gmail.com> * address comments Signed-off-by: Neil Shen <overvenus@gmail.com> * conn, restore: paginate scan regions (#165) * conn, restore: paginate scan regions Signed-off-by: Neil Shen <overvenus@gmail.com> * tests: large timeout Signed-off-by: Neil Shen <overvenus@gmail.com> * Batch restore (#167) * *: unify Range and RangeTree Signed-off-by: Neil Shen <overvenus@gmail.com> * restore: split restore files into small batch Signed-off-by: Neil Shen <overvenus@gmail.com> * task: set default restore concurrency to 128 Signed-off-by: Neil Shen <overvenus@gmail.com> * restore: unused table worker pool Signed-off-by: Neil Shen <overvenus@gmail.com> * summary: sum up repeated duration and int Signed-off-by: Neil Shen <overvenus@gmail.com> * rtree: move rtree from utils to pkg Signed-off-by: Neil Shen <overvenus@gmail.com> * README, docker: add quick start (#181) * README, docker: add quick start Signed-off-by: Neil Shen <overvenus@gmail.com> * cmd: disable some TiDB log Signed-off-by: Neil Shen <overvenus@gmail.com> * docker: build go-ycsb automatically Signed-off-by: Neil Shen <overvenus@gmail.com> * cmd: add TODO about TiDB logs Signed-off-by: Neil Shen <overvenus@gmail.com> * *: update tidb dependency build with go1.14 (#176) * *: add license header (#182) * rtree: move checkFile into backup Signed-off-by: Neil Shen <overvenus@gmail.com> * *: add license header Signed-off-by: Neil Shen <overvenus@gmail.com> * Update LICENSE.md Co-Authored-By: kennytm <kennytm@gmail.com> Co-authored-by: kennytm <kennytm@gmail.com> Co-authored-by: 3pointer <luancheng@pingcap.com> * conn: support not shutting down the storage when closing the connection (#185) Co-authored-by: 3pointer <luancheng@pingcap.com> * conn: use GetDomain to avoid some TiDB breaking changes (#186) * conn: use GetDomain to avoid some TiDB breaking changes Signed-off-by: Neil Shen <overvenus@gmail.com> * minor usability improvement Signed-off-by: Neil Shen <overvenus@gmail.com> Co-authored-by: kennytm <kennytm@gmail.com> * fix check safepoint & unhide experimental features (#175) * backup: check safepoint for last backup ts Signed-off-by: 5kbpers <tangminghua@pingcap.com> * check lastbackupts > 0 Signed-off-by: 5kbpers <tangminghua@pingcap.com> * unhide experimental features Signed-off-by: 5kbpers <tangminghua@pingcap.com> * address comment Signed-off-by: 5kbpers <tangminghua@pingcap.com> * Update tests/br_z_gc_safepoint/run.sh Co-Authored-By: kennytm <kennytm@gmail.com> Co-authored-by: kennytm <kennytm@gmail.com> * support backupts (#172) * support backupts * address comment * address comment * fix space * *: update pd deps to v4 (#184) Co-authored-by: 3pointer <luancheng@pingcap.com> * restore: support online restore (#114) Signed-off-by: disksing <i@disksing.com> * metrics: add grafana scripts (#140) * add grafana scripts * fix Co-authored-by: 3pointer <luancheng@pingcap.com> Co-authored-by: glorv <glorvs@163.com> Co-authored-by: kennytm <kennytm@gmail.com> * filter out all TiFlash nodes when retrieving lists of stores from PD (#187) * conn: ignore nodes with label engine=tiflash * conn: disallow TiFlash on restore, only skip TiFlash on backup * Create integration test for S3 storage (#174) * Fix summary log (#191) * *: fix restore summary log after restore logic changed to files * fix * fix * fix Co-authored-by: kennytm <kennytm@gmail.com> * Implement Raw Restore (#104) * Update kvproto * Implement raw restore * fix build * Set range for file importer Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com> * Remove unnecessary comments Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com> * check cf and support multi ranges in BackupMeta Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com> * Check files' cf; address comments * adjust structure to keep consistent with master * Fix build Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com> * Fix build and make check, avoid accessing TiDB in rawkv mode * Fix test Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com> * Fix tests Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com> * Fix broken logic after merging master * Update pkg/task/restore_raw.go Co-Authored-By: Neil Shen <overvenus@gmail.com> * Address comments * Address comments * Mark raw restore as experimental * Fix build * Address comments * test: Add check for deleting data and partial backup * Fix build * Add license header * fix ci * fix ci Co-authored-by: MyonKeminta <MyonKeminta@users.noreply.github.com> Co-authored-by: 3pointer <luancheng@pingcap.com> Co-authored-by: Neil Shen <overvenus@gmail.com> Co-authored-by: pingcap-github-bot <sre-bot@pingcap.com> * update dep * restore: remove tiflash replica before restore (#194) * restore: remove tiflash replica before restore Signed-off-by: 5kbpers <tangminghua@pingcap.com> * rename errSplit variable Signed-off-by: 5kbpers <tangminghua@pingcap.com> * address comments Signed-off-by: 5kbpers <tangminghua@pingcap.com> * check replica count by region info Signed-off-by: 5kbpers <tangminghua@pingcap.com> * cleanup Signed-off-by: 5kbpers <tangminghua@pingcap.com> * save tiflash replica count to backupmeta Signed-off-by: 5kbpers <tangminghua@pingcap.com> * fix save crcxor Signed-off-by: 5kbpers <tangminghua@pingcap.com> * fix decode the key of placement rule Signed-off-by: 5kbpers <tangminghua@pingcap.com> * address lint Signed-off-by: 5kbpers <tangminghua@pingcap.com> * address comments Signed-off-by: 5kbpers <tangminghua@pingcap.com> * close domain after restoring tiflash-replica Signed-off-by: 5kbpers <tangminghua@pingcap.com> * address comments Signed-off-by: 5kbpers <tangminghua@pingcap.com> * address comments Signed-off-by: 5kbpers <tangminghua@pingcap.com> * Update pkg/task/restore.go Co-Authored-By: 3pointer <qdlc2010@gmail.com> Co-authored-by: 3pointer <qdlc2010@gmail.com> * summary: put summary log at last (#197) * summary: put summary log at last * fix switch sql * *: abstract the progress channel (updateCh) into the glue package (#196) * *: abstract the progress channel (updateCh) into the glue package * restore: fix crash in truncateTS() when the bound is unlimited * task: fix comment Co-authored-by: Ian <ArGregoryIan@gmail.com> * *: refline logs (#189) * adapt pd/tidb related 3.1 changes * tests: disable TLS test (#204) Signed-off-by: Neil Shen <overvenus@gmail.com> * *: add S3 quick start and few enhancement of log (#202) * README, docker: add quick start about S3 storage Signed-off-by: Neil Shen <overvenus@gmail.com> * pkg/summary: make sure to output correct summary Signed-off-by: Neil Shen <overvenus@gmail.com> * cmd, tests: log to terminal if BR_LOG_TO_TERM is set Signed-off-by: Neil Shen <overvenus@gmail.com> * Update pkg/task/common.go Co-Authored-By: kennytm <kennytm@gmail.com> * address comments Signed-off-by: Neil Shen <overvenus@gmail.com> * address comments Signed-off-by: Neil Shen <overvenus@gmail.com> * tests: cat log if br fails Signed-off-by: Neil Shen <overvenus@gmail.com> Co-authored-by: kennytm <kennytm@gmail.com> * restore: add error field to `DownloadResponse` (#195) * restore: add error field to `DownloadResponse` Signed-off-by: 5kbpers <tangminghua@pingcap.com> * restore: populate restore cancel error (#207) Signed-off-by: Neil Shen <overvenus@gmail.com> Co-authored-by: kennytm <kennytm@gmail.com> * enhance usability of br (#208) * silenceUsage only when parse cmd flags failed * udpate tidb Co-authored-by: kennytm <kennytm@gmail.com> * task: do not run checksum if restore failed (#209) * fix incremental bug in llroad test (#199) * restore: filter same table ddl * *: do not return error when backup/restore data is empty * fix create database double during incremental restore * add tests * fix ci * address comment * add skip create sqls (#211) * Revert "tests: disable TLS test (#204)" (#218) This reverts commit e168a60. * doc: add `minio` to dependence list. (#221) The README of test omitted `minio` in the dependence list, which is needed for run the integration test. Co-authored-by: Neil Shen <overvenus@gmail.com> * move waiting reject stores in import file (#222) * move wait rejectstores into import files * restore: use new table id to search placementRules * Update pkg/restore/import.go Co-Authored-By: Neil Shen <overvenus@gmail.com> * Update pkg/restore/import.go Co-Authored-By: kennytm <kennytm@gmail.com> * fix ci Co-authored-by: Neil Shen <overvenus@gmail.com> Co-authored-by: kennytm <kennytm@gmail.com> * Max index length (#220) * restore: set max-index-length to max * restore:add max-index-length params * address comment * address comment * glue: create schema/table directly with info (#216) * glue: create schema/table directly with info * go.mod: change to use the master version * gluetidb: fix failure to create schema * gluetidb: exclude non-public indices when restoring * go.mod: removed unused replace Co-authored-by: 3pointer <luancheng@pingcap.com> * update deps Co-authored-by: 5kbpers <20279863+5kbpers@users.noreply.github.com> Co-authored-by: Neil Shen <overvenus@gmail.com> Co-authored-by: kennytm <kennytm@gmail.com> Co-authored-by: disksing <i@disksing.com> Co-authored-by: Ian <ArGregoryIan@gmail.com> Co-authored-by: Kolbe Kegel <kolbe@pingcap.com> Co-authored-by: WangXiangUSTC <wx347249478@gmail.com> Co-authored-by: glorv <glorvs@163.com> Co-authored-by: MyonKeminta <9948422+MyonKeminta@users.noreply.github.com> Co-authored-by: MyonKeminta <MyonKeminta@users.noreply.github.com> Co-authored-by: pingcap-github-bot <sre-bot@pingcap.com> Co-authored-by: 庄天翼 <zty0826@gmail.com> Co-authored-by: 山岚 <36239017+YuJuncen@users.noreply.github.com>
1 parent 78c162a commit 9b76002

129 files changed

Lines changed: 7415 additions & 1194 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.codecov.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
codecov:
2+
require_ci_to_pass: yes
3+
4+
coverage:
5+
status:
6+
project:
7+
default:
8+
# Allow the coverage to drop by 3%
9+
threshold: 3%
10+
patch: off

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.gitignore

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ backupmeta
77
*.ngo
88
*.coverprofile
99
coverage.txt
10+
docker/data/
11+
docker/logs/

LICENSE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ Apache License
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright {}
189+
Copyright [yyyy] [name of copyright owner]
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.
@@ -198,4 +198,4 @@ Apache License
198198
distributed under the License is distributed on an "AS IS" BASIS,
199199
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200200
See the License for the specific language governing permissions and
201-
limitations under the License.
201+
limitations under the License.

Makefile

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,28 @@ LDFLAGS += -X "$(BR_PKG)/pkg/utils.BRBuildTS=$(shell date -u '+%Y-%m-%d %I:%M:%S
1212
LDFLAGS += -X "$(BR_PKG)/pkg/utils.BRGitHash=$(shell git rev-parse HEAD)"
1313
LDFLAGS += -X "$(BR_PKG)/pkg/utils.BRGitBranch=$(shell git rev-parse --abbrev-ref HEAD)"
1414

15-
all: check test build
15+
ifeq ("$(WITH_RACE)", "1")
16+
RACEFLAG = -race
17+
endif
1618

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

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

2324
build_for_integration_test:
2425
GO111MODULE=on go test -c -cover -covermode=count \
2526
-coverpkg=$(BR_PKG)/... \
2627
-o bin/br.test
2728
# build key locker
28-
GO111MODULE=on go build -race -o bin/locker tests/br_key_locked/*.go
29+
GO111MODULE=on go build ${RACEFLAG} -o bin/locker tests/br_key_locked/*.go
2930
# build gc
30-
GO111MODULE=on go build -race -o bin/gc tests/br_z_gc_safepoint/*.go
31+
GO111MODULE=on go build ${RACEFLAG} -o bin/gc tests/br_z_gc_safepoint/*.go
32+
# build rawkv client
33+
GO111MODULE=on go build ${RACEFLAG} -o bin/rawkv tests/br_rawkv/*.go
3134

3235
test:
33-
GO111MODULE=on go test -race -tags leak ./...
36+
GO111MODULE=on go test ${RACEFLAG} -tags leak ./...
3437

3538
testcover:
3639
GO111MODULE=on retool do overalls \
@@ -46,6 +49,7 @@ integration_test: build build_for_integration_test
4649
@which bin/pd-server
4750
@which bin/pd-ctl
4851
@which bin/go-ycsb
52+
@which bin/minio
4953
@which bin/br
5054
tests/run.sh
5155

@@ -71,6 +75,12 @@ static:
7175
--disable interfacer \
7276
--disable goimports \
7377
--disable gofmt \
78+
--disable wsl \
79+
--disable funlen \
80+
--disable whitespace \
81+
--disable gocognit \
82+
--disable godox \
83+
--disable gomnd \
7484
$$($(PACKAGE_DIRECTORIES))
7585

7686
lint:

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,55 @@ Notice BR supports building with Go version `Go >= 1.13`
3636

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

39+
## Quick start
40+
41+
```sh
42+
# Start TiDB cluster
43+
docker-compose -f docker-compose.yaml rm -s -v && \
44+
docker-compose -f docker-compose.yaml build && \
45+
docker-compose -f docker-compose.yaml up --remove-orphans
46+
47+
# Attach to control container to run BR
48+
docker exec -it br_control_1 bash
49+
50+
# Load testing data to TiDB
51+
go-ycsb load mysql -p workload=core \
52+
-p mysql.host=tidb -p mysql.port=4000 -p mysql.user=root \
53+
-p recordcount=100000 -p threadcount=100
54+
55+
# How many rows do we get? 100000 rows.
56+
mysql -uroot -htidb -P4000 -E -e "SELECT COUNT(*) FROM test.usertable"
57+
58+
# Build BR and backup!
59+
make build && \
60+
bin/br backup full --pd pd0:2379 --storage "local:///data/backup/full" \
61+
--log-file "/logs/br_backup.log"
62+
63+
# Let's drop database.
64+
mysql -uroot -htidb -P4000 -E -e "DROP DATABASE test; SHOW DATABASES;"
65+
66+
# Restore!
67+
bin/br restore full --pd pd0:2379 --storage "local:///data/backup/full" \
68+
--log-file "/logs/br_restore.log"
69+
70+
# How many rows do we get again? Expected to be 100000 rows.
71+
mysql -uroot -htidb -P4000 -E -e "SELECT COUNT(*) FROM test.usertable"
72+
73+
# Test S3 compatible storage (MinIO).
74+
# Create a bucket to save backup by mc (a MinIO Client).
75+
mc config host add minio $S3_ENDPOINT $MINIO_ACCESS_KEY $MINIO_SECRET_KEY && \
76+
mc mb minio/mybucket
77+
78+
# Backup to S3 compatible storage.
79+
bin/br backup full --pd pd0:2379 --storage "s3://mybucket/full" \
80+
--s3.endpoint="$S3_ENDPOINT"
81+
82+
# Drop database and restore!
83+
mysql -uroot -htidb -P4000 -E -e "DROP DATABASE test; SHOW DATABASES;" && \
84+
bin/br restore full --pd pd0:2379 --storage "s3://mybucket/full" \
85+
--s3.endpoint="$S3_ENDPOINT"
86+
```
87+
3988
## Contributing
4089

4190
Contributions are welcomed and greatly appreciated. See [CONTRIBUTING](./CONTRIBUTING.md)

cmd/backup.go

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
// Copyright 2020 PingCAP, Inc. Licensed under Apache-2.0.
2+
13
package cmd
24

35
import (
46
"github.com/pingcap/tidb/ddl"
57
"github.com/pingcap/tidb/session"
68
"github.com/spf13/cobra"
79

10+
"github.com/pingcap/br/pkg/gluetikv"
811
"github.com/pingcap/br/pkg/summary"
912
"github.com/pingcap/br/pkg/task"
1013
"github.com/pingcap/br/pkg/utils"
@@ -13,16 +16,27 @@ import (
1316
func runBackupCommand(command *cobra.Command, cmdName string) error {
1417
cfg := task.BackupConfig{Config: task.Config{LogProgress: HasLogFile()}}
1518
if err := cfg.ParseFromFlags(command.Flags()); err != nil {
19+
command.SilenceUsage = false
1620
return err
1721
}
18-
return task.RunBackup(GetDefaultContext(), cmdName, &cfg)
22+
return task.RunBackup(GetDefaultContext(), tidbGlue, cmdName, &cfg)
23+
}
24+
25+
func runBackupRawCommand(command *cobra.Command, cmdName string) error {
26+
cfg := task.RawKvConfig{Config: task.Config{LogProgress: HasLogFile()}}
27+
if err := cfg.ParseFromFlags(command.Flags()); err != nil {
28+
command.SilenceUsage = false
29+
return err
30+
}
31+
return task.RunBackupRaw(GetDefaultContext(), gluetikv.Glue{}, cmdName, &cfg)
1932
}
2033

2134
// NewBackupCommand return a full backup subcommand.
2235
func NewBackupCommand() *cobra.Command {
2336
command := &cobra.Command{
24-
Use: "backup",
25-
Short: "backup a TiDB cluster",
37+
Use: "backup",
38+
Short: "backup a TiDB/TiKV cluster",
39+
SilenceUsage: true,
2640
PersistentPreRunE: func(c *cobra.Command, args []string) error {
2741
if err := Init(c); err != nil {
2842
return err
@@ -43,6 +57,7 @@ func NewBackupCommand() *cobra.Command {
4357
newFullBackupCommand(),
4458
newDbBackupCommand(),
4559
newTableBackupCommand(),
60+
newRawBackupCommand(),
4661
)
4762

4863
task.DefineBackupFlags(command.PersistentFlags())
@@ -87,3 +102,18 @@ func newTableBackupCommand() *cobra.Command {
87102
task.DefineTableFlags(command)
88103
return command
89104
}
105+
106+
// newRawBackupCommand return a raw kv range backup subcommand.
107+
func newRawBackupCommand() *cobra.Command {
108+
// TODO: remove experimental tag if it's stable
109+
command := &cobra.Command{
110+
Use: "raw",
111+
Short: "(experimental) backup a raw kv range from TiKV cluster",
112+
RunE: func(command *cobra.Command, _ []string) error {
113+
return runBackupRawCommand(command, "Raw backup")
114+
},
115+
}
116+
117+
task.DefineRawBackupFlags(command)
118+
return command
119+
}

cmd/cmd.go

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,35 @@
1+
// Copyright 2020 PingCAP, Inc. Licensed under Apache-2.0.
2+
13
package cmd
24

35
import (
46
"context"
57
"net/http"
68
"net/http/pprof"
9+
"os"
10+
"path/filepath"
711
"sync"
812
"sync/atomic"
13+
"time"
914

1015
"github.com/pingcap/log"
1116
"github.com/pingcap/tidb/util/logutil"
1217
"github.com/sirupsen/logrus"
1318
"github.com/spf13/cobra"
1419
"go.uber.org/zap"
1520

21+
"github.com/pingcap/br/pkg/gluetidb"
22+
"github.com/pingcap/br/pkg/summary"
1623
"github.com/pingcap/br/pkg/task"
1724
"github.com/pingcap/br/pkg/utils"
1825
)
1926

2027
var (
21-
initOnce = sync.Once{}
22-
defaultContext context.Context
23-
hasLogFile uint64
28+
initOnce = sync.Once{}
29+
defaultContext context.Context
30+
hasLogFile uint64
31+
tidbGlue = gluetidb.Glue{}
32+
envLogToTermKey = "BR_LOG_TO_TERM"
2433
)
2534

2635
const (
@@ -37,6 +46,10 @@ const (
3746
flagVersionShort = "V"
3847
)
3948

49+
func timestampLogFileName() string {
50+
return filepath.Join(os.TempDir(), "br.log."+time.Now().Format(time.RFC3339))
51+
}
52+
4053
// AddFlags adds flags to the given cmd.
4154
func AddFlags(cmd *cobra.Command) {
4255
cmd.Version = utils.BRInfo()
@@ -45,8 +58,8 @@ func AddFlags(cmd *cobra.Command) {
4558

4659
cmd.PersistentFlags().StringP(FlagLogLevel, "L", "info",
4760
"Set the log level")
48-
cmd.PersistentFlags().String(FlagLogFile, "",
49-
"Set the log file path. If not set, logs will output to stdout")
61+
cmd.PersistentFlags().String(FlagLogFile, timestampLogFileName(),
62+
"Set the log file path. If not set, logs will output to temp file")
5063
cmd.PersistentFlags().String(FlagStatusAddr, "",
5164
"Set the HTTP listening address for the status report service. Set to empty string to disable")
5265
task.DefineCommonFlags(cmd.PersistentFlags())
@@ -69,8 +82,15 @@ func Init(cmd *cobra.Command) (err error) {
6982
if err != nil {
7083
return
7184
}
85+
_, outputLogToTerm := os.LookupEnv(envLogToTermKey)
86+
if outputLogToTerm {
87+
// Log to term if env `BR_LOG_TO_TERM` is set.
88+
conf.File.Filename = ""
89+
}
7290
if len(conf.File.Filename) != 0 {
7391
atomic.StoreUint64(&hasLogFile, 1)
92+
summary.InitCollector(true)
93+
cmd.Printf("Detial BR log in %s\n", conf.File.Filename)
7494
}
7595
lg, p, e := log.InitLogger(conf)
7696
if e != nil {
@@ -84,16 +104,20 @@ func Init(cmd *cobra.Command) (err error) {
84104
err = e
85105
return
86106
}
107+
tidbLogCfg := logutil.LogConfig{}
87108
if len(slowLogFilename) != 0 {
88-
slowCfg := logutil.LogConfig{SlowQueryFile: slowLogFilename}
89-
e = logutil.InitLogger(&slowCfg)
90-
if e != nil {
91-
err = e
92-
return
93-
}
109+
tidbLogCfg.SlowQueryFile = slowLogFilename
94110
} else {
95111
// Hack! Discard slow log by setting log level to PanicLevel
96112
logutil.SlowQueryLogger.SetLevel(logrus.PanicLevel)
113+
// Disable annoying TiDB Log.
114+
// TODO: some error logs outputs randomly, we need to fix them in TiDB.
115+
tidbLogCfg.Level = "fatal"
116+
}
117+
e = logutil.InitLogger(&tidbLogCfg)
118+
if e != nil {
119+
err = e
120+
return
97121
}
98122

99123
// Initialize the pprof server.

0 commit comments

Comments
 (0)