Skip to content

Commit

Permalink
test: fix shard row id bits test (#14489)
Browse files Browse the repository at this point in the history
  • Loading branch information
tangenta committed Feb 12, 2020
1 parent 17d9bc8 commit 472ae25
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 24 deletions.
8 changes: 4 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ type Config struct {
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.
// Currently not support dynamic modify, because this need to reload all old version schema.
TreatOldVersionUTF8AsUTF8MB4 bool `toml:"treat-old-version-utf8-as-utf8mb4" json:"treat-old-version-utf8-as-utf8mb4"`
SplitRegionMaxNum uint64 `toml:"split-region-max-num" json:"split-region-max-num"`
StmtSummary StmtSummary `toml:"stmt-summary" json:"stmt-summary"`
Experimental Experimental `toml:"experimental" json:"experimental"`
TreatOldVersionUTF8AsUTF8MB4 bool `toml:"treat-old-version-utf8-as-utf8mb4" json:"treat-old-version-utf8-as-utf8mb4"`
SplitRegionMaxNum uint64 `toml:"split-region-max-num" json:"split-region-max-num"`
StmtSummary StmtSummary `toml:"stmt-summary" json:"stmt-summary"`
Experimental Experimental `toml:"experimental" json:"experimental"`
}

// Log is the log section of config.
Expand Down
2 changes: 1 addition & 1 deletion ddl/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ const (
codeSystemVersioningWrongPartitions = terror.ErrCode(mysql.ErrSystemVersioningWrongPartitions)
codeWrongPartitionTypeExpectedSystemTime = terror.ErrCode(mysql.ErrWrongPartitionTypeExpectedSystemTime)
codeWrongTypeColumnValue = terror.ErrCode(mysql.ErrWrongTypeColumnValue)
codeInvalidAutoRandom = terror.ErrCode(mysql.ErrInvalidAutoRandom)
codeInvalidAutoRandom = terror.ErrCode(mysql.ErrInvalidAutoRandom)
)

func init() {
Expand Down
18 changes: 4 additions & 14 deletions executor/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,11 +633,9 @@ func (s *testSuite3) TestShardRowIDBits(c *C) {

tk.MustExec("use test")
tk.MustExec("create table t (a int) shard_row_id_bits = 15")
var insertingValues = make([]string, 100)
for i := 0; i < 100; i++ {
insertingValues[i] = fmt.Sprintf("(%d)", i)
tk.MustExec("insert into t values (?)", i)
}
tk.MustExec("insert into t values " + strings.Join(insertingValues, ","))

dom := domain.GetDomain(tk.Se)
tbl, err := dom.InfoSchema().TableByName(model.NewCIStr("test"), model.NewCIStr("t"))
Expand Down Expand Up @@ -711,11 +709,9 @@ func (s *testSuite3) TestShardRowIDBits(c *C) {

// Test shard_row_id_bits with auto_increment column
tk.MustExec("create table auto (a int, b int auto_increment unique) shard_row_id_bits = 15")
insertingValues = make([]string, 100)
for i := 0; i < 100; i++ {
insertingValues[i] = fmt.Sprintf("(%d)", i)
tk.MustExec("insert into auto(a) values (?)", i)
}
tk.MustExec("insert auto(a) values " + strings.Join(insertingValues, ","))
tbl, err = dom.InfoSchema().TableByName(model.NewCIStr("test"), model.NewCIStr("auto"))
assertCountAndShard(tbl, 100)
prevB, err := strconv.Atoi(tk.MustQuery("select b from auto where a=0").Rows()[0][0].(string))
Expand Down Expand Up @@ -762,12 +758,9 @@ func (s *testAutoRandomSuite) TestAutoRandomBitsData(c *C) {
defer testutil.ConfigTestUtils.RestoreAutoRandomTestConfig()

tk.MustExec("create table t (a bigint primary key auto_random(15), b int)")
insertingValues := make([]string, 100)
for i := 0; i < 100; i++ {
insertingValues[i] = fmt.Sprintf("(%d)", i)
tk.MustExec("insert into t(b) values (?)", i)
}
tk.MustExec(fmt.Sprintf("insert into t (b) values %s;", strings.Join(insertingValues, ",")))

dom := domain.GetDomain(tk.Se)
tbl, err := dom.InfoSchema().TableByName(model.NewCIStr("test_auto_random_bits"), model.NewCIStr("t"))
c.Assert(err, IsNil)
Expand Down Expand Up @@ -800,12 +793,9 @@ func (s *testAutoRandomSuite) TestAutoRandomBitsData(c *C) {

// Test explicit insert.
tk.MustExec("create table t (a tinyint primary key auto_random(2), b int)")
insertingValues = make([]string, 100)
for i := 0; i < 100; i++ {
insertingValues[i] = fmt.Sprintf("(%d, %d)", i, i)
tk.MustExec("insert into t values (?, ?)", i, i)
}
tk.MustExec(fmt.Sprintf("insert into t values %s;", strings.Join(insertingValues, ",")))

_, err = tk.Exec("insert into t (b) values (0)")
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, autoid.ErrAutoRandReadFailed.GenWithStackByArgs().Error())
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ github.com/blacktear23/go-proxyprotocol v0.0.0-20180807104634-af7a81e8dd0d/go.mo
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20171208011716-f6d7a1f6fbf3/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa h1:OaNxuTZr7kxeODyLWsRMC+OD03aFUH+mW6r2d+MWa5Y=
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
Expand Down
6 changes: 3 additions & 3 deletions meta/autoid/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import (

// Error instances.
var (
ErrAutoincReadFailed = terror.ClassAutoid.New(mysql.ErrAutoincReadFailed, mysql.MySQLErrName[mysql.ErrAutoincReadFailed])
ErrWrongAutoKey = terror.ClassAutoid.New(mysql.ErrWrongAutoKey, mysql.MySQLErrName[mysql.ErrWrongAutoKey])
ErrAutoincReadFailed = terror.ClassAutoid.New(mysql.ErrAutoincReadFailed, mysql.MySQLErrName[mysql.ErrAutoincReadFailed])
ErrWrongAutoKey = terror.ClassAutoid.New(mysql.ErrWrongAutoKey, mysql.MySQLErrName[mysql.ErrWrongAutoKey])
errInvalidTableID = terror.ClassAutoid.New(codeInvalidTableID, "invalid TableID")
errInvalidAllocatorType = terror.ClassAutoid.New(mysql.ErrUnknownAllocatorType, mysql.MySQLErrName[mysql.ErrUnknownAllocatorType])
ErrAutoRandReadFailed = terror.ClassAutoid.New(mysql.ErrAutoRandReadFailed, mysql.MySQLErrName[mysql.ErrAutoRandReadFailed])
ErrAutoRandReadFailed = terror.ClassAutoid.New(mysql.ErrAutoRandReadFailed, mysql.MySQLErrName[mysql.ErrAutoRandReadFailed])
)

// codeInvalidTableID is the code of autoid error.
Expand Down
4 changes: 2 additions & 2 deletions util/admin/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ func (s *testSuite) TestScan(c *C) {
c.Assert(err, IsNil)
tbInfo := tbl.Meta()

alloc := autoid.NewAllocator(s.store, dbInfo.ID, false)
tb, err := tables.TableFromMeta(alloc, tbInfo)
allocs := autoid.NewAllocatorsFromTblInfo(s.store, dbInfo.ID, tbInfo)
tb, err := tables.TableFromMeta(allocs, tbInfo)
c.Assert(err, IsNil)
indices := tb.Indices()
c.Assert(s.ctx.NewTxn(context.Background()), IsNil)
Expand Down
5 changes: 5 additions & 0 deletions util/kvencoder/allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ func (alloc *Allocator) Alloc(tableID int64, n uint64) (int64, int64, error) {
return min, atomic.AddInt64(&alloc.base, int64(n)), nil
}

// GetType always returns autoid.RowIDAllocType.
func (alloc *Allocator) GetType() autoid.AllocatorType {
return autoid.RowIDAllocType
}

// Reset allow newBase smaller than alloc.base, and will set the alloc.base to newBase.
func (alloc *Allocator) Reset(newBase int64) {
atomic.StoreInt64(&alloc.base, newBase)
Expand Down

0 comments on commit 472ae25

Please sign in to comment.