init push

This commit is contained in:
oceanbase-admin
2021-05-31 22:56:52 +08:00
commit cea7de1475
7020 changed files with 5689869 additions and 0 deletions

View File

@ -0,0 +1,59 @@
/**
* Copyright (c) 2021 OceanBase
* OceanBase CE 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.
*/
#include "ob_fake_partition_location_cache.h"
using namespace oceanbase::common;
namespace oceanbase {
namespace share {
ObFakePartitionLocationCache::ObFakePartitionLocationCache()
{
int ret = OB_SUCCESS;
if (OB_SUCCESS != (ret = partition_loc_map_.create(10000, ObModIds::OB_SQL_EXECUTOR))) {
SQL_ENG_LOG(WARN, "fail to create location map", K(ret));
}
}
ObFakePartitionLocationCache::~ObFakePartitionLocationCache()
{}
int ObFakePartitionLocationCache::get(const uint64_t table_id, const int64_t partition_id,
ObPartitionLocation& location, const int64_t expire_renew_time, bool&)
{
UNUSED(expire_renew_time);
int ret = OB_SUCCESS;
ObFakePartitionKey key;
key.table_id_ = table_id;
key.partition_id_ = partition_id;
if (hash::HASH_EXIST == (ret = partition_loc_map_.get(key, location))) {
ret = OB_SUCCESS;
}
return ret;
}
int ObFakePartitionLocationCache::add_location(ObFakePartitionKey key, ObPartitionLocation location)
{
int ret = OB_SUCCESS;
location.set_table_id(key.table_id_);
location.set_partition_id(key.partition_id_);
if (location.get_partition_cnt() <= key.partition_id_) {
location.set_partition_cnt(key.partition_id_ + 1);
}
location.is_valid();
if (hash::HASH_INSERT_SUCC == (ret = partition_loc_map_.set(key, location))) {
ret = OB_SUCCESS;
}
return ret;
}
} // namespace share
} // namespace oceanbase

View File

@ -0,0 +1,53 @@
/**
* Copyright (c) 2021 OceanBase
* OceanBase CE 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 OCEANBASE_FAKE_PARTITION_LOCATION_CACHE_
#define OCEANBASE_FAKE_PARTITION_LOCATION_CACHE_
#include "share/partition_table/ob_partition_location_cache.h"
#include "lib/hash/ob_hashmap.h"
namespace oceanbase {
namespace share {
class ObFakePartitionKey {
public:
uint64_t table_id_;
int64_t partition_id_;
inline int64_t hash() const
{
return table_id_ + partition_id_;
}
inline bool operator==(const ObFakePartitionKey& other) const
{
return table_id_ == other.table_id_ && partition_id_ == other.partition_id_;
}
};
class ObFakePartitionLocationCache : public ObPartitionLocationCache {
public:
ObFakePartitionLocationCache();
virtual ~ObFakePartitionLocationCache();
// get partition location of a partition
virtual int get(const uint64_t table_id, const int64_t partition_id, ObPartitionLocation& location,
const int64_t expire_renew_time, bool&);
int add_location(ObFakePartitionKey key, ObPartitionLocation location);
private:
common::hash::ObHashMap<ObFakePartitionKey, ObPartitionLocation> partition_loc_map_;
DISALLOW_COPY_AND_ASSIGN(ObFakePartitionLocationCache);
};
} // namespace share
} // namespace oceanbase
#endif /* OCEANBASE_FAKE_PARTITION_LOCATION_CACHE_ */

View File

