Skip to content

Commit d90db34

Browse files
authored
Merge branch 'master' into copr/fix-row-hint
2 parents 73379d8 + a21098f commit d90db34

File tree

468 files changed

+30196
-17802
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

468 files changed

+30196
-17802
lines changed

DEPS.bzl

+131-54
Large diffs are not rendered by default.

Makefile

+7-11
Original file line numberDiff line numberDiff line change
@@ -405,11 +405,7 @@ bazel_test: failpoint-enable bazel_ci_prepare
405405

406406
bazel_coverage_test: failpoint-enable bazel_ci_prepare
407407
bazel $(BAZEL_GLOBAL_CONFIG) coverage $(BAZEL_CMD_CONFIG) \
408-
--build_event_json_file=bazel_1.json --@io_bazel_rules_go//go/config:cover_format=go_cover \
409-
-- //... -//cmd/... -//tests/graceshutdown/... \
410-
-//tests/globalkilltest/... -//tests/readonlytest/... -//br/pkg/task:task_test -//tests/realtikvtest/...
411-
bazel $(BAZEL_GLOBAL_CONFIG) coverage $(BAZEL_CMD_CONFIG) \
412-
--build_event_json_file=bazel_2.json --@io_bazel_rules_go//go/config:cover_format=go_cover --define gotags=featuretag \
408+
--build_event_json_file=bazel_1.json --@io_bazel_rules_go//go/config:cover_format=go_cover --define gotags=deadlock \
413409
-- //... -//cmd/... -//tests/graceshutdown/... \
414410
-//tests/globalkilltest/... -//tests/readonlytest/... -//br/pkg/task:task_test -//tests/realtikvtest/...
415411

@@ -442,27 +438,27 @@ bazel_golangcilinter:
442438
-- run $$($(PACKAGE_DIRECTORIES)) --config ./.golangci.yaml
443439

444440
bazel_brietest: failpoint-enable bazel_ci_prepare
445-
bazel $(BAZEL_GLOBAL_CONFIG) test $(BAZEL_CMD_CONFIG) --test_arg=-with-real-tikv \
441+
bazel $(BAZEL_GLOBAL_CONFIG) test $(BAZEL_CMD_CONFIG) --test_arg=-with-real-tikv --define gotags=deadlock \
446442
-- //tests/realtikvtest/brietest/...
447443

448444
bazel_pessimistictest: failpoint-enable bazel_ci_prepare
449-
bazel $(BAZEL_GLOBAL_CONFIG) test $(BAZEL_CMD_CONFIG) --test_arg=-with-real-tikv \
445+
bazel $(BAZEL_GLOBAL_CONFIG) test $(BAZEL_CMD_CONFIG) --test_arg=-with-real-tikv --define gotags=deadlock \
450446
-- //tests/realtikvtest/pessimistictest/...
451447

452448
bazel_sessiontest: failpoint-enable bazel_ci_prepare
453-
bazel $(BAZEL_GLOBAL_CONFIG) test $(BAZEL_CMD_CONFIG) --test_arg=-with-real-tikv \
449+
bazel $(BAZEL_GLOBAL_CONFIG) test $(BAZEL_CMD_CONFIG) --test_arg=-with-real-tikv --define gotags=deadlock \
454450
-- //tests/realtikvtest/sessiontest/...
455451

456452
bazel_statisticstest: failpoint-enable bazel_ci_prepare
457-
bazel $(BAZEL_GLOBAL_CONFIG) test $(BAZEL_CMD_CONFIG) --test_arg=-with-real-tikv \
453+
bazel $(BAZEL_GLOBAL_CONFIG) test $(BAZEL_CMD_CONFIG) --test_arg=-with-real-tikv --define gotags=deadlock \
458454
-- //tests/realtikvtest/statisticstest/...
459455

460456
bazel_txntest: failpoint-enable bazel_ci_prepare
461-
bazel $(BAZEL_GLOBAL_CONFIG) test $(BAZEL_CMD_CONFIG) --test_arg=-with-real-tikv \
457+
bazel $(BAZEL_GLOBAL_CONFIG) test $(BAZEL_CMD_CONFIG) --test_arg=-with-real-tikv --define gotags=deadlock \
462458
-- //tests/realtikvtest/txntest/...
463459

