Skip to content

Commit

Permalink
Merge branch 'master' into issue-26743
Browse files Browse the repository at this point in the history
  • Loading branch information
tisonkun committed Aug 6, 2021
2 parents 1ea7c19 + 312ec6c commit 94f5c7b
Show file tree
Hide file tree
Showing 945 changed files with 127,651 additions and 676 deletions.
44 changes: 44 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
run:
timeout: 6m
linters:
disable-all: true
enable:
- misspell
- ineffassign
- typecheck
- varcheck
- unused
- structcheck
- deadcode
- gosimple
- goimports
- errcheck
- staticcheck
- stylecheck
- gosec
linters-settings:
staticcheck:
checks: ["S1002","S1004","S1007","S1009","S1010","S1012","S1019","S1020","S1021","S1024","S1030","SA2*","SA3*","SA4009","SA5*","SA6000","SA6001","SA6005", "-SA2002"]
stylecheck:
checks: ["-ST1003"]
gosec:
excludes:
- G107
- G108
- G110
- G306
- G401
- G402
- G403
- G404
- G501
- G502
- G505
- G601

issues:
exclude-rules:
- path: _test\.go
linters:
- errcheck
- gosec
155 changes: 107 additions & 48 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,9 @@ parser:
dev: checklist check test

# Install the check tools.
check-setup:tools/bin/revive tools/bin/goword tools/bin/gometalinter tools/bin/gosec
check-setup:tools/bin/revive tools/bin/goword

check: fmt errcheck unconvert lint tidy testSuite check-static vet staticcheck errdoc

# These need to be fixed before they can be ran regularly
check-fail: goword check-slow
check: fmt unconvert lint tidy testSuite check-static vet errdoc

fmt:
@echo "gofmt (simplify)"
Expand All @@ -44,34 +41,12 @@ fmt:
goword:tools/bin/goword
tools/bin/goword $(FILES) 2>&1 | $(FAIL_ON_STDOUT)

gosec:tools/bin/gosec
tools/bin/gosec $$($(PACKAGE_DIRECTORIES))

check-static: tools/bin/golangci-lint
tools/bin/golangci-lint run -v --disable-all --deadline=3m \
--enable=misspell \
--enable=ineffassign \
--enable=typecheck \
--enable=varcheck \
--enable=unused \
--enable=structcheck \
--enable=deadcode \
--enable=gosimple \
--enable=goimports \
$$($(PACKAGE_DIRECTORIES))

check-slow:tools/bin/gometalinter tools/bin/gosec
tools/bin/gometalinter --disable-all \
--enable errcheck \
$$($(PACKAGE_DIRECTORIES))

errcheck:tools/bin/errcheck
@echo "errcheck"
@GO111MODULE=on tools/bin/errcheck -exclude ./tools/check/errcheck_excludes.txt -ignoretests -blank $(PACKAGES)
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 All @@ -89,10 +64,6 @@ vet:
@echo "vet"
$(GO) vet -all $(PACKAGES) 2>&1 | $(FAIL_ON_STDOUT)

staticcheck:
$(GO) get honnef.co/go/tools/cmd/staticcheck
$(STATICCHECK) ./...

tidy:
@echo "go mod tidy"
./tools/check/check-tidy.sh
Expand All @@ -110,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 @@ -132,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 @@ -218,18 +191,6 @@ tools/bin/goword: tools/check/go.mod
cd tools/check; \
$(GO) build -o ../bin/goword github.com/chzchzchz/goword

tools/bin/gometalinter: tools/check/go.mod
cd tools/check; \
$(GO) build -o ../bin/gometalinter gopkg.in/alecthomas/gometalinter.v3

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

tools/bin/errcheck: tools/check/go.mod
cd tools/check; \
$(GO) build -o ../bin/errcheck github.com/kisielk/errcheck

tools/bin/unconvert: tools/check/go.mod
cd tools/check; \
$(GO) build -o ../bin/unconvert github.com/mdempsky/unconvert
Expand All @@ -245,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 @@ -271,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
Loading

0 comments on commit 94f5c7b

Please sign in to comment.