Skip to content

Commit

Permalink
Merge branch 'master' into join-reorder-dp
Browse files Browse the repository at this point in the history
  • Loading branch information
winoros committed Dec 25, 2018
2 parents 0fc7469 + 3040788 commit 373d455
Show file tree
Hide file tree
Showing 119 changed files with 3,575 additions and 2,170 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ coverage.out
*.swp
*.log
tags
temp_parser_file
y.output
profile.coverprofile
explain_test
cmd/explaintest/explain-test.out
cmd/explaintest/explaintest_tidb-server
_tools/
*.fail.go
tools/bin/
vendor
63 changes: 46 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ PACKAGES := $$($(PACKAGE_LIST))
PACKAGE_DIRECTORIES := $(PACKAGE_LIST) | sed 's|github.com/pingcap/$(PROJECT)/||'
FILES := $$(find $$($(PACKAGE_DIRECTORIES)) -name "*.go")

GOFAIL_ENABLE := $$(find $$PWD/ -type d | grep -vE "(\.git|_tools)" | xargs gofail enable)
GOFAIL_DISABLE := $$(find $$PWD/ -type d | grep -vE "(\.git|_tools)" | xargs gofail disable)
GOFAIL_ENABLE := $$(find $$PWD/ -type d | grep -vE "(\.git|tools)" | xargs gofail enable)
GOFAIL_DISABLE := $$(find $$PWD/ -type d | grep -vE "(\.git|tools)" | xargs gofail disable)

LDFLAGS += -X "github.com/pingcap/parser/mysql.TiDBReleaseVersion=$(shell git describe --tags --dirty)"
LDFLAGS += -X "github.com/pingcap/tidb/util/printer.TiDBBuildTS=$(shell date -u '+%Y-%m-%d %I:%M:%S')"
Expand Down Expand Up @@ -59,12 +59,10 @@ dev: checklist test check
build:
$(GOBUILD)

# The retool tools.json is setup from hack/retool-install.sh
check-setup:
@which retool >/dev/null 2>&1 || go get github.com/twitchtv/retool
@GO111MODULE=off retool sync
# Install the check tools.
check-setup:tools/bin/megacheck tools/bin/revive tools/bin/goword tools/bin/gometalinter tools/bin/gosec

check: check-setup fmt lint vet tidy
check: fmt errcheck lint tidy

# These need to be fixed before they can be ran regularly
check-fail: goword check-static check-slow
Expand All @@ -73,34 +71,41 @@ fmt:
@echo "gofmt (simplify)"
@gofmt -s -l -w $(FILES) 2>&1 | $(FAIL_ON_STDOUT)

goword:
retool do goword $(FILES) 2>&1 | $(FAIL_ON_STDOUT)
goword:tools/bin/goword
tools/bin/goword $(FILES) 2>&1 | $(FAIL_ON_STDOUT)

check-static:
gosec:tools/bin/gosec
tools/bin/gosec $$($(PACKAGE_DIRECTORIES))

check-static:tools/bin/gometalinter
@ # vet and fmt have problems with vendor when ran through metalinter
CGO_ENABLED=0 retool do gometalinter.v2 --disable-all --deadline 120s \
tools/bin/gometalinter --disable-all --deadline 120s \
--enable misspell \
--enable megacheck \
--enable ineffassign \
$$($(PACKAGE_DIRECTORIES))

check-slow:
CGO_ENABLED=0 retool do gometalinter.v2 --disable-all \
check-slow:tools/bin/gometalinter tools/bin/gosec
tools/bin/gometalinter --disable-all \
--enable errcheck \
$$($(PACKAGE_DIRECTORIES))
CGO_ENABLED=0 retool do gosec $$($(PACKAGE_DIRECTORIES))

lint:
errcheck:tools/bin/errcheck
@echo "errcheck"
@$(GO) mod vendor
@tools/bin/errcheck -exclude ./tools/check/errcheck_excludes.txt -blank $(PACKAGES) | grep -v "_test\.go" | awk '{print} END{if(NR>0) {exit 1}}'

lint:tools/bin/revive
@echo "linting"
@CGO_ENABLED=0 retool do revive -formatter friendly -config revive.toml $(PACKAGES)
@tools/bin/revive -formatter friendly -config tools/check/revive.toml $(FILES)

