-
Notifications
You must be signed in to change notification settings - Fork 1.1k
chore(tiering): Optimize serialization #6164
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(tiering): Optimize serialization #6164
Conversation
6dee45e to
9c5e607
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.
Pull request overview
This PR optimizes tiering serialization by eliminating intermediate allocations and enabling zero-copy operations. The changes simplify the stash logic, improve API ergonomics, and reduce memory overhead during offloading operations.
Key Changes
- SmallBins API refactoring: Changed
FilledBinfrompair<BinId, string>to a struct with an explicitSerializeBin()method that writes directly to a destination buffer, eliminating intermediate string allocations - Zero-copy string access: Modified
CompactObj::GetRawString()to returnarray<string_view, 2>instead ofStringOrView, enabling copyless size determination and access to small strings split across two memory segments - Direct listpack serialization: Updated
SerializedMap::Serialize()to acceptListpackWrapdirectly instead of materializing an intermediate vector of string pairs
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/server/tiering/small_bins.h | Redefined FilledBin as a struct with private members; added SerializeBin() method declaration; updated IsPending() to use new structure |
| src/server/tiering/small_bins.cc | Implemented SerializeBin() to write directly to destination buffer; updated internal state management to use FilledBin struct; added memory reuse optimization for bin entries |
| src/server/tiering/small_bins_test.cc | Changed test fixture from class to struct; added Serialize() helper method; updated all tests to use new FilledBin API |
| src/server/tiering/serialized_map.h | Replaced SerializeSize() with EstimateSize(); changed Serialize() signature to accept ListpackWrap instead of span of pairs |
| src/server/tiering/serialized_map.cc | Implemented EstimateSize() and updated Serialize() to iterate directly over listpack; moved kLenBytes constant to file scope |
| src/server/tiering/serialized_map_test.cc | Added test suite setup to initialize zmalloc; updated test to create and use ListpackWrap instead of vector of pairs |
| src/server/tiering/op_manager.h | Added PrepareAndStash() helper method declaration |
| src/server/tiering/op_manager.cc | Implemented PrepareAndStash() to combine buffer preparation, serialization, and stashing in one call |
| src/server/tiering/op_manager_test.cc | Refactored Stash() test helper to use new PrepareAndStash() pattern |
| src/server/tiered_storage.cc | Simplified TryStash() to use PrepareAndStash() with bind_front for both large values and small bins; updated serialization logic to handle two-part string views |
| src/core/compact_object.h | Changed GetRawString() return type from StringOrView to array<string_view, 2> |
| src/core/compact_object.cc | Implemented new GetRawString() to return two views; handles both ROBJ_TAG (single view) and SMALL_TAG (two views) cases |
| src/core/compact_object_test.cc | Updated test to handle new GetRawString() return type by combining both views |
| src/core/detail/listpack_wrap.h | Added Bytes() method declaration |
| src/core/detail/listpack_wrap.cc | Implemented Bytes() to return total listpack size via lpBytes() |
|
pls respond to copilot comments |
|
augment review |
|
Sorry, Augment does not have access to the org this pull request's branch is from. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Vladislav <vladislav.oleshko@gmail.com>
7c73931 to
0a6daa2
Compare
|
@romange PTAL at the updates |
src/core/detail/listpack_wrap.cc
Outdated
| return Iterator{lp_, nullptr, intbuf_}; | ||
| } | ||
|
|
||
| size_t ListpackWrap::Bytes() const { |
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.
nit: BytesUsed()
src/server/tiering/small_bins.h
Outdated
| explicit FilledBin(BinId id) : id{id} { | ||
| } | ||
|
|
||
| unsigned bytes = 0; |
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.
bytes_
src/server/tiering/small_bins.h
Outdated
| } | ||
|
|
||
| unsigned bytes = 0; | ||
| tiering::EntryMap<std::string> entries; |
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.
entries_
Signed-off-by: Vladislav Oleshko <vlad@dragonflydb.io>
TieredStorage::Stashlogic by usingOpManager::PrepareAndStashhelperstring_view[2]fromCompactObj::GetRawStringto determine size/get string copyless with small strings