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

Method put

tx.go:602–629  ·  view source on GitHub ↗

put sets the value for a key in the bucket. Returns an error if tx is closed, if performing a write operation on a read-only transaction, if the key is empty.

(bucket string, key, value []byte, ttl uint32, flag uint16, timestamp uint64, ds uint16)

Source from the content-addressed store, hash-verified

600// put sets the value for a key in the bucket.
601// Returns an error if tx is closed, if performing a write operation on a read-only transaction, if the key is empty.
602func (tx *Tx) put(bucket string, key, value []byte, ttl uint32, flag uint16, timestamp uint64, ds uint16) (err error) {
603 if err := tx.checkTxIsClosed(); err != nil {
604 return err
605 }
606
607 bucketStatus, b := tx.getBucketAndItsStatus(ds, bucket)
608 if isBucketNotFoundStatus(bucketStatus) {
609 return ErrBucketNotFound
610 }
611
612 if !tx.writable {
613 return ErrTxNotWritable
614 }
615 bucketId := b.Id
616
617 meta := core.NewMetaData().WithTimeStamp(timestamp).WithKeySize(uint32(len(key))).WithValueSize(uint32(len(value))).WithFlag(flag).
618 WithTTL(ttl).WithStatus(UnCommitted).WithDs(ds).WithTxID(tx.id).WithBucketId(bucketId)
619
620 e := core.NewEntry().WithKey(key).WithMeta(meta).WithValue(value)
621
622 err = e.Valid()
623 if err != nil {
624 return err
625 }
626 tx.submitEntry(ds, bucket, e)
627 tx.size += e.Size()
628 return nil
629}
630
631// setStatusCommitting will change the tx status to txStatusCommitting
632func (tx *Tx) setStatusCommitting() {

Callers 15

pushMethod · 0.95
ZAddMethod · 0.95
ZPopMaxMethod · 0.95
ZPopMinMethod · 0.95
ZRemMethod · 0.95
ZRemRangeByRankMethod · 0.95
PutWithTimestampMethod · 0.95
PutMethod · 0.95
PutIfNotExistsMethod · 0.95
DeleteMethod · 0.95
updateMethod · 0.95
updateOrPutMethod · 0.95

Calls 15

checkTxIsClosedMethod · 0.95
getBucketAndItsStatusMethod · 0.95
submitEntryMethod · 0.95
NewMetaDataFunction · 0.92
NewEntryFunction · 0.92
isBucketNotFoundStatusFunction · 0.85
WithBucketIdMethod · 0.80
WithDsMethod · 0.80
WithStatusMethod · 0.80
WithFlagMethod · 0.80
WithKeySizeMethod · 0.80
WithTimeStampMethod · 0.80

Tested by

no test coverage detected