You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 9, 2019. It is now read-only.
I'm not sure if this is really a bug, but I've been unable to explain myself the following behavior.
In a bucket, when trying to delete a non-existing key, which has a common prefix with a subbucket, the cursor in https://github.com/boltdb/bolt/blob/master/bucket.go#L315 seems to seek mistakenly on the subbucket, thus throwing a ErrIncompatibleValue.
Here's a failing test illustrating this:
// Ensure that deleting a non-existing key doesn't try to delete a bucket with a common prefix.funcTestCursor_DeleteNonExistingKey_CommonPrefixBucket(t*testing.T) {
db:=NewTestDB()
deferdb.Close()
prefix:=make([]byte, 16)
n, err:=rand.Read(prefix)
ok(t, err)
assert(t, n==16, "failed to read 16 bytes")
bucketSuffix:= []byte(".shapes") // .n_shape < .shapesdb.Update(func(tx*bolt.Tx) error {
b, err:=tx.CreateBucket([]byte("widgets"))
ok(t, err)
// Create an empty subbucket which has prefix as prefix in its key_, err=b.CreateBucketIfNotExists(append(prefix, bucketSuffix...))
ok(t, err)
returnnil
})
db.Update(func(tx*bolt.Tx) error {
b:=tx.Bucket([]byte("widgets"))
// Delete a non-existing key which has kPrefix as prefixerr:=b.Delete(append(prefix, []byte(".n_shapes")...))
ok(t, err)
// Delete the empty subbucketerr=b.DeleteBucket(append(prefix, bucketSuffix...))
ok(t, err)
returnnil
})
}
The fact that .n_shapes < .shapes matters. If bucketSuffix := []byte(".items") instead, the test passes, because the subbucket is virtually ordered before the non-existing searched key.
Thanks in advance for any enlightenment :)
The text was updated successfully, but these errors were encountered:
Doc for Bucket.Delete says that a Delete() on non-existing key is a
no-op. Right now it tries to delete the next key returned by the
cursor. Fix this by checking for key equivalence before deletion.
Fixesboltdb#349
Signed-off-by: Pavel Borzenkov <pavel.borzenkov@gmail.com>
I'm not sure if this is really a bug, but I've been unable to explain myself the following behavior.
In a bucket, when trying to delete a non-existing key, which has a common prefix with a subbucket, the cursor in https://github.com/boltdb/bolt/blob/master/bucket.go#L315 seems to seek mistakenly on the subbucket, thus throwing a
ErrIncompatibleValue
.Here's a failing test illustrating this:
The fact that
.n_shapes < .shapes
matters. IfbucketSuffix := []byte(".items")
instead, the test passes, because the subbucket is virtually ordered before the non-existing searched key.Thanks in advance for any enlightenment :)
The text was updated successfully, but these errors were encountered: