-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove-Get concurrency fix #27
base: rc/v1.7.next1
Are you sure you want to change the base?
Changes from 5 commits
100b248
2bacb0e
5fca300
f6cf07c
c36344b
2294bdc
9b7d17c
00f58ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package common | |
|
||
import ( | ||
"errors" | ||
|
||
"github.com/multiversx/mx-chain-core-go/core" | ||
) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,19 +10,21 @@ import ( | |
var _ types.Batcher = (*batch)(nil) | ||
|
||
type batch struct { | ||
batch *leveldb.Batch | ||
cachedData map[string][]byte | ||
removedData map[string]struct{} | ||
mutBatch sync.RWMutex | ||
batch *leveldb.Batch | ||
cachedData map[string][]byte | ||
removedData map[string]struct{} | ||
previouslyRemoved map[string]struct{} | ||
mutBatch sync.RWMutex | ||
} | ||
|
||
// NewBatch creates a batch | ||
func NewBatch() *batch { | ||
func NewBatch(previouslyRemoved map[string]struct{}) *batch { | ||
return &batch{ | ||
batch: &leveldb.Batch{}, | ||
cachedData: make(map[string][]byte), | ||
removedData: make(map[string]struct{}), | ||
mutBatch: sync.RWMutex{}, | ||
batch: &leveldb.Batch{}, | ||
cachedData: make(map[string][]byte), | ||
removedData: make(map[string]struct{}), | ||
previouslyRemoved: previouslyRemoved, | ||
mutBatch: sync.RWMutex{}, | ||
} | ||
} | ||
|
||
|
@@ -69,6 +71,14 @@ func (b *batch) IsRemoved(key []byte) bool { | |
defer b.mutBatch.RUnlock() | ||
|
||
_, found := b.removedData[string(key)] | ||
if found { | ||
return true | ||
} | ||
_, found = b.cachedData[string(key)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could be a situation when both, cachedData[key} and previouslyRemoved[key], return true? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. The situation is the following: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
if found { | ||
return false | ||
} | ||
_, found = b.previouslyRemoved[string(key)] | ||
|
||
return found | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package leveldb | ||
|
||
// PutBatch will call the unexported putBatch function | ||
func (s *SerialDB) PutBatch() { | ||
_ = s.putBatch() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package lrucache | ||
|
||
// AddedDataHandlers - | ||
func (c *lruCache) AddedDataHandlers() map[string]func(key []byte, value interface{}) { | ||
return c.mapDataHandlers | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't forget proper tag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after testing will do 👍