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

Function runReadsSequential

cmd/bbolt/command/command_bench.go:441–477  ·  view source on GitHub ↗
(cmd *cobra.Command, db *bolt.DB, options *benchOptions, results *benchResults)

Source from the content-addressed store, hash-verified

439type nestedKey struct{ bucket, key []byte }
440
441func runReadsSequential(cmd *cobra.Command, db *bolt.DB, options *benchOptions, results *benchResults) error {
442 return db.View(func(tx *bolt.Tx) error {
443 t := time.Now()
444
445 for {
446 numReads := int64(0)
447 err := func() error {
448 defer func() { results.addCompletedOps(numReads) }()
449
450 c := tx.Bucket(benchBucketName).Cursor()
451 for k, v := c.First(); k != nil; k, v = c.Next() {
452 numReads++
453 if v == nil {
454 return ErrInvalidValue
455 }
456 }
457
458 return nil
459 }()
460
461 if err != nil {
462 return err
463 }
464
465 if options.writeMode == "seq" && numReads != options.iterations {
466 return fmt.Errorf("read seq: iter mismatch: expected %d, got %d", options.iterations, numReads)
467 }
468
469 // Make sure we do this for at least a second.
470 if time.Since(t) >= time.Second {
471 break
472 }
473 }
474
475 return nil
476 })
477}
478
479func runReadsRandom(cmd *cobra.Command, db *bolt.DB, options *benchOptions, keys []nestedKey, results *benchResults) error {
480 return db.View(func(tx *bolt.Tx) error {

Callers 1

runReadsFunction · 0.85

Calls 7

ViewMethod · 0.80
addCompletedOpsMethod · 0.80
FirstMethod · 0.80
NextMethod · 0.80
ErrorfMethod · 0.65
CursorMethod · 0.45
BucketMethod · 0.45

Tested by

no test coverage detected