Skip to content

Commit

Permalink
Merge branch 'master' into convert-bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jyz0309 authored Mar 2, 2021
2 parents a34c82f + 2a5aa13 commit a2ea26f
Show file tree
Hide file tree
Showing 105 changed files with 1,270 additions and 448 deletions.
2 changes: 1 addition & 1 deletion .build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ check-static: tools/bin/golangci-lint
tools/bin/golangci-lint run -v --disable-all --deadline=3m \
--enable=misspell \
--enable=ineffassign \
--enable=varcheck \
$$($(PACKAGE_DIRECTORIES))

check-slow:tools/bin/gometalinter tools/bin/gosec
Expand Down
10 changes: 7 additions & 3 deletions cmd/ddltest/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,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)

Expand Down Expand Up @@ -304,7 +304,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
}
Expand Down
8 changes: 6 additions & 2 deletions cmd/ddltest/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
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,
Expand Down
2 changes: 1 addition & 1 deletion cmd/explaintest/t/generated_columns.test
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
18 changes: 12 additions & 6 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(`
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions config/config_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

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

// CloneConf deeply clones this config.
Expand Down Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions config/config_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

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

func (s *testConfigSuite) TestCloneConf(c *C) {
Expand Down Expand Up @@ -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")
}
1 change: 0 additions & 1 deletion ddl/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ var (
errIncorrectPrefixKey = dbterror.ClassDDL.NewStd(mysql.ErrWrongSubKey)
errTooLongKey = dbterror.ClassDDL.NewStd(mysql.ErrTooLongKey)
errKeyColumnDoesNotExits = dbterror.ClassDDL.NewStd(mysql.ErrKeyColumnDoesNotExits)
errUnknownTypeLength = dbterror.ClassDDL.NewStd(mysql.ErrUnknownTypeLength)
errInvalidDDLJobVersion = dbterror.ClassDDL.NewStd(mysql.ErrInvalidDDLJobVersion)
errInvalidUseOfNull = dbterror.ClassDDL.NewStd(mysql.ErrInvalidUseOfNull)
errTooManyFields = dbterror.ClassDDL.NewStd(mysql.ErrTooManyFields)
Expand Down
19 changes: 6 additions & 13 deletions ddl/placement_sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
"sort"

. "github.com/pingcap/check"
"github.com/pingcap/failpoint"
"github.com/pingcap/parser/model"
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/ddl/placement"
"github.com/pingcap/tidb/session"
Expand Down Expand Up @@ -440,9 +440,6 @@ func (s *testDBSuite1) TestPlacementPolicyCache(c *C) {
}

func (s *testSerialDBSuite) TestTxnScopeConstraint(c *C) {
defer func() {
config.GetGlobalConfig().Labels["zone"] = ""
}()
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1")
Expand Down Expand Up @@ -569,9 +566,8 @@ PARTITION BY RANGE (c) (

for _, testcase := range testCases {
c.Log(testcase.name)
config.GetGlobalConfig().Labels = map[string]string{
"zone": testcase.zone,
}
failpoint.Enable("github.com/pingcap/tidb/config/injectTxnScope",
fmt.Sprintf(`return("%v")`, testcase.zone))
se, err := session.CreateSession4Test(s.store)
c.Check(err, IsNil)
tk.Se = se
Expand All @@ -591,6 +587,7 @@ PARTITION BY RANGE (c) (
c.Assert(err, NotNil)
c.Assert(err.Error(), Matches, testcase.err.Error())
}
failpoint.Disable("github.com/pingcap/tidb/config/injectTxnScope")
}
}

Expand Down Expand Up @@ -661,9 +658,6 @@ add placement policy
}

func (s *testSerialSuite) TestGlobalTxnState(c *C) {
defer func() {
config.GetGlobalConfig().Labels["zone"] = ""
}()
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1")
Expand Down Expand Up @@ -704,9 +698,8 @@ PARTITION BY RANGE (c) (
},
},
}
config.GetGlobalConfig().Labels = map[string]string{
"zone": "bj",
}
failpoint.Enable("github.com/pingcap/tidb/config/injectTxnScope", `return("bj")`)
defer failpoint.Disable("github.com/pingcap/tidb/config/injectTxnScope")
dbInfo := testGetSchemaByName(c, tk.Se, "test")
tk2 := testkit.NewTestKit(c, s.store)
var chkErr error
Expand Down
31 changes: 31 additions & 0 deletions docs/tidb_http_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,37 @@
}
```

If the handle is clustered, specify the primary key column values in the query string

```shell
$curl http://{TiDBIP}:10080/mvcc/key/{db}/{table}?${c1}={v1}&${c2}=${v2}
```

```shell
$curl http://127.0.0.1:10080/mvcc/key/test/t\?a\=aaa\&b\=2020-01-01
{
"key": "7480000000000000365F72016161610000000000FA0419A5420000000000",
"region_id": 52,
"value": {
"info": {
"writes": [
{
"start_ts": 423158426542538752,
"commit_ts": 423158426543587328,
"short_value": "gAACAAAAAQMDAAQAYWFhZA=="
}
],
"values": [
{
"start_ts": 423158426542538752,
"value": "gAACAAAAAQMDAAQAYWFhZA=="
}
]
}
}
}
```

1. Get MVCC Information of the first key in the table with a specified start ts

```shell
Expand Down
3 changes: 0 additions & 3 deletions domain/infosync/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ const (
// ErrPrometheusAddrIsNotSet is the error that Prometheus address is not set in PD and etcd
var ErrPrometheusAddrIsNotSet = dbterror.ClassDomain.NewStd(errno.ErrPrometheusAddrIsNotSet)

// errPlacementRulesDisabled is exported for internal usage, indicating PD rejected the request due to disabled placement feature.
var errPlacementRulesDisabled = errors.New("placement rules feature is disabled")

// InfoSyncer stores server info to etcd when the tidb-server starts and delete when tidb-server shuts down.
type InfoSyncer struct {
etcdCli *clientv3.Client
Expand Down
1 change: 1 addition & 0 deletions errno/errcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,7 @@ const (
ErrInvalidTableSample = 8128
ErrJSONObjectKeyTooLong = 8129
ErrMultiStatementDisabled = 8130
ErrBuildGlobalLevelStatsFailed = 8131

// Error codes used by TiDB ddl package
ErrUnsupportedDDLOperation = 8200
Expand Down
3 changes: 2 additions & 1 deletion errno/errname.go
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,8 @@ var MySQLErrName = map[uint16]*mysql.ErrMessage{

ErrInvalidTableSample: mysql.Message("Invalid TABLESAMPLE: %s", nil),

ErrJSONObjectKeyTooLong: mysql.Message("TiDB does not yet support JSON objects with the key length >= 65536", nil),
ErrJSONObjectKeyTooLong: mysql.Message("TiDB does not yet support JSON objects with the key length >= 65536", nil),
ErrBuildGlobalLevelStatsFailed: mysql.Message("Build global-level stats failed due to missing partition-level stats", nil),

ErrInvalidPlacementSpec: mysql.Message("Invalid placement policy '%s': %s", nil),
ErrPlacementPolicyCheck: mysql.Message("Placement policy didn't meet the constraint, reason: %s", nil),
Expand Down
5 changes: 5 additions & 0 deletions errors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1571,6 +1571,11 @@ error = '''
TiDB does not yet support JSON objects with the key length >= 65536
'''

["types:8131"]
error = '''
Build global-level stats failed due to missing partition-level stats
'''

["variable:1193"]
error = '''
Unknown system variable '%-.64s'
Expand Down
Loading

0 comments on commit a2ea26f

Please sign in to comment.