wyxxxcat commented on code in PR #54527:
URL: https://github.com/apache/doris/pull/54527#discussion_r2284212726
##########
cloud/src/recycler/meta_checker.cpp:
##########
@@ -356,6 +355,186 @@ bool MetaChecker::do_meta_schema_key_check(MYSQL* conn) {
return check_res;
}
+bool MetaChecker::do_version_partition_key_check(MYSQL* conn) {
+ std::vector<PartitionInfo> partitions_info;
+ bool check_res = true;
+
+ // scan and collect tablet_idx
+ std::string start_key;
+ std::string end_key;
+ partition_version_key({instance_id_, 0, 0, 0}, &start_key);
+ partition_version_key({instance_id_, INT64_MAX, 0, 0}, &end_key);
+ scan_and_handle_kv(
+ start_key, end_key,
+ [&partitions_info](std::string_view key, std::string_view value)
-> int {
+ VersionPB partition_version;
+ if (!partition_version.ParseFromArray(value.data(),
value.size())) {
+ LOG(WARNING) << "malformed tablet index value";
+ return -1;
+ }
+ auto k1 = key;
+ k1.remove_prefix(1);
+ // 0x01 "version" ${instance_id} "partition" ${db_id}
${tbl_id} ${partition_id}
+ std::vector<std::tuple<std::variant<int64_t, std::string>,
int, int>> out;
+ decode_key(&k1, &out);
+ DCHECK_EQ(out.size(), 6) << key;
+ auto db_id = std::get<int64_t>(std::get<0>(out[3]));
+ auto table_id = std::get<int64_t>(std::get<0>(out[4]));
+ auto partition_id = std::get<int64_t>(std::get<0>(out[5]));
+ partitions_info.emplace_back(PartitionInfo {
+ .db_id = db_id, .table_id = table_id, .partition_id =
partition_id});
+ return 0;
+ });
+
+ for (const auto& partition_info : partitions_info) {
+ if (!db_meta_.contains(partition_info.db_id)) {
+ LOG(WARNING) << "partition_info.db_id not found in fe meta, db_id
= "
+ << partition_info.db_id
+ << "partition_info meta: " <<
partition_info.debug_string();
+ continue;
+ }
+ std::string db_name = db_meta_.at(partition_info.db_id);
+ if (db_name == "__internal_schema" || db_name == "information_schema"
||
+ db_name == "mysql") {
+ continue;
+ }
+
+ if (mysql_select_db(conn, db_name.c_str())) {
+ LOG(WARNING) << "mysql select db error, db_name: " << db_name
+ << " error: " << mysql_error(conn);
+ continue;
+ }
+ MYSQL_RES* result;
+ std::string sql_stmt = fmt::format("show partition {}",
partition_info.partition_id);
+ mysql_query(conn, sql_stmt.c_str());
+
+ result = mysql_store_result(conn);
+ if (result) {
+ MYSQL_ROW row = mysql_fetch_row(result);
+ if (partition_info.table_id != atoll(row[4])) {
+ LOG(WARNING) << "check failed, fdb meta: " <<
partition_info.debug_string()
+ << " fe partition of table_id: " << atoll(row[4]);
+ check_res = false;
+ } else if (partition_info.db_id != atoll(row[3])) {
+ LOG(WARNING) << "check failed, fdb meta: " <<
partition_info.debug_string()
+ << " fe partition of db_id: " << atoll(row[3]);
+ check_res = false;
+ }
+ mysql_free_result(result);
+ } else {
+ LOG(WARNING) << "check failed, fdb meta: " <<
partition_info.debug_string()
+ << " fe partition not found";
+ check_res = false;
+ }
+ stat_info_.check_fe_partition_version_num++;
+ }
+
+ return check_res;
+}
+
+bool MetaChecker::do_version_table_key_check(MYSQL* conn) {
+ std::vector<TableInfo> tables_info;
+ bool check_res = true;
+
+ // table id -> version
+ std::unordered_map<int64_t, int64_t> fe_tables_info;
+ std::string start_key;
+ std::string end_key;
+ table_version_key({instance_id_, 0, 0}, &start_key);
+ table_version_key({instance_id_, INT64_MAX, 0}, &end_key);
+
+ // collect table version from fdb
+ scan_and_handle_kv(
+ start_key, end_key,
+ [&tables_info, this](std::string_view key, std::string_view value)
-> int {
+ int64_t version = 0;
+ std::unique_ptr<Transaction> txn;
+ TxnErrorCode err = txn_kv_->create_txn(&txn);
+ if (err != TxnErrorCode::TXN_OK) {
+ LOG(WARNING) << "failed to create txn";
+ return -1;
+ }
+ if (!txn->decode_atomic_int(value, &version)) {
+ LOG(WARNING) << "malformed table version value";
+ return -1;
+ }
+ auto k1 = key;
+ k1.remove_prefix(1);
+ // 0x01 "version" ${instance_id} "table" ${db_id} ${tbl_id} ->
${version}
+ std::vector<std::tuple<std::variant<int64_t, std::string>,
int, int>> out;
+ decode_key(&k1, &out);
+ DCHECK_EQ(out.size(), 5) << key;
+ auto db_id = std::get<int64_t>(std::get<0>(out[3]));
+ auto table_id = std::get<int64_t>(std::get<0>(out[4]));
+ tables_info.emplace_back(TableInfo {.db_id = db_id, .table_id
= table_id});
+ return 0;
+ });
+
+ // collect table version from fe meta
+ for (const auto& table_info : tables_info) {
+ if (!db_meta_.contains(table_info.db_id)) {
+ LOG(WARNING) << "table_info.db_id not found in fe meta, db_id = "
<< table_info.db_id
+ << "table_info meta: " << table_info.debug_string();
+ continue;
Review Comment:
ditto
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]