/** * Copyright (c) 2021 OceanBase * OceanBase Database Proxy(ODP) is licensed under Mulan PubL v2. * You can use this software according to the terms and conditions of the Mulan PubL v2. * You may obtain a copy of Mulan PubL v2 at: * http://license.coscl.org.cn/MulanPubL-2.0 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PubL v2 for more details. */ #ifndef _OB_PART_DESC_HASH_H #define _OB_PART_DESC_HASH_H 1 //#include "common/ob_object.h" #include "share/part/ob_part_desc.h" #include "share/part/ob_part_mgr_util.h" #include "proxy/route/obproxy_part_mgr.h" namespace oceanbase { namespace common { class ObObj; class ObPartDescHash : public ObPartDesc { public: ObPartDescHash(); virtual ~ObPartDescHash() {} virtual int get_part(ObNewRange &range, ObIAllocator &allocator, ObIArray &part_ids, ObPartDescCtx &ctx, ObIArray &tablet_ids); virtual int get_part_by_num(const int64_t num, ObIArray &part_ids, ObIArray &tablet_ids); void set_part_num(int64_t part_num) { part_num_ = part_num; } void set_part_space(int64_t part_space) { part_space_ = part_space; } void set_first_part_id(int64_t first_part_id) { first_part_id_ = first_part_id; } int64_t get_first_part_id() { return first_part_id_; } void set_part_array(int64_t *part_array) { part_array_ = part_array; } void set_oracle_mode(bool is_oracle_mode) { is_oracle_mode_ = is_oracle_mode; } ObIArray &get_obj_types() { return obj_types_; } ObIArray &get_cs_types() { return cs_types_; } VIRTUAL_TO_STRING_KV("part_type", "hash", K_(is_oracle_mode), K_(part_num), K_(part_space), K_(part_level), K_(part_func_type)); private: uint64_t calc_hash_value_with_seed(const ObObj &obj, const int64_t cluster_version, int64_t seed); bool is_oracle_supported_type(const ObObjType type); int calc_value_for_oracle(const ObObj *objs, int64_t objs_cnt, int64_t &result, ObPartDescCtx &ctx); int calc_value_for_mysql(const ObObj *obj, int64_t &result); int get_part_hash_idx(const int64_t part_idx, int64_t &part_id); int calc_hash_part_idx(const uint64_t val, const int64_t part_num, int64_t &partition_idx); private: bool is_oracle_mode_; int64_t part_num_; int64_t part_space_; int64_t first_part_id_; // multiple key ObSEArray obj_types_; ObSEArray cs_types_; int64_t *part_array_; }; } } #endif /* _OB_PART_DESC_HASH_H */