Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into global-stats-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
qw4990 committed Mar 8, 2021
2 parents 69692f7 + 4218f28 commit f49be19
Show file tree
Hide file tree
Showing 38 changed files with 307 additions and 149 deletions.
10 changes: 10 additions & 0 deletions distsql/request_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"sort"

"github.com/pingcap/errors"
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/tidb/ddl/placement"
"github.com/pingcap/tidb/infoschema"
Expand Down Expand Up @@ -235,6 +236,15 @@ func (builder *RequestBuilder) SetFromSessionVars(sv *variable.SessionVars) *Req
builder.Request.SchemaVar = sv.TxnCtx.SchemaVersion
}
builder.txnScope = sv.TxnCtx.TxnScope
builder.IsStaleness = sv.TxnCtx.IsStaleness
if builder.IsStaleness && builder.txnScope != oracle.GlobalTxnScope {
builder.MatchStoreLabels = []*metapb.StoreLabel{
{
Key: placement.DCLabelKey,
Value: builder.txnScope,
},
}
}
return builder
}

Expand Down
2 changes: 1 addition & 1 deletion docs/design/2018-10-08-online-DDL.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ This operation requires writing the corresponding column data in the table to th
To reduce the impact on other read and write operations, its default priority is low.

## Compatibility
About specific compatibility, you can view [MySQL’s compatibility](https://github.com/pingcap/docs/blob/master/sql/mysql-compatibility.md#ddl).
About specific compatibility, you can view [MySQL’s compatibility](https://github.com/pingcap/docs/blob/master/mysql-compatibility.md#ddl).
13 changes: 13 additions & 0 deletions executor/batch_point_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ import (
"sync/atomic"

"github.com/pingcap/failpoint"
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/parser/model"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/tidb/ddl/placement"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/store/tikv"
"github.com/pingcap/tidb/store/tikv/oracle"
"github.com/pingcap/tidb/tablecodec"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/chunk"
Expand Down Expand Up @@ -113,6 +116,16 @@ func (e *BatchPointGetExec) Open(context.Context) error {
snapshot.SetOption(kv.ReplicaRead, kv.ReplicaReadFollower)
}
snapshot.SetOption(kv.TaskID, e.ctx.GetSessionVars().StmtCtx.TaskID)
isStaleness := e.ctx.GetSessionVars().TxnCtx.IsStaleness
snapshot.SetOption(kv.IsStalenessReadOnly, isStaleness)
if isStaleness && e.ctx.GetSessionVars().TxnCtx.TxnScope != oracle.GlobalTxnScope {
snapshot.SetOption(kv.MatchStoreLabels, []*metapb.StoreLabel{
{
Key: placement.DCLabelKey,
Value: e.ctx.GetSessionVars().TxnCtx.TxnScope,
},
})
}
var batchGetter kv.BatchGetter = snapshot
if txn.Valid() {
lock := e.tblInfo.Lock
Expand Down
8 changes: 6 additions & 2 deletions executor/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func (s *testSuite6) TestCreateTable(c *C) {
c.Assert(req.GetRow(0).GetString(1), Equals, "double")
}
}
c.Assert(rs.Close(), IsNil)

// test multiple collate specified in column when create.
tk.MustExec("drop table if exists test_multiple_column_collate;")
Expand Down Expand Up @@ -470,7 +471,7 @@ func (s *testSuite6) TestAlterTableAddColumn(c *C) {
row := req.GetRow(0)
c.Assert(row.Len(), Equals, 1)
c.Assert(now, GreaterEqual, row.GetTime(0).String())
r.Close()
c.Assert(r.Close(), IsNil)
tk.MustExec("alter table alter_test add column c3 varchar(50) default 'CURRENT_TIMESTAMP'")
tk.MustQuery("select c3 from alter_test").Check(testkit.Rows("CURRENT_TIMESTAMP"))
tk.MustExec("create or replace view alter_view as select c1,c2 from alter_test")
Expand All @@ -497,7 +498,7 @@ func (s *testSuite6) TestAlterTableAddColumns(c *C) {
c.Assert(err, IsNil)
row := req.GetRow(0)
c.Assert(row.Len(), Equals, 1)
r.Close()
c.Assert(r.Close(), IsNil)
tk.MustQuery("select c3 from alter_test").Check(testkit.Rows("CURRENT_TIMESTAMP"))
tk.MustExec("create or replace view alter_view as select c1,c2 from alter_test")
_, err = tk.Exec("alter table alter_view add column (c4 varchar(50), c5 varchar(50))")
Expand Down Expand Up @@ -1167,6 +1168,9 @@ func (s *testSuite6) TestSetDDLReorgWorkerCnt(c *C) {
tk.MustExec("set @@global.tidb_ddl_reorg_worker_cnt = 100")
res = tk.MustQuery("select @@global.tidb_ddl_reorg_worker_cnt")
res.Check(testkit.Rows("100"))

_, err = tk.Exec("set @@global.tidb_ddl_reorg_worker_cnt = 129")
c.Assert(terror.ErrorEqual(err, variable.ErrWrongValueForVar), IsTrue, Commentf("err %v", err))
}

func (s *testSuite6) TestSetDDLReorgBatchSize(c *C) {
Expand Down
6 changes: 3 additions & 3 deletions executor/distsql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (s *testSuite3) TestCopClientSend(c *C) {
err = rs.Next(ctx, req)
c.Assert(err, IsNil)
c.Assert(req.GetRow(0).GetMyDecimal(0).String(), Equals, "499500")
rs.Close()
c.Assert(rs.Close(), IsNil)

// Split one region.
key := tablecodec.EncodeRowKeyWithHandle(tblID, kv.IntHandle(500))
Expand All @@ -95,15 +95,15 @@ func (s *testSuite3) TestCopClientSend(c *C) {
err = rs.Next(ctx, req)
c.Assert(err, IsNil)
c.Assert(req.GetRow(0).GetMyDecimal(0).String(), Equals, "499500")
rs.Close()
c.Assert(rs.Close(), IsNil)

// Check there is no goroutine leak.
rs, err = tk.Exec("select * from copclient order by id")
c.Assert(err, IsNil)
req = rs.NewChunk()
err = rs.Next(ctx, req)
c.Assert(err, IsNil)
rs.Close()
c.Assert(rs.Close(), IsNil)
keyword := "(*copIterator).work"
c.Check(checkGoroutineExists(keyword), IsFalse)
}
Expand Down
Loading

0 comments on commit f49be19

Please sign in to comment.