patch 4.0

This commit is contained in:
wangzelin.wzl
2022-10-24 10:34:53 +08:00
parent 4ad6e00ec3
commit 93a1074b0c
10533 changed files with 2588271 additions and 2299373 deletions

View File

@ -11,24 +11,29 @@
*/
#include <sys/prctl.h>
#include "lib/thread/ob_async_task_queue.h"
#include "ob_ddl_task_executor.h"
#include "share/ob_thread_mgr.h"
#define USING_LOG_PREFIX STORAGE
using namespace oceanbase::share;
using namespace oceanbase::common;
ObDDLTaskQueue::ObDDLTaskQueue() : task_list_(), task_set_(), lock_(), is_inited_(false), allocator_()
ObDDLTaskQueue::ObDDLTaskQueue()
: task_list_(), task_set_(), lock_(), is_inited_(false), allocator_()
{
allocator_.set_label(common::ObModIds::OB_BUILD_INDEX_SCHEDULER);
}
ObDDLTaskQueue::~ObDDLTaskQueue()
{}
{
}
void ObDDLTaskQueue::destroy()
{
int ret = OB_SUCCESS;
ObIDDLTask* task = NULL;
ObIDDLTask *task = NULL;
common::ObSpinLockGuard guard(lock_);
while (OB_SUCC(ret) && task_list_.get_size() > 0) {
if (OB_ISNULL(task = task_list_.remove_first())) {
@ -44,14 +49,16 @@ void ObDDLTaskQueue::destroy()
is_inited_ = false;
}
int ObDDLTaskQueue::init(
const int64_t bucket_num, const int64_t total_mem_limit, const int64_t hold_mem_limit, const int64_t page_size)
int ObDDLTaskQueue::init(const int64_t bucket_num, const int64_t total_mem_limit,
const int64_t hold_mem_limit, const int64_t page_size)
{
int ret = OB_SUCCESS;
common::ObSpinLockGuard guard(lock_);
if (bucket_num <= 0 || total_mem_limit <= 0 || hold_mem_limit <= 0 || page_size <= 0) {
if (bucket_num <= 0 || total_mem_limit <= 0
|| hold_mem_limit <= 0 || page_size <= 0) {
ret = common::OB_INVALID_ARGUMENT;
STORAGE_LOG(WARN, "invalid argument", K(ret), K(bucket_num), K(total_mem_limit), K(hold_mem_limit), K(page_size));
STORAGE_LOG(WARN, "invalid argument", K(ret), K(bucket_num), K(total_mem_limit),
K(hold_mem_limit), K(page_size));
} else if (OB_FAIL(task_set_.create(bucket_num))) {
STORAGE_LOG(WARN, "fail to create task set", K(ret), K(bucket_num));
} else if (OB_FAIL(allocator_.init(total_mem_limit, hold_mem_limit, page_size))) {
@ -62,18 +69,18 @@ int ObDDLTaskQueue::init(
return ret;
}
int ObDDLTaskQueue::push_task(const ObIDDLTask& task)
int ObDDLTaskQueue::push_task(const ObIDDLTask &task)
{
int ret = OB_SUCCESS;
ObIDDLTask* task_copy = NULL;
char* buf = NULL;
ObIDDLTask *task_copy = NULL;
char *buf = NULL;
bool task_add_to_list = false;
common::ObSpinLockGuard guard(lock_);
const int64_t deep_copy_size = task.get_deep_copy_size();
if (OB_UNLIKELY(!is_inited_)) {
ret = common::OB_NOT_INIT;
STORAGE_LOG(WARN, "ObBuildIndexTaskQueue has not been inited", K(ret));
} else if (OB_ISNULL(buf = static_cast<char*>(allocator_.alloc(deep_copy_size)))) {
} else if (OB_ISNULL(buf = static_cast<char *>(allocator_.alloc(deep_copy_size)))) {
ret = common::OB_ALLOCATE_MEMORY_FAILED;
STORAGE_LOG(WARN, "fail to allocate memory for ObBuildIndexTask", K(ret));
} else if (OB_ISNULL(task_copy = task.deep_copy(buf, deep_copy_size))) {
@ -83,7 +90,7 @@ int ObDDLTaskQueue::push_task(const ObIDDLTask& task)
ret = common::OB_ERR_UNEXPECTED;
STORAGE_LOG(ERROR, "unexpected error, add build index task failed", K(ret));
} else {
int is_overwrite = 0; // do not overwrite
int is_overwrite = 0; // do not overwrite
task_add_to_list = true;
if (OB_FAIL(task_set_.set_refactored(task_copy, is_overwrite))) {
if (common::OB_HASH_EXIST == ret) {
@ -110,7 +117,7 @@ int ObDDLTaskQueue::push_task(const ObIDDLTask& task)
return ret;
}
int ObDDLTaskQueue::get_next_task(ObIDDLTask*& task)
int ObDDLTaskQueue::get_next_task(ObIDDLTask *&task)
{
int ret = OB_SUCCESS;
common::ObSpinLockGuard guard(lock_);
@ -126,7 +133,7 @@ int ObDDLTaskQueue::get_next_task(ObIDDLTask*& task)
return ret;
}
int ObDDLTaskQueue::remove_task(ObIDDLTask* task)
int ObDDLTaskQueue::remove_task(ObIDDLTask *task)
{
int ret = OB_SUCCESS;
common::ObSpinLockGuard guard(lock_);
@ -148,7 +155,7 @@ int ObDDLTaskQueue::remove_task(ObIDDLTask* task)
return ret;
}
int ObDDLTaskQueue::add_task_to_last(ObIDDLTask* task)
int ObDDLTaskQueue::add_task_to_last(ObIDDLTask *task)
{
int ret = OB_SUCCESS;
common::ObSpinLockGuard guard(lock_);
@ -165,11 +172,14 @@ int ObDDLTaskQueue::add_task_to_last(ObIDDLTask* task)
return ret;
}
ObDDLTaskExecutor::ObDDLTaskExecutor() : is_inited_(false), task_queue_(), cond_(), tg_id_(-1)
{}
ObDDLTaskExecutor::ObDDLTaskExecutor()
: is_inited_(false), task_queue_(), cond_(), tg_id_(-1)
{
}
ObDDLTaskExecutor::~ObDDLTaskExecutor()
{}
{
}
void ObDDLTaskExecutor::stop()
{
@ -224,8 +234,8 @@ void ObDDLTaskExecutor::run1()
{
int ret = OB_SUCCESS;
int64_t executed_task_count = 0;
ObIDDLTask* task = NULL;
ObIDDLTask* first_retry_task = NULL;
ObIDDLTask *task = NULL;
ObIDDLTask *first_retry_task = NULL;
(void)prctl(PR_SET_NAME, "DDLTaskExecutor", 0, 0, 0);
while (!has_set_stop()) {
while (!has_set_stop() && executed_task_count < BATCH_EXECUTE_COUNT) {
@ -266,3 +276,62 @@ void ObDDLTaskExecutor::run1()
first_retry_task = NULL;
}
}
ObDDLReplicaBuilder::ObDDLReplicaBuilder()
: is_thread_started_(false),
is_stopped_(false)
{
}
ObDDLReplicaBuilder::~ObDDLReplicaBuilder()
{
destroy();
}
int ObDDLReplicaBuilder::start()
{
int ret = OB_SUCCESS;
if (is_thread_started_) {
// do nothing
} else if (OB_FAIL(TG_START(lib::TGDefIDs::DdlBuild))) {
LOG_WARN("index build thread start failed", KR(ret));
} else {
is_thread_started_ = true;
}
if (OB_SUCC(ret)) {
is_stopped_ = false;
}
return ret;
}
void ObDDLReplicaBuilder::stop()
{
is_stopped_ = true;
}
void ObDDLReplicaBuilder::destroy()
{
is_stopped_ = true;
if (is_thread_started_) {
TG_STOP(lib::TGDefIDs::DdlBuild);
TG_WAIT(lib::TGDefIDs::DdlBuild);
TG_DESTROY(lib::TGDefIDs::DdlBuild);
is_thread_started_ = false;
}
}
int ObDDLReplicaBuilder::push_task(ObAsyncTask &task)
{
int ret = OB_SUCCESS;
if (OB_UNLIKELY(!is_thread_started_)) {
ret = OB_ERR_SYS;
LOG_WARN("ddl builder thread not started", K(ret), K(is_thread_started_));
} else if (is_stopped_) {
ret = OB_STATE_NOT_MATCH;
LOG_WARN("ddl builder has stopped", K(ret), K(is_stopped_));
} else if (OB_FAIL(TG_PUSH_TASK(lib::TGDefIDs::DdlBuild, task))) {
LOG_WARN("add task to queue failed", K(ret));
}
return ret;
}