[PALF] PALF Cluster Test Framework

This commit is contained in:
BinChenn
2023-09-27 08:43:51 +00:00
committed by ob-robot
parent 6d33b0ece6
commit 5cede3d9ea
30 changed files with 5781 additions and 0 deletions

View File

@ -0,0 +1,79 @@
/**
* 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_PALF_CLUSTER_RPC_PROCESSOR_H_
#define OCEANBASE_PALF_CLUSTER_RPC_PROCESSOR_H_
#include "palf_cluster_rpc_req.h"
#include "palf_cluster_request_handler.h"
#include "palf_cluster_rpc_proxy.h"
#include "lib/ob_errno.h"
namespace oceanbase
{
namespace palfcluster
{
#define DEFINE_LOGSERVICE_RPC_PROCESSOR(CLASS, PROXY, REQTYPE, PCODE) \
class CLASS : public obrpc::ObRpcProcessor<PROXY::ObRpc<PCODE>> \
{ \
public: \
CLASS() : filter_(NULL) {} \
virtual ~CLASS() { filter_ = NULL; } \
int process() \
{ \
int ret = OB_SUCCESS; \
const REQTYPE &req = arg_; \
const common::ObAddr server = req.src_; \
const uint64_t tenant_id = rpc_pkt_->get_tenant_id(); \
LogRequestHandler handler; \
handler.set_log_service(log_service_); \
if (OB_UNLIKELY(NULL != filter_ && true == (*filter_)(server))) { \
} else if (OB_FAIL(handler.handle_request(req))) { \
CLOG_LOG(WARN, "Processor handle_request failed", K(ret), K(req)); \
} else { \
CLOG_LOG(INFO, "Processor handle_request success", K(ret), K(req)); \
} \
return ret; \
} \
void set_filter(void *filter) \
{ \
filter_ = reinterpret_cast<ObFunction<bool(const ObAddr &src)> *>(filter); \
} \
void set_log_service(void *log_service) \
{ \
log_service_ = reinterpret_cast<LogService *>(log_service); \
} \
private: \
ObFunction<bool(const ObAddr &src)> *filter_; \
palfcluster::LogService *log_service_; \
}
DEFINE_LOGSERVICE_RPC_PROCESSOR(LogCreateReplicaCmdP,
obrpc::PalfClusterRpcProxy,
palfcluster::LogCreateReplicaCmd,
obrpc::OB_LOG_CREATE_REPLICA_CMD);
DEFINE_LOGSERVICE_RPC_PROCESSOR(LogSubmitLogP,
obrpc::PalfClusterRpcProxy,
palfcluster::SubmitLogCmd,
obrpc::OB_LOG_SUBMIT_LOG_CMD);
DEFINE_LOGSERVICE_RPC_PROCESSOR(LogSubmitLogRespP,
obrpc::PalfClusterRpcProxy,
SubmitLogCmdResp,
obrpc::OB_LOG_SUBMIT_LOG_CMD_RESP);
} // end namespace palfcluster
} // end namespace oceanbase
#endif

View File

@ -0,0 +1,123 @@
/**
* 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 "palf_cluster_request_handler.h"
#include "palf_cluster_rpc_req.h"
#include "palf_cluster_rpc_proxy.h"
#include "logservice/ob_log_service.h"
#include "logservice/palf/log_define.h"
namespace oceanbase
{
namespace palfcluster
{
LogRequestHandler::LogRequestHandler()
: log_service_(NULL)
{
}
LogRequestHandler::~LogRequestHandler()
{
}
int LogRequestHandler::get_self_addr_(common::ObAddr &self) const
{
int ret = OB_SUCCESS;
const common::ObAddr self_addr = GCTX.self_addr();
if (false == self_addr.is_valid()) {
ret = OB_ERR_UNEXPECTED;
} else {
self = self_addr;
}
return ret;
}
template <>
int LogRequestHandler::handle_request<LogCreateReplicaCmd>(
const LogCreateReplicaCmd &req)
{
int ret = common::OB_SUCCESS;
const int64_t palf_id = req.ls_id_;
const common::ObAddr &server = req.src_;
share::ObLSID ls_id(palf_id);
if (OB_ISNULL(log_service_)) {
ret = OB_ERR_UNEXPECTED;
CLOG_LOG(ERROR, "get_log_service failed", K(ret));
} else if (false == req.is_valid()) {
ret = OB_INVALID_ARGUMENT;
CLOG_LOG(ERROR, "Invalid argument!!!", K(ret), K(req));
} else if (OB_FAIL(log_service_->create_palf_replica(req.ls_id_, req.member_list_, req.replica_num_, req.leader_idx_))) {
CLOG_LOG(ERROR, "create_palf_replica failed", K(ret));
}
CLOG_LOG(ERROR, "create_palf_replica finish", K(ret), K(req));
return ret;
}
template <>
int LogRequestHandler::handle_request<SubmitLogCmd>(
const SubmitLogCmd &req)
{
int ret = common::OB_SUCCESS;
if (false == req.is_valid()) {
ret = OB_INVALID_ARGUMENT;
CLOG_LOG(ERROR, "Invalid argument!!!", K(ret), K(req));
} else {
const int64_t palf_id = req.ls_id_;
share::ObLSID ls_id(palf_id);
const common::ObAddr &src = req.src_;
const int64_t client_id = req.client_id_;
palfcluster::LogClientMap *log_clients = nullptr;
palfcluster::ObLogClient *log_client = nullptr;
if (OB_ISNULL(log_service_)) {
ret = OB_ERR_UNEXPECTED;
CLOG_LOG(ERROR, "get_log_service failed", K(ret));
} else if (FALSE_IT(log_clients = log_service_->get_log_client_map())) {
} else if (OB_FAIL(log_clients->get(ls_id, log_client))) {
CLOG_LOG(ERROR, "get_log_client failed", K(ret), K(palf_id));
} else if (OB_FAIL(log_client->submit_log(src, client_id, req.log_buf_))) {
CLOG_LOG(ERROR, "submit_log failed", K(ret));
}
ret = OB_SUCCESS;
}
return ret;
}
template <>
int LogRequestHandler::handle_request<SubmitLogCmdResp>(
const SubmitLogCmdResp &req)
{
int ret = common::OB_SUCCESS;
if (false == req.is_valid()) {
ret = OB_INVALID_ARGUMENT;
CLOG_LOG(ERROR, "Invalid argument!!!", K(ret), K(req));
} else {
const int64_t palf_id = req.ls_id_;
share::ObLSID ls_id(palf_id);
const common::ObAddr &server = req.src_;
const int64_t client_id = req.client_id_;
palfcluster::LogClientMap *log_clients = nullptr;
palfcluster::ObLogClient *log_client = nullptr;
if (OB_ISNULL(log_service_)) {
ret = OB_ERR_UNEXPECTED;
CLOG_LOG(ERROR, "get_log_service failed", K(ret));
} else {
log_service_->clients_[client_id].has_returned();
}
ret = OB_SUCCESS;
}
return ret;
}
} // end namespace logservice
} // end namespace oceanbase

View File

@ -0,0 +1,74 @@
/**
* 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_PALF_CLUSTER_LOG_REQUEST_HANDLER_
#define OCEANBASE_PALF_CLUSTER_LOG_REQUEST_HANDLER_
#include "lib/ob_errno.h" // OB_SUCCESS...
#include "logservice/ob_reporter_adapter.h" // ObLogReporterAdapter
#include "logservice/palf_handle_guard.h" // palf::PalfHandleGuard
#include "palf_cluster_rpc_req.h" // Req...
#include "mittest/palf_cluster/logservice/log_service.h"
namespace oceanbase
{
namespace palf
{
class PalfEnv;
}
namespace obrpc
{
class PalfClusterRpcProxy;
}
namespace palfcluster
{
class ObLogHandler;
class ObLogReplayService;
class LogRequestHandler
{
public:
LogRequestHandler();
~LogRequestHandler();
template <typename ReqType, typename RespType>
int handle_sync_request(const ReqType &req, RespType &resp);
template <typename ReqType>
int handle_request(const ReqType &req);
void set_log_service(palfcluster::LogService *log_service) { log_service_ = log_service; }
private:
int get_self_addr_(common::ObAddr &self) const;
int get_rpc_proxy_(obrpc::PalfClusterRpcProxy *&rpc_proxy) const;
palfcluster::LogService *log_service_;
};
class ConfigChangeCmdHandler{
public:
explicit ConfigChangeCmdHandler(palf::PalfHandle *palf_handle)
{
if (NULL != palf_handle) {
palf_handle_ = palf_handle;
}
}
~ConfigChangeCmdHandler()
{
palf_handle_ = NULL;
}
private:
palf::PalfHandle *palf_handle_;
};
} // end namespace logservice
} // end namespace oceanbase
#endif

View File

@ -0,0 +1,80 @@
/**
* 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_PALF_CLUSTER_RPC_PROCESSOR_H_
#define OCEANBASE_PALF_CLUSTER_RPC_PROCESSOR_H_
#include "palf_cluster_rpc_req.h"
#include "palf_cluster_request_handler.h"
#include "palf_cluster_rpc_proxy.h"
#include "lib/ob_errno.h"
namespace oceanbase
{
namespace palfcluster
{
class LogService;
#define DEFINE_LOGSERVICE_RPC_PROCESSOR(CLASS, PROXY, REQTYPE, PCODE) \
class CLASS : public obrpc::ObRpcProcessor<PROXY::ObRpc<PCODE>> \
{ \
public: \
CLASS() : filter_(NULL) {} \
virtual ~CLASS() { filter_ = NULL; } \
int process() \
{ \
int ret = OB_SUCCESS; \
const REQTYPE &req = arg_; \
const common::ObAddr server = req.src_; \
const uint64_t tenant_id = rpc_pkt_->get_tenant_id(); \
LogRequestHandler handler; \
handler.set_log_service(log_service_); \
if (OB_UNLIKELY(NULL != filter_ && true == (*filter_)(server))) { \
} else if (OB_FAIL(handler.handle_request(req))) { \
CLOG_LOG(WARN, "Processor handle_request failed", K(ret), K(req)); \
} else { \
CLOG_LOG(INFO, "Processor handle_request success", K(ret), K(req)); \
} \
return ret; \
} \
void set_filter(void *filter) \
{ \
filter_ = reinterpret_cast<ObFunction<bool(const ObAddr &src)> *>(filter); \
} \
void set_log_service(void *log_service) \
{ \
log_service_ = reinterpret_cast<palfcluster::LogService *>(log_service); \
} \
private: \
ObFunction<bool(const ObAddr &src)> *filter_; \
palfcluster::LogService *log_service_; \
}
DEFINE_LOGSERVICE_RPC_PROCESSOR(LogCreateReplicaCmdP,
obrpc::PalfClusterRpcProxy,
palfcluster::LogCreateReplicaCmd,
obrpc::OB_LOG_CREATE_REPLICA_CMD);
DEFINE_LOGSERVICE_RPC_PROCESSOR(LogSubmitLogP,
obrpc::PalfClusterRpcProxy,
palfcluster::SubmitLogCmd,
obrpc::OB_LOG_SUBMIT_LOG_CMD);
DEFINE_LOGSERVICE_RPC_PROCESSOR(LogSubmitLogRespP,
obrpc::PalfClusterRpcProxy,
SubmitLogCmdResp,
obrpc::OB_LOG_SUBMIT_LOG_CMD_RESP);
} // end namespace palfcluster
} // end namespace oceanbase
#endif

View File

@ -0,0 +1,74 @@
/**
* 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_PALF_CLUSTER_LOG_RPC_PROXY_
#define OCEANBASE_PALF_CLUSTER_LOG_RPC_PROXY_
#include "palf_cluster_rpc_req.h"
#include "rpc/obrpc/ob_rpc_proxy.h" // ObRpcProxy
namespace oceanbase
{
namespace obrpc
{
class PalfClusterRpcProxy : public obrpc::ObRpcProxy
{
public:
DEFINE_TO(PalfClusterRpcProxy);
RPC_AP(PR3 send_submit_log_cmd, OB_LOG_SUBMIT_LOG_CMD,
(palfcluster::SubmitLogCmd));
RPC_AP(PR3 send_submit_log_resp, OB_LOG_SUBMIT_LOG_CMD_RESP,
(palfcluster::SubmitLogCmdResp));
RPC_AP(PR3 send_create_replica_cmd, OB_LOG_CREATE_REPLICA_CMD,
(palfcluster::LogCreateReplicaCmd));
};
template <obrpc::ObRpcPacketCode pcode>
class ObLogRpcCB: public PalfClusterRpcProxy::AsyncCB<pcode>
{
public:
ObLogRpcCB() {}
~ObLogRpcCB() {}
void set_args(const typename PalfClusterRpcProxy::AsyncCB<pcode>::Request &args) {
UNUSED(args);
}
rpc::frame::ObReqTransport::AsyncCB *clone(const rpc::frame::SPAlloc &alloc) const {
void *buf = alloc(sizeof (*this));
ObLogRpcCB<pcode> *newcb = NULL;
if (NULL != buf) {
newcb = new (buf) ObLogRpcCB<pcode>();
}
return newcb;
}
int process() {
const common::ObAddr &dst = PalfClusterRpcProxy::AsyncCB<pcode>::dst_;
obrpc::ObRpcResultCode &rcode = PalfClusterRpcProxy::AsyncCB<pcode>::rcode_;
int ret = rcode.rcode_;
if (common::OB_SUCCESS != rcode.rcode_) {
PALF_LOG(WARN, "there is an rpc error in logservice", K(rcode), K(dst), K(pcode));
} else {
// do nothing
}
return common::OB_SUCCESS;
}
void on_timeout() {
const common::ObAddr &dst = PalfClusterRpcProxy::AsyncCB<pcode>::dst_;
//PALF_LOG(WARN, "logservice rpc timeout", K(dst));
}
};
} // end namespace obrpc
} // end namespace oceanbase
#endif

View File

@ -0,0 +1,134 @@
/**
* 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 "palf_cluster_rpc_req.h"
#include "logservice/palf/log_define.h"
namespace oceanbase
{
using namespace share;
namespace palfcluster
{
// ============= LogCreateReplicaCmd start =============
LogCreateReplicaCmd::LogCreateReplicaCmd()
: src_(),
ls_id_(-1),
member_list_(),
replica_num_(-1),
leader_idx_(-1) { }
LogCreateReplicaCmd::LogCreateReplicaCmd(
const common::ObAddr &src,
const int64_t ls_id,
const common::ObMemberList &member_list,
const int64_t replica_num,
const int64_t leader_idx)
: src_(src),
ls_id_(ls_id),
member_list_(member_list),
replica_num_(replica_num),
leader_idx_(leader_idx) { }
bool LogCreateReplicaCmd::is_valid() const
{
return src_.is_valid() &&
-1 != ls_id_ &&
member_list_.is_valid() &&
replica_num_ > 0 &&
replica_num_ <= common::OB_MAX_MEMBER_NUMBER;
}
void LogCreateReplicaCmd::reset()
{
src_.reset();
ls_id_ = -1;
member_list_.reset();
replica_num_ = -1;
leader_idx_ = -1;
}
OB_SERIALIZE_MEMBER(LogCreateReplicaCmd, src_, ls_id_,
member_list_, replica_num_, leader_idx_);
// ============= LogCreateReplicaCmd end =============
// ============= SubmitLogCmd start =============
SubmitLogCmd::SubmitLogCmd()
: src_(),
ls_id_(-1),
client_id_(-1),
log_buf_()
{ }
SubmitLogCmd::SubmitLogCmd(
const common::ObAddr &src,
const int64_t ls_id,
const int64_t client_id,
const palf::LogWriteBuf &log_buf)
: src_(src),
ls_id_(ls_id),
client_id_(client_id),
log_buf_(log_buf)
{ }
bool SubmitLogCmd::is_valid() const
{
return src_.is_valid() &&
-1 != ls_id_ &&
log_buf_.is_valid();
}
void SubmitLogCmd::reset()
{
src_.reset();
ls_id_ = -1;
client_id_ = -1;
log_buf_.reset();
}
OB_SERIALIZE_MEMBER(SubmitLogCmd, src_, ls_id_, client_id_, log_buf_);
// ============= SubmitLogCmd end =============
// ============= SubmitLogCmdResp start =============
SubmitLogCmdResp::SubmitLogCmdResp()
: src_(),
ls_id_(-1),
client_id_(-1)
{ }
SubmitLogCmdResp::SubmitLogCmdResp(
const common::ObAddr &src,
const int64_t ls_id,
const int64_t client_id)
: src_(src),
ls_id_(ls_id),
client_id_(client_id)
{ }
bool SubmitLogCmdResp::is_valid() const
{
return src_.is_valid() &&
-1 != ls_id_;
}
void SubmitLogCmdResp::reset()
{
src_.reset();
ls_id_ = -1;
client_id_ = -1;
}
OB_SERIALIZE_MEMBER(SubmitLogCmdResp, src_, ls_id_, client_id_);
// ============= SubmitLogCmdResp end =============
} // end namespace logservice
}// end namespace oceanbase

View File

@ -0,0 +1,94 @@
/**
* 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_PALF_CLUSTER_RPC_REQ_H_
#define OCEANBASE_PALF_CLUSTER_RPC_REQ_H_
#include "lib/utility/ob_unify_serialize.h" // OB_UNIS_VERSION
#include "lib/utility/ob_print_utils.h" // TO_STRING_KV
#include "common/ob_member_list.h" // ObMemberList
#include "logservice/palf/palf_handle_impl.h" // PalfStat
#include "share/scn.h"
#include "logservice/palf/log_writer_utils.h" // LogWriteBuf
namespace oceanbase
{
namespace palfcluster
{
struct LogCreateReplicaCmd {
OB_UNIS_VERSION(1);
public:
LogCreateReplicaCmd();
LogCreateReplicaCmd(const common::ObAddr &src,
const int64_t ls_id,
const common::ObMemberList &member_list,
const int64_t replica_num,
const int64_t leader_idx);
~LogCreateReplicaCmd()
{
reset();
}
bool is_valid() const;
void reset();
TO_STRING_KV(K_(src), K_(ls_id), K_(member_list), K_(replica_num), K_(leader_idx));
common::ObAddr src_;
int64_t ls_id_;
common::ObMemberList member_list_;
int64_t replica_num_;
int64_t leader_idx_;
};
struct SubmitLogCmd {
OB_UNIS_VERSION(1);
public:
SubmitLogCmd();
SubmitLogCmd(const common::ObAddr &src,
const int64_t ls_id,
const int64_t client_id,
const palf::LogWriteBuf &log_buf_);
~SubmitLogCmd()
{
reset();
}
bool is_valid() const;
void reset();
TO_STRING_KV(K_(src), K_(ls_id));
common::ObAddr src_;
int64_t ls_id_;
int64_t client_id_;
palf::LogWriteBuf log_buf_;
};
struct SubmitLogCmdResp {
OB_UNIS_VERSION(1);
public:
SubmitLogCmdResp();
SubmitLogCmdResp(const common::ObAddr &src,
const int64_t ls_id,
const int64_t client_id);
~SubmitLogCmdResp()
{
reset();
}
bool is_valid() const;
void reset();
TO_STRING_KV(K_(src), K_(ls_id));
common::ObAddr src_;
int64_t ls_id_;
int64_t client_id_;
};
} // end namespace palfcluster
}// end namespace oceanbase
#endif