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

Method Delete

bucket.go:499–535  ·  view source on GitHub ↗

Delete removes a key from the bucket. If the key does not exist then nothing is done and a nil error is returned. Returns an error if the bucket was created from a read-only transaction.

(key []byte)

Source from the content-addressed store, hash-verified

497// If the key does not exist then nothing is done and a nil error is returned.
498// Returns an error if the bucket was created from a read-only transaction.
499func (b *Bucket) Delete(key []byte) (err error) {
500 if lg := b.tx.db.Logger(); lg != discardLogger {
501 lg.Debugf("Deleting key %q", key)
502 defer func() {
503 if err != nil {
504 lg.Errorf("Deleting key %q failed: %v", key, err)
505 } else {
506 lg.Debugf("Deleting key %q successfully", key)
507 }
508 }()
509 }
510
511 if b.tx.db == nil {
512 return errors.ErrTxClosed
513 } else if !b.Writable() {
514 return errors.ErrTxNotWritable
515 }
516
517 // Move cursor to correct position.
518 c := b.Cursor()
519 k, _, flags := c.seek(key)
520
521 // Return nil if the key doesn't exist.
522 if !bytes.Equal(key, k) {
523 return nil
524 }
525
526 // Return an error if there is already existing bucket value.
527 if (flags & common.BucketLeafFlag) != 0 {
528 return errors.ErrIncompatibleValue
529 }
530
531 // Delete the node if we have a matching key.
532 c.node().del(key)
533
534 return nil
535}
536
537// Sequence returns the current integer for the bucket without incrementing it.
538func (b *Bucket) Sequence() uint64 {

Callers 15

TestCursor_DeleteFunction · 0.45
TestBucket_DeleteFunction · 0.45
TestBucket_Delete_LargeFunction · 0.45
TestBucket_Delete_BucketFunction · 0.45
TestBucket_Delete_ClosedFunction · 0.45
TestBucket_Delete_QuickFunction · 0.45
ExampleBucket_DeleteFunction · 0.45

Calls 8

WritableMethod · 0.95
CursorMethod · 0.95
LoggerMethod · 0.80
seekMethod · 0.80
delMethod · 0.80
DebugfMethod · 0.65
ErrorfMethod · 0.65
nodeMethod · 0.45

Tested by 15

TestCursor_DeleteFunction · 0.36
TestBucket_DeleteFunction · 0.36
TestBucket_Delete_LargeFunction · 0.36
TestBucket_Delete_BucketFunction · 0.36
TestBucket_Delete_ClosedFunction · 0.36
TestBucket_Delete_QuickFunction · 0.36
ExampleBucket_DeleteFunction · 0.36