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

kv: fix err check #22994

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion kv/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ func (s testMockSuite) TestInterface(c *C) {
_, err = transaction.IterReverse(Key("lock"))
c.Check(err, IsNil)
}
transaction.Commit(context.Background())
// to fix: cannot assert err, e.g. KV error safe to retry %s
_ = transaction.Commit(context.Background())
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

This code just check the API interface, even if here returns an error, it doesn't matter.


transaction, err = storage.Begin()
c.Check(err, IsNil)
Expand Down
55 changes: 44 additions & 11 deletions store/tikv/unionstore/memdb_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ func BenchmarkLargeIndex(b *testing.B) {
b.ResetTimer()

for i := range buf {
db.Set(buf[i][:keySize], buf[i][:])
err := db.Set(buf[i][:keySize], buf[i][:])
if err != nil {
b.Fatal(err)
}
}
}

Expand All @@ -55,7 +58,10 @@ func BenchmarkPut(b *testing.B) {
b.ResetTimer()

for i := range buf {
p.Set(buf[i][:keySize], buf[i][:])
err := p.Set(buf[i][:keySize], buf[i][:])
if err != nil {
b.Fatal(err)
}
}
}

Expand All @@ -69,7 +75,10 @@ func BenchmarkPutRandom(b *testing.B) {
b.ResetTimer()

for i := range buf {
p.Set(buf[i][:keySize], buf[i][:])
err := p.Set(buf[i][:keySize], buf[i][:])
if err != nil {
b.Fatal(err)
}
}
}

Expand All @@ -81,12 +90,18 @@ func BenchmarkGet(b *testing.B) {

p := newMemDBForBench()
for i := range buf {
p.Set(buf[i][:keySize], buf[i][:])
err := p.Set(buf[i][:keySize], buf[i][:])
if err != nil {
b.Fatal(err)
}
}

b.ResetTimer()
for i := range buf {
p.Get(buf[i][:keySize])
_, err := p.Get(buf[i][:keySize])
if err != nil {
b.Fatal(err)
}
}
}

Expand All @@ -98,12 +113,18 @@ func BenchmarkGetRandom(b *testing.B) {

p := newMemDBForBench()
for i := range buf {
p.Set(buf[i][:keySize], buf[i][:])
err := p.Set(buf[i][:keySize], buf[i][:])
if err != nil {
b.Fatal(err)
}
}

b.ResetTimer()
for i := 0; i < b.N; i++ {
p.Get(buf[i][:keySize])
_, err := p.Get(buf[i][:keySize])
if err != nil {
b.Fatal(err)
}
}
}

Expand Down Expand Up @@ -155,17 +176,26 @@ func benchmarkSetGet(b *testing.B, buffer *MemDB, data [][]byte) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
for _, k := range data {
buffer.Set(k, k)
err := buffer.Set(k, k)
if err != nil {
b.Fatal(err)
}
}
for _, k := range data {
buffer.Get(k)
_, err := buffer.Get(k)
if err != nil {
b.Fatal(err)
}
}
}
}

func benchIterator(b *testing.B, buffer *MemDB) {
for k := 0; k < opCnt; k++ {
buffer.Set(encodeInt(k), encodeInt(k))
err := buffer.Set(encodeInt(k), encodeInt(k))
if err != nil {
b.Fatal(err)
}
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
Expand All @@ -174,7 +204,10 @@ func benchIterator(b *testing.B, buffer *MemDB) {
b.Error(err)
}
for iter.Valid() {
iter.Next()
err := iter.Next()
if err != nil {
b.Fatal(err)
}
}
iter.Close()
}
Expand Down
21 changes: 14 additions & 7 deletions store/tikv/unionstore/memdb_norace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ func (s testMemDBSuite) TestRandom(c *C) {
p1 := newMemDB()
p2 := leveldb.New(comparer.DefaultComparer, 4*1024)
for _, k := range keys {
p1.Set(k, k)
err := p1.Set(k, k)
c.Assert(err, IsNil)
_ = p2.Put(k, k)
}

Expand All @@ -50,11 +51,13 @@ func (s testMemDBSuite) TestRandom(c *C) {
op := rand.Float64()
if op < 0.35 {
p1.DeleteKey(k)
p2.Delete(k)
// to fix: delete key not found
_ = p2.Delete(k)
Copy link
Contributor

Choose a reason for hiding this comment

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

@tiancaiamao
I think we need to check this error.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it does not need to be so strict, there is already _ = p2.Put(k, k) in the previous code. And it is a test case.

} else {
newValue := make([]byte, rand.Intn(19)+1)
rand.Read(newValue)
p1.Set(k, newValue)
err := p1.Set(k, newValue)
c.Assert(err, IsNil)
_ = p2.Put(k, newValue)
}
}
Expand Down Expand Up @@ -102,14 +105,16 @@ func (s testMemDBSuite) testRandomDeriveRecur(c *C, db *MemDB, golden *leveldb.D
h := db.Staging()
opLog := make([][2][]byte, 0, len(keys))
for i := range keys {
db.Set(keys[i], vals[i])
err := db.Set(keys[i], vals[i])
c.Assert(err, IsNil)
old, err := golden.Get(keys[i])
if err != nil {
opLog = append(opLog, [2][]byte{keys[i], nil})
} else {
opLog = append(opLog, [2][]byte{keys[i], old})
}
golden.Put(keys[i], vals[i])
err = golden.Put(keys[i], vals[i])
c.Assert(err, IsNil)
}

if depth < 2000 {
Expand All @@ -121,9 +126,11 @@ func (s testMemDBSuite) testRandomDeriveRecur(c *C, db *MemDB, golden *leveldb.D
db.Cleanup(h)
for i := len(opLog) - 1; i >= 0; i-- {
if opLog[i][1] == nil {
golden.Delete(opLog[i][0])
err := golden.Delete(opLog[i][0])
c.Assert(err, IsNil)
} else {
golden.Put(opLog[i][0], opLog[i][1])
err := golden.Put(opLog[i][0], opLog[i][1])
c.Assert(err, IsNil)
}
}
opLog = nil
Expand Down
Loading