@ -0,0 +1,513 @@
/**
* Copyright (c) 2021 OceanBase
* OceanBase CE 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.
*/
#include "ob_fake_partition_service.h"
#include "storage/transaction/ob_trans_service.h"
#include "clog/ob_clog_mgr.h"
using namespace oceanbase::common;
using namespace oceanbase::sql;
namespace oceanbase {
namespace sql {
int ObFakeTableScanIterator::get_next_row(common::ObNewRow*& row)
{
int ret = common::OB_SUCCESS;
common::ObNewRow* cur_row = OB_NEW(ObNewRow, ObModIds::TEST);
ObObj* objs = (ObObj*)ob_malloc(sizeof(ObObj) * col_num_, ObModIds::TEST);
if (!cur_row || !objs) {
ret = OB_ALLOCATE_MEMORY_FAILED;
SQL_ENG_LOG(WARN, "no memory");
if (cur_row) {
OB_DELETE(ObNewRow, ObModIds::TEST, cur_row);
}
if (objs) {
ob_free(objs);
}
} else {
for (int64_t i = 0; i < col_num_; ++i) {
new (objs + i) ObObj();
}
cur_row->count_ = col_num_;
cur_row->cells_ = objs;
if (OB_SUCCESS != (ret = row_store_it_.get_next_row(*cur_row))) {
if (OB_ITER_END != ret) {
SQL_ENG_LOG(WARN, "fail to get next row", K(ret));
}
} else {
row = cur_row;
}
}
if (NULL == cur_row->cells_) {
SQL_ENG_LOG(WARN, "cur_row->cells_ is NULL");
}
return ret;
}
} // namespace sql
namespace storage {
ObFakePartitionService::ObFakePartitionService()
{}
ObFakePartitionService::~ObFakePartitionService()
{}
int ObFakePartitionService::table_scan(ObTableScanParam& param, ObNewRowIterator*& result)
{
ObFakeTableScanIterator* iter = OB_NEW(ObFakeTableScanIterator, ObModIds::TEST);
iter->init(scanner_.begin(), col_num_);
result = static_cast<ObNewRowIterator*>(iter);
SQL_ENG_LOG(INFO, "table scan", K(param));
return OB_SUCCESS;
}
int ObFakePartitionService::revert_scan_iter(ObNewRowIterator* iter)
{
OB_DELETE(ObNewRowIterator, ObModIds::TEST, iter);
SQL_ENG_LOG(INFO, "revert_scan_iter");
return OB_SUCCESS;
}
bool ObFakePartitionService::is_empty() const
{
return false;
}
int ObFakePartitionService::init(const blocksstable::ObStorageEnv& env, const common::ObAddr& self_addr,
ObIPartitionComponentFactory* cp_fty, share::schema::ObMultiVersionSchemaService* schema_service,
share::ObIPartitionLocationCache* location_cache, common::ObIRSCb* rs_cb, rpc::frame::ObReqTransport* req_transport)
{
UNUSED(env);
UNUSED(self_addr);
UNUSED(cp_fty);
UNUSED(schema_service);
UNUSED(location_cache);
UNUSED(rs_cb);
UNUSED(req_transport);
return OB_SUCCESS;
}
int ObFakePartitionService::start()
{
return OB_SUCCESS;
}
int ObFakePartitionService::destroy()
{
return OB_SUCCESS;
}
void ObFakePartitionService::set_component_service(ObIPartitionComponentFactory& cp_fty)
{
UNUSED(cp_fty);
}
int ObFakePartitionService::load_partition(const char* buf, const int64_t buf_len, int64_t& pos)
{
UNUSED(buf);
UNUSED(buf_len);
UNUSED(pos);
return OB_SUCCESS;
}
int ObFakePartitionService::replay_base_storage_log(
const int64_t log_seq_num, const int64_t subcmd, const char* buf, const int64_t len, int64_t& pos)
{
UNUSED(log_seq_num);
UNUSED(subcmd);
UNUSED(buf);
UNUSED(len);
UNUSED(pos);
return OB_SUCCESS;
}
int ObFakePartitionService::create_partition(const ObPartitionKey& key, const common::ObVersion data_version,
const int64_t replica_num, const common::ObMemberList& mem_list)
{
UNUSED(key);
UNUSED(data_version);
UNUSED(replica_num);
UNUSED(mem_list);
return OB_SUCCESS;
}
int ObFakePartitionService::online_partition()
{
return OB_SUCCESS;
}
int ObFakePartitionService::offline_partition(const common::ObPartitionKey& leader_key, const common::ObAddr& server)
{
UNUSED(leader_key);
UNUSED(server);
return OB_SUCCESS;
}
int ObFakePartitionService::remove_partition(const common::ObPartitionKey& key)
{
UNUSED(key);
return OB_SUCCESS;
}
int ObFakePartitionService::remove_orphans()
{
return OB_SUCCESS;
}
int ObFakePartitionService::freeze()
{
return OB_SUCCESS;
}
int ObFakePartitionService::on_leader_revoke(const common::ObPartitionKey& partition_key)
{
UNUSED(partition_key);
return OB_SUCCESS;
}
int ObFakePartitionService::on_leader_takeover(const common::ObPartitionKey& partition_key)
{
UNUSED(partition_key);
return OB_SUCCESS;
}
int64_t ObFakePartitionService::get_min_using_file_id() const
{
return OB_SUCCESS;
}
ObBaseStorage* ObFakePartitionService::get_base_storage()
{
return NULL;
}
share::schema::ObMultiVersionSchemaService* ObFakePartitionService::get_schema_service()
{
return NULL;
}
ObIPartitionComponentFactory* ObFakePartitionService::get_cp_fty()
{
return NULL;
}
// ==========================================================================
// transaction service interfaces
int ObFakePartitionService::start_trans(
const uint64_t tenant_id, const transaction::ObStartTransParam& req, transaction::ObTransDesc& trans_desc)
{
UNUSED(tenant_id);
UNUSED(req);
UNUSED(trans_desc);
return OB_SUCCESS;
}
int ObFakePartitionService::end_trans(bool is_rollback, const transaction::ObTransDesc& trans_desc)
{
UNUSED(is_rollback);
UNUSED(trans_desc);
return OB_SUCCESS;
}
int ObFakePartitionService::start_stmt(
const uint64_t tenant_id, transaction::ObTransDesc& trans_desc, const common::ObPartitionArray& participants)
{
UNUSED(tenant_id);
UNUSED(trans_desc);
UNUSED(participants);
return OB_SUCCESS;
}
int ObFakePartitionService::end_stmt(bool is_rollback, const transaction::ObTransDesc& trans_desc)
{
UNUSED(is_rollback);
UNUSED(trans_desc);
return OB_SUCCESS;
}
// ==========================================================================
// partition storage interfaces
#if 0
int ObFakePartitionService::table_scan(ObTableScanParam &param,
common::ObNewRowIterator *&result)
{
UNUSED(param);
UNUSED(result);
return OB_SUCCESS;
}
int ObFakePartitionService::revert_scan_iter(common::ObNewRowIterator *iter)
{
UNUSED(iter);
return OB_SUCCESS;
}
#endif
int ObFakePartitionService::delete_rows(const transaction::ObTransDesc& trans_desc, const int64_t timeout,
const common::ObPartitionKey& pkey, const common::ObIArray<uint64_t>& column_ids,
common::ObNewRowIterator* row_iter, int64_t& affected_rows)
{
UNUSED(trans_desc);
UNUSED(timeout);
UNUSED(pkey);
UNUSED(column_ids);
UNUSED(row_iter);
UNUSED(affected_rows);
return OB_SUCCESS;
}
int ObFakePartitionService::insert_rows(const transaction::ObTransDesc& trans_desc, const int64_t timeout,
const common::ObPartitionKey& pkey, const common::ObIArray<uint64_t>& column_ids,
common::ObNewRowIterator* row_iter, int64_t& affected_rows)
{
UNUSED(trans_desc);
UNUSED(timeout);
UNUSED(pkey);
UNUSED(column_ids);
UNUSED(row_iter);
UNUSED(affected_rows);
return OB_SUCCESS;
}
int ObFakePartitionService::update_rows(const transaction::ObTransDesc& trans_desc, const int64_t timeout,
const common::ObPartitionKey& pkey, const common::ObIArray<uint64_t>& column_ids,
const common::ObIArray<uint64_t>& updated_column_ids, common::ObNewRowIterator* row_iter, int64_t& affected_rows)
{
UNUSED(trans_desc);
UNUSED(timeout);
UNUSED(pkey);
UNUSED(column_ids);
UNUSED(updated_column_ids);
UNUSED(row_iter);
UNUSED(affected_rows);
return OB_SUCCESS;
}
int ObFakePartitionService::lock_rows(const transaction::ObTransDesc& trans_desc, const int64_t timeout,
const common::ObPartitionKey& pkey, common::ObNewRowIterator* row_iter, const ObLockFlag lock_flag,
int64_t& affected_rows)
{
UNUSED(trans_desc);
UNUSED(timeout);
UNUSED(pkey);
UNUSED(row_iter);
UNUSED(lock_flag);
UNUSED(affected_rows);
return OB_SUCCESS;
}
// ==========================================================================
// partition manager interfaces
int ObFakePartitionService::get_all_partitions(common::ObIArray<ObIPartition*>& partition_list)
{
UNUSED(partition_list);
return 0;
}
int ObFakePartitionService::get_partition(const common::ObPartitionKey& pkey, ObIPartitionGroup*& partition)
{
UNUSED(pkey);
UNUSED(partition);
return OB_SUCCESS;
}
int ObFakePartitionService::get_partition_count(int64_t& partition_count) const
{
UNUSED(partition_count);
return OB_SUCCESS;
}
void revert_replay_status(ObReplayStatus* replay_status)
{
UNUSED(replay_status);
}
ObIPartitionIter* ObFakePartitionService::alloc_pg_iter()
{
return NULL;
}
void ObFakePartitionService::revert_pg_iter(ObIPartitionIter* iter)
{
UNUSED(iter);
}
ObPGPartitionIterator* ObFakePartitionService::alloc_pg_partition_iter()
{
return NULL;
}
void ObFakePartitionService::revert_pg_partition_iter(ObPGPartitionIterator* iter)
{
UNUSED(iter);
}
// ==========================================================================
// replay interfaces
int ObFakePartitionService::replay_redo_log(
const common::ObPartitionKey& pkey, const ObStoreCtx& ctx, const int64_t ts, const char* buf, const int64_t size)
{
UNUSED(pkey);
UNUSED(ctx);
UNUSED(ts);
UNUSED(buf);
UNUSED(size);
return OB_SUCCESS;
}
transaction::ObITransService* ObFakePartitionService::get_trans_service()
{
return NULL;
}
clog::ObICLogMgr* ObFakePartitionService::get_clog_mgr()
{
return NULL;
}
// ==========================================================================
// major freeze
int ObFakePartitionService::set_major_freeze_cb(ObIMajorFreezeCb* cb)
{
UNUSED(cb);
return OB_SUCCESS;
}
int ObFakePartitionService::prepare_major_freeze(
const obrpc::ObPartitionList& partitions, const int64_t frozen_version, const int64_t frozen_timestamp)
{
UNUSED(partitions);
UNUSED(frozen_version);
UNUSED(frozen_timestamp);
return OB_SUCCESS;
}
int ObFakePartitionService::commit_major_freeze(
const obrpc::ObPartitionList& partitions, const int64_t frozen_version, const int64_t frozen_timestamp)
{
UNUSED(partitions);
UNUSED(frozen_version);
UNUSED(frozen_timestamp);
return OB_SUCCESS;
}
int ObFakePartitionService::abort_major_freeze(
const obrpc::ObPartitionList& partitions, const int64_t frozen_version, const int64_t frozen_timestamp)
{
UNUSED(partitions);
UNUSED(frozen_version);
UNUSED(frozen_timestamp);
return OB_SUCCESS;
}
int ObFakePartitionService::set_major_freeze_status(
const common::ObPartitionKey& pkey, const int64_t frozen_version, const int64_t major_freeze_status)
{
UNUSED(pkey);
UNUSED(frozen_version);
UNUSED(major_freeze_status);
return OB_SUCCESS;
}
int ObFakePartitionService::get_major_freeze_status(
const common::ObPartitionKey& pkey, int64_t& frozen_version, int64_t& major_freeze_status)
{
UNUSED(pkey);
UNUSED(frozen_version);
UNUSED(major_freeze_status);
return OB_SUCCESS;
}
int ObFakePartitionService::replay(const ObPartitionKey& partition, const char* log, const int64_t size)
{
UNUSED(partition);
UNUSED(log);
UNUSED(size);
return OB_SUCCESS;
}
int ObFakePartitionService::finish_replay(const ObPartitionKey& partition)
{
UNUSED(partition);
return OB_SUCCESS;
}
int ObFakePartitionService::leader_freeze_success(const ObPartitionKey& pkey, const int64_t freeze_cmd)
{
UNUSED(pkey);
UNUSED(freeze_cmd);
return OB_SUCCESS;
}
int ObFakePartitionService::leader_freeze_fail(const ObPartitionKey& pkey, const int64_t freeze_cmd)
{
UNUSED(pkey);
UNUSED(freeze_cmd);
return OB_SUCCESS;
}
int ObFakePartitionService::follower_freeze_success(const ObPartitionKey& pkey, const int64_t freeze_cmd)
{
UNUSED(pkey);
UNUSED(freeze_cmd);
return OB_SUCCESS;
}
int ObFakePartitionService::follower_freeze_fail(const ObPartitionKey& pkey, const int64_t freeze_cmd)
{
UNUSED(pkey);
UNUSED(freeze_cmd);
return OB_SUCCESS;
}
int ObFakePartitionService::submit_freeze_log_success(const int64_t cmd_type, const ObPartitionKey& pkey)
{
UNUSED(cmd_type);
UNUSED(pkey);
return OB_SUCCESS;
}
int ObFakePartitionService::get_role(const common::ObPartitionKey& pkey, common::ObRole& role) const
{
UNUSED(pkey);
UNUSED(role);
return OB_SUCCESS;
}
int ObFakePartitionService::get_leader_curr_member_list(
const common::ObPartitionKey& pkey, common::ObMemberList& member_list) const
{
UNUSED(pkey);
UNUSED(member_list);
return OB_SUCCESS;
}
int ObFakePartitionService::on_member_change_success(const common::ObPartitionKey& partition_key,
const int64_t mc_timestamp, const common::ObMemberList& prev_member_list,
const common::ObMemberList& curr_member_list)
{
UNUSED(partition_key);
UNUSED(mc_timestamp);
UNUSED(prev_member_list);
UNUSED(curr_member_list);
return OB_SUCCESS;
}
int ObFakePartitionService::get_active_memtable_version(const ObPartitionKey& pkey, int64_t& version)
{
UNUSED(pkey);
UNUSED(version);
return OB_SUCCESS;
}
} // namespace storage
} // namespace oceanbase

