-
Notifications
You must be signed in to change notification settings - Fork 981
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
chore: simplify BumpUps deduplication #4098
Conversation
src/server/db_slice.cc
Outdated
using RestoreType = absl::flat_hash_set<CompactObjectView>; | ||
explicit FetchedItemsRestorer(RestoreType* dst) : dst_to_restore_(dst) { | ||
cached_ = std::move(*dst_to_restore_); | ||
// using RestoreType = absl::flat_hash_set<CompactObjectView>; |
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.
this code should be deleted. hacking it as a noop to get the initial feedback for review. @adiholden @chakaz FYI
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.
As far as I understand this code comes to protect from DbSlice::OnCbFinish calling fetched_items_.clear to not clear the fetched items in caller transaction while the preempt
OnCbFinish is called on each transaction finish so if we have 2 interliving transactions one running the OnCbFinish after a single key was fetched before another one was fetched it will clear the vector not as expected
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.
Have you read the PR description? My claim is that if a tx preempts we do not need to protect iterators - and that was the purpose of fetched_items_
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.
so why did you keep fetched_items_ logic and moved to finger print ? if this is the claim we can remove fetched_items_ at all
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.
for MGET case, see your PR #2474 :) and the linked issue.
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.
Generally, this sounds right. I would like to get Adi's general approval as well, as specifically I don't know the areas of bumping up items
struct FpHasher { | ||
size_t operator()(uint64_t val) const { | ||
return val; | ||
} | ||
}; | ||
|
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.
Why not use the default hasher?
(I get that this is not the core of this draft PR, still I'm curious :)
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.
The default one hashes :)
I find it redundant for keys that are already mixed (results of a hash function )
|
||
// ordered from the smallest to largest version. | ||
std::list<std::pair<uint64_t, ChangeCallback>> change_cb_; | ||
|
||
// Used in temporary computations in Find item and CbFinish | ||
mutable absl::flat_hash_set<CompactObjectView> fetched_items_; | ||
mutable absl::flat_hash_set<uint64_t, FpHasher> fetched_items_; |
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.
lets add a comment why we need this hashset , why we can not bumpup item twice in transaction without preemption but ok to to bumpup twice when we do preempt
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.
expect this comment the changes looks ok and we can merge
This pr #2474 introduced iterator protection by tracking which keys where bumped up during the transaction operation. This was done by managing keys view set. However, this can be simplified using fingerprints. Also, fingerprints do not require that the original keys exist. In addition, this #3241 PR introduces FetchedItemsRestorer that tracks bumped set and saves it to protect against fiber context switch. My claim is that it's redundant. Since we only keep the auto-laundering iterators, when a fiber preempts these iterators recognize it (see IteratorT::LaunderIfNeeded) and refresh themselves anyway. To summarize: fetched_items_ protect us from iterator invalidation during atomic scenarios, and auto-laundering protects us from everything else, so fetched_items_ can be cleared in that case. Signed-off-by: Roman Gershman <roman@dragonflydb.io>
1f956ae
to
5ac7a9a
Compare
Signed-off-by: Roman Gershman <roman@dragonflydb.io>
5ac7a9a
to
08772bf
Compare
This pr #2474 introduced iterator protection by
tracking which keys where bumped up during the transaction operation. This was done by managing keys view set. However, this can be simplified using fingerprints. Also, fingerprints do not require that the original keys exist.
In addition, this #3241 PR introduces FetchedItemsRestorer that tracks bumped set and saves it to protect against fiber context switch. My claim is that it's redundant. Since we only keep the auto-laundering iterators, when a fiber preempts these iterators recognize it (see IteratorT::LaunderIfNeeded) and refresh themselves anyway.
To summarize: fetched_items_ protect us from iterator invalidation during atomic scenarios, and auto-laundering protects us from everything else, so fetched_items_ can be cleared in that case.