MCPcopy
hub / github.com/etcd-io/bbolt / validateBatchBench

Function validateBatchBench

db_test.go:2174–2207  ·  view source on GitHub ↗
(b *testing.B, db *btesting.DB)

Source from the content-addressed store, hash-verified

2172}
2173
2174func validateBatchBench(b *testing.B, db *btesting.DB) {
2175 var rollback = errors.New("sentinel error to cause rollback")
2176 validate := func(tx *bolt.Tx) error {
2177 bucket := tx.Bucket([]byte("bench"))
2178 h := fnv.New32a()
2179 buf := make([]byte, 4)
2180 for id := uint32(0); id < 1000; id++ {
2181 binary.LittleEndian.PutUint32(buf, id)
2182 h.Reset()
2183 _, _ = h.Write(buf[:])
2184 k := h.Sum(nil)
2185 v := bucket.Get(k)
2186 if v == nil {
2187 b.Errorf("not found id=%d key=%x", id, k)
2188 continue
2189 }
2190 if g, e := v, []byte("filler"); !bytes.Equal(g, e) {
2191 b.Errorf("bad value for id=%d key=%x: %s != %q", id, k, g, e)
2192 }
2193 if err := bucket.Delete(k); err != nil {
2194 return err
2195 }
2196 }
2197 // should be empty now
2198 c := bucket.Cursor()
2199 for k, v := c.First(); k != nil; k, v = c.Next() {
2200 b.Errorf("unexpected key: %x = %q", k, v)
2201 }
2202 return rollback
2203 }
2204 if err := db.Update(validate); err != nil && err != rollback {
2205 b.Error(err)
2206 }
2207}
2208
2209// tempfile returns a temporary file path.
2210func tempfile() string {

Callers 3

BenchmarkDBBatchSingleFunction · 0.85

Calls 10

FirstMethod · 0.80
NextMethod · 0.80
UpdateMethod · 0.80
WriteMethod · 0.65
ErrorfMethod · 0.65
ErrorMethod · 0.65
BucketMethod · 0.45
GetMethod · 0.45
DeleteMethod · 0.45
CursorMethod · 0.45

Tested by

no test coverage detected