patch 4.0
This commit is contained in:
54
deps/oblib/src/rpc/frame/ob_req_queue_thread.cpp
vendored
54
deps/oblib/src/rpc/frame/ob_req_queue_thread.cpp
vendored
@ -31,7 +31,11 @@ using namespace oceanbase::rpc::frame;
|
||||
using namespace oceanbase::common;
|
||||
using namespace oceanbase::lib;
|
||||
|
||||
ObReqQueue::ObReqQueue(int queue_capacity) : wait_finish_(false), stop_(true), queue_(), qhandler_(NULL), host_()
|
||||
ObReqQueue::ObReqQueue(int queue_capacity)
|
||||
: wait_finish_(false),
|
||||
queue_(),
|
||||
qhandler_(NULL),
|
||||
host_()
|
||||
{
|
||||
queue_.init(queue_capacity);
|
||||
}
|
||||
@ -41,7 +45,7 @@ ObReqQueue::~ObReqQueue()
|
||||
queue_.destroy();
|
||||
}
|
||||
|
||||
void ObReqQueue::set_qhandler(ObiReqQHandler* qhandler)
|
||||
void ObReqQueue::set_qhandler(ObiReqQHandler *qhandler)
|
||||
{
|
||||
if (OB_ISNULL(qhandler)) {
|
||||
LOG_ERROR("invalid argument", K(qhandler));
|
||||
@ -49,15 +53,12 @@ void ObReqQueue::set_qhandler(ObiReqQHandler* qhandler)
|
||||
qhandler_ = qhandler;
|
||||
}
|
||||
|
||||
bool ObReqQueue::push(ObRequest* req, int max_queue_len, bool block)
|
||||
bool ObReqQueue::push(ObRequest *req, int max_queue_len, bool block)
|
||||
{
|
||||
bool bret = true;
|
||||
if (stop_) {
|
||||
bret = false;
|
||||
LOG_WARN("thread is stopped", K(stop_), K(bret));
|
||||
} else if (max_queue_len > 0 && queue_.size() >= max_queue_len) {
|
||||
if (max_queue_len > 0 && queue_.size() >= max_queue_len) {
|
||||
if (!block) {
|
||||
bret = false;
|
||||
bret = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,12 +72,12 @@ bool ObReqQueue::push(ObRequest* req, int max_queue_len, bool block)
|
||||
return bret;
|
||||
}
|
||||
|
||||
void ObReqQueue::set_host(const ObAddr& host)
|
||||
void ObReqQueue::set_host(const ObAddr &host)
|
||||
{
|
||||
host_ = host;
|
||||
}
|
||||
|
||||
int ObReqQueue::process_task(void* task)
|
||||
int ObReqQueue::process_task(void *task)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_ISNULL(task) || OB_ISNULL(qhandler_)) {
|
||||
@ -85,16 +86,16 @@ int ObReqQueue::process_task(void* task)
|
||||
} else {
|
||||
lib::ContextParam param;
|
||||
param.set_mem_attr(common::OB_SERVER_TENANT_ID, ObModIds::OB_ROOT_CONTEXT, ObCtxIds::WORK_AREA)
|
||||
.set_properties(USE_TL_PAGE_OPTIONAL);
|
||||
CREATE_WITH_TEMP_CONTEXT(param)
|
||||
{
|
||||
ObRequest* req = reinterpret_cast<ObRequest*>(task);
|
||||
.set_properties(USE_TL_PAGE_OPTIONAL);
|
||||
CREATE_WITH_TEMP_CONTEXT(param) {
|
||||
ObRequest *req = reinterpret_cast<ObRequest *>(task);
|
||||
|
||||
// init trace id
|
||||
if (ObRequest::OB_RPC == req->get_type()) {
|
||||
// internal RPC request
|
||||
const obrpc::ObRpcPacket& packet = static_cast<const obrpc::ObRpcPacket&>(req->get_packet());
|
||||
const uint64_t* trace_id = packet.get_trace_id();
|
||||
const obrpc::ObRpcPacket &packet
|
||||
= static_cast<const obrpc::ObRpcPacket&>(req->get_packet());
|
||||
const uint64_t *trace_id = packet.get_trace_id();
|
||||
if (0 == trace_id[0]) {
|
||||
// new trace id
|
||||
ObCurTraceId::init(host_);
|
||||
@ -108,16 +109,15 @@ int ObReqQueue::process_task(void* task)
|
||||
// mysql command request
|
||||
ObCurTraceId::init(host_);
|
||||
}
|
||||
// Set the chid of the source package to the thread
|
||||
//Set the chid of the source package to the thread
|
||||
// int64_t st = ::oceanbase::common::ObTimeUtility::current_time();
|
||||
// PROFILE_LOG(DEBUG, HANDLE_PACKET_START_TIME PCODE, st, packet->get_pcode());
|
||||
|
||||
// setup and init warning buffer
|
||||
// For general SQL processing, the rpc processing function entry uses set_tsi_warning_buffer to set the session
|
||||
// warning buffer The warning buffer is set to the thread part; but for the handler of the task remote execution,
|
||||
// because After the error message reaches the process() function, it needs to be used when serializing
|
||||
// result_code Therefore, the warning buffer member of the session cannot be used. Therefore, one is set by
|
||||
// default.
|
||||
// For general SQL processing, the rpc processing function entry uses set_tsi_warning_buffer to set the session warning buffer
|
||||
// The warning buffer is set to the thread part; but for the handler of the task remote execution, because
|
||||
// After the error message reaches the process() function, it needs to be used when serializing result_code
|
||||
// Therefore, the warning buffer member of the session cannot be used. Therefore, one is set by default.
|
||||
ob_setup_default_tsi_warning_buffer();
|
||||
ob_reset_tsi_warning_buffer();
|
||||
// go!
|
||||
@ -136,7 +136,7 @@ void ObReqQueue::loop()
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int64_t timeout = 300 * 1000;
|
||||
void* task = NULL;
|
||||
void *task = NULL;
|
||||
|
||||
if (OB_ISNULL(qhandler_)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
@ -144,9 +144,8 @@ void ObReqQueue::loop()
|
||||
} else if (OB_FAIL(qhandler_->onThreadCreated(nullptr))) {
|
||||
LOG_ERROR("do thread craeted fail, thread will exit", K(ret));
|
||||
} else {
|
||||
stop_ = false;
|
||||
// The main loop threads process tasks.
|
||||
while (!this_thread::has_set_stop()) {
|
||||
while (!Thread::current().has_set_stop()) {
|
||||
if (OB_FAIL(queue_.pop(task, timeout))) {
|
||||
LOG_DEBUG("queue pop task fail", K(&queue_));
|
||||
} else if (NULL != task) {
|
||||
@ -156,13 +155,10 @@ void ObReqQueue::loop()
|
||||
LOG_ERROR("queue pop successfully but task is NULL");
|
||||
}
|
||||
} // main loop
|
||||
stop_ = true;
|
||||
|
||||
if (!wait_finish_) {
|
||||
LOG_INFO("exiting queue thread without "
|
||||
"wait finish, remain %ld task",
|
||||
"qsize",
|
||||
queue_.size());
|
||||
"wait finish, remain %ld task", "qsize", queue_.size());
|
||||
} else if (0 != queue_.size()) {
|
||||
LOG_INFO("exiting queue thread and wait remain finish");
|
||||
// Process remains if we should wait until all task has been
|
||||
|
||||
Reference in New Issue
Block a user