fix(skipmap): lost writes when Store races with Delete#37
Open
jmasters-git wants to merge 1 commit intobytedance:mainfrom
Open
fix(skipmap): lost writes when Store races with Delete#37jmasters-git wants to merge 1 commit intobytedance:mainfrom
jmasters-git wants to merge 1 commit intobytedance:mainfrom
Conversation
…rent delete Store could write to a node being concurrently deleted, losing the value. LoadOrStore and LoadOrStoreLazy could read from a half-linked node not yet visible to Load. Require fullyLinked before operating on found nodes, and hold the node lock across the marked check and value write in Store.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #37 +/- ##
==========================================
- Coverage 96.42% 96.27% -0.15%
==========================================
Files 34 34
Lines 3828 3843 +15
==========================================
+ Hits 3691 3700 +9
+ Misses 95 94 -1
- Partials 42 49 +7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #36
Problem
Two linearizability bugs in skipmap's concurrent operations:
Store writes to a dead node. Between checking
!markedand callingstoreVal, a concurrentDelete/LoadAndDeletecan mark and unlink the node. The value is written to a node that is no longer reachable.LoadOrStore reads from a half-linked node.
LoadOrStoreandLoadOrStoreLazyonly checked!markedbefore returning a loaded value, butLoadalso requiresfullyLinked. A "loser"LoadOrStorecan report a key as present while a concurrentLoadreturns nil for the same key.Both were found using porcupine linearizability testing.
Fix
fullyLinked && !markedbefore touching the node, then lock and recheckmarkedbefore writing.fullyLinked && !marked(viaMGet) before returning the loaded value, matching whatLoadalready does.types.go.LoadAndDelete,Delete,Load, andRangealready had the correct checks.Tests
TestStoreLoadAndDeleteRace: racesStorevsLoadAndDeleteon a pre-populated key, asserts the post-condition matches a valid linearization.TestLoadOrStoreLoadRace: races 8LoadOrStoregoroutines on the same absent key, assertsLoadsucceeds immediately after on each goroutine.Both tests fail reliably on the old code and pass on the fix.