[#805] pilorama: Fix TreeDrop
All checks were successful
DCO action / DCO (pull_request) Successful in 1m18s
Build / Build Components (1.21) (pull_request) Successful in 3m25s
Vulncheck / Vulncheck (pull_request) Successful in 3m22s
Build / Build Components (1.20) (pull_request) Successful in 4m12s
Tests and linters / Staticcheck (pull_request) Successful in 5m6s
Tests and linters / Lint (pull_request) Successful in 6m3s
Tests and linters / Tests (1.20) (pull_request) Successful in 7m22s
Tests and linters / Tests with -race (pull_request) Successful in 7m31s
Tests and linters / Tests (1.21) (pull_request) Successful in 7m46s

* If treeID is empty then deleting buckets for cursor may get
  invalidated. So, buckets should be gathered before deleting.

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
This commit is contained in:
Airat Arifullin 2023-11-15 12:03:31 +03:00
parent 3534d6d05b
commit 8d5300c41a

View file

@ -1115,11 +1115,12 @@ func (t *boltForest) TreeDrop(ctx context.Context, cid cidSDK.ID, treeID string)
c := tx.Cursor()
prefix := make([]byte, 32)
cid.Encode(prefix)
for k, _ := c.Seek(prefix); k != nil && bytes.HasPrefix(k, prefix); k, _ = c.Next() {
for k, _ := c.Seek(prefix); k != nil && bytes.HasPrefix(k, prefix); k, _ = c.Seek(prefix) {
err := tx.DeleteBucket(k)
if err != nil {
return err
}
_, _ = c.First() // rewind the cursor to the root page
}
return nil
}