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

chore: simplify BumpUps deduplication #4098

Merged
merged 2 commits into from
Nov 13, 2024
Merged

chore: simplify BumpUps deduplication #4098

merged 2 commits into from
Nov 13, 2024

Conversation

romange
Copy link
Collaborator

@romange romange commented Nov 9, 2024

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.

@romange romange requested review from chakaz and adiholden November 9, 2024 19:28
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>;
Copy link
Collaborator Author

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

Copy link
Collaborator

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

Copy link
Collaborator Author

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_

Copy link
Collaborator

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

Copy link
Collaborator Author

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.

Copy link
Collaborator

@chakaz chakaz left a 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

Comment on lines +595 to +600
struct FpHasher {
size_t operator()(uint64_t val) const {
return val;
}
};

Copy link
Collaborator

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 :)

Copy link
Collaborator Author

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 )

@romange romange marked this pull request as ready for review November 10, 2024 15:48

// 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_;
Copy link
Collaborator

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

Copy link
Collaborator

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>
Signed-off-by: Roman Gershman <roman@dragonflydb.io>
@romange romange merged commit ab6088f into main Nov 13, 2024
12 checks passed
@romange romange deleted the SimplifyBumpups branch November 13, 2024 15:27
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