vet:
@echo "vet"
$(GO) vet -all -shadow $(PACKAGES) 2>&1 | $(FAIL_ON_STDOUT)

tidy:
@echo "go mod tidy"
./hack/check-tidy.sh
./tools/check/check-tidy.sh

clean:
$(GO) clean -i ./...
Expand Down Expand Up @@ -201,3 +206,27 @@ gofail-disable:

checkdep:
$(GO) list -f '{{ join .Imports "\n" }}' github.com/pingcap/tidb/store/tikv | grep ^github.com/pingcap/parser$$ || exit 0; exit 1

tools/bin/megacheck:
cd tools/check; \
$go build -o ../bin/megacheck honnef.co/go/tools/cmd/megacheck

tools/bin/revive:
cd tools/check; \
$(GO) build -o ../bin/revive github.com/mgechev/revive

tools/bin/goword:
cd tools/check; \
$(GO) build -o ../bin/goword github.com/chzchzchz/goword

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

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

tools/bin/errcheck:
cd tools/check; \
$(GO) build -o ../bin/errcheck github.com/kisielk/errcheck
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ jobs:
command: make dev
- run:
name: "Check go mod replace is removed"
command: ./hack/check_parser_replace.sh
command: ./tools/check/check_parser_replace.sh
2 changes: 1 addition & 1 deletion cmd/explaintest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package main
import (
"bytes"
"database/sql"
"flag"
"fmt"
"io"
"io/ioutil"
Expand All @@ -24,7 +25,6 @@ import (
"os/exec"
"strings"

"flag"
"github.com/go-sql-driver/mysql"
"github.com/pingcap/errors"
"github.com/pingcap/parser/ast"
Expand Down
2 changes: 1 addition & 1 deletion cmd/explaintest/r/select.result
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ select !(1 + 2);
!(1 + 2)
0
select + - 1, --1, +-+-+1, + "123";
+ - 1 --1 +-+-+1 + "123"
+ - 1 --1 +-+-+1 123
-1 1 1 123
select --------------------1, ++++++++++++++++++++1;
--------------------1 ++++++++++++++++++++1
Expand Down
16 changes: 13 additions & 3 deletions ddl/column_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ func (s *testColumnChangeSuite) TestColumnChange(c *C) {
row := types.MakeDatums(1, 2)
h, err := originTable.AddRecord(ctx, row, false)
c.Assert(err, IsNil)
err = ctx.Txn(true).Commit(context.Background())
txn, err := ctx.Txn(true)
c.Assert(err, IsNil)
err = txn.Commit(context.Background())
c.Assert(err, IsNil)

var mu sync.Mutex
Expand Down Expand Up @@ -127,7 +129,11 @@ func (s *testColumnChangeSuite) TestColumnChange(c *C) {
}
mu.Unlock()
}
err = hookCtx.Txn(true).Commit(context.Background())
txn, err := hookCtx.Txn(true)
if err != nil {
checkErr = errors.Trace(err)
}
err = txn.Commit(context.Background())
if err != nil {
checkErr = errors.Trace(err)
}
Expand Down Expand Up @@ -179,7 +185,11 @@ func (s *testColumnChangeSuite) testAddColumnNoDefault(c *C, ctx sessionctx.Cont
checkErr = errors.Trace(err)
}
}
err = hookCtx.Txn(true).Commit(context.TODO())
txn, err := hookCtx.Txn(true)
if err != nil {
checkErr = errors.Trace(err)
}
err = txn.Commit(context.TODO())
if err != nil {
checkErr = errors.Trace(err)
}
Expand Down
28 changes: 22 additions & 6 deletions ddl/column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,17 @@ func (s *testColumnSuite) checkColumnKVExist(ctx sessionctx.Context, t table.Tab
if err != nil {
return errors.Trace(err)
}
defer ctx.Txn(true).Commit(context.Background())
defer func() {
if txn, err1 := ctx.Txn(true); err1 == nil {
txn.Commit(context.Background())
}
}()
key := t.RecordKey(handle)
data, err := ctx.Txn(true).Get(key)
txn, err := ctx.Txn(true)
if err != nil {
return errors.Trace(err)
}
data, err := txn.Get(key)
if !isExist {
if terror.ErrorEqual(err, kv.ErrNotExist) {
return nil
Expand Down Expand Up @@ -760,7 +768,9 @@ func (s *testColumnSuite) TestAddColumn(c *C) {
handle, err := t.AddRecord(ctx, oldRow, false)
c.Assert(err, IsNil)

err = ctx.Txn(true).Commit(context.Background())
txn, err := ctx.Txn(true)
c.Assert(err, IsNil)
err = txn.Commit(context.Background())
c.Assert(err, IsNil)

newColName := "c4"
Expand Down Expand Up @@ -823,7 +833,9 @@ func (s *testColumnSuite) TestAddColumn(c *C) {
job = testDropTable(c, ctx, d, s.dbInfo, tblInfo)
testCheckJobDone(c, d, job, false)

err = ctx.Txn(true).Commit(context.Background())
txn, err = ctx.Txn(true)
c.Assert(err, IsNil)
txn.Commit(context.Background())
c.Assert(err, IsNil)

d.Stop()
Expand All @@ -847,7 +859,9 @@ func (s *testColumnSuite) TestDropColumn(c *C) {
_, err = t.AddRecord(ctx, append(row, types.NewDatum(defaultColValue)), false)
c.Assert(err, IsNil)

err = ctx.Txn(true).Commit(context.Background())
txn, err := ctx.Txn(true)
c.Assert(err, IsNil)
err = txn.Commit(context.Background())
c.Assert(err, IsNil)

checkOK := false
Expand Down Expand Up @@ -896,7 +910,9 @@ func (s *testColumnSuite) TestDropColumn(c *C) {
job = testDropTable(c, ctx, d, s.dbInfo, tblInfo)
testCheckJobDone(c, d, job, false)

err = ctx.Txn(true).Commit(context.Background())
txn, err = ctx.Txn(true)
c.Assert(err, IsNil)
err = txn.Commit(context.Background())
c.Assert(err, IsNil)

d.Stop()
Expand Down
1 change: 1 addition & 0 deletions ddl/db_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func (s *testIntegrationSuite) SetUpSuite(c *C) {
session.SetSchemaLease(s.lease)
session.SetStatsLease(0)
s.dom, err = session.BootstrapSession(s.store)
c.Assert(err, IsNil)

se, err := session.CreateSession4Test(s.store)
c.Assert(err, IsNil)
Expand Down
17 changes: 14 additions & 3 deletions ddl/db_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/pingcap/parser/model"
tmysql "github.com/pingcap/parser/mysql"
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/ddl/testutil"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/meta"
Expand Down Expand Up @@ -952,7 +953,7 @@ func (s *testIntegrationSuite) TestPartitionDropIndex(c *C) {
}
c.Assert(idx1, NotNil)

sessionExecInGoroutine(c, s.store, "drop index idx1 on partition_drop_idx;", done)
testutil.SessionExecInGoroutine(c, s.store, "drop index idx1 on partition_drop_idx;", done)
ticker := time.NewTicker(s.lease / 2)
defer ticker.Stop()
LOOP:
Expand Down Expand Up @@ -1105,7 +1106,12 @@ func backgroundExecOnJobUpdatedExported(c *C, store kv.Storage, ctx sessionctx.C
return
}
jobIDs := []int64{job.ID}
errs, err := admin.CancelJobs(hookCtx.Txn(true), jobIDs)
txn, err := hookCtx.Txn(true)
if err != nil {
checkErr = errors.Trace(err)
return
}
errs, err := admin.CancelJobs(txn, jobIDs)
if err != nil {
checkErr = errors.Trace(err)
return
Expand All @@ -1115,7 +1121,12 @@ func backgroundExecOnJobUpdatedExported(c *C, store kv.Storage, ctx sessionctx.C
checkErr = errors.Trace(errs[0])
return
}
err = hookCtx.Txn(true).Commit(context.Background())
txn, err = hookCtx.Txn(true)
if err != nil {
checkErr = errors.Trace(err)
return
}
err = txn.Commit(context.Background())
if err != nil {
checkErr = errors.Trace(err)
}
Expand Down
Loading

0 comments on commit 373d455

Please sign in to comment.