Skip to content

Commit

Permalink
Merge branch 'master' into issue23897
Browse files Browse the repository at this point in the history
  • Loading branch information
wshwsh12 authored Jun 10, 2021
2 parents ebc9264 + 0ed8eaf commit 8cf7932
Show file tree
Hide file tree
Showing 559 changed files with 39,091 additions and 9,950 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# limitations under the License.

# Builder image
FROM golang:1.13-alpine as builder
FROM golang:1.16-alpine as builder

RUN apk add --no-cache \
wget \
Expand Down
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ check-static: tools/bin/golangci-lint
--enable=unused \
--enable=structcheck \
--enable=deadcode \
--enable=gosimple \
$$($(PACKAGE_DIRECTORIES))

check-slow:tools/bin/gometalinter tools/bin/gosec
Expand Down Expand Up @@ -238,11 +239,13 @@ tools/bin/unconvert: tools/check/go.mod
cd tools/check; \
$(GO) build -o ../bin/unconvert github.com/mdempsky/unconvert

tools/bin/failpoint-ctl: go.mod
$(GO) build -o $@ github.com/pingcap/failpoint/failpoint-ctl
tools/bin/failpoint-ctl: tools/check/go.mod
cd tools/check; \
$(GO) build -o ../bin/failpoint-ctl github.com/pingcap/failpoint/failpoint-ctl

tools/bin/errdoc-gen: go.mod
$(GO) build -o $@ github.com/pingcap/errors/errdoc-gen
tools/bin/errdoc-gen: tools/check/go.mod
cd tools/check; \
$(GO) build -o ../bin/errdoc-gen github.com/pingcap/errors/errdoc-gen

