From 8fd515bb25bbba5be143394bd40e8fb8dbeda0d5 Mon Sep 17 00:00:00 2001 From: zzg19950727 <1071026277@qq.com> Date: Sun, 16 Feb 2025 17:16:40 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=8D=E5=88=B6=E8=A1=A8?= =?UTF-8?q?=E5=9C=A8=E5=88=97=E5=AD=98=E5=89=AF=E6=9C=AC=E5=9C=BA=E6=99=AF?= =?UTF-8?q?=E4=B8=8B=E5=89=AF=E6=9C=AC=E9=80=89=E6=8B=A9=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/share/stat/ob_basic_stats_estimator.cpp | 4 ++++ src/sql/das/ob_das_location_router.cpp | 3 ++- src/sql/optimizer/ob_phy_table_location_info.cpp | 16 ++++++++++++---- src/sql/optimizer/ob_phy_table_location_info.h | 6 ++++-- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/share/stat/ob_basic_stats_estimator.cpp b/src/share/stat/ob_basic_stats_estimator.cpp index ed126a7fe8..6c1fa8f117 100644 --- a/src/share/stat/ob_basic_stats_estimator.cpp +++ b/src/share/stat/ob_basic_stats_estimator.cpp @@ -489,9 +489,12 @@ int ObBasicStatsEstimator::get_tablet_locations(ObExecContext &ctx, int ret = OB_SUCCESS; ObDASLocationRouter &loc_router = ctx.get_das_ctx().get_location_router(); ObSQLSessionInfo *session = ctx.get_my_session(); + int64_t route_policy = 0; if (OB_ISNULL(session) || OB_UNLIKELY(tablet_ids.count() != partition_ids.count())) { ret = OB_ERR_UNEXPECTED; LOG_WARN("get unexpected null", K(ret), K(session), K(tablet_ids.count()), K(partition_ids.count())); + } else if (OB_FAIL(session->get_sys_variable(SYS_VAR_OB_ROUTE_POLICY, route_policy))) { + LOG_WARN("get route policy failed", K(ret)); } else { candi_tablet_locs.reset(); if (OB_FAIL(candi_tablet_locs.prepare_allocate(tablet_ids.count()))) { @@ -504,6 +507,7 @@ int ObBasicStatsEstimator::get_tablet_locations(ObExecContext &ctx, loc_meta.ref_table_id_ = ref_table_id; loc_meta.table_loc_id_ = ref_table_id; loc_meta.select_leader_ = 0; + loc_meta.route_policy_ = route_policy; if (OB_FAIL(loc_router.nonblock_get_candi_tablet_locations(loc_meta, tablet_ids, partition_ids, diff --git a/src/sql/das/ob_das_location_router.cpp b/src/sql/das/ob_das_location_router.cpp index 5772e30400..b216d3c026 100755 --- a/src/sql/das/ob_das_location_router.cpp +++ b/src/sql/das/ob_das_location_router.cpp @@ -1017,7 +1017,8 @@ int ObDASLocationRouter::nonblock_get_candi_tablet_locations(const ObDASTableLoc if (OB_FAIL(candi_tablet_loc.set_part_loc_with_only_readable_replica(partition_ids.at(i), first_level_part_id, tablet_ids.at(i), - location))) { + location, + static_cast(loc_meta.route_policy_)))) { LOG_WARN("fail to set partition location with only readable replica", K(ret),K(i), K(location), K(candi_tablet_locs), K(tablet_ids), K(partition_ids)); } diff --git a/src/sql/optimizer/ob_phy_table_location_info.cpp b/src/sql/optimizer/ob_phy_table_location_info.cpp index 0d183d50d5..a293a9491d 100644 --- a/src/sql/optimizer/ob_phy_table_location_info.cpp +++ b/src/sql/optimizer/ob_phy_table_location_info.cpp @@ -59,7 +59,8 @@ int ObOptTabletLoc::assign(const ObOptTabletLoc &other) int ObOptTabletLoc::assign_with_only_readable_replica(const ObObjectID &partition_id, const ObObjectID &first_level_part_id, const common::ObTabletID &tablet_id, - const ObLSLocation &ls_location) + const ObLSLocation &ls_location, + const ObRoutePolicyType route_policy) { int ret = OB_SUCCESS; reset(); @@ -81,7 +82,12 @@ int ObOptTabletLoc::assign_with_only_readable_replica(const ObObjectID &partitio } else if (OB_FAIL(ObBLService::get_instance().check_in_black_list(bl_key, in_black_list))) { LOG_WARN("check in black list failed", K(ret)); } else if (!in_black_list) { - if (OB_FAIL(replica_locations_.push_back(replica_loc))) { + if ((route_policy == COLUMN_STORE_ONLY && replica_loc.get_replica_type() != REPLICA_TYPE_COLUMNSTORE) || + (route_policy != COLUMN_STORE_ONLY && replica_loc.get_replica_type() == REPLICA_TYPE_COLUMNSTORE) || + (route_policy == FORCE_READONLY_ZONE && replica_loc.get_replica_type() != REPLICA_TYPE_READONLY)) { + // skip the tmp_replica_loc + LOG_TRACE("skip the replica due to the replica policy.", K(ret), K(replica_loc)); + } else if (OB_FAIL(replica_locations_.push_back(replica_loc))) { LOG_WARN("Failed to push back replica locations", K(ret), K(i), K(replica_loc), K(replica_locations_)); } @@ -343,7 +349,8 @@ int ObCandiTabletLoc::get_selected_replica(ObRoutePolicy::CandidateReplica &repl int ObCandiTabletLoc::set_part_loc_with_only_readable_replica(const ObObjectID &partition_id, const ObObjectID &first_level_part_id, const common::ObTabletID &tablet_id, - const ObLSLocation &partition_location) + const ObLSLocation &partition_location, + const ObRoutePolicyType route_policy) { int ret = OB_SUCCESS; if (OB_UNLIKELY(has_selected_replica())) { @@ -353,7 +360,8 @@ int ObCandiTabletLoc::set_part_loc_with_only_readable_replica(const ObObjectID & } else if (OB_FAIL(opt_tablet_loc_.assign_with_only_readable_replica(partition_id, first_level_part_id, tablet_id, - partition_location))) { + partition_location, + route_policy))) { LOG_WARN("fail to assign partition location with only readable replica", K(ret), K(partition_location)); } diff --git a/src/sql/optimizer/ob_phy_table_location_info.h b/src/sql/optimizer/ob_phy_table_location_info.h index 9ddfdc75a5..c4ff280a40 100644 --- a/src/sql/optimizer/ob_phy_table_location_info.h +++ b/src/sql/optimizer/ob_phy_table_location_info.h @@ -38,7 +38,8 @@ public: int assign_with_only_readable_replica(const ObObjectID &partition_id, const ObObjectID &first_level_part_id, const common::ObTabletID &tablet_id, - const share::ObLSLocation &partition_location); + const share::ObLSLocation &partition_location, + const ObRoutePolicyType route_policy); bool is_valid() const; bool operator==(const ObOptTabletLoc &other) const; @@ -105,7 +106,8 @@ public: int set_part_loc_with_only_readable_replica(const ObObjectID &partition_id, const ObObjectID &first_level_part_id, const common::ObTabletID &tablet_id, - const share::ObLSLocation &partition_location); + const share::ObLSLocation &partition_location, + const ObRoutePolicyType route_policy); const ObOptTabletLoc &get_partition_location() const { return opt_tablet_loc_; } ObOptTabletLoc &get_partition_location() { return opt_tablet_loc_; } const common::ObIArray &get_priority_replica_idxs() const { return priority_replica_idxs_; }