Skip to content

Commit

Permalink
Merge release 3.0 into release 3.1 (#15414)
Browse files Browse the repository at this point in the history
  • Loading branch information
lonng committed Mar 17, 2020
1 parent ec54b20 commit f7e6943
Show file tree
Hide file tree
Showing 104 changed files with 2,233 additions and 858 deletions.
3 changes: 3 additions & 0 deletions bindinfo/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,9 @@ func (s *testSuite) TestGlobalAndSessionBindingBothExist(c *C) {
// Session bindings should be able to cover the global bindings.
tk.MustExec("drop session binding for select * from t where a = 10")
tk.MustContains("select * from t where a = -1", "IndexLookUp")
res := tk.MustQuery("show session bindings")
c.Assert(len(res.Rows()), Equals, 1)
c.Assert(res.Rows()[0][3], Equals, "deleted")
}

func (s *testSuite) TestExplain(c *C) {
Expand Down
16 changes: 11 additions & 5 deletions cmd/ddltest/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
zaplog "github.com/pingcap/log"
"github.com/pingcap/parser/model"
"github.com/pingcap/parser/terror"
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/session"
Expand Down Expand Up @@ -104,9 +105,8 @@ func (s *TestDDLSuite) SetUpSuite(c *C) {
// Make sure the schema lease of this session is equal to other TiDB servers'.
session.SetSchemaLease(time.Duration(*lease) * time.Second)

dom, err := session.BootstrapSession(s.store)
s.dom, err = session.BootstrapSession(s.store)
c.Assert(err, IsNil)
s.dom = dom

s.s, err = session.CreateSession(s.store)
c.Assert(err, IsNil)
Expand All @@ -116,14 +116,20 @@ func (s *TestDDLSuite) SetUpSuite(c *C) {
_, err = s.s.Execute(goCtx, "create database if not exists test_ddl")
c.Assert(err, IsNil)

_, err = s.s.Execute(goCtx, "use test_ddl")
c.Assert(err, IsNil)

s.Bootstrap(c)

// Stop current DDL worker, so that we can't be the owner now.
err = domain.GetDomain(s.ctx).DDL().Stop()
c.Assert(err, IsNil)
ddl.RunWorker = false
session.ResetStoreForWithTiKVTest(s.store)
s.s, err = session.CreateSession(s.store)
c.Assert(err, IsNil)
s.dom, err = session.BootstrapSession(s.store)
c.Assert(err, IsNil)
s.ctx = s.s.(sessionctx.Context)
_, err = s.s.Execute(goCtx, "use test_ddl")
c.Assert(err, IsNil)

addEnvPath("..")

Expand Down
78 changes: 40 additions & 38 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ const (
DefTxnEntryCountLimit = 300 * 1000
// DefTxnTotalSizeLimit is the default value of TxnTxnTotalSizeLimit.
DefTxnTotalSizeLimit = 100 * 1024 * 1024
// DefMaxIndexLength is the maximum index length(in bytes). This value is consistent with MySQL.
DefMaxIndexLength = 3072
// DefMaxOfMaxIndexLength is the maximum index length(in bytes) for TiDB v3.0.7 and previous version.
DefMaxOfMaxIndexLength = 3072 * 4
)

// Valid config maps
Expand Down Expand Up @@ -90,6 +94,7 @@ type Config struct {
Plugin Plugin `toml:"plugin" json:"plugin"`
PessimisticTxn PessimisticTxn `toml:"pessimistic-txn" json:"pessimistic-txn"`
CheckMb4ValueInUTF8 bool `toml:"check-mb4-value-in-utf8" json:"check-mb4-value-in-utf8"`
MaxIndexLength int `toml:"max-index-length" json:"max-index-length"`
// AlterPrimaryKey is used to control alter primary key feature.
AlterPrimaryKey bool `toml:"alter-primary-key" json:"alter-primary-key"`
// TreatOldVersionUTF8AsUTF8MB4 is use to treat old version table/column UTF8 charset as UTF8MB4. This is for compatibility.
Expand Down Expand Up @@ -126,13 +131,14 @@ type Log struct {

// Security is the security section of the config.
type Security struct {
SkipGrantTable bool `toml:"skip-grant-table" json:"skip-grant-table"`
SSLCA string `toml:"ssl-ca" json:"ssl-ca"`
SSLCert string `toml:"ssl-cert" json:"ssl-cert"`
SSLKey string `toml:"ssl-key" json:"ssl-key"`
ClusterSSLCA string `toml:"cluster-ssl-ca" json:"cluster-ssl-ca"`
ClusterSSLCert string `toml:"cluster-ssl-cert" json:"cluster-ssl-cert"`
ClusterSSLKey string `toml:"cluster-ssl-key" json:"cluster-ssl-key"`
SkipGrantTable bool `toml:"skip-grant-table" json:"skip-grant-table"`
SSLCA string `toml:"ssl-ca" json:"ssl-ca"`
SSLCert string `toml:"ssl-cert" json:"ssl-cert"`
SSLKey string `toml:"ssl-key" json:"ssl-key"`
ClusterSSLCA string `toml:"cluster-ssl-ca" json:"cluster-ssl-ca"`
ClusterSSLCert string `toml:"cluster-ssl-cert" json:"cluster-ssl-cert"`
ClusterSSLKey string `toml:"cluster-ssl-key" json:"cluster-ssl-key"`
ClusterVerifyCN []string `toml:"cluster-verify-cn" json:"cluster-verify-cn"`
}

// The ErrConfigValidationFailed error is used so that external callers can do a type assertion
Expand All @@ -149,47 +155,39 @@ func (e *ErrConfigValidationFailed) Error() string {
}

// ToTLSConfig generates tls's config based on security section of the config.
func (s *Security) ToTLSConfig() (tlsConfig *tls.Config, err error) {
func (s *Security) ToTLSConfig() (*tls.Config, error) {
var tlsConfig *tls.Config
if len(s.ClusterSSLCA) != 0 {
certPool := x509.NewCertPool()
var certificates = make([]tls.Certificate, 0)
if len(s.ClusterSSLCert) != 0 && len(s.ClusterSSLKey) != 0 {
// Load the client certificates from disk
certificate, err := tls.LoadX509KeyPair(s.ClusterSSLCert, s.ClusterSSLKey)
if err != nil {
return nil, errors.Errorf("could not load client key pair: %s", err)
}
certificates = append(certificates, certificate)
}

// Create a certificate pool from the certificate authority
var ca []byte
ca, err = ioutil.ReadFile(s.ClusterSSLCA)
certPool := x509.NewCertPool()
ca, err := ioutil.ReadFile(s.ClusterSSLCA)
if err != nil {
err = errors.Errorf("could not read ca certificate: %s", err)
return
return nil, errors.Errorf("could not read ca certificate: %s", err)
}

// Append the certificates from the CA
if !certPool.AppendCertsFromPEM(ca) {
err = errors.New("failed to append ca certs")
return
}
tlsConfig = &tls.Config{
RootCAs: certPool,
return nil, errors.New("failed to append ca certs")
}

if len(s.ClusterSSLCert) != 0 && len(s.ClusterSSLKey) != 0 {
getCert := func() (*tls.Certificate, error) {
// Load the client certificates from disk
cert, err := tls.LoadX509KeyPair(s.ClusterSSLCert, s.ClusterSSLKey)
if err != nil {
return nil, errors.Errorf("could not load client key pair: %s", err)
}
return &cert, nil
}
// pre-test cert's loading.
if _, err = getCert(); err != nil {
return
}
tlsConfig.GetClientCertificate = func(info *tls.CertificateRequestInfo) (certificate *tls.Certificate, err error) {
return getCert()
}
tlsConfig.GetCertificate = func(info *tls.ClientHelloInfo) (certificate *tls.Certificate, err error) {
return getCert()
}
tlsConfig = &tls.Config{
Certificates: certificates,
RootCAs: certPool,
ClientCAs: certPool,
}
}
return

return tlsConfig, nil
}

// Status is the status section of the config.
Expand Down Expand Up @@ -380,6 +378,7 @@ var defaultConf = Config{
EnableStreaming: false,
EnableBatchDML: false,
CheckMb4ValueInUTF8: true,
MaxIndexLength: 3072,
AlterPrimaryKey: false,
TreatOldVersionUTF8AsUTF8MB4: true,
SplitRegionMaxNum: 1000,
Expand Down Expand Up @@ -626,6 +625,9 @@ func (c *Config) Valid() error {
if c.Store == "mocktikv" && !c.RunDDL {
return fmt.Errorf("can't disable DDL on mocktikv")
}
if c.MaxIndexLength < DefMaxIndexLength || c.MaxIndexLength > DefMaxOfMaxIndexLength {
return fmt.Errorf("max-index-length should be [%d, %d]", DefMaxIndexLength, DefMaxOfMaxIndexLength)
}
if c.Log.File.MaxSize > MaxLogFileSize {
return fmt.Errorf("invalid max log file size=%v which is larger than max=%v", c.Log.File.MaxSize, MaxLogFileSize)
}
Expand Down
3 changes: 3 additions & 0 deletions config/config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ check-mb4-value-in-utf8 = true
# treat-old-version-utf8-as-utf8mb4 use for upgrade compatibility. Set to true will treat old version table/column UTF8 charset as UTF8MB4.
treat-old-version-utf8-as-utf8mb4 = true

# max-index-length is used to deal with compatibility issues from v3.0.7 and previous version upgrades. It can only be in [3072, 3072*4].
max-index-length = 3072

# Maximum number of the splitting region, which is used by the split region statement.
split-region-max-num = 1000

Expand Down
14 changes: 14 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ split-region-max-num=10000
server-version = "test_version"
enable-table-lock = true
delay-clean-table-lock = 5
max-index-length = 3080
[performance]
txn-entry-count-limit=2000
txn-total-size-limit=2000
Expand Down Expand Up @@ -122,6 +123,7 @@ allow-auto-random = true
c.Assert(conf.DelayCleanTableLock, Equals, uint64(5))
c.Assert(conf.IsolationRead.Engines, DeepEquals, []string{"tiflash"})
c.Assert(conf.Experimental.AllowAutoRandom, IsTrue)
c.Assert(conf.MaxIndexLength, Equals, 3080)
c.Assert(f.Close(), IsNil)
c.Assert(os.Remove(configFile), IsNil)

Expand Down Expand Up @@ -269,3 +271,15 @@ func (s *testConfigSuite) TestAllowAutoRandomValid(c *C) {
checkValid(false, true, true)
checkValid(false, false, true)
}

func (s *testConfigSuite) TestMaxIndexLength(c *C) {
conf := NewConfig()
checkValid := func(indexLen int, shouldBeValid bool) {
conf.MaxIndexLength = indexLen
c.Assert(conf.Valid() == nil, Equals, shouldBeValid)
}
checkValid(DefMaxIndexLength, true)
checkValid(DefMaxIndexLength-1, false)
checkValid(DefMaxOfMaxIndexLength, true)
checkValid(DefMaxOfMaxIndexLength+1, false)
}
4 changes: 0 additions & 4 deletions ddl/column_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ func (s *testColumnChangeSuite) TestColumnChange(c *C) {
}

func (s *testColumnChangeSuite) testAddColumnNoDefault(c *C, ctx sessionctx.Context, d *ddl, tblInfo *model.TableInfo) {
d.Stop()
tc := &TestDDLCallback{}
// set up hook
prevState := model.StateNone
Expand Down Expand Up @@ -190,14 +189,12 @@ func (s *testColumnChangeSuite) testAddColumnNoDefault(c *C, ctx sessionctx.Cont
}
}
d.SetHook(tc)
d.start(context.Background(), nil)
job := testCreateColumn(c, ctx, d, s.dbInfo, tblInfo, "c3", &ast.ColumnPosition{Tp: ast.ColumnPositionNone}, nil)
c.Assert(errors.ErrorStack(checkErr), Equals, "")
testCheckJobDone(c, d, job, true)
}

func (s *testColumnChangeSuite) testColumnDrop(c *C, ctx sessionctx.Context, d *ddl, tbl table.Table) {
d.Stop()
dropCol := tbl.Cols()[2]
tc := &TestDDLCallback{}
// set up hook
Expand All @@ -219,7 +216,6 @@ func (s *testColumnChangeSuite) testColumnDrop(c *C, ctx sessionctx.Context, d *
}
}
d.SetHook(tc)
d.start(context.Background(), nil)
c.Assert(errors.ErrorStack(checkErr), Equals, "")
testDropColumn(c, ctx, d, s.dbInfo, tbl.Meta(), dropCol.Name.L, false)
}
Expand Down
Loading

0 comments on commit f7e6943

Please sign in to comment.