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
65 changes: 50 additions & 15 deletions meta/meta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,17 @@ func (s *testSuite) TestMeta(c *C) {
defer testleak.AfterTest(c)()
store, err := mockstore.NewMockStore()
c.Assert(err, IsNil)
defer store.Close()
defer func() {
// to fix: close fails
_ = store.Close()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to fix it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not very familiar with the code in meta package, but I assume store.Close() should be err nil, however it returned err in this line. So either we ignore the err or somewhat fix the test?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look at this code, I think we can remove line57-60. Because we commit this txn on line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed and test passed.

}()

txn, err := store.Begin()
c.Assert(err, IsNil)
defer txn.Rollback()
defer func() {
// to fix : occasion failure
_ = txn.Rollback()
}()

t := meta.NewMeta(txn)

Expand Down Expand Up @@ -275,23 +281,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,12 +344,18 @@ 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()
defer func() {
// to fix: codeText:"kv:8024", message:"invalid transaction"
_ = txn.Rollback()
}()

t := meta.NewMeta(txn)

Expand Down Expand Up @@ -437,7 +456,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 +489,10 @@ func (s *testSuite) TestDDL(c *C) {
// Test for add index job.
txn1, err := store.Begin()
c.Assert(err, IsNil)
defer txn1.Rollback()
defer func() {
// to fix : occasion failure
_ = txn1.Rollback()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you check this code too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}()

m := meta.NewMeta(txn1, meta.AddIndexJobListKey)
err = m.EnQueueDDLJob(job)
Expand Down Expand Up @@ -498,11 +521,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 +548,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