Skip to content

Remove-Get concurrency fix#27

Draft
iulianpascalau wants to merge 8 commits intorc/v1.7.next1from
remove-get-concurrency-fix
Draft

Remove-Get concurrency fix#27
iulianpascalau wants to merge 8 commits intorc/v1.7.next1from
remove-get-concurrency-fix

Conversation

@iulianpascalau
Copy link
Copy Markdown
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
Comment thread leveldb/leveldbSerial.go Outdated
result := <-ch
close(ch)

s.mutBatch.Lock()
Copy link
Copy Markdown
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
Copy Markdown
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
Comment thread storageUnit/storageunit_test.go Outdated
return nil
},
GetCalled: func(key []byte) ([]byte, error) {
assert.Fail(t, "should have not called Has")
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment thread storageUnit/storageunit_test.go Outdated
return nil
},
GetCalled: func(key []byte) ([]byte, error) {
assert.Fail(t, "should have not called Has")
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment thread go.mod Outdated
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
Copy Markdown
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
Copy Markdown
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
Comment thread leveldb/batch.go
if found {
return true
}
_, found = b.cachedData[string(key)]
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ok

Comment thread rtcache/removalTrackingCache.go Outdated

// Clear is used to completely clear both caches.
func (cache *removalTrackingCache) Clear() {
cache.mutCriticalArea.RLock()
Copy link
Copy Markdown
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
Copy Markdown
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

Comment thread testscommon/cacherMock.go
defer mock.mut.Unlock()

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

Copy link
Copy Markdown
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
Copy Markdown
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

Comment thread testscommon/cacherMock.go Outdated

mock.data[string(key)] = value

return !found, found
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

right, thanks

Comment thread types/interface.go Outdated
UnknownRemovalStatus RemovalStatus = "unknown"
// ExplicitlyRemovedStatus defines the explicitly removed status
ExplicitlyRemovedStatus RemovalStatus = "explicitly removed"
// NotRemovedStatus the key is not removed
Copy link
Copy Markdown
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
Copy Markdown
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