(tx *bolt.Tx, bucket []byte, key []byte, writeBytes bytesRange, noopWriteRatio int)
| 463 | } |
| 464 | |
| 465 | func executeWrite(tx *bolt.Tx, bucket []byte, key []byte, writeBytes bytesRange, noopWriteRatio int) (historyRecord, error) { |
| 466 | var rec historyRecord |
| 467 | |
| 468 | if mrand.Intn(100) < noopWriteRatio { |
| 469 | // A no-op write transaction has two consequences: |
| 470 | // 1. The txid increases by 1; |
| 471 | // 2. Two meta pages point to the same root page. |
| 472 | rec = historyRecord{ |
| 473 | OperationType: Write, |
| 474 | Bucket: string(bucket), |
| 475 | Key: noopTxKey, |
| 476 | Value: nil, |
| 477 | Txid: tx.ID(), |
| 478 | } |
| 479 | return rec, nil |
| 480 | } |
| 481 | |
| 482 | b := tx.Bucket(bucket) |
| 483 | |
| 484 | valueBytes := randomIntInRange(writeBytes.min, writeBytes.max) |
| 485 | v := make([]byte, valueBytes) |
| 486 | if _, cErr := crand.Read(v); cErr != nil { |
| 487 | return rec, cErr |
| 488 | } |
| 489 | |
| 490 | putErr := b.Put(key, v) |
| 491 | if putErr == nil { |
| 492 | rec = historyRecord{ |
| 493 | OperationType: Write, |
| 494 | Bucket: string(bucket), |
| 495 | Key: string(key), |
| 496 | Value: v, |
| 497 | Txid: tx.ID(), |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | return rec, putErr |
| 502 | } |
| 503 | |
| 504 | func executeDelete(tx *bolt.Tx, bucket []byte, key []byte) (historyRecord, error) { |
| 505 | var rec historyRecord |
no test coverage detected