diff --git a/mittest/simple_server/test_ob_tablet_to_ls_operator.cpp b/mittest/simple_server/test_ob_tablet_to_ls_operator.cpp index 0b92a3dab7..37e772dd8d 100644 --- a/mittest/simple_server/test_ob_tablet_to_ls_operator.cpp +++ b/mittest/simple_server/test_ob_tablet_to_ls_operator.cpp @@ -427,6 +427,14 @@ TEST_F(TestTabletToLSOperatorBatchGet, test_batch_get) ASSERT_TRUE(common::has_exist_in_array(tablet_ids, tablet_ls_caches.at(idx).get_tablet_id())); } + // test batch_get_tablet_ls_pairs + ObArray tablet_ls_pairs; + ASSERT_EQ(OB_SUCCESS, ObTabletToLSTableOperator::batch_get_tablet_ls_pairs(sql_proxy, tenant_id, tablet_ids, tablet_ls_pairs)); + ASSERT_TRUE(tablet_ids.count() == tablet_ls_pairs.count()); + ARRAY_FOREACH(tablet_ls_pairs, idx) { + ASSERT_TRUE(common::has_exist_in_array(tablet_ids, tablet_ls_caches.at(idx).get_tablet_id())); + } + } } // share diff --git a/src/share/tablet/ob_tablet_to_ls_operator.cpp b/src/share/tablet/ob_tablet_to_ls_operator.cpp index 313faafafa..485f130a9c 100644 --- a/src/share/tablet/ob_tablet_to_ls_operator.cpp +++ b/src/share/tablet/ob_tablet_to_ls_operator.cpp @@ -677,5 +677,39 @@ int ObTabletToLSTableOperator::construct_results_( return ret; } +int ObTabletToLSTableOperator::batch_get_tablet_ls_pairs( + common::ObISQLClient &sql_proxy, + const uint64_t tenant_id, + const ObIArray &tablet_ids, + ObIArray &tablet_ls_pairs) +{ + int ret = OB_SUCCESS; + BATCH_GET(sql_proxy, tenant_id, tablet_ids, tablet_ls_pairs); + if (OB_SUCC(ret) && OB_UNLIKELY(tablet_ls_pairs.count() != tablet_ids.count())) { + ret = OB_ITEM_NOT_MATCH; + LOG_WARN("count of tablet_ls_pairs and tablet_ids do not match," + " there may be duplicates or nonexistent values in tablet_ids", + KR(ret), "tablet_ids count", tablet_ids.count(), "tablet_ls_pairs count", + tablet_ls_pairs.count(), K(tenant_id), K(tablet_ids), K(tablet_ls_pairs)); + } + return ret; +} + +int ObTabletToLSTableOperator::inner_batch_get_( + common::ObISQLClient &sql_proxy, + const uint64_t tenant_id, + const ObIArray &tablet_ids, + const int64_t start_idx, + const int64_t end_idx, + ObIArray &tablet_ls_pairs) +{ + int ret = OB_SUCCESS; + const char *query_column_str = "tablet_id, ls_id"; + const bool keep_order = false; + INNER_BATCH_GET(sql_proxy, tenant_id, tablet_ids, start_idx, end_idx, + query_column_str, keep_order, tablet_ls_pairs); + return ret; +} + } // end namespace share } // end namespace oceanbase diff --git a/src/share/tablet/ob_tablet_to_ls_operator.h b/src/share/tablet/ob_tablet_to_ls_operator.h index 8fdf216823..1815549607 100644 --- a/src/share/tablet/ob_tablet_to_ls_operator.h +++ b/src/share/tablet/ob_tablet_to_ls_operator.h @@ -173,6 +173,22 @@ public: const common::ObIArray &tablet_ids, common::ObIArray &tablet_ls_caches); + // Gets ObTabletLSPair according to ObTableIDs + // + // @param [in] sql_proxy, ObMySQLProxy or ObMySQLTransaction + // @param [in] tenant_id, tenant for query + // @param [in] tablet_ids, ObTabletIDs for query (no duplicate values) + // @param [out] tablet_ls_pairs, array of + // @return OB_SUCCESS if success; + // OB_ITEM_NOT_MATCH if tablet_ids have duplicates or + // tablet_id which is not recorded in __all_tablet_to_ls; + // Other error according to unexpected situation + static int batch_get_tablet_ls_pairs( + common::ObISQLClient &sql_proxy, + const uint64_t tenant_id, + const ObIArray &tablet_ids, + ObIArray &tablet_ls_pairs); + const static int64_t MAX_BATCH_COUNT = 200; private: static int inner_batch_get_( @@ -196,6 +212,13 @@ private: const int64_t start_idx, const int64_t end_idx, common::ObIArray &tablet_ls_caches); + static int inner_batch_get_( + common::ObISQLClient &sql_proxy, + const uint64_t tenant_id, + const ObIArray &tablet_ids, + const int64_t start_idx, + const int64_t end_idx, + ObIArray &tablet_ls_pairs); static int inner_batch_update_by_sql_( common::ObISQLClient &sql_proxy,