Skip to content

Commit

Permalink
meta/memkv: fix the conflict between scan and write operations (#3838)
Browse files Browse the repository at this point in the history
  • Loading branch information
SandyXSD authored Jun 20, 2023
1 parent 4867ec4 commit 5aea39c
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions pkg/meta/tkv_mem.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,17 +236,16 @@ func (c *memKV) txn(f func(*kvTxn) error, retry int) error {

func (c *memKV) scan(prefix []byte, handler func(key []byte, value []byte)) error {
c.Lock()
defer c.Unlock()
snap := c.items.Clone()
c.Unlock()
begin := string(prefix)
end := string(nextKey(prefix))
c.items.AscendGreaterOrEqual(&kvItem{key: begin}, func(i btree.Item) bool {
snap.AscendGreaterOrEqual(&kvItem{key: begin}, func(i btree.Item) bool {
it := i.(*kvItem)
if end != "" && it.key >= end {
return false
}
c.Unlock()
handler([]byte(it.key), it.value)
c.Lock()
return true
})
return nil
Expand Down

0 comments on commit 5aea39c

Please sign in to comment.