Skip to content

Commit

Permalink
Support remove region by ps-ctl (#9807)
Browse files Browse the repository at this point in the history
ref #9722

Signed-off-by: Calvin Neo <[email protected]>
Signed-off-by: JaySon-Huang <[email protected]>

Co-authored-by: JaySon-Huang <[email protected]>
Co-authored-by: JaySon <[email protected]>
  • Loading branch information
CalvinNeo and JaySon-Huang authored Feb 17, 2025
1 parent b035bbe commit f2fe643
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions dbms/src/Storages/Page/tools/PageCtl/PageStorageCtlV3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <Storages/Page/V3/Universal/UniversalPageId.h>
#include <Storages/Page/V3/Universal/UniversalPageIdFormatImpl.h>
#include <Storages/Page/V3/Universal/UniversalPageStorage.h>
#include <Storages/Page/WriteBatchImpl.h>
#include <Storages/PathPool.h>
#include <TestUtils/MockDiskDelegator.h>
#include <TestUtils/TiFlashTestEnv.h>
Expand All @@ -54,6 +55,7 @@ struct ControlOptions
DISPLAY_WAL_ENTRIES = 5,
DISPLAY_REGION_INFO = 6,
DISPLAY_BLOB_DATA = 7,
DELETE_KVSTORE_REGION = 8,
};

std::vector<std::string> paths;
Expand Down Expand Up @@ -95,6 +97,7 @@ ControlOptions ControlOptions::parse(int argc, char ** argv)
5 is dump entries in WAL log files
6 is display all region info
7 is display blob data (in hex)
8 is delete regino in kvstore
)") //
("show_entries",
value<bool>()->default_value(true),
Expand Down Expand Up @@ -314,7 +317,10 @@ class PageStorageControlV3
}

// Other display mode need to restore ps instance
auto display = [](auto & mvcc_table_directory, auto & blob_store, const ControlOptions & opts) {
auto display = []([[maybe_unused]] auto & ps,
auto & mvcc_table_directory,
auto & blob_store,
const ControlOptions & opts) {
switch (opts.mode)
{
case ControlOptions::DisplayType::DISPLAY_SUMMARY_INFO:
Expand Down Expand Up @@ -378,6 +384,28 @@ class PageStorageControlV3
fmt::println("hex:{}", hex_data);
break;
}
case ControlOptions::DisplayType::DELETE_KVSTORE_REGION:
{
if constexpr (std::is_same_v<Trait, u128::PageStorageControlV3Trait>)
{
if (KVSTORE_NAMESPACE_ID != opts.namespace_id)
{
LOG_WARNING(
DB::Logger::get(),
"A valid KVStore namespace should with namespace id {}",
KVSTORE_NAMESPACE_ID);
}
LOG_INFO(DB::Logger::get(), "Remove region, region_id={}", opts.page_id);
WriteBatch wb(opts.namespace_id);
wb.delPage(opts.page_id);
ps.write(std::move(wb));
}
else if constexpr (std::is_same_v<Trait, universal::PageStorageControlV3Trait>)
{
std::cout << "Do not support in Unips mode." << std::endl;
}
break;
}
default:
std::cout << "Invalid display mode." << std::endl;
break;
Expand All @@ -390,15 +418,15 @@ class PageStorageControlV3
ps.restore();
auto & mvcc_table_directory = ps.page_directory->mvcc_table_directory;
auto & blobstore = ps.blob_store;
display(mvcc_table_directory, blobstore, options);
display(ps, mvcc_table_directory, blobstore, options);
}
else if constexpr (std::is_same_v<Trait, universal::PageStorageControlV3Trait>)
{
auto ps = UniversalPageStorage::create(String(NAME), delegator, config, provider);
ps->restore();
auto & mvcc_table_directory = ps->page_directory->mvcc_table_directory;
auto & blobstore = ps->blob_store;
display(mvcc_table_directory, *blobstore, options);
display(ps, mvcc_table_directory, *blobstore, options);
}

return 0;
Expand Down Expand Up @@ -455,6 +483,7 @@ class PageStorageControlV3
return stats_info.toString();
}

// mode 2 DISPLAY_DIRECTORY_INFO
static String getDirectoryInfo(
typename Trait::PageDirectory::MVCCMapType & mvcc_table_directory,
bool show_entries,
Expand Down

0 comments on commit f2fe643

Please sign in to comment.