-
Notifications
You must be signed in to change notification settings - Fork 428
[Store] Serialize/Deserialize Offset Allocator #760
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
Conversation
xiaguan
left a comment
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.
It introduces additional complexity.
From my perspective, I'd suggest:
std::vector<char> serialize();
tl::expected<T, ErrorCode> deserialize(char*, size_t); // vector works fine tooSince m_max_capacity is currently static, I believe the size of __Allocator should be static as well? The other members in OffsetAllocator also have static sizes.
My proposal is to modify its memory layout so it resides in a contiguous buffer with a static size.
For serialization/deserialization, we could simply allocate a buffer and perform a memcpy.
| const uint64_t m_multiplier_bits; | ||
| const uint64_t m_capacity; | ||
| uint64_t m_multiplier_bits; | ||
| uint64_t m_capacity; |
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.
Since the allocator always allocates a max_capacity array, I believe m_current_capacity serves no purpose?
|
for example #include <array>
#include <cstddef>
#include <cstring>
#include <iostream>
#include <new>
struct Record {
int id;
std::array<int, 5> values;
};
inline constexpr std::size_t kWireSize = sizeof(Record);
int main() {
Record r{42, {1, 2, 3, 4, 5}};
char* buffer = new char[kWireSize];
memcpy(buffer, &r, kWireSize);
Record* r1 = (Record*)buffer;
std::cout << "id=" << r1->id << " values:";
for (int v : r1->values) std::cout << ' ' << v;
std::cout << '\n';
return 0;
} |
|
We had an offline discussion about this issue, and here is a summary of the conclusion. The value of |
This feature will be used for persisting master KV metadata. The serialize and deserialize methods of OffsetAllocator are implemented as templates; otherwise, offset_allocator.h would need to directly or indirectly include type.h, which would result in circular dependencies and compilation failure.