Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into clustered-index-s…
Browse files Browse the repository at this point in the history
…yntax
  • Loading branch information
tangenta committed Jan 26, 2021
2 parents 3f5a248 + 0aa4760 commit 437e55c
Show file tree
Hide file tree
Showing 24 changed files with 682 additions and 508 deletions.
32 changes: 22 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
[![Coverage Status](https://codecov.io/gh/pingcap/tidb/branch/master/graph/badge.svg)](https://codecov.io/gh/pingcap/tidb)
[![GoDoc](https://img.shields.io/badge/Godoc-reference-blue.svg)](https://godoc.org/github.com/pingcap/tidb)

- [**Slack Channel**](https://slack.tidb.io)
- [**Slack Channel**](https://slack.tidb.io/invite?team=tidb-community&channel=everyone&ref=pingcap-tidb)
- **Twitter**: [@PingCAP](https://twitter.com/PingCAP)
- [**Reddit**](https://www.reddit.com/r/TiDB/)
- **Mailing list**: [Google Group](https://groups.google.com/forum/#!forum/tidb-user)
- [**Blog**](https://www.pingcap.com/blog/)
- [**For support, please contact PingCAP**](http://bit.ly/contact_us_via_github)

## What is TiDB?
Expand All @@ -27,11 +26,11 @@ TiDB ("Ti" stands for Titanium) is an open-source NewSQL database that supports

- __MySQL Compatible Syntax__

TiDB acts like it is a MySQL 5.7 server to your applications. You can continue to use all of the existing MySQL client libraries, and in many cases, you will not need to change a single line of code in your application. Because TiDB is built from scratch, not a MySQL fork, please check out the list of [known compatibility differences](https://pingcap.com/docs/v3.0/reference/mysql-compatibility/).
TiDB acts like it is a MySQL 5.7 server to your applications. You can continue to use all of the existing MySQL client libraries, and in many cases, you will not need to change a single line of code in your application. Because TiDB is built from scratch, not a MySQL fork, please check out the list of [known compatibility differences](https://docs.pingcap.com/tidb/stable/mysql-compatibility).

- __Distributed Transactions with Strong Consistency__

TiDB internally shards table into small range-based chunks that we refer to as "regions". Each region defaults to approximately 100MiB in size, and TiDB uses a Two-phase commit internally to ensure that regions are maintained in a transactionally consistent way.
TiDB internally shards table into small range-based chunks that we refer to as "Regions". Each Region defaults to approximately 100 MiB in size, and TiDB uses a Two-phase commit internally to ensure that Regions are maintained in a transactionally consistent way.

- __Cloud Native__

Expand All @@ -47,12 +46,10 @@ TiDB ("Ti" stands for Titanium) is an open-source NewSQL database that supports

TiDB uses the Raft consensus algorithm to ensure that data is highly available and safely replicated throughout storage in Raft groups. In the event of failure, a Raft group will automatically elect a new leader for the failed member, and self-heal the TiDB cluster without any required manual intervention. Failure and self-healing operations are also transparent to applications.

For more details and latest updates, see [official TiDB blog](https://www.pingcap.com/blog/).

For more details and latest updates, see [TiDB docs](https://docs.pingcap.com/tidb/stable) and [release notes](https://docs.pingcap.com/tidb/dev/release-notes).

## Quick start


See [Quick Start Guide](https://pingcap.com/docs/stable/quick-start-with-tidb/ ), which includes deployment methods using TiUP, Ansible, Docker, and Kubernetes.

### To start developing TiDB
Expand All @@ -67,14 +64,18 @@ for details on submitting patches and the contribution workflow. For more contri

## Adopters

View the current list of in-production TiDB adopters [here](https://pingcap.com/docs/adopters/).
View the current list of in-production TiDB adopters [here](https://docs.pingcap.com/tidb/stable/adopters).

## Case studies

- [English](https://pingcap.com/case-studies)
- [简体中文](https://pingcap.com/cases-cn/)

## Roadmap

Read the [Roadmap](https://pingcap.com/docs/ROADMAP).


## Getting Help
## Getting help

- [**Stack Overflow**](https://stackoverflow.com/questions/tagged/tidb)
- [**User Group (Chinese)**](https://asktug.com)
Expand All @@ -84,13 +85,24 @@ Read the [Roadmap](https://pingcap.com/docs/ROADMAP).
+ [English](https://pingcap.com/docs)
+ [简体中文](https://pingcap.com/docs-cn)

## Blog

- [English](https://www.pingcap.com/blog/)
- [简体中文](https://pingcap.com/blog-cn/)

## TiDB Monthly

[TiDB Monthly](https://pingcap.com/weekly/)

## Architecture

![architecture](./docs/architecture.png)

## License

TiDB is under the Apache 2.0 license. See the [LICENSE](./LICENSE) file for details.

## Acknowledgments

- Thanks [cznic](https://github.com/cznic) for providing some great open source tools.
- Thanks [GolevelDB](https://github.com/syndtr/goleveldb), [BoltDB](https://github.com/boltdb/bolt), and [RocksDB](https://github.com/facebook/rocksdb) for their powerful storage engines.
4 changes: 2 additions & 2 deletions ddl/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -1108,9 +1108,9 @@ func onTruncateTablePartition(d *ddlCtx, t *meta.Meta, job *model.Job) (int64, e
oldBundle, ok := d.infoHandle.Get().BundleByName(placement.GroupID(oldID))
if ok && !oldBundle.IsEmpty() {
yoldIDs = append(yoldIDs, oldID)
newIDs = append(newIDs, newIDs[i])
newIDs = append(newIDs, newPartitions[i].ID)
bundles = append(bundles, placement.BuildPlacementDropBundle(oldID))
bundles = append(bundles, placement.BuildPlacementCopyBundle(oldBundle, newIDs[i]))
bundles = append(bundles, placement.BuildPlacementCopyBundle(oldBundle, newPartitions[i].ID))
}
}
job.CtxVars = []interface{}{yoldIDs, newIDs}
Expand Down
9 changes: 5 additions & 4 deletions ddl/placement/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,11 @@ func GetLeaderDCByBundle(bundle *Bundle, dcLabelKey string) (string, bool) {
}

func isValidLeaderRule(rule *Rule, dcLabelKey string) bool {
if rule.Role == Leader && rule.Count == 1 && len(rule.LabelConstraints) == 1 {
cons := rule.LabelConstraints[0]
if cons.Op == In && cons.Key == dcLabelKey && len(cons.Values) == 1 {
return true
if rule.Role == Leader && rule.Count == 1 {
for _, con := range rule.LabelConstraints {
if con.Op == In && con.Key == dcLabelKey && len(con.Values) == 1 {
return true
}
}
}
return false
Expand Down
35 changes: 35 additions & 0 deletions ddl/placement/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ func (t *testUtilsSuite) TestGetLeaderDCByBundle(c *C) {
Op: In,
Values: []string{"bj"},
},
{
Key: EngineLabelKey,
Op: NotIn,
Values: []string{EngineLabelTiFlash},
},
},
Count: 1,
},
Expand All @@ -161,6 +166,11 @@ func (t *testUtilsSuite) TestGetLeaderDCByBundle(c *C) {
Op: In,
Values: []string{"bj"},
},
{
Key: EngineLabelKey,
Op: NotIn,
Values: []string{EngineLabelTiFlash},
},
},
Count: 3,
},
Expand All @@ -182,6 +192,11 @@ func (t *testUtilsSuite) TestGetLeaderDCByBundle(c *C) {
Op: In,
Values: []string{"sh"},
},
{
Key: EngineLabelKey,
Op: NotIn,
Values: []string{EngineLabelTiFlash},
},
},
Count: 1,
},
Expand All @@ -194,6 +209,11 @@ func (t *testUtilsSuite) TestGetLeaderDCByBundle(c *C) {
Op: In,
Values: []string{"bj"},
},
{
Key: EngineLabelKey,
Op: NotIn,
Values: []string{EngineLabelTiFlash},
},
},
Count: 3,
},
Expand All @@ -215,6 +235,11 @@ func (t *testUtilsSuite) TestGetLeaderDCByBundle(c *C) {
Op: In,
Values: []string{"sh"},
},
{
Key: EngineLabelKey,
Op: NotIn,
Values: []string{EngineLabelTiFlash},
},
},
Count: 1,
},
Expand All @@ -236,6 +261,11 @@ func (t *testUtilsSuite) TestGetLeaderDCByBundle(c *C) {
Op: NotIn,
Values: []string{"sh"},
},
{
Key: EngineLabelKey,
Op: NotIn,
Values: []string{EngineLabelTiFlash},
},
},
Count: 1,
},
Expand All @@ -257,6 +287,11 @@ func (t *testUtilsSuite) TestGetLeaderDCByBundle(c *C) {
Op: In,
Values: []string{"sh", "bj"},
},
{
Key: EngineLabelKey,
Op: NotIn,
Values: []string{EngineLabelTiFlash},
},
},
Count: 1,
},
Expand Down
16 changes: 15 additions & 1 deletion ddl/placement_sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package ddl_test

import (
"fmt"
"sort"

. "github.com/pingcap/check"
"github.com/pingcap/parser/model"
Expand Down Expand Up @@ -378,14 +379,17 @@ func (s *testDBSuite1) TestPlacementPolicyCache(c *C) {

initTable := func() []string {
tk.MustExec("drop table if exists t1")
tk.MustExec("create table t1(id int) partition by hash(id) partitions 2")
tk.MustExec(`create table t1(id int) partition by range(id)
(partition p0 values less than (100), partition p1 values less than (200))`)

is := s.dom.InfoSchema()

tb, err := is.TableByName(model.NewCIStr("test"), model.NewCIStr("t1"))
c.Assert(err, IsNil)
partDefs := tb.Meta().GetPartitionInfo().Definitions

sort.Slice(partDefs, func(i, j int) bool { return partDefs[i].Name.L < partDefs[j].Name.L })

rows := []string{}
for k, v := range partDefs {
ptID := placement.GroupID(v.ID)
Expand All @@ -401,10 +405,20 @@ func (s *testDBSuite1) TestPlacementPolicyCache(c *C) {
// test drop
rows := initTable()
tk.MustQuery("select * from information_schema.placement_policy order by REPLICAS").Check(testkit.Rows(rows...))
tk.MustExec("alter table t1 drop partition p0")
tk.MustQuery("select * from information_schema.placement_policy").Check(testkit.Rows(rows[1:]...))

rows = initTable()
tk.MustQuery("select * from information_schema.placement_policy order by REPLICAS").Check(testkit.Rows(rows...))
tk.MustExec("drop table t1")
tk.MustQuery("select * from information_schema.placement_policy").Check(testkit.Rows())

// test truncate
rows = initTable()
tk.MustQuery("select * from information_schema.placement_policy order by REPLICAS").Check(testkit.Rows(rows...))
tk.MustExec("alter table t1 truncate partition p0")
tk.MustQuery("select * from information_schema.placement_policy").Check(testkit.Rows(rows[1:]...))

rows = initTable()
tk.MustQuery("select * from information_schema.placement_policy order by REPLICAS").Check(testkit.Rows(rows...))
tk.MustExec("truncate table t1")
Expand Down
2 changes: 1 addition & 1 deletion executor/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,7 @@ func asyncDelayShutdown(p *os.Process, delay time.Duration) {

func (e *SimpleExec) executeAdminReloadStatistics(s *ast.AdminStmt) error {
if s.Tp != ast.AdminReloadStatistics {
return errors.New("This AdminStmt is not ADMIN RELOAD TIDB_STATS")
return errors.New("This AdminStmt is not ADMIN RELOAD STATS_EXTENDED")
}
if !e.ctx.GetSessionVars().EnableExtendedStats {
return errors.New("Extended statistics feature is not generally available now, and tidb_enable_extended_stats is OFF")
Expand Down
18 changes: 9 additions & 9 deletions executor/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -774,28 +774,28 @@ func (s *testSuite3) TestExtendedStatsPrivileges(c *C) {
ctx := context.Background()
_, err = se.Execute(ctx, "set session tidb_enable_extended_stats = on")
c.Assert(err, IsNil)
_, err = se.Execute(ctx, "alter table test.t add tidb_stats s1 correlation(a,b)")
_, err = se.Execute(ctx, "alter table test.t add stats_extended s1 correlation(a,b)")
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "[planner:1142]ALTER command denied to user 'u1'@'%' for table 't'")
tk.MustExec("grant alter on test.* to 'u1'@'%'")
_, err = se.Execute(ctx, "alter table test.t add tidb_stats s1 correlation(a,b)")
_, err = se.Execute(ctx, "alter table test.t add stats_extended s1 correlation(a,b)")
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "[planner:1142]ADD TIDB_STATS command denied to user 'u1'@'%' for table 't'")
c.Assert(err.Error(), Equals, "[planner:1142]ADD STATS_EXTENDED command denied to user 'u1'@'%' for table 't'")
tk.MustExec("grant select on test.* to 'u1'@'%'")
_, err = se.Execute(ctx, "alter table test.t add tidb_stats s1 correlation(a,b)")
_, err = se.Execute(ctx, "alter table test.t add stats_extended s1 correlation(a,b)")
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "[planner:1142]ADD TIDB_STATS command denied to user 'u1'@'%' for table 'stats_extended'")
c.Assert(err.Error(), Equals, "[planner:1142]ADD STATS_EXTENDED command denied to user 'u1'@'%' for table 'stats_extended'")
tk.MustExec("grant insert on mysql.stats_extended to 'u1'@'%'")
_, err = se.Execute(ctx, "alter table test.t add tidb_stats s1 correlation(a,b)")
_, err = se.Execute(ctx, "alter table test.t add stats_extended s1 correlation(a,b)")
c.Assert(err, IsNil)

_, err = se.Execute(ctx, "use test")
c.Assert(err, IsNil)
_, err = se.Execute(ctx, "alter table t drop tidb_stats s1")
_, err = se.Execute(ctx, "alter table t drop stats_extended s1")
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "[planner:1142]DROP TIDB_STATS command denied to user 'u1'@'%' for table 'stats_extended'")
c.Assert(err.Error(), Equals, "[planner:1142]DROP STATS_EXTENDED command denied to user 'u1'@'%' for table 'stats_extended'")
tk.MustExec("grant update on mysql.stats_extended to 'u1'@'%'")
_, err = se.Execute(ctx, "alter table t drop tidb_stats s1")
_, err = se.Execute(ctx, "alter table t drop stats_extended s1")
c.Assert(err, IsNil)
tk.MustExec("drop user 'u1'@'%'")
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ require (
github.com/pingcap/goleveldb v0.0.0-20191226122134-f82aafb29989
github.com/pingcap/kvproto v0.0.0-20201215060142-f3dafca4c7fd
github.com/pingcap/log v0.0.0-20201112100606-8f1e84a3abc8
github.com/pingcap/parser v0.0.0-20210118071602-cd841b82c643
github.com/pingcap/parser v0.0.0-20210125075924-ffe0fda947cb
github.com/pingcap/sysutil v0.0.0-20201130064824-f0c8aa6a6966
github.com/pingcap/tidb-tools v4.0.9-0.20201127090955-2707c97b3853+incompatible
github.com/pingcap/tipb v0.0.0-20201229060814-148bc717ce4c
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,8 @@ github.com/pingcap/log v0.0.0-20201112100606-8f1e84a3abc8 h1:M+DNpOu/I3uDmwee6vc
github.com/pingcap/log v0.0.0-20201112100606-8f1e84a3abc8/go.mod h1:4rbK1p9ILyIfb6hU7OG2CiWSqMXnp3JMbiaVJ6mvoY8=
github.com/pingcap/parser v0.0.0-20190506092653-e336082eb825/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA=
github.com/pingcap/parser v0.0.0-20200422082501-7329d80eaf2c/go.mod h1:9v0Edh8IbgjGYW2ArJr19E+bvL8zKahsFp+ixWeId+4=
github.com/pingcap/parser v0.0.0-20210118071602-cd841b82c643 h1:yiihVTO/fFdbSQRqRKE5E96v67SpAZSvZvwSkSasFYY=
github.com/pingcap/parser v0.0.0-20210118071602-cd841b82c643/go.mod h1:GbEr2PgY72/4XqPZzmzstlOU/+il/wrjeTNFs6ihsSE=
github.com/pingcap/parser v0.0.0-20210125075924-ffe0fda947cb h1:16lZkJzsAOIY781DmUgSU0El+GpV8fl3BohzVmHO1rE=
github.com/pingcap/parser v0.0.0-20210125075924-ffe0fda947cb/go.mod h1:GbEr2PgY72/4XqPZzmzstlOU/+il/wrjeTNFs6ihsSE=
github.com/pingcap/pd v2.1.5+incompatible/go.mod h1:nD3+EoYes4+aNNODO99ES59V83MZSI+dFbhyr667a0E=
github.com/pingcap/pd/v4 v4.0.0-rc.1.0.20200422143320-428acd53eba2/go.mod h1:s+utZtXDznOiL24VK0qGmtoHjjXNsscJx3m1n8cC56s=
github.com/pingcap/sysutil v0.0.0-20200206130906-2bfa6dc40bcd/go.mod h1:EB/852NMQ+aRKioCpToQ94Wl7fktV+FNnxf3CX/TTXI=
Expand Down
Loading

0 comments on commit 437e55c

Please sign in to comment.