Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

meta: fix err check #22995

Merged
merged 10 commits into from
Mar 3, 2021
59 changes: 48 additions & 11 deletions meta/autoid/autoid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ func (*testSuite) TestT(c *C) {

store, err := mockstore.NewMockStore()
c.Assert(err, IsNil)
defer store.Close()
defer func() {
err := store.Close()
c.Assert(err, IsNil)
}()

err = kv.RunInNewTxn(context.Background(), store, false, func(ctx context.Context, txn kv.Transaction) error {
m := meta.NewMeta(txn)
Expand Down Expand Up @@ -254,7 +257,10 @@ func (*testSuite) TestUnsignedAutoid(c *C) {

store, err := mockstore.NewMockStore()
c.Assert(err, IsNil)
defer store.Close()
defer func() {
err := store.Close()
c.Assert(err, IsNil)
}()

err = kv.RunInNewTxn(context.Background(), store, false, func(ctx context.Context, txn kv.Transaction) error {
m := meta.NewMeta(txn)
Expand Down Expand Up @@ -412,7 +418,10 @@ func (*testSuite) TestUnsignedAutoid(c *C) {
func (*testSuite) TestConcurrentAlloc(c *C) {
store, err := mockstore.NewMockStore()
c.Assert(err, IsNil)
defer store.Close()
defer func() {
err := store.Close()
c.Assert(err, IsNil)
}()
autoid.SetStep(100)
defer func() {
autoid.SetStep(5000)
Expand Down Expand Up @@ -500,7 +509,10 @@ func (*testSuite) TestConcurrentAlloc(c *C) {
func (*testSuite) TestRollbackAlloc(c *C) {
store, err := mockstore.NewMockStore()
c.Assert(err, IsNil)
defer store.Close()
defer func() {
err := store.Close()
c.Assert(err, IsNil)
}()
dbID := int64(1)
tblID := int64(2)
err = kv.RunInNewTxn(context.Background(), store, false, func(ctx context.Context, txn kv.Transaction) error {
Expand Down Expand Up @@ -545,7 +557,12 @@ func BenchmarkAllocator_Alloc(b *testing.B) {
if err != nil {
return
}
defer store.Close()
defer func() {
err := store.Close()
if err != nil {
b.Fatal(err)
}
}()
dbID := int64(1)
tblID := int64(2)
err = kv.RunInNewTxn(context.Background(), store, false, func(ctx context.Context, txn kv.Transaction) error {
Expand All @@ -567,7 +584,10 @@ func BenchmarkAllocator_Alloc(b *testing.B) {
alloc := autoid.NewAllocator(store, 1, false, autoid.RowIDAllocType)
b.StartTimer()
for i := 0; i < b.N; i++ {
alloc.Alloc(ctx, 2, 1, 1, 1)
_, _, err := alloc.Alloc(ctx, 2, 1, 1, 1)
if err != nil {
b.Fatal(err)
}
}
}

Expand All @@ -577,7 +597,12 @@ func BenchmarkAllocator_SequenceAlloc(b *testing.B) {
if err != nil {
return
}
defer store.Close()
defer func() {
err := store.Close()
if err != nil {
b.Fatal(err)
}
}()
var seq *model.SequenceInfo
var sequenceBase int64
err = kv.RunInNewTxn(context.Background(), store, false, func(ctx context.Context, txn kv.Transaction) error {
Expand Down Expand Up @@ -623,14 +648,20 @@ func BenchmarkAllocator_Seek(b *testing.B) {
increment := int64(3)
b.StartTimer()
for i := 0; i < b.N; i++ {
autoid.CalcSequenceBatchSize(base, 3, increment, offset, math.MinInt64, math.MaxInt64)
_, err := autoid.CalcSequenceBatchSize(base, 3, increment, offset, math.MinInt64, math.MaxInt64)
if err != nil {
b.Fatal(err)
}
}
}

func (*testSuite) TestSequenceAutoid(c *C) {
store, err := mockstore.NewMockStore()
c.Assert(err, IsNil)
defer store.Close()
defer func() {
err := store.Close()
c.Assert(err, IsNil)
}()

var seq *model.SequenceInfo
var sequenceBase int64
Expand Down Expand Up @@ -751,7 +782,10 @@ func (*testSuite) TestSequenceAutoid(c *C) {
func (*testSuite) TestConcurrentAllocSequence(c *C) {
store, err := mockstore.NewMockStore()
c.Assert(err, IsNil)
defer store.Close()
defer func() {
err := store.Close()
c.Assert(err, IsNil)
}()

var seq *model.SequenceInfo
var sequenceBase int64
Expand Down Expand Up @@ -841,7 +875,10 @@ func (*testSuite) TestAllocComputationIssue(c *C) {

store, err := mockstore.NewMockStore()
c.Assert(err, IsNil)
defer store.Close()
defer func() {
err := store.Close()
c.Assert(err, IsNil)
}()

err = kv.RunInNewTxn(context.Background(), store, false, func(ctx context.Context, txn kv.Transaction) error {
m := meta.NewMeta(txn)
Expand Down
54 changes: 38 additions & 16 deletions meta/meta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ func (s *testSuite) TestMeta(c *C) {
defer testleak.AfterTest(c)()
store, err := mockstore.NewMockStore()
c.Assert(err, IsNil)
defer store.Close()
defer func() {
err := store.Close()
c.Assert(err, IsNil)
}()

txn, err := store.Begin()
c.Assert(err, IsNil)
defer txn.Rollback()

t := meta.NewMeta(txn)

Expand Down Expand Up @@ -275,23 +277,30 @@ func (s *testSuite) TestSnapshot(c *C) {
defer testleak.AfterTest(c)()
store, err := mockstore.NewMockStore()
c.Assert(err, IsNil)
defer store.Close()
defer func() {
err := store.Close()
c.Assert(err, IsNil)
}()

txn, _ := store.Begin()
m := meta.NewMeta(txn)
m.GenGlobalID()
_, err = m.GenGlobalID()
c.Assert(err, IsNil)
n, _ := m.GetGlobalID()
c.Assert(n, Equals, int64(1))
txn.Commit(context.Background())
err = txn.Commit(context.Background())
c.Assert(err, IsNil)

ver1, _ := store.CurrentVersion(oracle.GlobalTxnScope)
time.Sleep(time.Millisecond)
txn, _ = store.Begin()
m = meta.NewMeta(txn)
m.GenGlobalID()
_, err = m.GenGlobalID()
c.Assert(err, IsNil)
n, _ = m.GetGlobalID()
c.Assert(n, Equals, int64(2))
txn.Commit(context.Background())
err = txn.Commit(context.Background())
c.Assert(err, IsNil)

snapshot := store.GetSnapshot(ver1)
snapMeta := meta.NewSnapshotMeta(snapshot)
Expand Down Expand Up @@ -331,13 +340,14 @@ func (s *testSuite) TestDDL(c *C) {
defer testleak.AfterTest(c)()
store, err := mockstore.NewMockStore()
c.Assert(err, IsNil)
defer store.Close()
defer func() {
err := store.Close()
c.Assert(err, IsNil)
}()

txn, err := store.Begin()
c.Assert(err, IsNil)

defer txn.Rollback()

t := meta.NewMeta(txn)

job := &model.Job{ID: 1}
Expand Down Expand Up @@ -437,7 +447,8 @@ func (s *testSuite) TestDDL(c *C) {
c.Assert(job.ID, Greater, lastID)
lastID = job.ID
arg1 := ""
job.DecodeArgs(&arg1)
err := job.DecodeArgs(&arg1)
c.Assert(err, IsNil)
if job.ID == historyJob1.ID {
c.Assert(*(job.Args[0].(*string)), Equals, historyJob1.Args[0])
} else {
Expand Down Expand Up @@ -469,7 +480,6 @@ func (s *testSuite) TestDDL(c *C) {
// Test for add index job.
txn1, err := store.Begin()
c.Assert(err, IsNil)
defer txn1.Rollback()

m := meta.NewMeta(txn1, meta.AddIndexJobListKey)
err = m.EnQueueDDLJob(job)
Expand Down Expand Up @@ -498,11 +508,17 @@ func (s *testSuite) BenchmarkGenGlobalIDs(c *C) {
defer testleak.AfterTest(c)()
store, err := mockstore.NewMockStore()
c.Assert(err, IsNil)
defer store.Close()
defer func() {
err := store.Close()
c.Assert(err, IsNil)
}()

txn, err := store.Begin()
c.Assert(err, IsNil)
defer txn.Rollback()
defer func() {
err := txn.Rollback()
c.Assert(err, IsNil)
}()

t := meta.NewMeta(txn)

Expand All @@ -519,11 +535,17 @@ func (s *testSuite) BenchmarkGenGlobalIDOneByOne(c *C) {
defer testleak.AfterTest(c)()
store, err := mockstore.NewMockStore()
c.Assert(err, IsNil)
defer store.Close()
defer func() {
err := store.Close()
c.Assert(err, IsNil)
}()

txn, err := store.Begin()
c.Assert(err, IsNil)
defer txn.Rollback()
defer func() {
err := txn.Rollback()
c.Assert(err, IsNil)
}()

t := meta.NewMeta(txn)

Expand Down