remove preallocation of memory for sql task

This commit is contained in:
obdev
2023-05-23 02:11:21 +00:00
committed by ob-robot
parent 4bd7e86da7
commit c7d7f34b18
3 changed files with 6 additions and 57 deletions

View File

@ -283,7 +283,7 @@ int ObTenantConfigMgr::add_tenant_config(uint64_t tenant_id)
}
} else {
ObTenantConfig *new_config = nullptr;
new_config = OB_NEW(ObTenantConfig, ObModIds::OMT, tenant_id);
new_config = OB_NEW(ObTenantConfig, "TenantConfig", tenant_id);
if (OB_NOT_NULL(new_config)) {
if(OB_FAIL(new_config->init(this))) {
LOG_WARN("new tenant config init failed", K(ret));

View File

@ -12,7 +12,6 @@
#define USING_LOG_PREFIX SQL
#include "lib/queue/ob_fixed_queue.h"
#include "ob_sql_task.h"
#include "ob_sql.h"
@ -97,63 +96,22 @@ int ObSqlTask::init(const int msg_type, const ObReqTimestamp &req_ts, const char
int ObSqlTaskFactory::init()
{
int ret = OB_SUCCESS;
int64_t fixed_num = 0;
if (!lib::is_mini_mode()) {
fixed_num = NORMAL_FIXED_TASK_NUM;
} else {
fixed_num = MINI_FIXED_TASK_NUM;
}
if (OB_FAIL(fixed_queue_.init(fixed_num))) {
SQL_LOG(WARN, "init fixed queue failed", K(ret), K(fixed_num));
} else {
for (int64_t i = 0; OB_SUCC(ret) && i < fixed_num; i++) {
ObSqlTask *task = alloc_(common::OB_SERVER_TENANT_ID);
if (OB_ISNULL(task)) {
ret = OB_ALLOCATE_MEMORY_FAILED;
} else {
task->set_fixed_alloc();
if (OB_FAIL(fixed_queue_.push(task))) {
free_(task);
task = NULL;
}
}
}
}
return ret;
// do nothing
return OB_SUCCESS;
}
void ObSqlTaskFactory::destroy()
{
ObSqlTask *task = NULL;
while (OB_SUCCESS == fixed_queue_.pop(task)) {
free_(task);
task = NULL;
}
}
ObSqlTask *ObSqlTaskFactory::alloc(const uint64_t tenant_id)
{
int ret = OB_SUCCESS;
ObSqlTask *task = NULL;
if (OB_FAIL(fixed_queue_.pop(task))) {
task = alloc_(tenant_id);
}
return task;
return alloc_(tenant_id);
}
void ObSqlTaskFactory::free(ObSqlTask *task)
{
int ret = OB_SUCCESS;
if (NULL != task) {
if (task->is_fixed_alloc()) {
if (OB_FAIL(fixed_queue_.push(task))) {
SQL_LOG(WARN, "free sql task failed", K(ret));
}
} else {
free_(task);
}
}
}
ObSqlTaskFactory &ObSqlTaskFactory::get_instance()

View File

@ -40,7 +40,7 @@ class ObSqlTask : public observer::ObSrvTask
{
friend class ObSqlTaskFactory;
public:
ObSqlTask() : msg_type_(0), size_(0), is_fixed_alloc_(false), handler_() {}
ObSqlTask() : msg_type_(0), size_(0), handler_() {}
~ObSqlTask() {}
int init(const int msg_type, const ObReqTimestamp &req_ts, const char *buf, const int64_t size, ObSql *sql_engine);
void reset();
@ -52,14 +52,10 @@ public:
TO_STRING_KV(KP(this), K_(msg_type));
public:
static const int64_t MAX_SQL_TASK_SIZE = 16 * 1024 - 128;
private:
void set_fixed_alloc() { is_fixed_alloc_ = true; }
bool is_fixed_alloc() const { return is_fixed_alloc_; }
private:
int msg_type_;
char buf_[MAX_SQL_TASK_SIZE];
int64_t size_;
bool is_fixed_alloc_;
ObSqlTaskHandler handler_;
ObReqTimestamp req_ts_;
};
@ -78,11 +74,6 @@ public:
private:
ObSqlTask *alloc_(const uint64_t tenant_id);
void free_(ObSqlTask *task);
private:
static const int64_t NORMAL_FIXED_TASK_NUM = 4096;
static const int64_t MINI_FIXED_TASK_NUM = 128;
private:
ObFixedQueue<ObSqlTask> fixed_queue_;
};
} // transaction