-
Notifications
You must be signed in to change notification settings - Fork 412
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
Storage: let stable meta using protobuf format #9054
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6fdf24d
Storage: let stable meta using protobuf format
Lloyd-Pottiger e4fc87e
refine
Lloyd-Pottiger 2d66873
refine
Lloyd-Pottiger 3169ef2
rollback
Lloyd-Pottiger b2ed209
address comments & add unit tests
Lloyd-Pottiger 6bcb284
address comments
Lloyd-Pottiger 260428a
address comments
Lloyd-Pottiger e2bcd67
address comments
Lloyd-Pottiger af4723c
Merge branch 'master' into proto-stable
ti-chi-bot[bot] 50ea4ae
address comments
Lloyd-Pottiger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
#include <Storages/Page/V3/Universal/UniversalPageStorage.h> | ||
#include <Storages/PathPool.h> | ||
|
||
|
||
namespace DB | ||
{ | ||
namespace ErrorCodes | ||
|
@@ -82,31 +83,94 @@ void StableValueSpace::saveMeta(WriteBatchWrapper & meta_wb) | |
{ | ||
MemoryWriteBuffer buf(0, 8192); | ||
// The method must call `buf.count()` to get the last seralized size before `buf.tryGetReadBuffer` | ||
auto data_size = saveMeta(buf); | ||
auto data_size = serializeMetaToBuf(buf); | ||
meta_wb.putPage(id, 0, buf.tryGetReadBuffer(), data_size); | ||
} | ||
|
||
UInt64 StableValueSpace::saveMeta(WriteBuffer & buf) const | ||
UInt64 StableValueSpace::serializeMetaToBuf(WriteBuffer & buf) const | ||
{ | ||
writeIntBinary(STORAGE_FORMAT_CURRENT.stable, buf); | ||
writeIntBinary(valid_rows, buf); | ||
writeIntBinary(valid_bytes, buf); | ||
writeIntBinary(static_cast<UInt64>(files.size()), buf); | ||
for (const auto & f : files) | ||
writeIntBinary(f->pageId(), buf); | ||
|
||
if (likely(STORAGE_FORMAT_CURRENT.stable == StableFormat::V1)) | ||
{ | ||
writeIntBinary(valid_rows, buf); | ||
writeIntBinary(valid_bytes, buf); | ||
writeIntBinary(static_cast<UInt64>(files.size()), buf); | ||
for (const auto & f : files) | ||
writeIntBinary(f->pageId(), buf); | ||
} | ||
else if (STORAGE_FORMAT_CURRENT.stable == StableFormat::V2) | ||
{ | ||
dtpb::StableLayerMeta meta; | ||
meta.set_valid_rows(valid_rows); | ||
meta.set_valid_bytes(valid_bytes); | ||
for (const auto & f : files) | ||
meta.add_files()->set_page_id(f->pageId()); | ||
|
||
auto data = meta.SerializeAsString(); | ||
writeStringBinary(data, buf); | ||
} | ||
else | ||
{ | ||
throw Exception("Unexpected version: {}", STORAGE_FORMAT_CURRENT.stable); | ||
} | ||
return buf.count(); | ||
} | ||
|
||
namespace | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this dummy namespace a typo? |
||
{ | ||
dtpb::StableLayerMeta derializeMetaV1FromBuf(ReadBuffer & buf) | ||
{ | ||
dtpb::StableLayerMeta meta; | ||
UInt64 valid_rows, valid_bytes, size; | ||
readIntBinary(valid_rows, buf); | ||
readIntBinary(valid_bytes, buf); | ||
readIntBinary(size, buf); | ||
meta.set_valid_rows(valid_rows); | ||
meta.set_valid_bytes(valid_bytes); | ||
for (size_t i = 0; i < size; ++i) | ||
{ | ||
UInt64 page_id; | ||
readIntBinary(page_id, buf); | ||
meta.add_files()->set_page_id(page_id); | ||
} | ||
return meta; | ||
} | ||
|
||
dtpb::StableLayerMeta derializeMetaV2FromBuf(ReadBuffer & buf) | ||
{ | ||
dtpb::StableLayerMeta meta; | ||
String data; | ||
readStringBinary(data, buf); | ||
RUNTIME_CHECK_MSG( | ||
meta.ParseFromString(data), | ||
"Failed to parse StableLayerMeta from string: {}", | ||
Redact::keyToHexString(data.data(), data.size())); | ||
return meta; | ||
} | ||
|
||
dtpb::StableLayerMeta derializeMetaFromBuf(ReadBuffer & buf) | ||
{ | ||
UInt64 version; | ||
readIntBinary(version, buf); | ||
if (version == StableFormat::V1) | ||
return derializeMetaV1FromBuf(buf); | ||
else if (version == StableFormat::V2) | ||
return derializeMetaV2FromBuf(buf); | ||
else | ||
throw Exception("Unexpected version: {}", version); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
} // namespace | ||
|
||
std::string StableValueSpace::serializeMeta() const | ||
{ | ||
WriteBufferFromOwnString wb; | ||
saveMeta(wb); | ||
serializeMetaToBuf(wb); | ||
return wb.releaseStr(); | ||
} | ||
|
||
StableValueSpacePtr StableValueSpace::restore(DMContext & dm_context, PageIdU64 id) | ||
{ | ||
// read meta page | ||
Page page = dm_context.storage_pool->metaReader()->read(id); // not limit restore | ||
ReadBufferFromMemory buf(page.data.begin(), page.data.size()); | ||
return StableValueSpace::restore(dm_context, buf, id); | ||
|
@@ -116,20 +180,11 @@ StableValueSpacePtr StableValueSpace::restore(DMContext & dm_context, ReadBuffer | |
{ | ||
auto stable = std::make_shared<StableValueSpace>(id); | ||
|
||
UInt64 version, valid_rows, valid_bytes, size; | ||
readIntBinary(version, buf); | ||
if (version != StableFormat::V1) | ||
throw Exception("Unexpected version: " + DB::toString(version)); | ||
|
||
readIntBinary(valid_rows, buf); | ||
readIntBinary(valid_bytes, buf); | ||
readIntBinary(size, buf); | ||
UInt64 page_id; | ||
auto metapb = derializeMetaFromBuf(buf); | ||
auto remote_data_store = dm_context.global_context.getSharedContextDisagg()->remote_data_store; | ||
for (size_t i = 0; i < size; ++i) | ||
for (int i = 0; i < metapb.files().size(); ++i) | ||
{ | ||
readIntBinary(page_id, buf); | ||
|
||
UInt64 page_id = metapb.files(i).page_id(); | ||
DMFilePtr dmfile; | ||
auto path_delegate = dm_context.path_pool->getStableDiskDelegator(); | ||
if (remote_data_store) | ||
|
@@ -170,8 +225,8 @@ StableValueSpacePtr StableValueSpace::restore(DMContext & dm_context, ReadBuffer | |
stable->files.push_back(dmfile); | ||
} | ||
|
||
stable->valid_rows = valid_rows; | ||
stable->valid_bytes = valid_bytes; | ||
stable->valid_rows = metapb.valid_rows(); | ||
stable->valid_bytes = metapb.valid_bytes(); | ||
|
||
return stable; | ||
} | ||
|
@@ -192,22 +247,11 @@ StableValueSpacePtr StableValueSpace::createFromCheckpoint( // | |
ReadBufferFromMemory buf(page.data.begin(), page.data.size()); | ||
|
||
// read stable meta info | ||
UInt64 version, valid_rows, valid_bytes, size; | ||
{ | ||
readIntBinary(version, buf); | ||
if (version != StableFormat::V1) | ||
throw Exception("Unexpected version: " + DB::toString(version)); | ||
|
||
readIntBinary(valid_rows, buf); | ||
readIntBinary(valid_bytes, buf); | ||
readIntBinary(size, buf); | ||
} | ||
|
||
auto metapb = derializeMetaFromBuf(buf); | ||
auto remote_data_store = dm_context.global_context.getSharedContextDisagg()->remote_data_store; | ||
for (size_t i = 0; i < size; ++i) | ||
for (int i = 0; i < metapb.files().size(); ++i) | ||
{ | ||
UInt64 page_id; | ||
readIntBinary(page_id, buf); | ||
UInt64 page_id = metapb.files(i).page_id(); | ||
auto full_page_id = UniversalPageIdFormat::toFullPageId( | ||
UniversalPageIdFormat::toFullPrefix( | ||
dm_context.keyspace_id, | ||
|
@@ -234,8 +278,8 @@ StableValueSpacePtr StableValueSpace::createFromCheckpoint( // | |
stable->files.push_back(dmfile); | ||
} | ||
|
||
stable->valid_rows = valid_rows; | ||
stable->valid_bytes = valid_bytes; | ||
stable->valid_rows = metapb.valid_rows(); | ||
stable->valid_bytes = metapb.valid_bytes(); | ||
|
||
return stable; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.