Skip to content

Commit

Permalink
Merge pull request #2245 from CortexFoundation/dev
Browse files Browse the repository at this point in the history
faster delete range
  • Loading branch information
ucwong authored Jan 20, 2025
2 parents 0088737 + 84ba3bc commit 4ee3b68
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions ctxcdb/memorydb/memorydb.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package memorydb

import (
"bytes"
"errors"
"sort"
"strings"
Expand Down Expand Up @@ -129,12 +128,15 @@ func (db *Database) Delete(key []byte) error {
// DeleteRange deletes all of the keys (and values) in the range [start,end)
// (inclusive on start, exclusive on end).
func (db *Database) DeleteRange(start, end []byte) error {
it := db.NewIterator(nil, start)
defer it.Release()
db.lock.Lock()
defer db.lock.Unlock()
if db.db == nil {
return errMemorydbClosed
}

for it.Next() && bytes.Compare(end, it.Key()) > 0 {
if err := db.Delete(it.Key()); err != nil {
return err
for key := range db.db {
if key >= string(start) && key < string(end) {
delete(db.db, key)
}
}
return nil
Expand Down

0 comments on commit 4ee3b68

Please sign in to comment.