464460
bazel_addindextest: failpoint-enable bazel_ci_prepare
465-
bazel $(BAZEL_GLOBAL_CONFIG) test $(BAZEL_CMD_CONFIG) --test_arg=-with-real-tikv \
461+
bazel $(BAZEL_GLOBAL_CONFIG) test $(BAZEL_CMD_CONFIG) --test_arg=-with-real-tikv --define gotags=deadlock \
466462
-- //tests/realtikvtest/addindextest/...
467463

468464
bazel_lint: bazel_prepare

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
[![LICENSE](https://img.shields.io/github/license/pingcap/tidb.svg)](https://github.com/pingcap/tidb/blob/master/LICENSE)
44
[![Language](https://img.shields.io/badge/Language-Go-blue.svg)](https://golang.org/)
5-
[![Build Status](https://travis-ci.org/pingcap/tidb.svg?branch=master)](https://travis-ci.org/pingcap/tidb)
5+
[![Build Status](https://prow.tidb.net/badge.svg?jobs=pingcap/tidb/merged_*)](https://prow.tidb.net/?repo=pingcap%2Ftidb&type=postsubmit)
66
[![Go Report Card](https://goreportcard.com/badge/github.com/pingcap/tidb)](https://goreportcard.com/report/github.com/pingcap/tidb)
77
[![GitHub release](https://img.shields.io/github/tag/pingcap/tidb.svg?label=release)](https://github.com/pingcap/tidb/releases)
88
[![GitHub release date](https://img.shields.io/github/release-date/pingcap/tidb.svg)](https://github.com/pingcap/tidb/releases)
9-
[![CircleCI Status](https://circleci.com/gh/pingcap/tidb.svg?style=shield)](https://circleci.com/gh/pingcap/tidb)
109
[![Coverage Status](https://codecov.io/gh/pingcap/tidb/branch/master/graph/badge.svg)](https://codecov.io/gh/pingcap/tidb)
1110
[![GoDoc](https://img.shields.io/badge/Godoc-reference-blue.svg)](https://godoc.org/github.com/pingcap/tidb)
1211

@@ -44,12 +43,13 @@ See the [Get Started](https://pingcap.github.io/tidb-dev-guide/get-started/intro
4443

4544
You can join the following groups or channels to discuss or ask questions about TiDB, and to keep yourself informed of the latest TiDB updates:
4645

47-
- Discuss TiDB's implementation and design
48-
- [TiDB Internals forum](https://internals.tidb.io/)
4946
- Seek help when you use TiDB
47+
- [TiDB Forum](https://ask.pingcap.com/)
48+
- [Chinese TiDB Forum](https://asktug.com)
5049
- Slack channels: [#everyone](https://slack.tidb.io/invite?team=tidb-community&channel=everyone&ref=pingcap-tidb) (English), [#tidb-japan](https://slack.tidb.io/invite?team=tidb-community&channel=tidb-japan&ref=github-tidb) (Japanese)
51-
- [TiDB User Group forum](https://asktug.com) (Chinese)
5250
- [Stack Overflow](https://stackoverflow.com/questions/tagged/tidb) (questions tagged with #tidb)
51+
- Discuss TiDB's implementation and design
52+
- [TiDB Internals forum](https://internals.tidb.io/)
5353
- Get the latest TiDB news or updates
5454
- Follow [@PingCAP](https://twitter.com/PingCAP) on Twitter
5555
- Read the PingCAP [English Blog](https://www.pingcap.com/blog/?from=en) or [Chinese Blog](https://cn.pingcap.com/blog/)

WORKSPACE

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ go_download_sdk(
3535
"https://mirrors.aliyun.com/golang/{}",
3636
"https://dl.google.com/go/{}",
3737
],
38-
version = "1.19.3",
38+
version = "1.19.5",
3939
)
4040

4141
go_register_toolchains(

autoid_service/BUILD.bazel

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("@io_bazel_rules_go//go:def.bzl", "go_library")
1+
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
22

33
go_library(
44
name = "autoid_service",
@@ -9,6 +9,7 @@ go_library(
99
"//config",
1010
"//kv",
1111
"//meta",
12+
"//meta/autoid",
1213
"//metrics",
1314
"//owner",
1415
"//parser/model",
@@ -23,3 +24,18 @@ go_library(
2324
"@org_uber_go_zap//:zap",
2425
],
2526
)
27+
28+
go_test(
29+
name = "autoid_service_test",
30+
srcs = ["autoid_test.go"],
31+
embed = [":autoid_service"],
32+
deps = [
33+
"//parser/model",
34+
"//testkit",
35+
"@com_github_pingcap_kvproto//pkg/autoid",
36+
"@com_github_stretchr_testify//require",
37+
"@io_etcd_go_etcd_tests_v3//integration",
38+
"@org_golang_google_grpc//:grpc",
39+
"@org_golang_google_grpc//credentials/insecure",
40+
],
41+
)

autoid_service/autoid.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/pingcap/tidb/config"
2828
"github.com/pingcap/tidb/kv"
2929
"github.com/pingcap/tidb/meta"
30+
autoid1 "github.com/pingcap/tidb/meta/autoid"
3031
"github.com/pingcap/tidb/metrics"
3132
"github.com/pingcap/tidb/owner"
3233
"github.com/pingcap/tidb/parser/model"
@@ -253,6 +254,7 @@ type Service struct {
253254
func New(selfAddr string, etcdAddr []string, store kv.Storage, tlsConfig *tls.Config) *Service {
254255
cfg := config.GetGlobalConfig()
255256
etcdLogCfg := zap.NewProductionConfig()
257+
256258
cli, err := clientv3.New(clientv3.Config{
257259
LogConfig: &etcdLogCfg,
258260
Endpoints: etcdAddr,
@@ -270,9 +272,12 @@ func New(selfAddr string, etcdAddr []string, store kv.Storage, tlsConfig *tls.Co
270272
if err != nil {
271273
panic(err)
272274
}
275+
return newWithCli(selfAddr, cli, store)
276+
}
273277

278+
func newWithCli(selfAddr string, cli *clientv3.Client, store kv.Storage) *Service {
274279
l := owner.NewOwnerManager(context.Background(), cli, "autoid", selfAddr, autoIDLeaderPath)
275-
err = l.CampaignOwner()
280+
err := l.CampaignOwner()
276281
if err != nil {
277282
panic(err)
278283
}
@@ -299,7 +304,7 @@ func (m *mockClient) Rebase(ctx context.Context, in *autoid.RebaseRequest, opts
299304
var global = make(map[string]*mockClient)
300305

301306
// MockForTest is used for testing, the UT test and unistore use this.
302-
func MockForTest(store kv.Storage) *mockClient {
307+
func MockForTest(store kv.Storage) autoid.AutoIDAllocClient {
303308
uuid := store.UUID()
304309
ret, ok := global[uuid]
305310
if !ok {
@@ -515,3 +520,7 @@ func (s *Service) Rebase(ctx context.Context, req *autoid.RebaseRequest) (*autoi
515520
}
516521
return &autoid.RebaseResponse{}, nil
517522
}
523+
524+
func init() {
525+
autoid1.MockForTest = MockForTest
526+
}

autoid_service/autoid_test.go

+202
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
// Copyright 2022 PingCAP, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package autoid
16+
17+
import (
18+
"context"
19+
"fmt"
20+
"math"
21+
"net"
22+
"testing"
23+
"time"
24+
25+
"github.com/pingcap/kvproto/pkg/autoid"
26+
"github.com/pingcap/tidb/parser/model"
27+
"github.com/pingcap/tidb/testkit"
28+
"github.com/stretchr/testify/require"
29+
"go.etcd.io/etcd/tests/v3/integration"
30+
"google.golang.org/grpc"
31+
"google.golang.org/grpc/credentials/insecure"
32+
)
33+
34+
type autoIDResp struct {
35+
*autoid.AutoIDResponse
36+
error
37+
*testing.T
38+
}
39+
40+
func (resp autoIDResp) check(min, max int64) {
41+
require.NoError(resp.T, resp.error)
42+
require.Equal(resp.T, resp.AutoIDResponse, &autoid.AutoIDResponse{Min: min, Max: max})
43+
}
44+
45+
func (resp autoIDResp) checkErrmsg() {
46+
require.NoError(resp.T, resp.error)
47+
require.True(resp.T, len(resp.GetErrmsg()) > 0)
48+
}
49+
50+
type rebaseResp struct {
51+
*autoid.RebaseResponse
52+
error
53+
*testing.T
54+
}
55+
56+
func (resp rebaseResp) check(msg string) {
57+
require.NoError(resp.T, resp.error)
58+
require.Equal(resp.T, string(resp.RebaseResponse.GetErrmsg()), msg)
59+
}
60+
61+
func TestAPI(t *testing.T) {
62+
store, dom := testkit.CreateMockStoreAndDomain(t)
63+
tk := testkit.NewTestKit(t, store)
64+
cli := MockForTest(store)
65+
tk.MustExec("use test")
66+
tk.MustExec("create table t (id int key auto_increment);")
67+
is := dom.InfoSchema()
68+
dbInfo, ok := is.SchemaByName(model.NewCIStr("test"))
69+
require.True(t, ok)
70+
71+
tbl, err := is.TableByName(model.NewCIStr("test"), model.NewCIStr("t"))
72+
require.NoError(t, err)
73+
tbInfo := tbl.Meta()
74+
75+
ctx := context.Background()
76+
checkCurrValue := func(t *testing.T, cli autoid.AutoIDAllocClient, min, max int64) {
77+
req := &autoid.AutoIDRequest{DbID: dbInfo.ID, TblID: tbInfo.ID, N: 0}
78+
resp, err := cli.AllocAutoID(ctx, req)
79+
require.NoError(t, err)
80+
require.Equal(t, resp, &autoid.AutoIDResponse{Min: min, Max: max})
81+
}
82+
autoIDRequest := func(t *testing.T, cli autoid.AutoIDAllocClient, unsigned bool, n uint64, more ...int64) autoIDResp {
83+
increment := int64(1)
84+
offset := int64(1)
85+
if len(more) >= 1 {
86+
increment = more[0]
87+
}
88+
if len(more) >= 2 {
89+
offset = more[1]
90+
}
91+
req := &autoid.AutoIDRequest{DbID: dbInfo.ID, TblID: tbInfo.ID, IsUnsigned: unsigned, N: n, Increment: increment, Offset: offset}
92+
resp, err := cli.AllocAutoID(ctx, req)
93+
return autoIDResp{resp, err, t}
94+
}
95+
rebaseRequest := func(t *testing.T, cli autoid.AutoIDAllocClient, unsigned bool, n int64, force ...struct{}) rebaseResp {
96+
req := &autoid.RebaseRequest{
97+
DbID: dbInfo.ID,
98+
TblID: tbInfo.ID,
99+
Base: n,
100+
IsUnsigned: unsigned,
101+
Force: len(force) > 0,
102+
}
103+
resp, err := cli.Rebase(ctx, req)
104+
return rebaseResp{resp, err, t}
105+
}
106+
var force = struct{}{}
107+
108+
// basic auto id operation
109+
autoIDRequest(t, cli, false, 1).check(0, 1)
110+
autoIDRequest(t, cli, false, 10).check(1, 11)
111+
checkCurrValue(t, cli, 11, 11)
112+
autoIDRequest(t, cli, false, 128).check(11, 139)
113+
autoIDRequest(t, cli, false, 1, 10, 5).check(139, 145)
114+
115+
// basic rebase operation
116+
rebaseRequest(t, cli, false, 666).check("")
117+
autoIDRequest(t, cli, false, 1).check(666, 667)
118+
119+
rebaseRequest(t, cli, false, 6666).check("")
120+
autoIDRequest(t, cli, false, 1).check(6666, 6667)
121+
122+
// rebase will not decrease the value without 'force'
123+
rebaseRequest(t, cli, false, 44).check("")
124+
checkCurrValue(t, cli, 6667, 6667)
125+
rebaseRequest(t, cli, false, 44, force).check("")
126+
checkCurrValue(t, cli, 44, 44)
127+
128+
// max increase 1
129+
rebaseRequest(t, cli, false, math.MaxInt64, force).check("")
130+
checkCurrValue(t, cli, math.MaxInt64, math.MaxInt64)
131+
autoIDRequest(t, cli, false, 1).checkErrmsg()
132+
133+
rebaseRequest(t, cli, true, 0, force).check("")
134+
checkCurrValue(t, cli, 0, 0)
135+
autoIDRequest(t, cli, true, 1).check(0, 1)
136+
autoIDRequest(t, cli, true, 10).check(1, 11)
137+
autoIDRequest(t, cli, true, 128).check(11, 139)
138+
autoIDRequest(t, cli, true, 1, 10, 5).check(139, 145)
139+
140+
// max increase 1
141+
rebaseRequest(t, cli, true, math.MaxInt64).check("")
142+
checkCurrValue(t, cli, math.MaxInt64, math.MaxInt64)
143+
autoIDRequest(t, cli, true, 1).check(math.MaxInt64, math.MinInt64)
144+
autoIDRequest(t, cli, true, 1).check(math.MinInt64, math.MinInt64+1)
145+
146+
rebaseRequest(t, cli, true, -1).check("")
147+
checkCurrValue(t, cli, -1, -1)
148+
autoIDRequest(t, cli, true, 1).check(-1, 0)
149+
}
150+
151+
func TestGRPC(t *testing.T) {
152+
integration.BeforeTestExternal(t)
153+
store := testkit.CreateMockStore(t)
154+
cluster := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 1})
155+
defer cluster.Terminate(t)
156+
etcdCli := cluster.RandClient()
157+
158+
var addr string
159+
var listener net.Listener
160+
for port := 10080; ; port++ {
161+
var err error
162+
addr = fmt.Sprintf("127.0.0.1:%d", port)
163+
listener, err = net.Listen("tcp", addr)
164+
if err == nil {
165+
break
166+
}
167+
}
168+
defer listener.Close()
169+
170+
service := newWithCli(addr, etcdCli, store)
171+
defer service.Close()
172+
173+
var i int
174+
for !service.leaderShip.IsOwner() {
175+
time.Sleep(100 * time.Millisecond)
176+
i++
177+
if i >= 20 {
178+
break
179+
}
180+
}
181+
require.Less(t, i, 20)
182+
183+
grpcServer := grpc.NewServer()
184+
autoid.RegisterAutoIDAllocServer(grpcServer, service)
185+
go func() {
186+
grpcServer.Serve(listener)
187+
}()
188+
defer grpcServer.Stop()
189+
190+
grpcConn, err := grpc.Dial("127.0.0.1:10080", grpc.WithTransportCredentials(insecure.NewCredentials()))
191+
require.NoError(t, err)
192+
cli := autoid.NewAutoIDAllocClient(grpcConn)
193+
_, err = cli.AllocAutoID(context.Background(), &autoid.AutoIDRequest{
194+
DbID: 0,
195+
TblID: 0,
196+
N: 1,
197+
Increment: 1,
198+
Offset: 1,
199+
IsUnsigned: false,
200+
})
201+
require.NoError(t, err)
202+
}

bindinfo/session_handle_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -521,3 +521,14 @@ func TestPreparedStmt(t *testing.T) {
521521
require.Len(t, tk.Session().GetSessionVars().StmtCtx.IndexNames, 1)
522522
require.Equal(t, "t:idx_c", tk.Session().GetSessionVars().StmtCtx.IndexNames[0])
523523
}
524+
525+
func TestSetVarBinding(t *testing.T) {
526+
store := testkit.CreateMockStore(t)
527+
tk := testkit.NewTestKit(t, store)
528+
tk.MustExec("use test")
529+
tk.MustExec("create table t1 (a int, b varchar(20))")
530+
tk.MustExec("insert into t1 values (1, '111111111111111')")
531+
tk.MustExec("insert into t1 values (2, '222222222222222')")
532+
tk.MustExec("create binding for select group_concat(b) from test.t1 using select /*+ SET_VAR(group_concat_max_len = 4) */ group_concat(b) from test.t1 ;")
533+
tk.MustQuery("select group_concat(b) from test.t1").Check(testkit.Rows("1111"))
534+
}

br/pkg/checkpoint/BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ go_library(
66
importpath = "github.com/pingcap/tidb/br/pkg/checkpoint",
77
visibility = ["//visibility:public"],
88
deps = [
9+
"//br/pkg/logutil",
910
"//br/pkg/metautil",
1011
"//br/pkg/rtree",
1112
"//br/pkg/storage",

0 commit comments

Comments
 (0)