| 439 | type nestedKey struct{ bucket, key []byte } |
| 440 | |
| 441 | func 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 | |
| 479 | func runReadsRandom(cmd *cobra.Command, db *bolt.DB, options *benchOptions, keys []nestedKey, results *benchResults) error { |
| 480 | return db.View(func(tx *bolt.Tx) error { |