View File

@ -0,0 +1,195 @@
/**
* Copyright (c) 2021 OceanBase
* OceanBase CE 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 OCEANBASE_UNITTEST_ENGINE_TABLE_OB_FAKE_PARTITION_SERVICE_
#define OCEANBASE_UNITTEST_ENGINE_TABLE_OB_FAKE_PARTITION_SERVICE_
#include "storage/ob_partition_service.h"
#include "share/ob_scanner.h"
#include "common/row/ob_row.h"
namespace oceanbase {
namespace sql {
class ObFakeTableScanIterator : public common::ObNewRowIterator {
public:
ObFakeTableScanIterator()
{}
virtual ~ObFakeTableScanIterator()
{}
virtual int get_next_row(common::ObNewRow*& row);
inline virtual void reset()
{
row_store_it_.reset();
}
inline void init(const common::ObRowStore::Iterator& iter, int64_t col_num)
{
row_store_it_ = iter;
col_num_ = col_num;
}
private:
common::ObRowStore::Iterator row_store_it_;
int64_t col_num_;
private:
DISALLOW_COPY_AND_ASSIGN(ObFakeTableScanIterator);
};
} // namespace sql
namespace storage {
class ObFakePartitionService : public ObPartitionService {
public:
ObFakePartitionService();
virtual ~ObFakePartitionService();
//
virtual int init(const blocksstable::ObStorageEnv& env, const common::ObAddr& self_addr,
ObIPartitionComponentFactory* cp_fty, share::schema::ObMultiVersionSchemaService* schema_service,
share::ObIPartitionLocationCache* location_cache, common::ObIRSCb* rs_cb,
rpc::frame::ObReqTransport* req_transport);
virtual int start();
virtual int destroy();
virtual void set_component_service(ObIPartitionComponentFactory& cp_fty);
//
virtual int load_partition(const char* buf, const int64_t buf_len, int64_t& pos);
virtual int replay_base_storage_log(
const int64_t log_seq_num, const int64_t subcmd, const char* buf, const int64_t len, int64_t& pos);
virtual int create_partition(const common::ObPartitionKey& key, const common::ObVersion data_version,
const int64_t replica_num, const common::ObMemberList& mem_list);
virtual int online_partition();
virtual int offline_partition(const common::ObPartitionKey& leader_key, const common::ObAddr& server);
virtual int remove_partition(const common::ObPartitionKey& key);
virtual int remove_orphans();
virtual int freeze();
virtual int on_leader_revoke(const common::ObPartitionKey& partition_key);
virtual int on_leader_takeover(const common::ObPartitionKey& partition_key);
virtual int64_t get_min_using_file_id() const;
virtual ObBaseStorage* get_base_storage();
virtual share::schema::ObMultiVersionSchemaService* get_schema_service();
virtual ObIPartitionComponentFactory* get_cp_fty();
virtual int on_member_change_success(const common::ObPartitionKey& partition_key, const int64_t mc_timestamp,
const common::ObMemberList& prev_member_list, const common::ObMemberList& curr_member_list);
// ==========================================================================
// transaction service interfaces
virtual int start_trans(
const uint64_t tenant_id, const transaction::ObStartTransParam& req, transaction::ObTransDesc& trans_desc);
virtual int end_trans(bool is_rollback, const transaction::ObTransDesc& trans_desc);
virtual int start_stmt(
const uint64_t tenant_id, transaction::ObTransDesc& trans_desc, const common::ObPartitionArray& participants);
virtual int end_stmt(bool is_rollback, const transaction::ObTransDesc& trans_desc);
// ==========================================================================
// partition storage interfaces
virtual int table_scan(ObTableScanParam& param, common::ObNewRowIterator*& result);
virtual int revert_scan_iter(common::ObNewRowIterator* iter);
virtual int delete_rows(const transaction::ObTransDesc& trans_desc, const int64_t timeout,
const common::ObPartitionKey& pkey, const common::ObIArray<uint64_t>& column_ids,
common::ObNewRowIterator* row_iter, int64_t& affected_rows);
virtual int insert_rows(const transaction::ObTransDesc& trans_desc, const int64_t timeout,
const common::ObPartitionKey& pkey, const common::ObIArray<uint64_t>& column_ids,
common::ObNewRowIterator* row_iter, int64_t& affected_rows);
virtual int update_rows(const transaction::ObTransDesc& trans_desc, const int64_t timeout,
const common::ObPartitionKey& pkey, const common::ObIArray<uint64_t>& column_ids,
const common::ObIArray<uint64_t>& updated_column_ids, common::ObNewRowIterator* row_iter, int64_t& affected_rows);
virtual int lock_rows(const transaction::ObTransDesc& trans_desc, const int64_t timeout,
const common::ObPartitionKey& pkey, common::ObNewRowIterator* row_iter, const ObLockFlag lock_flag,
int64_t& affected_rows);
// ==========================================================================
// partition manager interfaces
virtual int get_all_partitions(common::ObIArray<ObIPartition*>& partition_list);
virtual int get_partition(const common::ObPartitionKey& pkey, ObIPartitionGroup*& partition);
virtual int get_partition_count(int64_t& partition_count) const;
virtual void revert_replay_status(ObReplayStatus* replay_status) const;
virtual ObIPartitionIter* alloc_pg_iter();
virtual void revert_pg_iter(ObIPartitionIter* iter);
virtual ObPGPartitionIterator* alloc_pg_partition_iter();
virtual void revert_pg_partition_iter(ObPGPartitionIterator* iter);
virtual bool is_empty() const;
// ==========================================================================
// replay interfaces
virtual int replay_redo_log(
const common::ObPartitionKey& pkey, const ObStoreCtx& ctx, const int64_t ts, const char* buf, const int64_t size);
virtual transaction::ObITransService* get_trans_service();
virtual clog::ObICLogMgr* get_clog_mgr();
// ==========================================================================
// major freeze
virtual int set_major_freeze_cb(ObIMajorFreezeCb* cb);
virtual int prepare_major_freeze(
const obrpc::ObPartitionList& partitions, const int64_t frozen_version, const int64_t frozen_timestamp);
virtual int commit_major_freeze(
const obrpc::ObPartitionList& partitions, const int64_t frozen_version, const int64_t frozen_timestamp);
virtual int abort_major_freeze(
const obrpc::ObPartitionList& partitions, const int64_t frozen_version, const int64_t frozen_timestamp);
virtual int set_major_freeze_status(
const common::ObPartitionKey& pkey, const int64_t frozen_version, const int64_t major_freeze_status);
virtual int get_major_freeze_status(
const common::ObPartitionKey& pkey, int64_t& frozen_version, int64_t& major_freeze_status);
virtual int replay(const ObPartitionKey& partition, const char* log, const int64_t size);
virtual int finish_replay(const ObPartitionKey& partition);
virtual int leader_freeze_success(const ObPartitionKey& pkey, const int64_t freeze_cmd);
virtual int leader_freeze_fail(const ObPartitionKey& pkey, const int64_t freeze_cmd);
virtual int follower_freeze_success(const ObPartitionKey& pkey, const int64_t freeze_cmd);
virtual int follower_freeze_fail(const ObPartitionKey& pkey, const int64_t freeze_cmd);
virtual int submit_freeze_log_success(const int64_t cmd_type, const ObPartitionKey& pkey);
// ==========================================================================
// misc functions
virtual int get_role(const common::ObPartitionKey& pkey, common::ObRole& role) const;
virtual int get_leader_curr_member_list(const common::ObPartitionKey& pkey, common::ObMemberList& member_list) const;
virtual int get_active_memtable_version(const ObPartitionKey& pkey, int64_t& version);
virtual int activate_tenant(const uint64_t tenant_id)
{
return OB_SUCCESS;
}
virtual int inactivate_tenant(const uint64_t tenant_id)
{
return OB_SUCCESS;
}
inline int add_row(const common::ObNewRow& row)
{
return scanner_.add_row(row);
}
inline void set_col_num(int64_t col_num)
{
col_num_ = col_num;
}
virtual ObBaseStorage* get_base_storage()
{
return NULL;
}
virtual int migrate_replica_batch(const obrpc::ObMigrateReplicaBatchArg& arg)
{
UNUSED(arg);
return OB_ERROR;
}
private:
common::ObScanner scanner_;
int64_t col_num_;
private:
DISALLOW_COPY_AND_ASSIGN(ObFakePartitionService);
};
} // namespace storage
} // namespace oceanbase
#endif /* OCEANBASE_UNITTEST_ENGINE_TABLE_OB_FAKE_PARTITION_SERVICE_ */

