diff --git a/be/src/storage/tablet.cpp b/be/src/storage/tablet.cpp index 46ff28b024e8c0..fc3bfea6b02ec3 100644 --- a/be/src/storage/tablet.cpp +++ b/be/src/storage/tablet.cpp @@ -1534,6 +1534,13 @@ bool Tablet::_contains_rowset(const RowsetId rowset_id) { } void Tablet::build_tablet_report_info(TTabletInfo* tablet_info) { + // primary key specified info will protected by independent lock context + // in TabletUpdates which means that those lock context can be sperated from + // the tablet meta_lock when trying to get the extra info + if (_updates) { + _updates->get_tablet_info_extra(tablet_info); + } + std::shared_lock rdlock(_meta_lock); tablet_info->__set_tablet_id(_tablet_meta->tablet_id()); tablet_info->__set_schema_hash(_tablet_meta->schema_hash()); @@ -1546,9 +1553,7 @@ void Tablet::build_tablet_report_info(TTabletInfo* tablet_info) { if (_tablet_meta->get_binlog_config() != nullptr) { tablet_info->__set_binlog_config_version(_tablet_meta->get_binlog_config()->version); } - if (_updates) { - _updates->get_tablet_info_extra(tablet_info); - } else { + if (_updates == nullptr) { int64_t max_version = _timestamped_version_tracker.get_max_continuous_version(); auto max_rowset = rowset_with_max_version(); if (max_rowset != nullptr) { diff --git a/be/src/storage/tablet_manager.cpp b/be/src/storage/tablet_manager.cpp index 792adf13e61578..72173402c2e948 100644 --- a/be/src/storage/tablet_manager.cpp +++ b/be/src/storage/tablet_manager.cpp @@ -983,28 +983,35 @@ Status TabletManager::report_all_tablets_info(std::map* tabl StarRocksMetrics::instance()->report_all_tablets_requests_total.increment(1); - size_t max_tablet_rowset_num = 0; + std::vector all_tablets; for (const auto& tablets_shard : _tablets_shards) { std::shared_lock rlock(tablets_shard.lock); - for (const auto& [tablet_id, tablet_ptr] : tablets_shard.tablet_map) { - TTablet t_tablet; - TTabletInfo tablet_info; - tablet_ptr->build_tablet_report_info(&tablet_info); - max_tablet_rowset_num = std::max(max_tablet_rowset_num, tablet_ptr->version_count()); - // find expired transaction corresponding to this tablet - TabletInfo tinfo(tablet_id, tablet_ptr->schema_hash(), tablet_ptr->tablet_uid()); - auto find = expire_txn_map.find(tinfo); - if (find != expire_txn_map.end()) { - tablet_info.__set_transaction_ids(find->second); - expire_txn_map.erase(find); - } - t_tablet.tablet_infos.push_back(tablet_info); + for (const auto& [_, tablet_ptr] : tablets_shard.tablet_map) { + all_tablets.push_back(tablet_ptr); + } + } - if (!t_tablet.tablet_infos.empty()) { - tablets_info->emplace(tablet_id, t_tablet); - } + size_t max_tablet_rowset_num = 0; + for (auto& tablet_ptr : all_tablets) { + TTablet t_tablet; + TTabletInfo tablet_info; + tablet_ptr->build_tablet_report_info(&tablet_info); + max_tablet_rowset_num = std::max(max_tablet_rowset_num, tablet_ptr->version_count()); + // find expired transaction corresponding to this tablet + TabletInfo tinfo(tablet_ptr->tablet_id(), tablet_ptr->schema_hash(), tablet_ptr->tablet_uid()); + auto find = expire_txn_map.find(tinfo); + if (find != expire_txn_map.end()) { + tablet_info.__set_transaction_ids(find->second); + expire_txn_map.erase(find); + } + t_tablet.tablet_infos.push_back(tablet_info); + + if (!t_tablet.tablet_infos.empty()) { + tablets_info->emplace(tablet_ptr->tablet_id(), t_tablet); } } + all_tablets.clear(); + LOG(INFO) << "Report all " << tablets_info->size() << " tablets info. max_tablet_rowset_num:" << max_tablet_rowset_num; StarRocksMetrics::instance()->max_tablet_rowset_num.set_value(max_tablet_rowset_num); diff --git a/be/test/storage/tablet_mgr_test.cpp b/be/test/storage/tablet_mgr_test.cpp index 66caea97327816..195a38c16accfd 100644 --- a/be/test/storage/tablet_mgr_test.cpp +++ b/be/test/storage/tablet_mgr_test.cpp @@ -516,4 +516,18 @@ TEST_F(TabletMgrTest, RemoveTabletInDiskDisable) { StorageEngine::instance()->tablet_manager()->drop_tablets_on_error_root_path(tablet_info_vec); } +TEST_F(TabletMgrTest, GetTabletReportInfo) { + TTabletId tablet_id = 4251234666; + TSchemaHash schema_hash = 3929134666; + TCreateTabletReq create_tablet_req = get_create_tablet_request(tablet_id, schema_hash); + Status create_st = StorageEngine::instance()->create_tablet(create_tablet_req); + ASSERT_TRUE(create_st.ok()); + + TReportRequest request; + request.__isset.tablets = true; + Status st_report = StorageEngine::instance()->tablet_manager()->report_all_tablets_info(&request.tablets); + ASSERT_TRUE(st_report.ok()); + ASSERT_TRUE(request.tablets.size() == 1); +} + } // namespace starrocks