tools/bin/golangci-lint:
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b ./tools/bin v1.29.0
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ In addition, you may enjoy following:
- [@PingCAP](https://twitter.com/PingCAP) on Twitter
- Question tagged [#tidb on StackOverflow](https://stackoverflow.com/questions/tagged/tidb)
- The PingCAP Team [English Blog](https://en.pingcap.com/blog) and [Chinese Blog](https://pingcap.com/blog-cn/)
- [TiDB Monthly](https://pingcap.com/weekly/)

For support, please contact [PingCAP](http://bit.ly/contact_us_via_github).

Expand Down
14 changes: 10 additions & 4 deletions bindinfo/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/pingcap/tidb/metrics"
plannercore "github.com/pingcap/tidb/planner/core"
"github.com/pingcap/tidb/session"
"github.com/pingcap/tidb/session/txninfo"
"github.com/pingcap/tidb/store/mockstore"
"github.com/pingcap/tidb/store/tikv/mockstore/cluster"
"github.com/pingcap/tidb/util"
Expand Down Expand Up @@ -70,6 +71,10 @@ type mockSessionManager struct {
PS []*util.ProcessInfo
}

func (msm *mockSessionManager) ShowTxnList() []*txninfo.TxnInfo {
panic("unimplemented!")
}

func (msm *mockSessionManager) ShowProcessList() map[uint64]*util.ProcessInfo {
ret := make(map[uint64]*util.ProcessInfo)
for _, item := range msm.PS {
Expand Down Expand Up @@ -151,7 +156,8 @@ func normalizeWithDefaultDB(c *C, sql, db string) (string, string) {
testParser := parser.New()
stmt, err := testParser.ParseOneStmt(sql, "", "")
c.Assert(err, IsNil)
return parser.NormalizeDigest(utilparser.RestoreWithDefaultDB(stmt, "test", ""))
normalized, digest := parser.NormalizeDigest(utilparser.RestoreWithDefaultDB(stmt, "test", ""))
return normalized, digest.String()
}

func (s *testSuite) TestBindParse(c *C) {
Expand All @@ -177,7 +183,7 @@ func (s *testSuite) TestBindParse(c *C) {
c.Check(bindHandle.Size(), Equals, 1)

sql, hash := parser.NormalizeDigest("select * from test . t")
bindData := bindHandle.GetBindRecord(hash, sql, "test")
bindData := bindHandle.GetBindRecord(hash.String(), sql, "test")
c.Check(bindData, NotNil)
c.Check(bindData.OriginalSQL, Equals, "select * from `test` . `t`")
bind := bindData.Bindings[0]
Expand Down Expand Up @@ -651,7 +657,7 @@ func (s *testSuite) TestBindingSymbolList(c *C) {
// Normalize
sql, hash := parser.NormalizeDigest("select a, b from test . t where a = 1 limit 0, 1")

bindData := s.domain.BindHandle().GetBindRecord(hash, sql, "test")
bindData := s.domain.BindHandle().GetBindRecord(hash.String(), sql, "test")
c.Assert(bindData, NotNil)
c.Check(bindData.OriginalSQL, Equals, "select `a` , `b` from `test` . `t` where `a` = ? limit ...")
bind := bindData.Bindings[0]
Expand Down Expand Up @@ -771,7 +777,7 @@ func (s *testSuite) TestErrorBind(c *C) {
c.Assert(err, IsNil, Commentf("err %v", err))

sql, hash := parser.NormalizeDigest("select * from test . t where i > ?")
bindData := s.domain.BindHandle().GetBindRecord(hash, sql, "test")
bindData := s.domain.BindHandle().GetBindRecord(hash.String(), sql, "test")
c.Check(bindData, NotNil)
c.Check(bindData.OriginalSQL, Equals, "select * from `test` . `t` where `i` > ?")
bind := bindData.Bindings[0]
Expand Down
12 changes: 6 additions & 6 deletions bindinfo/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (h *BindHandle) CreateBindRecord(sctx sessionctx.Context, record *BindRecor
}

sqlDigest := parser.DigestNormalized(record.OriginalSQL)
h.setBindRecord(sqlDigest, record)
h.setBindRecord(sqlDigest.String(), record)
}()

// Lock mysql.bind_info to synchronize with CreateBindRecord / AddBindRecord / DropBindRecord on other tidb instances.
Expand Down Expand Up @@ -256,7 +256,7 @@ func (h *BindHandle) AddBindRecord(sctx sessionctx.Context, record *BindRecord)
}

record.Db = strings.ToLower(record.Db)
oldRecord := h.GetBindRecord(parser.DigestNormalized(record.OriginalSQL), record.OriginalSQL, record.Db)
oldRecord := h.GetBindRecord(parser.DigestNormalized(record.OriginalSQL).String(), record.OriginalSQL, record.Db)
var duplicateBinding *Binding
if oldRecord != nil {
binding := oldRecord.FindBinding(record.Bindings[0].ID)
Expand Down Expand Up @@ -294,7 +294,7 @@ func (h *BindHandle) AddBindRecord(sctx sessionctx.Context, record *BindRecord)
return
}

h.appendBindRecord(parser.DigestNormalized(record.OriginalSQL), record)
h.appendBindRecord(parser.DigestNormalized(record.OriginalSQL).String(), record)
}()

// Lock mysql.bind_info to synchronize with CreateBindRecord / AddBindRecord / DropBindRecord on other tidb instances.
Expand Down Expand Up @@ -367,7 +367,7 @@ func (h *BindHandle) DropBindRecord(originalSQL, db string, binding *Binding) (e
if binding != nil {
record.Bindings = append(record.Bindings, *binding)
}
h.removeBindRecord(parser.DigestNormalized(originalSQL), record)
h.removeBindRecord(parser.DigestNormalized(originalSQL).String(), record)
}()

// Lock mysql.bind_info to synchronize with CreateBindRecord / AddBindRecord / DropBindRecord on other tidb instances.
Expand Down Expand Up @@ -515,7 +515,7 @@ func (h *BindHandle) newBindRecord(row chunk.Row) (string, *BindRecord, error) {
defer h.sctx.Unlock()
h.sctx.GetSessionVars().CurrentDB = bindRecord.Db
err := bindRecord.prepareHints(h.sctx.Context)
return hash, bindRecord, err
return hash.String(), bindRecord, err
}

// setBindRecord sets the BindRecord to the cache, if there already exists a BindRecord,
Expand Down Expand Up @@ -624,7 +624,7 @@ func (h *BindHandle) CaptureBaselines() {
}
dbName := utilparser.GetDefaultDB(stmt, bindableStmt.Schema)
normalizedSQL, digest := parser.NormalizeDigest(utilparser.RestoreWithDefaultDB(stmt, dbName, bindableStmt.Query))
if r := h.GetBindRecord(digest, normalizedSQL, dbName); r != nil && r.HasUsingBinding() {
if r := h.GetBindRecord(digest.String(), normalizedSQL, dbName); r != nil && r.HasUsingBinding() {
continue
}
bindSQL := GenerateBindSQL(context.TODO(), stmt, bindableStmt.PlanHint, true, dbName)
Expand Down
6 changes: 3 additions & 3 deletions bindinfo/session_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (h *SessionHandle) CreateBindRecord(sctx sessionctx.Context, record *BindRe
}

// update the BindMeta to the cache.
h.appendBindRecord(parser.DigestNormalized(record.OriginalSQL), record)
h.appendBindRecord(parser.DigestNormalized(record.OriginalSQL).String(), record)
return nil
}

Expand All @@ -78,14 +78,14 @@ func (h *SessionHandle) DropBindRecord(originalSQL, db string, binding *Binding)
} else {
newRecord = record
}
h.ch.setBindRecord(parser.DigestNormalized(record.OriginalSQL), newRecord)
h.ch.setBindRecord(parser.DigestNormalized(record.OriginalSQL).String(), newRecord)
updateMetrics(metrics.ScopeSession, oldRecord, newRecord, false)
return nil
}

// GetBindRecord return the BindMeta of the (normdOrigSQL,db) if BindMeta exist.
func (h *SessionHandle) GetBindRecord(normdOrigSQL, db string) *BindRecord {
hash := parser.DigestNormalized(normdOrigSQL)
hash := parser.DigestNormalized(normdOrigSQL).String()
bindRecords := h.ch[hash]
for _, bindRecord := range bindRecords {
if bindRecord.OriginalSQL == normdOrigSQL {
Expand Down
3 changes: 1 addition & 2 deletions cmd/benchfilesort/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"encoding/binary"
"flag"
"fmt"
"io/ioutil"
"math/rand"
"os"
"path/filepath"
Expand Down Expand Up @@ -332,7 +331,7 @@ func driveRunCmd() {
for i := 0; i < keySize; i++ {
byDesc[i] = false
}
dir, err = ioutil.TempDir(tmpDir, "benchfilesort_test")
dir, err = os.MkdirTemp(tmpDir, "benchfilesort_test")
terror.MustNil(err)
fs, err = fsBuilder.SetSC(sc).SetSchema(keySize, valSize).SetBuf(bufSize).SetWorkers(nWorkers).SetDesc(byDesc).SetDir(dir).Build()
terror.MustNil(err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/benchkv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"context"
"flag"
"fmt"
"io/ioutil"
"io"
"net/http"
_ "net/http/pprof"
"sync"
Expand Down Expand Up @@ -129,7 +129,7 @@ func main() {
terror.MustNil(err)

defer terror.Call(resp.Body.Close)
text, err1 := ioutil.ReadAll(resp.Body)
text, err1 := io.ReadAll(resp.Body)
terror.Log(errors.Trace(err1))

fmt.Println(string(text))
Expand Down
2 changes: 1 addition & 1 deletion cmd/ddltest/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (s *TestDDLSuite) SetUpSuite(c *C) {
s.procs = make([]*server, *serverNum)

// Set server restart retry count.
s.retryCount = 5
s.retryCount = 20

createLogFiles(c, *serverNum)
err = s.startServers()
Expand Down
14 changes: 5 additions & 9 deletions cmd/explaintest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"os/exec"
Expand All @@ -30,7 +29,6 @@ import (
"github.com/pingcap/errors"
"github.com/pingcap/log"
"github.com/pingcap/parser/ast"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/session"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/util/logutil"
Expand Down Expand Up @@ -164,7 +162,7 @@ LOOP:
}

func (t *tester) loadQueries() ([]query, error) {
data, err := ioutil.ReadFile(t.testFileName())
data, err := os.ReadFile(t.testFileName())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -428,12 +426,12 @@ func (t *tester) create(tableName string, qText string) error {
return err
}

js, err := ioutil.ReadAll(resp.Body)
js, err := io.ReadAll(resp.Body)
if err != nil {
return err
}

return ioutil.WriteFile(t.statsFileName(tableName), js, 0644)
return os.WriteFile(t.statsFileName(tableName), js, 0644)
}

func (t *tester) commit() error {
Expand Down Expand Up @@ -532,7 +530,7 @@ func (t *tester) flushResult() error {
if !record {
return nil
}
return ioutil.WriteFile(t.resultFileName(), t.buf.Bytes(), 0644)
return os.WriteFile(t.resultFileName(), t.buf.Bytes(), 0644)
}

func (t *tester) statsFileName(tableName string) string {
Expand All @@ -551,7 +549,7 @@ func (t *tester) resultFileName() string {

func loadAllTests() ([]string, error) {
// tests must be in t folder
files, err := ioutil.ReadDir("./t")
files, err := os.ReadDir("./t")
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -663,8 +661,6 @@ func main() {
log.Fatal(fmt.Sprintf("%s failed", sql), zap.Error(err))
}
}
// Wait global variables to reload.
time.Sleep(domain.GlobalVariableCacheExpiry)

if _, err = mdb.Exec("set sql_mode='STRICT_TRANS_TABLES'"); err != nil {
log.Fatal("set sql_mode='STRICT_TRANS_TABLES' failed", zap.Error(err))
Expand Down
Loading

0 comments on commit 8cf7932

Please sign in to comment.