Skip to content

Commit

Permalink
[Enhancement] Support get persistent index meta in meta tool (StarRoc…
Browse files Browse the repository at this point in the history
…ks#55424)

Signed-off-by: wyb <wybb86@gmail.com>
  • Loading branch information
wyb authored Jan 26, 2025
1 parent 9cc700a commit 2d41b74
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions be/src/tools/meta_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ using starrocks::PrimaryKeyDump;

DEFINE_string(root_path, "", "storage root path");
DEFINE_string(operation, "",
"valid operation: get_meta, flag, load_meta, delete_meta, delete_rowset_meta, show_meta, "
"check_table_meta_consistency, print_lake_metadata, print_lake_txn_log, print_lake_schema");
"valid operation: get_meta, flag, load_meta, delete_meta, delete_rowset_meta, get_persistent_index_meta, "
"delete_persistent_index_meta, show_meta, check_table_meta_consistency, print_lake_metadata, "
"print_lake_txn_log, print_lake_schema");
DEFINE_int64(tablet_id, 0, "tablet_id for tablet meta");
DEFINE_string(tablet_uid, "", "tablet_uid for tablet meta");
DEFINE_int64(table_id, 0, "table id for table meta");
Expand Down Expand Up @@ -133,6 +134,8 @@ std::string get_usage(const std::string& progname) {
{progname} --operation=delete_meta --tablet_file=<file_path>
delete_rowset_meta:
{progname} --operation=delete_rowset_meta --root_path=</path/to/storage/path> --tablet_uid=<tablet_uid> --rowset_id=<rowset_id>
get_persistent_index_meta:
{progname} --operation=get_persistent_index_meta --root_path=</path/to/storage/path> --tablet_id=<tabletid>
delete_persistent_index_meta:
{progname} --operation=delete_persistent_index_meta --root_path=</path/to/storage/path> --tablet_id=<tabletid>
{progname} --operation=delete_persistent_index_meta --root_path=</path/to/storage/path> --table_id=<tableid>
Expand Down Expand Up @@ -265,6 +268,25 @@ void delete_rowset_meta(DataDir* data_dir) {
std::cout << "delete rowset meta successfully" << std::endl;
}

void get_persistent_index_meta(DataDir* data_dir) {
starrocks::PersistentIndexMetaPB index_meta;
auto st = TabletMetaManager::get_persistent_index_meta(data_dir, FLAGS_tablet_id, &index_meta);
if (!st.ok()) {
std::cerr << "get persistent index meta failed for tablet: " << FLAGS_tablet_id
<< ", status: " << st.to_string() << std::endl;
return;
}
json2pb::Pb2JsonOptions options;
options.pretty_json = true;
std::string json;
std::string error;
if (!json2pb::ProtoMessageToJson(index_meta, &json, options, &error)) {
std::cerr << "Fail to convert protobuf to json: " << error << std::endl;
return;
}
std::cout << json << '\n';
}

void delete_persistent_index_meta(DataDir* data_dir) {
if (FLAGS_table_id != 0) {
auto st = TabletMetaManager::remove_table_persistent_index_meta(data_dir, FLAGS_table_id);
Expand Down Expand Up @@ -1206,6 +1228,7 @@ int meta_tool_main(int argc, char** argv) {
"load_meta",
"delete_meta",
"delete_rowset_meta",
"get_persistent_index_meta",
"delete_persistent_index_meta",
"compact_meta",
"get_meta_stats",
Expand All @@ -1220,7 +1243,8 @@ int meta_tool_main(int argc, char** argv) {

bool read_only = false;
if (FLAGS_operation == "get_meta" || FLAGS_operation == "get_meta_stats" || FLAGS_operation == "ls" ||
FLAGS_operation == "check_table_meta_consistency" || FLAGS_operation == "scan_dcgs") {
FLAGS_operation == "check_table_meta_consistency" || FLAGS_operation == "scan_dcgs" ||
FLAGS_operation == "get_persistent_index_meta") {
read_only = true;
}

Expand All @@ -1243,6 +1267,8 @@ int meta_tool_main(int argc, char** argv) {
delete_meta(data_dir.get());
} else if (FLAGS_operation == "delete_rowset_meta") {
delete_rowset_meta(data_dir.get());
} else if (FLAGS_operation == "get_persistent_index_meta") {
get_persistent_index_meta(data_dir.get());
} else if (FLAGS_operation == "delete_persistent_index_meta") {
delete_persistent_index_meta(data_dir.get());
} else if (FLAGS_operation == "compact_meta") {
Expand Down

0 comments on commit 2d41b74

Please sign in to comment.