From 173f1cfa7403b43bddb7ec3b8f94d8e66beb069f Mon Sep 17 00:00:00 2001 From: Benjamin Wang Date: Fri, 17 Nov 2023 20:20:04 +0000 Subject: [PATCH] update doc to clarify the behavior when removing key/value pair during iteration Signed-off-by: Benjamin Wang --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 254f02785..06eec0e9c 100644 --- a/README.md +++ b/README.md @@ -445,6 +445,11 @@ When you have iterated to the end of the cursor then `Next()` will return a before calling `Next()` or `Prev()`. If you do not seek to a position then these functions will return a `nil` key. +If you remove key/value pairs during iteration, the cursor may automatically +move to the next position if present in current node each time removing a key. +When you call `c.Next()` after removing a key, it may skip one key/value pair. +Refer to [pull/611](https://github.com/etcd-io/bbolt/pull/611) to get more detailed info. + During iteration, if the key is non-`nil` but the value is `nil`, that means the key refers to a bucket rather than a value. Use `Bucket.Bucket()` to access the sub-bucket. @@ -869,6 +874,12 @@ Here are a few things to note when evaluating and using Bolt: to grow. However, it's important to note that deleting large chunks of data will not allow you to reclaim that space on disk. +* Removing key/values pairs in a bucket during iteration on the bucket using + cursor may not work properly. Each time when removing a key/value pair, the + cursor may automatically move to the next position if present. When users + call `c.Next()` after removing a key, it may skip one key/value pair. + Refer to https://github.com/etcd-io/bbolt/pull/611 for more detailed info. + For more information on page allocation, [see this comment][page-allocation]. [page-allocation]: https://github.com/boltdb/bolt/issues/308#issuecomment-74811638