Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
ed8e14b
delete .dockerignore
ClamChowderTiDB Apr 26, 2024
17e5f4d
[submodule] include tikv-client-go submodule
ClamChowderTiDB May 7, 2024
3454b4c
disable flaky tests
ClamChowderTiDB Feb 24, 2025
52a6b24
cherry pick minRegionNum to 7.5
ClamChowderTiDB Aug 17, 2024
6da2dbe
remove 'pkg/extension/enterprise' submodule
ClamChowderTiDB Oct 25, 2024
7f5f157
util: Change the output dir of the PLAN REPLAYER to be temp_dir (#58228)
mengxian-li Dec 20, 2024
838f0b4
[lightning] customize on dup logic
ClamChowderTiDB Jan 3, 2025
e8168d2
planner: fix index range intersection for in-list and other predicate…
ghazalfamilyusa Dec 10, 2024
66af031
fix bazel breakages picked in
ClamChowderTiDB Mar 14, 2025
5c2978e
Cherry-pick: br/cmd: added operator checksum-as|force-flush (#58801)
ClamChowderTiDB Mar 25, 2025
34af037
[br] add unit tests to CI
ClamChowderTiDB Apr 1, 2025
4ef6d81
br: set default restore checksum to false (#60328)
Tristan1900 Apr 11, 2025
b05b568
br: mem dump when about to OOM (#59234)
ClamChowderTiDB May 7, 2025
91f4a06
br: metrics server and initial restore metrics (#60942)
ClamChowderTiDB May 12, 2025
5462297
update tikv go client to 8.5.2 branch
ClamChowderTiDB Jun 18, 2025
c877c3b
parser: update `pingcap/errors` to fix failed test cases (#61840)
Defined2014 Jun 19, 2025
676a2f0
disable flaky tests
ClamChowderTiDB Jun 24, 2025
769ca63
additional goleak exceptions to address CI failures
ClamChowderTiDB Jun 26, 2025
b386a91
meta/autoid: reduce get autoID's backoff
ClamChowderTiDB Jun 26, 2025
79d75da
log restore: filter backupmeta file by ts to speed up pitr (#61347) (…
ClamChowderTiDB Jul 11, 2025
6a0796a
[submodule] update client-go to bring prefer-leader fix
ClamChowderTiDB Aug 21, 2025
ac291c6
consume tikv/client-go as a go module
ClamChowderTiDB Aug 28, 2025
8eef555
Enable/disable PD restore mode during PiTR restore
ClamChowderTiDB Sep 4, 2025
4c4c6fa
fix defer value leak, pd client version
ClamChowderTiDB Sep 5, 2025
b2d2816
update client-go and instruction
ClamChowderTiDB Sep 11, 2025
41770e1
Support dynamic config overrides for TIKV during Restoring process.
ClamChowderTiDB Sep 12, 2025
a8665d7
Support dynamic config overrides for TIKV during Restoring process. R…
ClamChowderTiDB Sep 15, 2025
f7e0529
placement: fix alter meta range cannot work (#60889) (#61090)
ClamChowderTiDB Sep 16, 2025
aba32ce
fix unit test on arm v8.5
ClamChowderTiDB Nov 17, 2025
a7799ac
lightning Exit code=1 if terminate when job not finished
ClamChowderTiDB Dec 19, 2025
887f3dc
Fix DuplicateResolutionAlgorithm FromStringValue
ClamChowderTiDB Jan 5, 2026
556bcba
sessiontxn/staleread: don't overwrite StaleTSOProvider for single sta…
ClamChowderTiDB Jan 7, 2026
28d30a5
remove git key and deprecated image tags
ClamChowderTiDB Jan 13, 2026
b766946
fix empty pd addr
ClamChowderTiDB Feb 6, 2026
05f8c6a
parser (#62801)
fzzf678 Aug 4, 2025
3837ffb
ddl: support read only ddl (#63087)
fzzf678 Aug 20, 2025
6f403ff
ddl: add system table INFORMATION_SCHEMA.SCHEMATA_EXTENSIONS to check…
fzzf678 Aug 20, 2025
6a2daab
ddl: prohibit the execution of some ddl when database is in read only…
fzzf678 Aug 21, 2025
cc7a094
ddl: prohibit the execution of some DML when database is in read only…
fzzf678 Nov 12, 2025
d4331cd
ddl: add more integration test case for database read only (#64469)
fzzf678 Nov 20, 2025
03cdbea
ddl: supply some database read only test cases from mysql test (#64705)
fzzf678 Nov 27, 2025
0e06e84
ddl: correct the errno of database read only (#64788)
fzzf678 Dec 3, 2025
3b587eb
ddl: rollback read only ddl if meet error (#64951)
fzzf678 Dec 15, 2025
4a14a11
Allow users with RESTRICTED_REPLICA_WRITER_ADMIN grant to bypass per-…
ClamChowderTiDB Feb 25, 2026
4350166
[cherry-pick] fix SCHEMATA_EXTENSIONS read-only option display
ClamChowderTiDB Mar 5, 2026
27caf88
go.mod: point to ClamChowderTiDB shared branches
ClamChowderTiDB Mar 27, 2026
94bbe7a
upgrade tikv client
ClamChowderTiDB Mar 19, 2026
87e6372
[cherry-pick] test: fix failed test caused by new version of `mc` (#6…
ClamChowderTiDB Apr 1, 2026
e5909ee
go.mod: point to ClamChowderTiDB shared branches
ClamChowderTiDB Apr 1, 2026
e78d922
pkg/extension/enterprise: restore enterprise submodule
ClamChowderTiDB Apr 1, 2026
e6a44da
tests: download ClamChowderTiDB pd-server before starting PD in integ…
ClamChowderTiDB Apr 2, 2026
497360f
pluginpkg: propagate go.mod replace directives to plugin build via go…
ClamChowderTiDB Apr 2, 2026
8f8f280
pluginpkg: fix errcheck lint on go.work cleanup
ClamChowderTiDB Apr 2, 2026
4afbb14
pluginpkg: use toolchain Go version in generated go.work
ClamChowderTiDB Apr 2, 2026
f3d56fc
pluginpkg: use full Go patch version in generated go.work
ClamChowderTiDB Apr 2, 2026
6854b2d
mirror: preserve proxy.golang.org URLs added by fix_go_mod in generat…
ClamChowderTiDB Apr 2, 2026
81781ab
[infra] fix DEPS.bzl regeneration for fork modules and BUILD.bazel sh…
ClamChowderTiDB Apr 2, 2026
9c4b0f9
[infra] fix gofmt formatting in mirror.go
ClamChowderTiDB Apr 2, 2026
5adfaf1
[infra] fix mirror: parse urls in skylarkutil so reuseOldMirror works
ClamChowderTiDB Apr 2, 2026
139090e
[infra] remove proxy URL from isMirror branch output
ClamChowderTiDB Apr 2, 2026
23a9738
[infra] mirror: read committed DEPS.bzl via git to preserve proxy URLs
ClamChowderTiDB Apr 2, 2026
62a7db8
br: tolerate missing pitr-restore-mark endpoint on older PD versions
ClamChowderTiDB Apr 3, 2026
09fdc29
br: fix early-return lint in SetPitrRestoreMark fallback
ClamChowderTiDB Apr 3, 2026
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
8 changes: 0 additions & 8 deletions .dockerignore

This file was deleted.

44 changes: 20 additions & 24 deletions DEPS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5737,13 +5737,14 @@ def go_deps():
name = "com_github_pingcap_errors",
build_file_proto_mode = "disable_global",
importpath = "github.com/pingcap/errors",
sha256 = "1bb6a8df52d6fa2fdfda718c21fe8f9628d1c85d9c9ef91fa054b8663ae10048",
strip_prefix = "github.com/pingcap/errors@v0.11.5-0.20241219054535-6b8c588c3122",
sha256 = "b696ac3d19b74bd6c3454048767bf145c7d8b4d24c55337b27d2e0960d948949",
strip_prefix = "github.com/pingcap/errors@v0.11.5-0.20250523034308-74f78ae071ee",
urls = [
"http://bazel-cache.pingcap.net:8080/gomod/github.com/pingcap/errors/com_github_pingcap_errors-v0.11.5-0.20241219054535-6b8c588c3122.zip",
"http://ats.apps.svc/gomod/github.com/pingcap/errors/com_github_pingcap_errors-v0.11.5-0.20241219054535-6b8c588c3122.zip",
"https://cache.hawkingrei.com/gomod/github.com/pingcap/errors/com_github_pingcap_errors-v0.11.5-0.20241219054535-6b8c588c3122.zip",
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/pingcap/errors/com_github_pingcap_errors-v0.11.5-0.20241219054535-6b8c588c3122.zip",
"http://bazel-cache.pingcap.net:8080/gomod/github.com/pingcap/errors/com_github_pingcap_errors-v0.11.5-0.20250523034308-74f78ae071ee.zip",
"http://ats.apps.svc/gomod/github.com/pingcap/errors/com_github_pingcap_errors-v0.11.5-0.20250523034308-74f78ae071ee.zip",
"https://cache.hawkingrei.com/gomod/github.com/pingcap/errors/com_github_pingcap_errors-v0.11.5-0.20250523034308-74f78ae071ee.zip",
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/pingcap/errors/com_github_pingcap_errors-v0.11.5-0.20250523034308-74f78ae071ee.zip",
"https://proxy.golang.org/github.com/pingcap/errors/@v/v0.11.5-0.20250523034308-74f78ae071ee.zip",
],
)
go_repository(
Expand Down Expand Up @@ -5789,13 +5790,14 @@ def go_deps():
name = "com_github_pingcap_kvproto",
build_file_proto_mode = "disable_global",
importpath = "github.com/pingcap/kvproto",
sha256 = "6f2a7d747d05ae61a8f4a3c066058fa69f724480f8dc4a427d66fd066ce730c7",
strip_prefix = "github.com/pingcap/kvproto@v0.0.0-20240924080114-4a3e17f5e62d",
sha256 = "b3d04d57086652d41ad930c3359aa2f1a65cd6d8c47d7a3e360e72b7dbb1839f",
strip_prefix = "github.com/pingcap/kvproto@v0.0.0-20241216091609-64f8b30fe341",
urls = [
"http://bazel-cache.pingcap.net:8080/gomod/github.com/pingcap/kvproto/com_github_pingcap_kvproto-v0.0.0-20240924080114-4a3e17f5e62d.zip",
"http://ats.apps.svc/gomod/github.com/pingcap/kvproto/com_github_pingcap_kvproto-v0.0.0-20240924080114-4a3e17f5e62d.zip",
"https://cache.hawkingrei.com/gomod/github.com/pingcap/kvproto/com_github_pingcap_kvproto-v0.0.0-20240924080114-4a3e17f5e62d.zip",
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/pingcap/kvproto/com_github_pingcap_kvproto-v0.0.0-20240924080114-4a3e17f5e62d.zip",
"http://bazel-cache.pingcap.net:8080/gomod/github.com/pingcap/kvproto/com_github_pingcap_kvproto-v0.0.0-20241216091609-64f8b30fe341.zip",
"http://ats.apps.svc/gomod/github.com/pingcap/kvproto/com_github_pingcap_kvproto-v0.0.0-20241216091609-64f8b30fe341.zip",
"https://cache.hawkingrei.com/gomod/github.com/pingcap/kvproto/com_github_pingcap_kvproto-v0.0.0-20241216091609-64f8b30fe341.zip",
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/pingcap/kvproto/com_github_pingcap_kvproto-v0.0.0-20241216091609-64f8b30fe341.zip",
"https://proxy.golang.org/github.com/pingcap/kvproto/@v/v0.0.0-20241216091609-64f8b30fe341.zip",
],
)
go_repository(
Expand Down Expand Up @@ -6933,26 +6935,20 @@ def go_deps():
name = "com_github_tikv_client_go_v2",
build_file_proto_mode = "disable_global",
importpath = "github.com/tikv/client-go/v2",
sha256 = "c90c65a42afdadc516039343423efc126dde19faa143b86d20fee3f902715dea",
strip_prefix = "github.com/tikv/client-go/v2@v2.0.8-0.20250417032542-dfc632806f5f",
sha256 = "33407cf9792439b96ae2062a6b20233ea32c2e0907dc6baaa926cff09d68b309",
strip_prefix = "github.com/ClamChowderTiDB/client-go/v2@v2.0.8-0.20260327194506-26bf6c5f752d",
urls = [
"http://bazel-cache.pingcap.net:8080/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20250417032542-dfc632806f5f.zip",
"http://ats.apps.svc/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20250417032542-dfc632806f5f.zip",
"https://cache.hawkingrei.com/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20250417032542-dfc632806f5f.zip",
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20250417032542-dfc632806f5f.zip",
"https://proxy.golang.org/github.com/!clam!chowder!ti!d!b/client-go/v2/@v/v2.0.8-0.20260327194506-26bf6c5f752d.zip",
],
)
go_repository(
name = "com_github_tikv_pd_client",
build_file_proto_mode = "disable_global",
importpath = "github.com/tikv/pd/client",
sha256 = "8563346bf9562e5e92bde3795d68feb76d68c7967c75394b1706cfb4667c8605",
strip_prefix = "github.com/tikv/pd/client@v0.0.0-20250213080903-727c2086a763",
sha256 = "122e540d5c39eb0539948c641163abb6ac5c06462f5c1dc3b6ede570a0af62d3",
strip_prefix = "github.com/ClamChowderTiDB/pd/client@v0.0.0-20260325174811-bb159202fc25",
urls = [
"http://bazel-cache.pingcap.net:8080/gomod/github.com/tikv/pd/client/com_github_tikv_pd_client-v0.0.0-20250213080903-727c2086a763.zip",
"http://ats.apps.svc/gomod/github.com/tikv/pd/client/com_github_tikv_pd_client-v0.0.0-20250213080903-727c2086a763.zip",
"https://cache.hawkingrei.com/gomod/github.com/tikv/pd/client/com_github_tikv_pd_client-v0.0.0-20250213080903-727c2086a763.zip",
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/tikv/pd/client/com_github_tikv_pd_client-v0.0.0-20250213080903-727c2086a763.zip",
"https://proxy.golang.org/github.com/!clam!chowder!ti!d!b/pd/client/@v/v0.0.0-20260325174811-bb159202fc25.zip",
],
)
go_repository(
Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ br_unit_test: export ARGS=$$($(BR_PACKAGES))
br_unit_test:
@make failpoint-enable
@export TZ='Asia/Shanghai';
$(GOTEST) $(RACE_FLAG) -ldflags '$(LDFLAGS)' $(ARGS) -coverprofile=coverage.txt || ( make failpoint-disable && exit 1 )
$(GOTEST) --tags=deadlock,intest $(RACE_FLAG) -ldflags '$(LDFLAGS)' $(ARGS) -coverprofile=coverage.txt || ( make failpoint-disable && exit 1 )
@make failpoint-disable

.PHONY: br_unit_test_in_verify_ci
Expand All @@ -455,7 +455,7 @@ br_unit_test_in_verify_ci: tools/bin/gotestsum
@make failpoint-enable
@export TZ='Asia/Shanghai';
@mkdir -p $(TEST_COVERAGE_DIR)
CGO_ENABLED=1 tools/bin/gotestsum --junitfile "$(TEST_COVERAGE_DIR)/br-junit-report.xml" -- $(RACE_FLAG) -ldflags '$(LDFLAGS)' \
CGO_ENABLED=1 tools/bin/gotestsum --junitfile "$(TEST_COVERAGE_DIR)/br-junit-report.xml" -- --tags=deadlock,intest $(RACE_FLAG) -ldflags '$(LDFLAGS)' \
$(ARGS) -coverprofile="$(TEST_COVERAGE_DIR)/br_cov.unit_test.out" || ( make failpoint-disable && exit 1 )
@make failpoint-disable

Expand Down Expand Up @@ -624,21 +624,21 @@ bazel_test: failpoint-enable bazel_prepare
bazel $(BAZEL_GLOBAL_CONFIG) test $(BAZEL_CMD_CONFIG) --build_tests_only --test_keep_going=false \
--define gotags=deadlock,intest \
-- //... -//cmd/... -//tests/graceshutdown/... \
-//tests/globalkilltest/... -//tests/readonlytest/... -//br/pkg/task:task_test -//tests/realtikvtest/...
-//tests/globalkilltest/... -//tests/readonlytest/... -//tests/realtikvtest/...

.PHONY: bazel_coverage_test
bazel_coverage_test: failpoint-enable bazel_ci_simple_prepare
bazel $(BAZEL_GLOBAL_CONFIG) --nohome_rc coverage $(BAZEL_CMD_CONFIG) $(BAZEL_INSTRUMENTATION_FILTER) --jobs=35 --build_tests_only --test_keep_going=false \
--@io_bazel_rules_go//go/config:cover_format=go_cover --define gotags=deadlock,intest \
-- //... -//cmd/... -//tests/graceshutdown/... \
-//tests/globalkilltest/... -//tests/readonlytest/... -//br/pkg/task:task_test -//tests/realtikvtest/...
-//tests/globalkilltest/... -//tests/readonlytest/... -//tests/realtikvtest/...

.PHONY: bazel_coverage_test_ddlargsv1
bazel_coverage_test_ddlargsv1: failpoint-enable bazel_ci_simple_prepare
bazel $(BAZEL_GLOBAL_CONFIG) --nohome_rc coverage $(BAZEL_CMD_CONFIG) $(BAZEL_INSTRUMENTATION_FILTER) --jobs=35 --build_tests_only --test_keep_going=false \
--@io_bazel_rules_go//go/config:cover_format=go_cover --define gotags=deadlock,intest,ddlargsv1 \
-- //... -//cmd/... -//tests/graceshutdown/... \
-//tests/globalkilltest/... -//tests/readonlytest/... -//br/pkg/task:task_test -//tests/realtikvtest/...
-//tests/globalkilltest/... -//tests/readonlytest/... -//tests/realtikvtest/...

.PHONY: bazel_build
bazel_build:
Expand Down
13 changes: 9 additions & 4 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,15 @@ UNCONVERT_PACKAGES := $$($(UNCONVERT_PACKAGES_LIST))
FAILPOINT_ENABLE := find $$PWD/ -type d | grep -vE "(\.git|tools)" | xargs tools/bin/failpoint-ctl enable
FAILPOINT_DISABLE := find $$PWD/ -type d | grep -vE "(\.git|tools)" | xargs tools/bin/failpoint-ctl disable

LDFLAGS += -X "github.com/pingcap/tidb/pkg/parser/mysql.TiDBReleaseVersion=$(shell git describe --tags --dirty --always)"
LDFLAGS += -X "github.com/pingcap/tidb/pkg/util/versioninfo.TiDBBuildTS=$(shell date -u '+%Y-%m-%d %H:%M:%S')"
LDFLAGS += -X "github.com/pingcap/tidb/pkg/util/versioninfo.TiDBGitHash=$(shell git rev-parse HEAD)"
LDFLAGS += -X "github.com/pingcap/tidb/pkg/util/versioninfo.TiDBGitBranch=$(shell git rev-parse --abbrev-ref HEAD)"
RELEASE_VERSION := $(shell git describe --tags --dirty --always)
BUILDTS := $(shell date -u '+%Y-%m-%d %H:%M:%S')
GITHASH := $(shell git rev-parse HEAD)
GITBRANCH := $(shell git rev-parse --abbrev-ref HEAD)

LDFLAGS += -X "github.com/pingcap/tidb/pkg/parser/mysql.TiDBReleaseVersion=$(RELEASE_VERSION)"
LDFLAGS += -X "github.com/pingcap/tidb/pkg/util/versioninfo.TiDBBuildTS=$(BUILDTS)"
LDFLAGS += -X "github.com/pingcap/tidb/pkg/util/versioninfo.TiDBGitHash=$(GITHASH)"
LDFLAGS += -X "github.com/pingcap/tidb/pkg/util/versioninfo.TiDBGitBranch=$(GITBRANCH)"
LDFLAGS += -X "github.com/pingcap/tidb/pkg/util/versioninfo.TiDBEdition=$(TIDB_EDITION)"

EXTENSION_FLAG =
Expand Down
8 changes: 0 additions & 8 deletions br/cmd/br/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func runBackupCommand(command *cobra.Command, cmdName string) error {
command.SilenceUsage = false
return errors.Trace(err)
}
overrideDefaultBackupConfigIfNeeded(&cfg, command)

if err := metricsutil.RegisterMetricsForBR(cfg.PD, cfg.KeyspaceName); err != nil {
return errors.Trace(err)
Expand Down Expand Up @@ -212,10 +211,3 @@ func newTxnBackupCommand() *cobra.Command {
task.DefineTxnBackupFlags(command)
return command
}

func overrideDefaultBackupConfigIfNeeded(config *task.BackupConfig, cmd *cobra.Command) {
// override only if flag not set by user
if !cmd.Flags().Changed(task.FlagChecksum) {
config.Checksum = false
}
}
83 changes: 60 additions & 23 deletions br/cmd/br/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ const (

flagVersion = "version"
flagVersionShort = "V"

// Memory management related constants
quarterGiB uint64 = 256 * size.MB
halfGiB uint64 = 512 * size.MB
fourGiB uint64 = 4 * size.GB

// Environment variables
envBRHeapDumpDir = "BR_HEAP_DUMP_DIR"

// Default heap dump paths
defaultHeapDumpDir = "/tmp/br_heap_dumps"
)

func timestampLogFileName() string {
Expand Down Expand Up @@ -113,10 +124,6 @@ func DefineCommonFlags(cmd *cobra.Command) {
_ = cmd.PersistentFlags().MarkHidden(FlagRedactLog)
}

const quarterGiB uint64 = 256 * size.MB
const halfGiB uint64 = 512 * size.MB
const fourGiB uint64 = 4 * size.GB

func calculateMemoryLimit(memleft uint64) uint64 {
// memreserved = f(memleft) = 512MB * memleft / (memleft + 4GB)
// * f(0) = 0
Expand All @@ -132,6 +139,47 @@ func calculateMemoryLimit(memleft uint64) uint64 {
return memlimit
}

// setupMemoryMonitoring configures memory limits and starts the memory monitor.
// It returns an error if the setup fails.
func setupMemoryMonitoring(ctx context.Context, memTotal, memUsed uint64) error {
if memUsed >= memTotal {
log.Warn("failed to obtain memory size, skip setting memory limit",
zap.Uint64("memused", memUsed), zap.Uint64("memtotal", memTotal))
return nil
}

memleft := memTotal - memUsed
memlimit := calculateMemoryLimit(memleft)
// BR command needs 256 MiB at least, if the left memory is less than 256 MiB,
// the memory limit cannot limit anyway and then finally OOM.
memlimit = max(memlimit, quarterGiB)

log.Info("calculate the rest memory",
zap.Uint64("memtotal", memTotal),
zap.Uint64("memused", memUsed),
zap.Uint64("memlimit", memlimit))

// No need to set memory limit because the left memory is sufficient.
if memlimit >= uint64(math.MaxInt64) {
return nil
}

debug.SetMemoryLimit(int64(memlimit))

// Configure and start memory monitoring
dumpDir := os.Getenv(envBRHeapDumpDir)
if dumpDir == "" {
dumpDir = defaultHeapDumpDir
}

if err := utils.RunMemoryMonitor(ctx, dumpDir, memlimit); err != nil {
log.Warn("Failed to start memory monitor", zap.Error(err))
return err
}

return nil
}

// Init initializes BR cli.
func Init(cmd *cobra.Command) (err error) {
initOnce.Do(func() {
Expand Down Expand Up @@ -198,21 +246,10 @@ func Init(cmd *cobra.Command) (err error) {
err = e
return
}
if memused >= memtotal {
log.Warn("failed to obtain memory size, skip setting memory limit",
zap.Uint64("memused", memused), zap.Uint64("memtotal", memtotal))
} else {
memleft := memtotal - memused
memlimit := calculateMemoryLimit(memleft)
// BR command needs 256 MiB at least, if the left memory is less than 256 MiB,
// the memory limit cannot limit anyway and then finally OOM.
memlimit = max(memlimit, quarterGiB)
log.Info("calculate the rest memory",
zap.Uint64("memtotal", memtotal), zap.Uint64("memused", memused), zap.Uint64("memlimit", memlimit))
// No need to set memory limit because the left memory is sufficient.
if memlimit < uint64(math.MaxInt64) {
debug.SetMemoryLimit(int64(memlimit))
}

if e := setupMemoryMonitoring(GetDefaultContext(), memtotal, memused); e != nil {
// only log the error, don't fail initialization
log.Error("Failed to setup memory monitoring", zap.Error(e))
}
}

Expand All @@ -227,13 +264,13 @@ func Init(cmd *cobra.Command) (err error) {
return
}
redact.InitRedact(redactLog || redactInfoLog)
err = startPProf(cmd)
err = startStatusServer(cmd)
})
return errors.Trace(err)
}

func startPProf(cmd *cobra.Command) error {
// Initialize the pprof server.
// Initialize the metrics/pprof server.
func startStatusServer(cmd *cobra.Command) error {
statusAddr, err := cmd.Flags().GetString(FlagStatusAddr)
if err != nil {
return errors.Trace(err)
Expand All @@ -249,7 +286,7 @@ func startPProf(cmd *cobra.Command) error {
}

if statusAddr != "" {
return utils.StartPProfListener(statusAddr, tls)
return utils.StartStatusListener(statusAddr, tls)
}
utils.StartDynamicPProfListener(tls)
return nil
Expand Down
2 changes: 1 addition & 1 deletion br/cmd/br/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
func main() {
gCtx := context.Background()
ctx, cancel := utils.StartExitSingleListener(gCtx)
defer cancel()

rootCmd := &cobra.Command{
Use: "br",
Expand All @@ -34,7 +35,6 @@ func main() {

rootCmd.SetArgs(os.Args[1:])
if err := rootCmd.Execute(); err != nil {
cancel()
log.Error("br failed", zap.Error(err))
os.Exit(1) // nolint:gocritic
}
Expand Down
42 changes: 42 additions & 0 deletions br/cmd/br/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ func newOperatorCommand() *cobra.Command {
cmd.AddCommand(newPrepareForSnapshotBackupCommand(
"prepare-for-snapshot-backup",
"pause gc, schedulers and importing until the program exits, for snapshot backup."))
cmd.AddCommand(newForceFlushCommand())
cmd.AddCommand(newChecksumCommand())
return cmd
}

Expand All @@ -52,3 +54,43 @@ func newPrepareForSnapshotBackupCommand(use string, short string) *cobra.Command
operator.DefineFlagsForPrepareSnapBackup(cmd.Flags())
return cmd
}

func newChecksumCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "checksum-as",
Short: "calculate the checksum with rewrite rules",
Long: "Calculate the checksum of the current cluster (specified by `-u`) " +
"with applying the rewrite rules generated from a backup (specified by `-s`). " +
"This can be used when you have the checksum of upstream elsewhere.",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
cfg := operator.ChecksumWithRewriteRulesConfig{}
if err := cfg.ParseFromFlags(cmd.Flags()); err != nil {
return err
}
ctx := GetDefaultContext()
return operator.RunChecksumTable(ctx, tidbGlue, cfg)
},
}
task.DefineFilterFlags(cmd, []string{"!*.*"}, false)
operator.DefineFlagsForChecksumTableConfig(cmd.Flags())
return cmd
}

func newForceFlushCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "force-flush",
Short: "force a log backup task to flush",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
cfg := operator.ForceFlushConfig{}
if err := cfg.ParseFromFlags(cmd.Flags()); err != nil {
return err
}
ctx := GetDefaultContext()
return operator.RunForceFlush(ctx, &cfg)
},
}
operator.DefineFlagsForForceFlushConfig(cmd.Flags())
return cmd
}
1 change: 1 addition & 0 deletions br/pkg/restore/internal/rawkv/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//br/pkg/restore/utils",
"//pkg/metrics",
"//pkg/util/hack",
"@com_github_pingcap_errors//:errors",
"@com_github_tikv_client_go_v2//config",
Expand Down
Loading
Loading