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

Function executeWrite

concurrent_test.go:465–502  ·  concurrent_test.go::executeWrite
(tx *bolt.Tx, bucket []byte, key []byte, writeBytes bytesRange, noopWriteRatio int)

Source from the content-addressed store, hash-verified

463}
464
465func 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
504func executeDelete(tx *bolt.Tx, bucket []byte, key []byte) (historyRecord, error) {
505 var rec historyRecord

Callers 2

executeOperationFunction · 0.85

Calls 5

randomIntInRangeFunction · 0.85
IDMethod · 0.80
ReadMethod · 0.65
BucketMethod · 0.45
PutMethod · 0.45

Tested by

no test coverage detected