patch 4.0

This commit is contained in:
wangzelin.wzl
2022-10-24 10:34:53 +08:00
parent 4ad6e00ec3
commit 93a1074b0c
10533 changed files with 2588271 additions and 2299373 deletions

View File

@ -16,10 +16,12 @@
#include "common/ob_range.h"
#include "share/partition_table/ob_partition_location.h"
namespace oceanbase {
namespace sql {
class ObPhyTableLocationInfo;
class ObPhyPartitionLocationInfo;
namespace oceanbase
{
namespace sql
{
class ObCandiTableLoc;
class ObCandiTabletLoc;
typedef common::ObIArray<share::ObPartitionLocation> ObPartitionLocationIArray;
typedef common::ObSEArray<share::ObPartitionLocation, 1> ObPartitionLocationSEArray;
@ -27,69 +29,30 @@ typedef common::ObSEArray<share::ObPartitionLocation, 1> ObPartitionLocationSEAr
typedef common::ObIArray<share::ObPartitionReplicaLocation> ObPartitionReplicaLocationIArray;
typedef common::ObSEArray<share::ObPartitionReplicaLocation, 1> ObPartitionReplicaLocationSEArray;
class ObSplittedRanges {
OB_UNIS_VERSION(1);
public:
const common::ObIArray<common::ObNewRange>& get_ranges() const
{
return ranges_;
}
common::ObIArray<common::ObNewRange>& get_ranges()
{
return const_cast<common::ObIArray<common::ObNewRange>&>(static_cast<const ObSplittedRanges&>(*this).get_ranges());
}
int64_t get_offset(int64_t idx) const
{
return offsets_.at(idx);
}
const common::ObIArray<int64_t>& get_offsets() const
{
return offsets_;
}
common::ObIArray<int64_t>& get_offsets()
{
return const_cast<common::ObIArray<int64_t>&>(static_cast<const ObSplittedRanges&>(*this).get_offsets());
}
TO_STRING_KV(K_(ranges), K_(offsets));
private:
common::ObSEArray<common::ObNewRange, 1> ranges_;
common::ObSEArray<int64_t, 1> offsets_;
enum class ObDuplicateType : int64_t
{
NOT_DUPLICATE = 0, //非复制表
DUPLICATE, //复制表, 可以选择任意副本
DUPLICATE_IN_DML, //被DML更改的复制表, 此时只能选leader副本
};
typedef common::ObIArray<ObSplittedRanges> ObSplittedRangesIArray;
typedef common::ObSEArray<ObSplittedRanges, 1> ObSplittedRangesSEArray;
enum class ObDuplicateType : int64_t {
NOT_DUPLICATE = 0, // non duplicate table
DUPLICATE, // normal duplicate table, can choose any replica
DUPLICATE_IN_DML, // duplicate table in DML, only can choose leader
};
class ObPhyTableLocation final {
class ObPhyTableLocation final
{
OB_UNIS_VERSION(1);
public:
static bool compare_phy_part_loc_info_asc(
const ObPhyPartitionLocationInfo*& left, const ObPhyPartitionLocationInfo*& right);
static bool compare_phy_part_loc_info_desc(
const ObPhyPartitionLocationInfo*& left, const ObPhyPartitionLocationInfo*& right);
static bool compare_phy_part_loc_info_asc(const ObCandiTabletLoc *&left,
const ObCandiTabletLoc *&right);
static bool compare_phy_part_loc_info_desc(const ObCandiTabletLoc *&left,
const ObCandiTabletLoc *&right);
public:
ObPhyTableLocation();
void reset();
int assign(const ObPhyTableLocation& other);
int append(const ObPhyTableLocation& other);
int assign_from_phy_table_loc_info(const ObPhyTableLocationInfo& other);
inline bool operator==(const ObPhyTableLocation& other) const
int assign(const ObPhyTableLocation &other);
int append(const ObPhyTableLocation &other);
int assign_from_phy_table_loc_info(const ObCandiTableLoc &other);
inline bool operator== (const ObPhyTableLocation &other) const
{
return table_location_key_ == other.table_location_key_ && ref_table_id_ == other.ref_table_id_;
return table_location_key_ == other.table_location_key_ && ref_table_id_ == other.ref_table_id_;
}
inline void set_table_location_key(uint64_t table_location_key, uint64_t ref_table_id)
@ -97,83 +60,58 @@ public:
table_location_key_ = table_location_key;
ref_table_id_ = ref_table_id;
}
inline uint64_t get_table_location_key() const
{
return table_location_key_;
}
inline uint64_t get_ref_table_id() const
{
return ref_table_id_;
}
inline uint64_t get_table_location_key() const { return table_location_key_; }
inline uint64_t get_ref_table_id() const { return ref_table_id_; }
int add_partition_locations(const ObPhyTableLocationInfo& phy_location_info);
int add_partition_location(const ObPartitionReplicaLocationIArray& partition_locations);
int add_partition_location(const share::ObPartitionReplicaLocation& partition_location);
inline const ObPartitionReplicaLocationIArray& get_partition_location_list() const
int add_partition_locations(const ObCandiTableLoc &phy_location_info);
int add_partition_location(const ObPartitionReplicaLocationIArray &partition_locations);
int add_partition_location(const share::ObPartitionReplicaLocation &partition_location);
inline const ObPartitionReplicaLocationIArray &get_partition_location_list() const
{
return partition_location_list_;
}
inline ObPartitionReplicaLocationIArray& get_partition_location_list()
// 危险的接口
inline ObPartitionReplicaLocationIArray &get_partition_location_list()
{
return const_cast<ObPartitionReplicaLocationIArray&>(
(static_cast<const ObPhyTableLocation&>(*this)).get_partition_location_list());
return const_cast<ObPartitionReplicaLocationIArray &>
((static_cast<const ObPhyTableLocation&>(*this)).get_partition_location_list());
}
int64_t get_partition_cnt() const
{
return partition_location_list_.count();
}
TO_STRING_KV(K_(table_location_key), K_(ref_table_id), K_(partition_location_list), K_(splitted_range_list),
K_(duplicate_type));
const share::ObPartitionReplicaLocation* get_part_replic_by_part_id(int64_t part_id) const;
template <typename SrcArray, typename DstArray>
int find_not_include_part_ids(const SrcArray& all_part_ids, DstArray& expected_part_ids);
const ObSplittedRangesIArray& get_splitted_ranges_list() const
{
return splitted_range_list_;
}
ObSplittedRangesIArray& get_splitted_ranges_list()
{
return const_cast<common::ObIArray<ObSplittedRanges>&>(
static_cast<const ObPhyTableLocation&>(*this).get_splitted_ranges_list());
}
const share::ObPartitionReplicaLocation* get_part_replic_by_index(int64_t part_idx) const;
bool is_duplicate_table() const
{
return ObDuplicateType::NOT_DUPLICATE != duplicate_type_;
}
bool is_duplicate_table_not_in_dml() const
{
return ObDuplicateType::DUPLICATE == duplicate_type_;
}
void set_duplicate_type(ObDuplicateType v)
{
duplicate_type_ = v;
}
ObDuplicateType get_duplicate_type() const
{
return duplicate_type_;
}
static common::ObPartitionType get_partition_type(const common::ObPartitionKey& pkey,
const common::ObIArray<ObPhyTableLocation>& table_locations, bool is_retry_for_dup_tbl);
int64_t get_partition_cnt() const { return partition_location_list_.count(); }
TO_STRING_KV(K_(table_location_key),
K_(ref_table_id),
K_(partition_location_list),
K_(duplicate_type));
const share::ObPartitionReplicaLocation *get_part_replic_by_part_id(int64_t part_id) const;
template<typename SrcArray, typename DstArray>
int find_not_include_part_ids(const SrcArray &all_part_ids, DstArray &expected_part_ids);
int erase_partition_location(int64_t partition_id);
const share::ObPartitionReplicaLocation *get_part_replic_by_index(int64_t part_idx) const;
int get_location_idx_by_part_id(int64_t part_id, int64_t &loc_idx) const;
bool is_duplicate_table() const { return ObDuplicateType::NOT_DUPLICATE != duplicate_type_; }
bool is_duplicate_table_not_in_dml() const { return ObDuplicateType::DUPLICATE == duplicate_type_; }
void set_duplicate_type(ObDuplicateType v) { duplicate_type_ = v; }
ObDuplicateType get_duplicate_type() const { return duplicate_type_; }
private:
int try_build_location_idx_map();
private:
/* 用于表ID(可能是generated alias id)寻址location */
uint64_t table_location_key_;
/* 用于获取实际的物理表ID */
uint64_t ref_table_id_;
/* locations */
ObPartitionLocationSEArray part_loc_list_;
// The following two list has one element for each partition
ObPartitionReplicaLocationSEArray partition_location_list_;
ObSplittedRangesSEArray splitted_range_list_; // corresponding to partition list
ObDuplicateType duplicate_type_;
// for lookup performance
static const int FAST_LOOKUP_LOC_IDX_SIZE_THRES = 3;
common::hash::ObHashMap<int64_t, int64_t, common::hash::NoPthreadDefendMode> location_idx_map_;
};
template <typename SrcArray, typename DstArray>
int ObPhyTableLocation::find_not_include_part_ids(const SrcArray& all_part_ids, DstArray& expected_part_ids)
template<typename SrcArray, typename DstArray>
int ObPhyTableLocation::find_not_include_part_ids(const SrcArray &all_part_ids,
DstArray &expected_part_ids)
{
int ret = common::OB_SUCCESS;
for (int64_t i = 0; OB_SUCC(ret) && i < all_part_ids.count(); ++i) {
@ -186,9 +124,10 @@ int ObPhyTableLocation::find_not_include_part_ids(const SrcArray& all_part_ids,
return ret;
}
class ObPhyTableLocationGuard {
class ObPhyTableLocationGuard
{
public:
ObPhyTableLocationGuard() : loc_(nullptr){};
ObPhyTableLocationGuard() : loc_(nullptr) {};
~ObPhyTableLocationGuard()
{
if (loc_) {
@ -205,21 +144,17 @@ public:
ret = common::OB_ERR_UNEXPECTED;
} else if (nullptr == (buf = allocator.alloc(sizeof(ObPhyTableLocation)))) {
ret = common::OB_ALLOCATE_MEMORY_FAILED;
} else if (NULL == (loc_ = new (buf) ObPhyTableLocation())) {
} else if (NULL == (loc_ = new(buf)ObPhyTableLocation())) {
ret = common::OB_ERR_UNEXPECTED;
}
return ret;
}
// caller must ensure that the loc_ is not NULL before call get_loc()
ObPhyTableLocation *get_loc()
{
return loc_;
}
ObPhyTableLocation *get_loc() { return loc_; }
private:
ObPhyTableLocation *loc_;
};
} // namespace sql
} // namespace oceanbase
}
}
#endif /* OCEANBASE_SQL_OB_PHY_TABLE_LOCATION_ */