-
Notifications
You must be signed in to change notification settings - Fork 563
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
Optimized partition metadata lookup #4443
Optimized partition metadata lookup #4443
Conversation
2c898c2
to
2d7406a
Compare
ccf8cf9
to
2d7406a
Compare
@mmaslankaprv when you say fixes the issue can you do a simple |
2d7406a
to
7c59fc9
Compare
Optimized per partition metadata lookup by storing partition metadata in `absl::btree_set` the set provides fast lookup while keeping partitions ordered. Limited number of times partition metadata are copied by returning metadata object stored directly in a map. Signed-off-by: Michal Maslanka <[email protected]>
7c59fc9
to
33270b9
Compare
Introduced method returning reference to topic metadata. The reference returning method allow us to avoid copying metadata object when it has to be accessed by synchronous parts of code. Important: Remember not to use the reference when its lifetime has to span across multiple scheduling point. Reference returning method is provided not to copy metadata object when used by synchronous parts of code Signed-off-by: Michal Maslanka <[email protected]>
33270b9
to
d32572c
Compare
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.
LGTM nice refactor too!
/// span across multiple scheduling point. Reference returning method is | ||
/// provided not to copy metadata object when used by synchronous parts of | ||
/// code | ||
std::optional<std::reference_wrapper<const cluster::topic_metadata>> |
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.
Nice comment, thanks!
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.
@mmaslankaprv thanks for the comment.
It might be worthwhile to consider making this harder to use incorrectly. Perhaps by wrapping in a type that can't be copied or moved, so that it doesn't escape the scope as easily. The issue is that it really looks like it has value semantics at the call site:
auto metadata = _topics.local().get_topic_metadata_ref(tp_ns);
The other issue with visually seeing value semantics, is that the call site might not have a scheduling point to worry about, but might do something to the container that rebalances it--like any mutation.
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.
good point, i will consider wrapping it in a noncopyable nonmovable type.
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.
nbd. just thoughts in passing reading old PRs
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.
LGTM
Cover letter
Optimized per partition metadata lookup by storing partition metadata in
absl::btree_set
the set provides fast lookup while keeping partitionsordered. Limited number of times partition metadata are copied by
returning metadata object stored directly in a map.
Fixes: #4410
Fixes #4410
Release notes