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

executor: Merge pingcap/br into pingcap/tidb with squash #2

Draft
wants to merge 39 commits into
base: clone_br_squash
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
ebb7d70
expression: Support mathematical functions pushdown to tiflash (#25596)
chAngeZhaoZhanBo Aug 5, 2021
e46d9dd
expression: Push down ADDDATE(), DATE_ADD() on String, Real types (#2…
mengxin9014 Aug 5, 2021
ce429a4
expression: support date function pushed down to tiflash (#26640)
mengxin9014 Aug 5, 2021
b974e5f
test: fix unstable test TestAnalyzeGlobalStatsWithOpts2 (#26921)
rebelice Aug 5, 2021
0398c3f
executor: add some simple tests to cover unparallel HashAgg (#26753)
wshwsh12 Aug 5, 2021
8ebf6c3
planner: avoid unnecessary optimizer warning when sql_select_limit is…
eurekaka Aug 5, 2021
3cda7d0
*: insert of invalid timestamp succeeded (#26584)
mjonss Aug 5, 2021
c08de09
planner: show binding information in explain format = 'verbose' (#26930)
Reminiscent Aug 5, 2021
072cf27
*: fix some audit log error (#26767)
tiancaiamao Aug 5, 2021
cc1f990
planner: fix update panic when update in prepare and execute (#26759)
AilinKid Aug 5, 2021
cdaf996
expression/builtin: Add tidb_decode_sql_digests function (#26787)
MyonKeminta Aug 5, 2021
1a54708
*: merge BR into TiDB (#26655)
3pointer Aug 5, 2021
2a72f87
executor: use more clever spilling strategy for HashAgg (#26922)
wshwsh12 Aug 6, 2021
fff85d0
config: put allow-expression-index to deprecatedConfig (#26933)
wjhuang2016 Aug 6, 2021
300f159
planner: logically delete the bindinfo when create the new binding (#…
Reminiscent Aug 6, 2021
a8adc4c
*: fix many leaks of the test case (#26909)
tiancaiamao Aug 6, 2021
5561c0b
expression/builtin: Add privilege check to function tidb_decode_sql_d…
MyonKeminta Aug 6, 2021
d7681ae
planner/test: fix tests for SPM (#26951)
Reminiscent Aug 6, 2021
4d9473a
expression: Add missing pbcode for functions `InetAton/InetNtoa/Inet6…
LittleFall Aug 6, 2021
8594580
Squashed 'br/' changes from cf621d7c0..1b0e54c2f
3pointer Aug 6, 2021
446e431
Merge commit '8594580a26989f5fa9bbb1f6ec9336c39b79deb6' into clone_br…
3pointer Aug 6, 2021
d7538aa
change the import path of br cmd/pkg
3pointer Aug 4, 2021
ce1a96c
change the failpoint path of br/tests
3pointer Aug 4, 2021
ed05872
change the import path of br/web br/tools
3pointer Aug 4, 2021
d5c4cc3
change the import path of tidb
3pointer Aug 4, 2021
e4a28f5
remove cycle depenence in go.mod
3pointer Aug 4, 2021
5aa33de
update Makefile
3pointer Aug 4, 2021
98ea905
change the import path after subtree update
3pointer Aug 4, 2021
a5c0eee
update go mod after merge master
3pointer Aug 4, 2021
a64daa5
fix the issue that check failed after subtree update to master
3pointer Aug 5, 2021
c9407db
remove extra space in MakeFile
3pointer Aug 5, 2021
373b996
reorder the imports pkg in br
3pointer Aug 5, 2021
0c7d3fd
update go.mod after rebase master && kvproto updated
3pointer Aug 5, 2021
121d41d
reorder go imports by tidb requirements
3pointer Aug 5, 2021
dd67d96
br: reduce sleep seconds for unit test
3pointer Aug 5, 2021
ca2b0e6
Merge branch 'master' into merge_br_squash
3pointer Aug 5, 2021
642168d
fix: backup system table
3pointer Aug 5, 2021
b4a1e9f
address comment
3pointer Aug 5, 2021
ae30f39
Merge branch 'master' into merge_br_squash
3pointer Aug 6, 2021
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
108 changes: 104 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ check-static: tools/bin/golangci-lint
tools/bin/golangci-lint run -v $$($(PACKAGE_DIRECTORIES))

unconvert:tools/bin/unconvert
@echo "unconvert check"
@GO111MODULE=on tools/bin/unconvert ./...
@echo "unconvert check(skip check the genenrated or copied code in lightning)"
@GO111MODULE=on tools/bin/unconvert $(UNCONVERT_PACKAGES)

gogenerate:
@echo "go generate ./..."
Expand Down Expand Up @@ -81,7 +81,9 @@ test: test_part_1 test_part_2

test_part_1: checklist explaintest

test_part_2: gotest gogenerate
test_part_2: gotest gogenerate br_unit_test

test_part_br: br_unit_test br_integration_test

explaintest: server_check
@cd cmd/explaintest && ./run-tests.sh -s ../../bin/tidb-server
Expand All @@ -103,7 +105,7 @@ ifeq ("$(TRAVIS_COVERAGE)", "1")
@export log_level=info; \
$(OVERALLS) -project=github.com/pingcap/tidb \
-covermode=count \
-ignore='.git,vendor,cmd,docs,tests,LICENSES' \
-ignore='.git,br,vendor,cmd,docs,tests,LICENSES' \
-concurrency=4 \
-- -coverpkg=./... \
|| { $(FAILPOINT_DISABLE); exit 1; }
Expand Down Expand Up @@ -204,6 +206,10 @@ tools/bin/errdoc-gen: tools/check/go.mod
tools/bin/golangci-lint:
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b ./tools/bin v1.41.1

tools/bin/vfsgendev: tools/check/go.mod
cd tools/check; \
$(GO) build -o ../bin/vfsgendev github.com/shurcooL/vfsgen/cmd/vfsgendev

# Usage:
#
# $ make vectorized-bench VB_FILE=Time VB_FUNC=builtinCurrentDateSig
Expand All @@ -230,3 +236,97 @@ endif
bench-daily:
cd ./session && \
go test -run TestBenchDaily --date `git log -n1 --date=unix --pretty=format:%cd` --commit `git log -n1 --pretty=format:%h` --outfile $(TO)

build_tools: build_br build_lightning build_lightning-ctl

br_web:
@cd br/web && npm install && npm run build

build_br:
CGO_ENABLED=1 $(GOBUILD) $(RACE_FLAG) -ldflags '$(TOOL_LDFLAGS) $(CHECK_FLAG)' -o $(BR_BIN) br/cmd/br/*.go

build_lightning_for_web:
CGO_ENABLED=1 $(GOBUILD) -tags dev $(RACE_FLAG) -ldflags '$(TOOL_LDFLAGS) $(CHECK_FLAG)' -o $(LIGHTNING_BIN) br/cmd/tidb-lightning/main.go

build_lightning:
CGO_ENABLED=1 $(GOBUILD) $(RACE_FLAG) -ldflags '$(TOOL_LDFLAGS) $(CHECK_FLAG)' -o $(LIGHTNING_BIN) br/cmd/tidb-lightning/main.go

build_lightning-ctl:
CGO_ENABLED=1 $(GOBUILD) $(RACE_FLAG) -ldflags '$(TOOL_LDFLAGS) $(CHECK_FLAG)' -o $(LIGHTNING_CTL_BIN) br/cmd/tidb-lightning-ctl/main.go

build_for_br_integration_test:
@make failpoint-enable
($(GOTEST) -c -cover -covermode=count \
-coverpkg=github.com/pingcap/tidb/br/... \
-o $(BR_BIN).test \
github.com/pingcap/tidb/br/cmd/br && \
$(GOTEST) -c -cover -covermode=count \
-coverpkg=github.com/pingcap/tidb/br/... \
-o $(LIGHTNING_BIN).test \
github.com/pingcap/tidb/br/cmd/tidb-lightning && \
$(GOTEST) -c -cover -covermode=count \
-coverpkg=github.com/pingcap/tidb/br/... \
-o $(LIGHTNING_CTL_BIN).test \
github.com/pingcap/tidb/br/cmd/tidb-lightning-ctl && \
$(GOBUILD) $(RACE_FLAG) -o bin/locker br/tests/br_key_locked/*.go && \
$(GOBUILD) $(RACE_FLAG) -o bin/gc br/tests/br_z_gc_safepoint/*.go && \
$(GOBUILD) $(RACE_FLAG) -o bin/oauth br/tests/br_gcs/*.go && \
$(GOBUILD) $(RACE_FLAG) -o bin/rawkv br/tests/br_rawkv/*.go && \
$(GOBUILD) $(RACE_FLAG) -o bin/parquet_gen br/tests/lightning_checkpoint_parquet/*.go \
) || (make failpoint-disable && exit 1)
@make failpoint-disable

br_unit_test: export ARGS=$$($(BR_PACKAGES))
br_unit_test:
@make failpoint-enable
$(GOTEST) $(RACE_FLAG) -tags leak $(ARGS) || ( make failpoint-disable && exit 1 )
@make failpoint-disable

br_integration_test: br_bins build_br build_for_br_integration_test
@cd br && tests/run.sh

br_compatibility_test_prepare:
@cd br && tests/run_compatible.sh prepare

br_compatibility_test:
@cd br && tests/run_compatible.sh run

# There is no FreeBSD environment for GitHub actions. So cross-compile on Linux
# but that doesn't work with CGO_ENABLED=1, so disable cgo. The reason to have
# cgo enabled on regular builds is performance.
ifeq ("$(GOOS)", "freebsd")
GOBUILD = CGO_ENABLED=0 GO111MODULE=on go build -trimpath -ldflags '$(LDFLAGS)'
endif

br_coverage:
tools/bin/gocovmerge "$(TEST_DIR)"/cov.* | grep -vE ".*.pb.go|.*__failpoint_binding__.go" > "$(TEST_DIR)/all_cov.out"
ifeq ("$(JenkinsCI)", "1")
tools/bin/goveralls -coverprofile=$(TEST_DIR)/all_cov.out -service=jenkins-ci -repotoken $(COVERALLS_TOKEN)
else
go tool cover -html "$(TEST_DIR)/all_cov.out" -o "$(TEST_DIR)/all_cov.html"
grep -F '<option' "$(TEST_DIR)/all_cov.html"
endif

# TODO: adjust bins when br integraion tests reformat.
br_bins:
@which bin/tidb-server
@which bin/tikv-server
@which bin/pd-server
@which bin/pd-ctl
@which bin/go-ycsb
@which bin/minio
@which bin/tiflash
@which bin/libtiflash_proxy.so
@which bin/cdc
@which bin/fake-gcs-server
@which bin/tikv-importer
if [ ! -d bin/flash_cluster_manager ]; then echo "flash_cluster_manager not exist"; exit 1; fi

%_generated.go: %.rl
ragel -Z -G2 -o tmp_parser.go $<
@echo '// Code generated by ragel DO NOT EDIT.' | cat - tmp_parser.go | sed 's|//line |//.... |g' > $@
@rm tmp_parser.go

data_parsers: tools/bin/vfsgendev br/pkg/lightning/mydump/parser_generated.go br_web
PATH="$(GOPATH)/bin":"$(PATH)":"$(TOOLS)" protoc -I. -I"$(GOPATH)/src" br/pkg/lightning/checkpoints/checkpointspb/file_checkpoints.proto --gogofaster_out=.
tools/bin/vfsgendev -source='"github.com/pingcap/tidb/br/pkg/lightning/web".Res' && mv res_vfsdata.go br/pkg/lightning/web/
32 changes: 31 additions & 1 deletion Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ endif
ARCH := "`uname -s`"
LINUX := "Linux"
MAC := "Darwin"
PACKAGE_LIST := go list ./...| grep -vE "cmd|github.com\/pingcap\/tidb\/tests"
PACKAGE_LIST := go list ./...| grep -vE "cmd|github.com\/pingcap\/tidb\/tests|github.com\/pingcap\/tidb\/br"
PACKAGES ?= $$($(PACKAGE_LIST))
PACKAGE_DIRECTORIES := $(PACKAGE_LIST) | sed 's|github.com/pingcap/$(PROJECT)/||'
FILES := $$(find $$($(PACKAGE_DIRECTORIES)) -name "*.go")
UNCONVERT_PACKAGES_LIST := go list ./...| grep -vE "lightning\/checkpoints|lightning\/manual|lightning\/common"
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)
Expand Down Expand Up @@ -78,3 +80,31 @@ CHECK_FLAG =
ifeq ("$(WITH_CHECK)", "1")
CHECK_FLAG = $(TEST_LDFLAGS)
endif

BR_PKG := github.com/pingcap/tidb/br
BR_PACKAGES := go list ./...| grep "github.com\/pingcap\/tidb\/br"
LIGHTNING_BIN := bin/tidb-lightning
LIGHTNING_CTL_BIN := bin/tidb-lightning-ctl
BR_BIN := bin/br
TEST_DIR := /tmp/backup_restore_test

TOOL_RELEASE_VERSION =
ifeq ($(TOOL_RELEASE_VERSION),)
TOOL_RELEASE_VERSION := v4.0.0-dev
release_version_regex := ^v4\..*$$
release_branch_regex := "^release-[0-9]\.[0-9].*$$|^HEAD$$|^.*/*tags/v[0-9]\.[0-9]\..*$$"
ifneq ($(shell git rev-parse --abbrev-ref HEAD | egrep $(release_branch_regex)),)
# If we are in release branch, try to use tag version.
ifneq ($(shell git describe --tags --dirty | egrep $(release_version_regex)),)
TOOL_RELEASE_VERSION := $(shell git describe --tags --dirty)
endif
else ifneq ($(shell git status --porcelain),)
# Add -dirty if the working tree is dirty for non release branch.
TOOL_RELEASE_VERSION := $(TOOL_RELEASE_VERSION)-dirty
endif
endif

TOOL_LDFLAGS += -X "$(BR_PKG)/pkg/version/build.ReleaseVersion=$(TOOL_RELEASE_VERSION)"
TOOL_LDFLAGS += -X "$(BR_PKG)/pkg/version/build.BuildTS=$(shell date -u '+%Y-%m-%d %I:%M:%S')"
TOOL_LDFLAGS += -X "$(BR_PKG)/pkg/version/build.GitHash=$(shell git rev-parse HEAD)"
TOOL_LDFLAGS += -X "$(BR_PKG)/pkg/version/build.GitBranch=$(shell git rev-parse --abbrev-ref HEAD)"
33 changes: 18 additions & 15 deletions bindinfo/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ func (s *testSuite) TestGlobalBinding(c *C) {
c.Check(err, IsNil)
c.Check(chk.NumRows(), Equals, 0)

_, err = tk.Exec("delete from mysql.bind_info")
_, err = tk.Exec("delete from mysql.bind_info where source != 'builtin'")
c.Assert(err, IsNil)
}
}
Expand Down Expand Up @@ -1102,6 +1102,7 @@ func (s *testSuite) TestBaselineDBLowerCase(c *C) {
// default_db should have lower case.
c.Assert(rows[0][2], Equals, "spm")
tk.MustQuery("select original_sql, default_db, status from mysql.bind_info where original_sql = 'select * from `spm` . `t`'").Check(testkit.Rows(
"select * from `spm` . `t` SPM deleted",
"select * from `spm` . `t` spm using",
))
}
Expand Down Expand Up @@ -1512,9 +1513,9 @@ func (s *testSuite) TestReloadBindings(c *C) {
tk.MustExec("create global binding for select * from t using select * from t use index(idx)")
rows := tk.MustQuery("show global bindings").Rows()
c.Assert(len(rows), Equals, 1)
rows = tk.MustQuery("select * from mysql.bind_info").Rows()
rows = tk.MustQuery("select * from mysql.bind_info where source != 'builtin'").Rows()
c.Assert(len(rows), Equals, 1)
tk.MustExec("truncate table mysql.bind_info")
tk.MustExec("delete from mysql.bind_info where source != 'builtin'")
c.Assert(s.domain.BindHandle().Update(false), IsNil)
rows = tk.MustQuery("show global bindings").Rows()
c.Assert(len(rows), Equals, 1)
Expand Down Expand Up @@ -1595,7 +1596,7 @@ func (s *testSuite) TestOutdatedInfoSchema(c *C) {
tk.MustExec("create table t(a int, b int, index idx(a))")
tk.MustExec("create global binding for select * from t using select * from t use index(idx)")
c.Assert(s.domain.BindHandle().Update(false), IsNil)
tk.MustExec("truncate table mysql.bind_info")
s.cleanBindingEnv(tk)
tk.MustExec("create global binding for select * from t using select * from t use index(idx)")
}

Expand Down Expand Up @@ -2002,11 +2003,11 @@ func (s *testSuite) TestReCreateBind(c *C) {
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int, b int, index idx(a))")

tk.MustQuery("select * from mysql.bind_info").Check(testkit.Rows())
tk.MustQuery("select * from mysql.bind_info where source != 'builtin'").Check(testkit.Rows())
tk.MustQuery("show global bindings").Check(testkit.Rows())

tk.MustExec("create global binding for select * from t using select * from t")
tk.MustQuery("select original_sql, status from mysql.bind_info").Check(testkit.Rows(
tk.MustQuery("select original_sql, status from mysql.bind_info where source != 'builtin';").Check(testkit.Rows(
"select * from `test` . `t` using",
))
rows := tk.MustQuery("show global bindings").Rows()
Expand All @@ -2015,13 +2016,15 @@ func (s *testSuite) TestReCreateBind(c *C) {
c.Assert(rows[0][3], Equals, "using")

tk.MustExec("create global binding for select * from t using select * from t")
tk.MustQuery("select original_sql, status from mysql.bind_info").Check(testkit.Rows(
"select * from `test` . `t` using",
))
rows = tk.MustQuery("show global bindings").Rows()
c.Assert(len(rows), Equals, 1)
c.Assert(rows[0][0], Equals, "select * from `test` . `t`")
c.Assert(rows[0][3], Equals, "using")

rows = tk.MustQuery("select original_sql, status from mysql.bind_info where source != 'builtin';").Rows()
c.Assert(len(rows), Equals, 2)
c.Assert(rows[0][1], Equals, "deleted")
c.Assert(rows[1][1], Equals, "using")
}

func (s *testSuite) TestExplainShowBindSQL(c *C) {
Expand All @@ -2036,10 +2039,9 @@ func (s *testSuite) TestExplainShowBindSQL(c *C) {
"select * from `test` . `t` SELECT * FROM `test`.`t` USE INDEX (`a`)",
))

tk.MustExec("explain select * from t")
tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 Using the bindSQL: SELECT * FROM `test`.`t` USE INDEX (`a`)"))
tk.MustExec("explain analyze select * from t")
tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 Using the bindSQL: SELECT * FROM `test`.`t` USE INDEX (`a`)"))
tk.MustExec("explain format = 'verbose' select * from t")
tk.MustQuery("show warnings").Check(testkit.Rows("Note 1105 Using the bindSQL: SELECT * FROM `test`.`t` USE INDEX (`a`)"))
// explain analyze do not support verbose yet.
}

func (s *testSuite) TestDMLIndexHintBind(c *C) {
Expand Down Expand Up @@ -2097,8 +2099,9 @@ func (s *testSuite) TestConcurrentCapture(c *C) {
tk.MustExec("select * from t")
tk.MustExec("select * from t")
tk.MustExec("admin capture bindings")
tk.MustQuery("select original_sql, source from mysql.bind_info where source != 'builtin'").Check(testkit.Rows(
"select * from `test` . `t` capture",
tk.MustQuery("select original_sql, source, status from mysql.bind_info where source != 'builtin'").Check(testkit.Rows(
"select * from `test` . `t` manual deleted",
"select * from `test` . `t` capture using",
))
}

Expand Down
20 changes: 14 additions & 6 deletions bindinfo/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (h *BindHandle) Update(fullLoad bool) (err error) {

exec := h.sctx.Context.(sqlexec.RestrictedSQLExecutor)
stmt, err := exec.ParseWithParams(context.TODO(), `SELECT original_sql, bind_sql, default_db, status, create_time, update_time, charset, collation, source
FROM mysql.bind_info WHERE update_time > %? ORDER BY update_time`, updateTime)
FROM mysql.bind_info WHERE update_time > %? ORDER BY update_time, create_time`, updateTime)
if err != nil {
return err
}
Expand Down Expand Up @@ -218,14 +218,16 @@ func (h *BindHandle) CreateBindRecord(sctx sessionctx.Context, record *BindRecor
if err = h.lockBindInfoTable(); err != nil {
return err
}
// Binding recreation should physically delete previous bindings.
_, err = exec.ExecuteInternal(context.TODO(), `DELETE FROM mysql.bind_info WHERE original_sql = %?`, record.OriginalSQL)

now := types.NewTime(types.FromGoTime(time.Now()), mysql.TypeTimestamp, 3)

updateTs := now.String()
_, err = exec.ExecuteInternal(context.TODO(), `UPDATE mysql.bind_info SET status = %?, update_time = %? WHERE original_sql = %? AND update_time < %?`,
deleted, updateTs, record.OriginalSQL, updateTs)
if err != nil {
return err
}

now := types.NewTime(types.FromGoTime(time.Now()), mysql.TypeTimestamp, 3)

for i := range record.Bindings {
record.Bindings[i].CreateTime = now
record.Bindings[i].UpdateTime = now
Expand Down Expand Up @@ -697,7 +699,13 @@ func getHintsForSQL(sctx sessionctx.Context, sql string) (string, error) {
rs, err := sctx.(sqlexec.SQLExecutor).ExecuteInternal(context.TODO(), fmt.Sprintf("EXPLAIN FORMAT='hint' %s", sql))
sctx.GetSessionVars().UsePlanBaselines = origVals
if rs != nil {
defer terror.Call(rs.Close)
defer func() {
// Audit log is collected in Close(), set InRestrictedSQL to avoid 'create sql binding' been recorded as 'explain'.
origin := sctx.GetSessionVars().InRestrictedSQL
sctx.GetSessionVars().InRestrictedSQL = true
terror.Call(rs.Close)
sctx.GetSessionVars().InRestrictedSQL = origin
}()
}
if err != nil {
return "", err
Expand Down
Loading