Skip to content
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

Draft
wants to merge 8 commits into
base: rc/v1.7.next1
Choose a base branch
from

Conversation

iulianpascalau
Copy link
Contributor

@iulianpascalau iulianpascalau commented Sep 18, 2023

  • added unit test for the edge-case
  • fixed the persister edge-case
  • added & integrated a new type of cache that is removal-aware

@iulianpascalau iulianpascalau marked this pull request as draft September 18, 2023 18:57
@@ -262,6 +297,10 @@ func (s *SerialDB) putBatch() error {
result := <-ch
close(ch)

s.mutBatch.Lock()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a great solution, this can just set to nil the writing batch if another go-routine called putBatch and managed to set the writingBatch

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, reverted

- added & integrated removalTrackingCache implementation
@iulianpascalau iulianpascalau marked this pull request as ready for review September 20, 2023 14:45
@iulianpascalau iulianpascalau changed the title [WIP]Remove-Get concurrency fix Remove-Get concurrency fix Sep 20, 2023
return nil
},
GetCalled: func(key []byte) ([]byte, error) {
assert.Fail(t, "should have not called Has")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert.Fail(t, "should have not called Has")
assert.Fail(t, "should have not called Get")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

return nil
},
GetCalled: func(key []byte) ([]byte, error) {
assert.Fail(t, "should have not called Has")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert.Fail(t, "should have not called Has")
assert.Fail(t, "should have not called Get")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

go.mod Outdated
@@ -5,7 +5,7 @@ go 1.20
require (
github.com/hashicorp/golang-lru v0.6.0
github.com/multiversx/concurrent-map v0.1.4
github.com/multiversx/mx-chain-core-go v1.2.16
github.com/multiversx/mx-chain-core-go v1.2.17-0.20230919104727-566f55d213ab
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after testing will do 👍

@SebastianMarian SebastianMarian self-requested a review September 21, 2023 09:49
if found {
return true
}
_, found = b.cachedData[string(key)]
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

@iulianpascalau iulianpascalau Sep 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. The situation is the following:
the key existed and a call to Delete was made. The batch was written, and the data was deleted from the persister
and the new batch was created, the previously removed data was passed to the new batch. Then, immediately we call Put with the same key. Now, both caches contain the same key.
All is fine because in this case, we want the IsRemoved function to return false. Added a test with this exact scenario.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok


// Clear is used to completely clear both caches.
func (cache *removalTrackingCache) Clear() {
cache.mutCriticalArea.RLock()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lock / Unlock ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, to preserve the consistency as much as we can

defer mock.mut.Unlock()

_, found := mock.data[string(key)]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing here: if found { return found, !found} ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, changed also the other return as it was badly written


mock.data[string(key)] = value

return !found, found
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return found, !found ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, thanks

UnknownRemovalStatus RemovalStatus = "unknown"
// ExplicitlyRemovedStatus defines the explicitly removed status
ExplicitlyRemovedStatus RemovalStatus = "explicitly removed"
// NotRemovedStatus the key is not removed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// NotRemovedStatus defines the not removed status ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

sstanculeanu
sstanculeanu previously approved these changes Sep 27, 2023
@iulianpascalau iulianpascalau marked this pull request as draft October 24, 2023 08:55
@iulianpascalau iulianpascalau changed the base branch from rc/v1.6.0 to rc/v1.7.next1 February 5, 2024 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants