Skip to content

Commit 3cad810

Browse files
authored
PageCtl: Support getting blob data from PageStorage instance (release-7.5) (#9717)
close #9716 PageCtl: Support getting blob data from PageStorage instance And output the "PageEntryV3.offset" in decimal instead of hexadecimal Signed-off-by: JaySon-Huang <[email protected]>
1 parent 2849b81 commit 3cad810

File tree

3 files changed

+91
-33
lines changed

3 files changed

+91
-33
lines changed

dbms/src/Storages/Page/V3/PageEntry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ struct fmt::formatter<DB::PS::V3::PageEntryV3>
130130

131131
return format_to(
132132
ctx.out(),
133-
"PageEntry{{file: {}, offset: 0x{:X}, size: {}, checksum: 0x{:X}, tag: {}, field_offsets: [{}], "
133+
"PageEntry{{file: {}, offset: {}, size: {}, checksum: 0x{:X}, tag: {}, field_offsets: [{}], "
134134
"checkpoint_info: {}}}",
135135
entry.file_id,
136136
entry.offset,

dbms/src/Storages/Page/tools/PageCtl/PageStorageCtlV3.cpp

Lines changed: 87 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717
#include <Poco/ConsoleChannel.h>
1818
#include <Poco/PatternFormatter.h>
1919
#include <Server/CLIService.h>
20+
#include <Storages/Page/PageDefinesBase.h>
21+
#include <Storages/Page/V3/PageDefines.h>
2022
#include <Storages/Page/V3/PageDirectory.h>
2123
#include <Storages/Page/V3/PageDirectoryFactory.h>
2224
#include <Storages/Page/V3/PageStorageImpl.h>
2325
#include <Storages/Page/V3/Universal/RaftDataReader.h>
26+
#include <Storages/Page/V3/Universal/UniversalPageId.h>
2427
#include <Storages/Page/V3/Universal/UniversalPageIdFormatImpl.h>
2528
#include <Storages/Page/V3/Universal/UniversalPageStorage.h>
2629
#include <Storages/PathPool.h>
@@ -29,6 +32,7 @@
2932
#include <common/types.h>
3033

3134
#include <boost/program_options.hpp>
35+
#include <cstdint>
3236
#include <magic_enum.hpp>
3337
#include <unordered_set>
3438

@@ -47,12 +51,15 @@ struct ControlOptions
4751
CHECK_ALL_DATA_CRC = 4,
4852
DISPLAY_WAL_ENTRIES = 5,
4953
DISPLAY_REGION_INFO = 6,
54+
DISPLAY_BLOB_DATA = 7,
5055
};
5156

5257
std::vector<std::string> paths;
5358
DisplayType mode = DisplayType::DISPLAY_SUMMARY_INFO;
5459
UInt64 page_id = UINT64_MAX;
55-
UInt32 blob_id = UINT32_MAX;
60+
BlobFileId blob_id = INVALID_BLOBFILE_ID;
61+
BlobFileOffset blob_offset = INVALID_BLOBFILE_OFFSET;
62+
size_t blob_size = UINT64_MAX;
5663
UInt64 namespace_id = DB::TEST_NAMESPACE_ID;
5764
StorageType storage_type = StorageType::Unknown; // only useful for universal page storage
5865
UInt32 keyspace_id = NullspaceID; // only useful for universal page storage
@@ -85,6 +92,7 @@ ControlOptions ControlOptions::parse(int argc, char ** argv)
8592
4 is check every data is valid
8693
5 is dump entries in WAL log files
8794
6 is display all region info
95+
7 is display blob data (in hex)
8896
)") //
8997
("show_entries",
9098
value<bool>()->default_value(true),
@@ -106,8 +114,14 @@ ControlOptions ControlOptions::parse(int argc, char ** argv)
106114
value<UInt64>()->default_value(UINT64_MAX),
107115
"Query a single Page id, and print its version chain.") //
108116
("blob_id,B",
109-
value<UInt32>()->default_value(UINT32_MAX),
110-
"Query a single Blob id, and print its data distribution.") //
117+
value<BlobFileId>()->default_value(INVALID_BLOBFILE_ID),
118+
"Specify the blob_id") //
119+
("blob_offset",
120+
value<BlobFileOffset>()->default_value(INVALID_BLOBFILE_OFFSET),
121+
"Specify the offset.") //
122+
("blob_size",
123+
value<size_t>()->default_value(0),
124+
"Specify the size.") //
111125
//
112126
("imitative,I",
113127
value<bool>()->default_value(true),
@@ -140,7 +154,9 @@ ControlOptions ControlOptions::parse(int argc, char ** argv)
140154
opt.paths = options["paths"].as<std::vector<std::string>>();
141155
auto mode_int = options["mode"].as<int>();
142156
opt.page_id = options["page_id"].as<UInt64>();
143-
opt.blob_id = options["blob_id"].as<UInt32>();
157+
opt.blob_id = options["blob_id"].as<BlobFileId>();
158+
opt.blob_offset = options["blob_offset"].as<BlobFileOffset>();
159+
opt.blob_size = options["blob_size"].as<size_t>();
144160
opt.show_entries = options["show_entries"].as<bool>();
145161
opt.check_fields = options["check_fields"].as<bool>();
146162
auto storage_type_int = options["storage_type"].as<int>();
@@ -346,6 +362,12 @@ class PageStorageControlV3
346362
}
347363
break;
348364
}
365+
case ControlOptions::DisplayType::DISPLAY_BLOB_DATA:
366+
{
367+
String hex_data = getBlobData(blob_store, opts.blob_id, opts.blob_offset, opts.blob_size);
368+
fmt::print("hex:{}\n", hex_data);
369+
break;
370+
}
349371
default:
350372
std::cout << "Invalid display mode." << std::endl;
351373
break;
@@ -372,7 +394,7 @@ class PageStorageControlV3
372394
return 0;
373395
}
374396

375-
static String getBlobsInfo(typename Trait::BlobStore & blob_store, UInt32 blob_id)
397+
static String getBlobsInfo(typename Trait::BlobStore & blob_store, BlobFileId blob_id)
376398
{
377399
auto stat_info = [](const BlobStats::BlobStatPtr & stat, const String & path) {
378400
FmtBuffer stat_str;
@@ -402,7 +424,7 @@ class PageStorageControlV3
402424
{
403425
for (const auto & stat : stats)
404426
{
405-
if (blob_id != UINT32_MAX)
427+
if (blob_id != INVALID_BLOBFILE_ID)
406428
{
407429
if (stat->id == blob_id)
408430
{
@@ -416,7 +438,7 @@ class PageStorageControlV3
416438
}
417439
}
418440

419-
if (blob_id != UINT32_MAX)
441+
if (blob_id != INVALID_BLOBFILE_ID)
420442
{
421443
stats_info.fmtAppend(" no found blob {}", blob_id);
422444
}
@@ -447,34 +469,41 @@ class PageStorageControlV3
447469
size_t count = 0;
448470
for (const auto & [version, entry_or_del] : versioned_entries->entries)
449471
{
450-
const auto & entry = entry_or_del.entry;
451-
page_str.fmtAppend(
452-
" entry {}\n"
453-
" sequence: {}\n"
454-
" epoch: {}\n"
455-
" is del: {}\n"
456-
" blob id: {}\n"
457-
" offset: {}\n"
458-
" size: {}\n"
459-
" crc: 0x{:X}\n", //
460-
count++, //
461-
version.sequence, //
462-
version.epoch, //
463-
entry_or_del.isDelete(), //
464-
entry.file_id, //
465-
entry.offset, //
466-
entry.size, //
467-
entry.checksum, //
468-
entry.field_offsets.size() //
469-
);
470-
if (!entry.field_offsets.empty())
472+
if (entry_or_del.isEntry())
471473
{
472-
page_str.append(" field offset:\n");
473-
for (const auto & [offset, crc] : entry.field_offsets)
474+
const auto & entry = entry_or_del.entry;
475+
page_str.fmtAppend(
476+
" entry {}\n"
477+
" sequence: {}\n"
478+
" epoch: {}\n"
479+
" is del: false\n"
480+
" blob id: {}\n"
481+
" offset: {}\n"
482+
" size: {}\n"
483+
" crc: 0x{:X}\n", //
484+
count++, //
485+
version.sequence, //
486+
version.epoch, //
487+
entry.file_id, //
488+
entry.offset, //
489+
entry.size, //
490+
entry.checksum, //
491+
entry.field_offsets.size() //
492+
);
493+
if (!entry.field_offsets.empty())
474494
{
475-
page_str.fmtAppend(" offset: {} crc: 0x{:X}\n", offset, crc);
495+
page_str.append(" field offset:\n");
496+
for (const auto & [offset, crc] : entry.field_offsets)
497+
{
498+
page_str.fmtAppend(" offset: {} crc: 0x{:X}\n", offset, crc);
499+
}
500+
page_str.append("\n");
476501
}
477-
page_str.append("\n");
502+
}
503+
else
504+
{
505+
page_str.append(" entry is null\n"
506+
" is del: true\n");
478507
}
479508
}
480509
return page_str.toString();
@@ -814,6 +843,32 @@ class PageStorageControlV3
814843
return error_msg.toString();
815844
}
816845

846+
static String getBlobData(
847+
typename Trait::BlobStore & blob_store,
848+
BlobFileId blob_id,
849+
BlobFileOffset offset,
850+
size_t size)
851+
{
852+
auto page_id = []() {
853+
if constexpr (std::is_same_v<Trait, u128::PageStorageControlV3Trait>)
854+
return PageIdV3Internal(0, 0);
855+
else
856+
return UniversalPageId("");
857+
}();
858+
char * buffer = new char[size];
859+
blob_store.read(page_id, blob_id, offset, buffer, size, nullptr, false);
860+
861+
using ChecksumClass = Digest::CRC64;
862+
ChecksumClass digest;
863+
digest.update(buffer, size);
864+
auto checksum = digest.checksum();
865+
fmt::print("checksum: 0x{:X}\n", checksum);
866+
867+
auto hex_str = Redact::keyToHexString(buffer, size);
868+
delete[] buffer;
869+
return hex_str;
870+
}
871+
817872
private:
818873
ControlOptions options;
819874
};

release-centos7-llvm/env/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
tiflash-env
22
tiflash-env-*.tar.xz
3+
llvm-project
4+
sysroot
35
*.log
6+

0 commit comments

Comments
 (0)