Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into set-with-memory
Browse files Browse the repository at this point in the history
  • Loading branch information
wshwsh12 committed Mar 3, 2021
2 parents 83a26ce + 5b12f92 commit 10701a5
Showing 211 changed files with 2,930 additions and 1,832 deletions.
2 changes: 1 addition & 1 deletion .build.ps1
Original file line number Diff line number Diff line change
@@ -154,7 +154,7 @@ task DownloadLinter -If (-not (Test-Path $tools.Linter.Path)) {
}

task RunLinter DownloadLinter, {
exec { & $tools.Linter.Path run -v --disable-all --deadline=3m --enable=misspell --enable=ineffassign $directories }
exec { & $tools.Linter.Path run -v --disable-all --deadline=3m --enable=misspell --enable=ineffassign --enable=varcheck $directories }
}

task GoModTidy {
8 changes: 0 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -52,15 +52,7 @@ check-static: tools/bin/golangci-lint
tools/bin/golangci-lint run -v --disable-all --deadline=3m \
--enable=misspell \
--enable=ineffassign \
--enable=deadcode \
--enable=errcheck \
--enable=gosimple \
--enable=staticcheck \
--enable=typecheck \
--enable=unused \
--enable=varcheck \
--enable=structcheck \
--new-from-rev=HEAD~50 \
$$($(PACKAGE_DIRECTORIES))

check-slow:tools/bin/gometalinter tools/bin/gosec
154 changes: 77 additions & 77 deletions bindinfo/bind_test.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ version: 2
jobs:
build:
docker:
- image: golang:1.15
- image: golang:1.16
working_directory: /go/src/github.com/pingcap/tidb
steps:
- checkout
5 changes: 3 additions & 2 deletions cmd/ddltest/column_test.go
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@ import (
plannercore "github.com/pingcap/tidb/planner/core"
"github.com/pingcap/tidb/session"
"github.com/pingcap/tidb/table"
"github.com/pingcap/tidb/table/tables"
"github.com/pingcap/tidb/types"
log "github.com/sirupsen/logrus"
goctx "golang.org/x/net/context"
@@ -42,7 +43,7 @@ func (s *TestDDLSuite) checkAddColumn(c *C, rowID int64, defaultVal interface{},
newInsertCount := int64(0)
oldUpdateCount := int64(0)
newUpdateCount := int64(0)
err = tbl.IterRecords(ctx, tbl.FirstKey(), tbl.Cols(), func(_ kv.Handle, data []types.Datum, cols []*table.Column) (bool, error) {
err = tables.IterRecords(tbl, ctx, tbl.Cols(), func(_ kv.Handle, data []types.Datum, cols []*table.Column) (bool, error) {
col1Val := data[0].GetValue()
col2Val := data[1].GetValue()
col3Val := data[2].GetValue()
@@ -93,7 +94,7 @@ func (s *TestDDLSuite) checkDropColumn(c *C, rowID int64, alterColumn *table.Col
}
insertCount := int64(0)
updateCount := int64(0)
err = tbl.IterRecords(ctx, tbl.FirstKey(), tbl.Cols(), func(_ kv.Handle, data []types.Datum, cols []*table.Column) (bool, error) {
err = tables.IterRecords(tbl, ctx, tbl.Cols(), func(_ kv.Handle, data []types.Datum, cols []*table.Column) (bool, error) {
if reflect.DeepEqual(data[1].GetValue(), data[0].GetValue()) {
// Check inserted row.
insertCount++
27 changes: 16 additions & 11 deletions cmd/ddltest/ddl_test.go
Original file line number Diff line number Diff line change
@@ -43,6 +43,7 @@ import (
"github.com/pingcap/tidb/store"
tidbdriver "github.com/pingcap/tidb/store/driver"
"github.com/pingcap/tidb/table"
"github.com/pingcap/tidb/table/tables"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/logutil"
"github.com/pingcap/tidb/util/testkit"
@@ -97,11 +98,11 @@ type TestDDLSuite struct {
}

func (s *TestDDLSuite) SetUpSuite(c *C) {
logutil.InitLogger(&logutil.LogConfig{Config: zaplog.Config{Level: *logLevel}})
err := logutil.InitLogger(&logutil.LogConfig{Config: zaplog.Config{Level: *logLevel}})
c.Assert(err, IsNil)

s.quit = make(chan struct{})

var err error
s.store, err = store.New(fmt.Sprintf("tikv://%s%s", *etcd, *tikvPath))
c.Assert(err, IsNil)

@@ -304,7 +305,11 @@ func (s *TestDDLSuite) startServer(i int, fp *os.File) (*server, error) {
}
log.Warnf("ping addr %v failed, retry count %d err %v", addr, i, err)

db.Close()
err = db.Close()
if err != nil {
log.Warnf("close db failed, retry count %d err %v", i, err)
break
}
time.Sleep(sleepTime)
sleepTime += sleepTime
}
@@ -600,7 +605,7 @@ func (s *TestDDLSuite) TestSimpleInsert(c *C) {

tbl := s.getTable(c, "test_insert")
handles := kv.NewHandleMap()
err = tbl.IterRecords(ctx, tbl.FirstKey(), tbl.Cols(), func(h kv.Handle, data []types.Datum, cols []*table.Column) (bool, error) {
err = tables.IterRecords(tbl, ctx, tbl.Cols(), func(h kv.Handle, data []types.Datum, cols []*table.Column) (bool, error) {
handles.Set(h, struct{}{})
c.Assert(data[0].GetValue(), Equals, data[1].GetValue())
return true, nil
@@ -651,7 +656,7 @@ func (s *TestDDLSuite) TestSimpleConflictInsert(c *C) {

tbl := s.getTable(c, tblName)
handles := kv.NewHandleMap()
err = tbl.IterRecords(ctx, tbl.FirstKey(), tbl.Cols(), func(h kv.Handle, data []types.Datum, cols []*table.Column) (bool, error) {
err = tables.IterRecords(tbl, ctx, tbl.Cols(), func(h kv.Handle, data []types.Datum, cols []*table.Column) (bool, error) {
handles.Set(h, struct{}{})
c.Assert(keysMap, HasKey, data[0].GetValue())
c.Assert(data[0].GetValue(), Equals, data[1].GetValue())
@@ -704,7 +709,7 @@ func (s *TestDDLSuite) TestSimpleUpdate(c *C) {

tbl := s.getTable(c, tblName)
handles := kv.NewHandleMap()
err = tbl.IterRecords(ctx, tbl.FirstKey(), tbl.Cols(), func(h kv.Handle, data []types.Datum, cols []*table.Column) (bool, error) {
err = tables.IterRecords(tbl, ctx, tbl.Cols(), func(h kv.Handle, data []types.Datum, cols []*table.Column) (bool, error) {
handles.Set(h, struct{}{})
key := data[0].GetInt64()
c.Assert(data[1].GetValue(), Equals, keysMap[key])
@@ -777,7 +782,7 @@ func (s *TestDDLSuite) TestSimpleConflictUpdate(c *C) {

tbl := s.getTable(c, tblName)
handles := kv.NewHandleMap()
err = tbl.IterRecords(ctx, tbl.FirstKey(), tbl.Cols(), func(h kv.Handle, data []types.Datum, cols []*table.Column) (bool, error) {
err = tables.IterRecords(tbl, ctx, tbl.Cols(), func(h kv.Handle, data []types.Datum, cols []*table.Column) (bool, error) {
handles.Set(h, struct{}{})
c.Assert(keysMap, HasKey, data[0].GetValue())

@@ -827,7 +832,7 @@ func (s *TestDDLSuite) TestSimpleDelete(c *C) {

tbl := s.getTable(c, tblName)
handles := kv.NewHandleMap()
err = tbl.IterRecords(ctx, tbl.FirstKey(), tbl.Cols(), func(h kv.Handle, data []types.Datum, cols []*table.Column) (bool, error) {
err = tables.IterRecords(tbl, ctx, tbl.Cols(), func(h kv.Handle, data []types.Datum, cols []*table.Column) (bool, error) {
handles.Set(h, struct{}{})
return true, nil
})
@@ -897,7 +902,7 @@ func (s *TestDDLSuite) TestSimpleConflictDelete(c *C) {

tbl := s.getTable(c, tblName)
handles := kv.NewHandleMap()
err = tbl.IterRecords(ctx, tbl.FirstKey(), tbl.Cols(), func(h kv.Handle, data []types.Datum, cols []*table.Column) (bool, error) {
err = tables.IterRecords(tbl, ctx, tbl.Cols(), func(h kv.Handle, data []types.Datum, cols []*table.Column) (bool, error) {
handles.Set(h, struct{}{})
c.Assert(keysMap, HasKey, data[0].GetValue())
return true, nil
@@ -967,7 +972,7 @@ func (s *TestDDLSuite) TestSimpleMixed(c *C) {
tbl := s.getTable(c, tblName)
updateCount := int64(0)
insertCount := int64(0)
err = tbl.IterRecords(ctx, tbl.FirstKey(), tbl.Cols(), func(_ kv.Handle, data []types.Datum, cols []*table.Column) (bool, error) {
err = tables.IterRecords(tbl, ctx, tbl.Cols(), func(_ kv.Handle, data []types.Datum, cols []*table.Column) (bool, error) {
if reflect.DeepEqual(data[1].GetValue(), data[0].GetValue()) {
insertCount++
} else if reflect.DeepEqual(data[1].GetValue(), defaultValue) && data[0].GetInt64() < int64(rowCount) {
@@ -1037,7 +1042,7 @@ func (s *TestDDLSuite) TestSimpleInc(c *C) {
c.Assert(err, IsNil)

tbl := s.getTable(c, "test_inc")
err = tbl.IterRecords(ctx, tbl.FirstKey(), tbl.Cols(), func(_ kv.Handle, data []types.Datum, cols []*table.Column) (bool, error) {
err = tables.IterRecords(tbl, ctx, tbl.Cols(), func(_ kv.Handle, data []types.Datum, cols []*table.Column) (bool, error) {
if reflect.DeepEqual(data[0].GetValue(), int64(0)) {
if *enableRestart {
c.Assert(data[1].GetValue(), GreaterEqual, int64(rowCount))
10 changes: 7 additions & 3 deletions cmd/ddltest/index_test.go
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ func (s *TestDDLSuite) checkAddIndex(c *C, indexInfo *model.IndexInfo) {

// read handles form table
handles := kv.NewHandleMap()
err = tbl.IterRecords(ctx, tbl.FirstKey(), tbl.Cols(),
err = tables.IterRecords(tbl, ctx, tbl.Cols(),
func(h kv.Handle, data []types.Datum, cols []*table.Column) (bool, error) {
handles.Set(h, struct{}{})
return true, nil
@@ -64,7 +64,8 @@ func (s *TestDDLSuite) checkAddIndex(c *C, indexInfo *model.IndexInfo) {
txn, err := ctx.Txn(false)
c.Assert(err, IsNil)
defer func() {
txn.Rollback()
err = txn.Rollback()
c.Assert(err, IsNil)
}()

it, err := idx.SeekFirst(txn)
@@ -103,7 +104,10 @@ func (s *TestDDLSuite) checkDropIndex(c *C, indexInfo *model.IndexInfo) {
c.Assert(err, IsNil)
txn, err := ctx.Txn(false)
c.Assert(err, IsNil)
defer txn.Rollback()
defer func(){
err := txn.Rollback()
c.Assert(err, IsNil)
}()

it, err := idx.SeekFirst(txn)
c.Assert(err, IsNil)
2 changes: 1 addition & 1 deletion cmd/explaintest/r/generated_columns.result
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set @@tidb_partition_prune_mode='dynamic-only';
set @@tidb_partition_prune_mode='dynamic';
DROP TABLE IF EXISTS person;
CREATE TABLE person (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
2 changes: 1 addition & 1 deletion cmd/explaintest/t/generated_columns.test
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
-- Most of the cases are ported from other tests to make sure generated columns behaves the same.

-- Stored generated columns as indices
set @@tidb_partition_prune_mode='dynamic-only';
set @@tidb_partition_prune_mode='dynamic';

DROP TABLE IF EXISTS person;
CREATE TABLE person (
8 changes: 0 additions & 8 deletions config/config.toml.example
Original file line number Diff line number Diff line change
@@ -417,14 +417,6 @@ store-liveness-timeout = "5s"
# If the size(in byte) of a transaction is large than `ttl-refreshed-txn-size`, it update the lock TTL during the 2PC.
ttl-refreshed-txn-size = 33554432

[tikv-client.async-commit]
# The maximum allowed keys in an async commit transaction. Transactions with more keys than the limit
# will be committed with normal 2PC way.
keys-limit = 256
# The maximum length total of keys in bytes. Transactions will be committed with the normal 2PC way
# if the limit is exceeded.
total-key-size-limit = 4096

[tikv-client.copr-cache]
# Whether to enable the copr cache. The copr cache saves the result from TiKV Coprocessor in the memory and
# reuses the result when corresponding data in TiKV is unchanged, on a region basis.
18 changes: 12 additions & 6 deletions config/config_test.go
Original file line number Diff line number Diff line change
@@ -108,8 +108,10 @@ func (s *testConfigSuite) TestLogConfig(c *C) {
c.Assert(conf.Log.EnableTimestamp, Equals, expectedEnableTimestamp)
c.Assert(conf.Log.DisableTimestamp, Equals, expectedDisableTimestamp)
c.Assert(conf.Log.ToLogConfig(), DeepEquals, logutil.NewLogConfig("info", "text", "tidb-slow.log", conf.Log.File, resultedDisableTimestamp, func(config *zaplog.Config) { config.DisableErrorVerbose = resultedDisableErrorVerbose }))
f.Truncate(0)
f.Seek(0, 0)
err := f.Truncate(0)
c.Assert(err, IsNil)
_, err = f.Seek(0, 0)
c.Assert(err, IsNil)
}

testLoad(`
@@ -174,8 +176,10 @@ unrecognized-option-test = true
c.Assert(conf.Load(configFile), ErrorMatches, "(?:.|\n)*invalid configuration option(?:.|\n)*")
c.Assert(conf.MaxServerConnections, Equals, uint32(0))

f.Truncate(0)
f.Seek(0, 0)
err = f.Truncate(0)
c.Assert(err, IsNil)
_, err = f.Seek(0, 0)
c.Assert(err, IsNil)

_, err = f.WriteString(`
token-limit = 0
@@ -286,8 +290,10 @@ log-rotate = true`)

// Test telemetry config default value and whether it will be overwritten.
conf = NewConfig()
f.Truncate(0)
f.Seek(0, 0)
err = f.Truncate(0)
c.Assert(err, IsNil)
_, err = f.Seek(0, 0)
c.Assert(err, IsNil)
c.Assert(f.Sync(), IsNil)
c.Assert(conf.Load(configFile), IsNil)
c.Assert(conf.EnableTelemetry, Equals, true)
8 changes: 8 additions & 0 deletions config/config_util.go
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ import (

"github.com/BurntSushi/toml"
"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
)

// CloneConf deeply clones this config.
@@ -161,6 +162,13 @@ const (

// GetTxnScopeFromConfig extracts @@txn_scope value from config
func GetTxnScopeFromConfig() (bool, string) {
failpoint.Inject("injectTxnScope", func(val failpoint.Value) {
v := val.(string)
if len(v) > 0 {
failpoint.Return(false, v)
}
failpoint.Return(true, globalTxnScope)
})
v, ok := GetGlobalConfig().Labels["zone"]
if ok && len(v) > 0 {
return false, v
10 changes: 7 additions & 3 deletions config/config_util_test.go
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ import (

"github.com/BurntSushi/toml"
. "github.com/pingcap/check"
"github.com/pingcap/failpoint"
)

func (s *testConfigSuite) TestCloneConf(c *C) {
@@ -170,16 +171,19 @@ engines = ["tikv", "tiflash", "tidb"]
}

func (s *testConfigSuite) TestTxnScopeValue(c *C) {
GetGlobalConfig().Labels["zone"] = "bj"
failpoint.Enable("github.com/pingcap/tidb/config/injectTxnScope", `return("bj")`)
isGlobal, v := GetTxnScopeFromConfig()
c.Assert(isGlobal, IsFalse)
c.Assert(v, Equals, "bj")
GetGlobalConfig().Labels["zone"] = ""
failpoint.Disable("github.com/pingcap/tidb/config/injectTxnScope")
failpoint.Enable("github.com/pingcap/tidb/config/injectTxnScope", `return("")`)
isGlobal, v = GetTxnScopeFromConfig()
c.Assert(isGlobal, IsTrue)
c.Assert(v, Equals, "global")
GetGlobalConfig().Labels["zone"] = "global"
failpoint.Disable("github.com/pingcap/tidb/config/injectTxnScope")
failpoint.Enable("github.com/pingcap/tidb/config/injectTxnScope", `return("global")`)
isGlobal, v = GetTxnScopeFromConfig()
c.Assert(isGlobal, IsFalse)
c.Assert(v, Equals, "global")
failpoint.Disable("github.com/pingcap/tidb/config/injectTxnScope")
}
2 changes: 1 addition & 1 deletion ddl/backfilling.go
Original file line number Diff line number Diff line change
@@ -690,7 +690,7 @@ func iterateSnapshotRows(store kv.Storage, priority int, t table.Table, version
if err != nil {
return errors.Trace(err)
}
rk := t.RecordKey(handle)
rk := tablecodec.EncodeRecordKey(t.RecordPrefix(), handle)

more, err := fn(handle, rk, it.Value())
if !more || err != nil {
Loading

0 comments on commit 10701a5

Please sign in to comment.