View File

@ -0,0 +1,358 @@
/**
* Copyright (c) 2021 OceanBase
* OceanBase CE 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 OCEANBASE_UNITTEST_SQL_ENGINE_TABLE_OB_FAKE_TABLE_H_
#define OCEANBASE_UNITTEST_SQL_ENGINE_TABLE_OB_FAKE_TABLE_H_
#include "share/object/ob_obj_cast.h"
#include "common/row/ob_row_store.h"
#include "lib/time/ob_time_utility.h"
#include "lib/timezone/ob_time_convert.h"
#include "sql/engine/ob_no_children_phy_operator.h"
#include "sql/engine/ob_exec_context.h"
#include "lib/allocator/ob_allocator.h"
using namespace oceanbase::common;
using namespace oceanbase::sql;
#define null static_cast<const char*>(NULL)
#define timestamp(val) convert_to_timestamp(val)
#define COL(val) \
({ \
ObObj* _obj = new ObObj(); \
int err = OB_SUCCESS; \
if (OB_SUCCESS != (err = set_value(*_obj, val))) { \
_OB_LOG(WARN, "fail to set value, err=%d", err); \
} \
_obj; \
})
#define COL_T(type, val) \
({ \
ObObj* _obj = new ObObj(); \
_obj->set_##type(val); \
_obj; \
})
#define ADD_ROW(table_op, args...) \
if (OB_SUCC(ret)) { \
ObObj _cells[OB_MAX_COLUMN_NUMBER]; \
ObNewRow _row; \
_row.cells_ = _cells; \
_row.count_ = table_op.get_column_count(); \
if (OB_SUCCESS != (ret = fill_row(_row, ##args))) { \
_OB_LOG(WARN, "fail to fill row, ret=%d", ret); \
} else if (OB_SUCCESS != (ret = table_op.add_row(_row))) { \
_OB_LOG(WARN, "fail to add row, ret=%d", ret); \
} \
}
#define EXCEPT_RESULT(_ctx, _result_table, op, collation) \
EXCEPT_RESULT_WITH_IDX(_ctx, _result_table, op, 0, 0, collation)
#define EXCEPT_RESULT_SET(_ctx, _result_table, op, start_idx, end_idx, collation) \
EXCEPT_RESULT_WITH_IDX(_ctx, _result_table, op, start_idx, end_idx, collation)
#define EXCEPT_RESULT_WITH_IDX(_ctx, _result_table, op, start_idx, end_idx, collation) \
if (OB_SUCC(ret)) { \
int _ret = OB_SUCCESS; \
const ObNewRow* result_row = NULL; \
while (OB_SUCCESS == (_ret = op.get_next_row(_ctx, result_row))) { \
const ObNewRow* except_row = NULL; \
printf("row=%s\n", to_cstring(*result_row)); \
ASSERT_EQ(OB_SUCCESS, _result_table.get_next_row(_ctx, except_row)); \
printf("except_row=%s\n", to_cstring(*except_row)); \
ASSERT_TRUE(except_row->count_ == result_row->count_); \
for (int64_t i = start_idx; i < end_idx; ++i) { \
printf("index=%ld, cell=%s, respect_cell=%s\n", \
i, \
to_cstring(result_row->cells_[i]), \
to_cstring(except_row->cells_[i])); \
ASSERT_TRUE(0 == except_row->cells_[i].compare(result_row->cells_[i], collation)); \
} \
result_row = NULL; \
} \
ASSERT_EQ(OB_ITER_END, _ret); \
}
namespace oceanbase {
namespace common {
extern void init_global_memory_pool();
} // namespace common
} // namespace oceanbase
typedef struct TimeStampWrap {
int64_t usec_;
} TimeStampWrap;
TimeStampWrap convert_to_timestamp(int64_t usec)
{
TimeStampWrap time_stamp;
time_stamp.usec_ = usec;
return time_stamp;
}
TimeStampWrap convert_to_timestamp(const char* str)
{
TimeStampWrap time_stamp;
ObString date = ObString::make_string(str);
// ObTimeUtility::str_to_usec(date, time_stamp.usec_);
ObTimeConvertCtx cvrt_ctx(NULL, false);
(void)ObTimeConverter::str_to_datetime(date, cvrt_ctx, time_stamp.usec_, NULL);
return time_stamp;
}
int set_value(ObObj& obj, int val)
{
obj.set_int(static_cast<int64_t>(val));
return OB_SUCCESS;
}
int set_value(ObObj& obj, int64_t val)
{
obj.set_int(val);
return OB_SUCCESS;
}
int set_value(ObObj& obj, float val)
{
int ret = OB_SUCCESS;
ObObj obj1;
obj1.set_float(val);
ObCastCtx cast_ctx(global_default_allocator, NULL, 0, CM_NONE, CS_TYPE_INVALID, NULL);
if (OB_FAIL(ObObjCaster::to_type(ObNumberType, cast_ctx, obj1, obj))) {
_OB_LOG(WARN, "fail to cast obj, ret=%d", ret);
}
return ret;
}
int set_value(ObObj& obj, double val)
{
ObObj obj1;
int ret = OB_SUCCESS;
obj1.set_double(val);
ObCastCtx cast_ctx(global_default_allocator, NULL, 0, CM_NONE, CS_TYPE_INVALID, NULL);
if (OB_FAIL(ObObjCaster::to_type(ObNumberType, cast_ctx, obj1, obj))) {
_OB_LOG(WARN, "fail to cast obj, ret=%d", ret);
}
return ret;
}
int set_value(ObObj& obj, const char* val)
{
if (NULL == val) {
obj.set_null();
} else {
obj.set_varchar(val, static_cast<ObString::obstr_size_t>(strlen(val)));
}
return OB_SUCCESS;
}
int set_value(ObObj& obj, const ObObj& val)
{
obj = val;
return OB_SUCCESS;
}
int set_value(ObObj& obj, TimeStampWrap val)
{
obj.set_timestamp(val.usec_);
return OB_SUCCESS;
}
int fill_row(ObNewRow& row, ...)
{
int ret = OB_SUCCESS;
ObObj* ptr = NULL;
va_list ap;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wvarargs"
va_start(ap, row);
for (int64_t i = 0; OB_SUCC(ret) && i < row.count_; ++i) {
if (NULL == (ptr = va_arg(ap, ObObj*))) {
ret = OB_INVALID_ARGUMENT;
_OB_LOG(WARN, "argument is null");
} else {
row.cells_[i] = *ptr;
row.cells_[i].set_collation_type(ObCharset::get_default_collation(ObCharset::get_default_charset()));
delete ptr;
ptr = NULL;
}
}
va_end(ap);
#pragma GCC diagnostic pop
return ret;
}
static ObArenaAllocator alloc_;
class ObFakeTable : public ObNoChildrenPhyOperator {
private:
class ObFakeTableCtx : public ObPhyOperatorCtx {
public:
ObFakeTableCtx(ObExecContext& ctx) : ObPhyOperatorCtx(ctx)
{}
int init(int64_t projector_size)
{
int ret = OB_SUCCESS;
projector_size_ = projector_size;
projector_ = static_cast<int32_t*>(exec_ctx_.get_allocator().alloc(sizeof(int32_t) * projector_size_));
if (NULL == projector_) {
ret = OB_ALLOCATE_MEMORY_FAILED;
}
if (OB_SUCC(ret)) {
for (int64_t i = 0; i < projector_size_; i++) {
projector_[i] = static_cast<int32_t>(i);
}
}
return ret;
}
virtual void destroy()
{
return ObPhyOperatorCtx::destroy_base();
}
int64_t projector_size_;
int32_t* projector_;
private:
ObRowStore::Iterator row_store_it_;
friend class ObFakeTable;
};
public:
ObFakeTable(ObIAllocator& alloc) : ObNoChildrenPhyOperator(alloc), no_rescan_(false)
{}
ObFakeTable() : ObNoChildrenPhyOperator(alloc_), no_rescan_(false)
{}
~ObFakeTable()
{}
void set_no_rescan()
{
no_rescan_ = true;
}
void reset()
{
row_store_.reset();
ObNoChildrenPhyOperator::reset();
}
int add_row(const ObNewRow& row)
{
return row_store_.add_row(row);
}
ObPhyOperatorType get_type() const
{
return PHY_FAKE_TABLE;
}
int inner_open(ObExecContext& ctx) const
{
int ret = OB_SUCCESS;
ObFakeTableCtx* table_ctx = NULL;
if (OB_SUCCESS != (ret = init_op_ctx(ctx))) {
_OB_LOG(WARN, "fail to init operator context, ret=%d", ret);
} else if (NULL == (table_ctx = GET_PHY_OPERATOR_CTX(ObFakeTableCtx, ctx, get_id()))) {
ret = OB_ERR_UNEXPECTED;
_OB_LOG(WARN, "fail to get physical operator context");
} else if (OB_FAIL(table_ctx->init(column_count_))) {
_OB_LOG(WARN, "fail to init project size, ret=%d", ret);
} else {
table_ctx->row_store_it_ = row_store_.begin();
}
return ret;
}
int rescan(ObExecContext& ctx) const
{
if (no_rescan_) {
return OB_SUCCESS;
} else {
ObFakeTableCtx* fake_table_ctx = NULL;
fake_table_ctx = GET_PHY_OPERATOR_CTX(ObFakeTableCtx, ctx, get_id());
OB_ASSERT(fake_table_ctx);
fake_table_ctx->row_store_it_ = row_store_.begin();
return ObNoChildrenPhyOperator::rescan(ctx);
}
}
int inner_close(ObExecContext& ctx) const
{
UNUSED(ctx);
return OB_SUCCESS;
}
private:
/**
* @brief create operator context, only child operator can know it's specific operator type,
* so must be overwrited by child operator,
* @param ctx[in], execute context
* @param op_ctx[out], the pointer of operator context
* @return if success, return OB_SUCCESS, otherwise, return errno
*/
virtual int init_op_ctx(ObExecContext& ctx) const
{
int ret = OB_SUCCESS;
ObPhyOperatorCtx* op_ctx = NULL;
if (OB_SUCCESS != (ret = CREATE_PHY_OPERATOR_CTX(ObFakeTableCtx, ctx, get_id(), get_type(), op_ctx))) {
SQL_EXE_LOG(WARN, "create physical operator context failed", K(ret));
} else if (OB_SUCCESS != (ret = op_ctx->create_cur_row(get_column_count(), projector_, projector_size_))) {
SQL_EXE_LOG(WARN, "create current row failed", K(ret));
}
return ret;
}
/**
* @brief called by get_next_row(), get a row from the child operator or row_store
* @param ctx[in], execute context
* @param row[out], ObSqlRow an obj array and row_size
*/
virtual int inner_get_next_row(ObExecContext& ctx, const ObNewRow*& row) const
{
int ret = OB_SUCCESS;
ObFakeTableCtx* table_ctx = NULL;
if (NULL == (table_ctx = GET_PHY_OPERATOR_CTX(ObFakeTableCtx, ctx, get_id()))) {
ret = OB_ERR_UNEXPECTED;
_OB_LOG(WARN, "fail to get physical operator context");
} else if (OB_SUCCESS != (ret = table_ctx->row_store_it_.get_next_row(table_ctx->get_cur_row()))) {
if (OB_ITER_END != ret) {
_OB_LOG(WARN, "fail to get next row, ret=%d", ret);
}
} else {
row = &table_ctx->get_cur_row();
const_cast<ObNewRow*>(row)->projector_ = table_ctx->projector_;
const_cast<ObNewRow*>(row)->projector_size_ = table_ctx->projector_size_;
}
return ret;
}
virtual int64_t to_string_kv(char* buf, const int64_t buf_len) const
{
int64_t pos = 0;
J_KV(N_ROW_STORE, row_store_);
return pos;
}
DISALLOW_COPY_AND_ASSIGN(ObFakeTable);
private:
ObRowStore row_store_;
bool no_rescan_;
};
#endif /* OCEANBASE_UNITTEST_SQL_ENGINE_TABLE_OB_FAKE_TABLE_H_ */