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)
| 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. |
| 602 | func (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 |
| 632 | func (tx *Tx) setStatusCommitting() { |
no test coverage detected