MCPcopy Create free account
hub / github.com/nutsdb/nutsdb / writeData

Method writeData

tx.go:507–533  ·  view source on GitHub ↗
(data []byte)

Source from the content-addressed store, hash-verified

505}
506
507func (tx *Tx) writeData(data []byte) (n int, err error) {
508 if len(data) == 0 {
509 return
510 }
511
512 writeOffset := tx.db.ActiveFile.ActualSize
513
514 l := len(data)
515 if writeOffset+int64(l) > tx.db.opt.SegmentSize {
516 return 0, errors.New("not enough file space")
517 }
518
519 if n, err = tx.db.ActiveFile.WriteAt(data, writeOffset); err != nil {
520 return
521 }
522
523 tx.db.ActiveFile.writeOff += int64(l)
524 tx.db.ActiveFile.ActualSize += int64(l)
525
526 if tx.db.opt.SyncEnable {
527 if err := tx.db.ActiveFile.rwManager.Sync(); err != nil {
528 return 0, err
529 }
530 }
531
532 return
533}
534
535// Rollback closes the transaction.
536func (tx *Tx) Rollback() error {

Callers 1

CommitMethod · 0.95

Calls 2

WriteAtMethod · 0.65
SyncMethod · 0.65

Tested by

no test coverage detected