patch 4.0
This commit is contained in:
117
src/rootserver/ddl_task/ob_drop_primary_key_task.cpp
Normal file
117
src/rootserver/ddl_task/ob_drop_primary_key_task.cpp
Normal file
@ -0,0 +1,117 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#define USING_LOG_PREFIX RS
|
||||
#include "ob_drop_primary_key_task.h"
|
||||
#include "lib/rc/context.h"
|
||||
#include "share/schema/ob_multi_version_schema_service.h"
|
||||
#include "share/ob_ddl_error_message_table_operator.h"
|
||||
#include "share/ob_autoincrement_service.h"
|
||||
#include "share/ob_ddl_checksum.h"
|
||||
#include "rootserver/ddl_task/ob_ddl_scheduler.h"
|
||||
#include "rootserver/ob_root_service.h"
|
||||
#include "rootserver/ddl_task/ob_ddl_redefinition_task.h"
|
||||
#include "storage/tablelock/ob_table_lock_service.h"
|
||||
|
||||
using namespace oceanbase::lib;
|
||||
using namespace oceanbase::common;
|
||||
using namespace oceanbase::share;
|
||||
using namespace oceanbase::share::schema;
|
||||
using namespace oceanbase::rootserver;
|
||||
|
||||
ObDropPrimaryKeyTask::ObDropPrimaryKeyTask()
|
||||
: ObTableRedefinitionTask()
|
||||
{
|
||||
}
|
||||
|
||||
ObDropPrimaryKeyTask::~ObDropPrimaryKeyTask()
|
||||
{
|
||||
}
|
||||
|
||||
int ObDropPrimaryKeyTask::init(const uint64_t tenant_id, const int64_t task_id, const share::ObDDLType &ddl_type,
|
||||
const int64_t data_table_id, const int64_t dest_table_id, const int64_t schema_version, const int64_t parallelism,
|
||||
const obrpc::ObAlterTableArg &alter_table_arg, const int64_t task_status, const int64_t snapshot_version)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(ObTableRedefinitionTask::init(tenant_id, task_id, ddl_type, data_table_id,
|
||||
dest_table_id, schema_version, parallelism,
|
||||
alter_table_arg, task_status, snapshot_version))) {
|
||||
LOG_WARN("fail to init ObDropPrimaryKeyTask", K(ret));
|
||||
} else {
|
||||
task_version_ = OB_DROP_PRIMARY_KEY_TASK_VERSION;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDropPrimaryKeyTask::process()
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_UNLIKELY(!is_inited_)) {
|
||||
ret = OB_NOT_INIT;
|
||||
LOG_WARN("ObDropPrimaryKeyTask has not been inited", K(ret));
|
||||
} else if (OB_FAIL(check_health())) {
|
||||
LOG_WARN("check task health failed", K(ret));
|
||||
} else {
|
||||
switch(task_status_) {
|
||||
case ObDDLTaskStatus::PREPARE:
|
||||
if (OB_FAIL(prepare(ObDDLTaskStatus::WAIT_TRANS_END))) {
|
||||
LOG_WARN("fail to prepare drop primary key task", K(ret));
|
||||
}
|
||||
break;
|
||||
case ObDDLTaskStatus::WAIT_TRANS_END:
|
||||
if (OB_FAIL(wait_trans_end(wait_trans_ctx_, ObDDLTaskStatus::LOCK_TABLE))) {
|
||||
LOG_WARN("fail to wait trans end", K(ret));
|
||||
}
|
||||
break;
|
||||
case ObDDLTaskStatus::LOCK_TABLE:
|
||||
if (OB_FAIL(lock_table(ObDDLTaskStatus::REDEFINITION))) {
|
||||
LOG_WARN("fail to wait trans end", K(ret));
|
||||
}
|
||||
break;
|
||||
case ObDDLTaskStatus::REDEFINITION:
|
||||
if (OB_FAIL(table_redefinition(ObDDLTaskStatus::COPY_TABLE_DEPENDENT_OBJECTS))) {
|
||||
LOG_WARN("fail to do table redefinition", K(ret));
|
||||
}
|
||||
break;
|
||||
case ObDDLTaskStatus::COPY_TABLE_DEPENDENT_OBJECTS:
|
||||
if (OB_FAIL(copy_table_dependent_objects(ObDDLTaskStatus::MODIFY_AUTOINC))) {
|
||||
LOG_WARN("fail to copy table dependent objects", K(ret));
|
||||
}
|
||||
break;
|
||||
case ObDDLTaskStatus::MODIFY_AUTOINC:
|
||||
if (OB_FAIL(modify_autoinc(ObDDLTaskStatus::TAKE_EFFECT))) {
|
||||
LOG_WARN("fail to modify autoinc", K(ret));
|
||||
}
|
||||
break;
|
||||
case ObDDLTaskStatus::TAKE_EFFECT:
|
||||
if (OB_FAIL(take_effect(ObDDLTaskStatus::SUCCESS))) {
|
||||
LOG_WARN("fail to take effect", K(ret));
|
||||
}
|
||||
break;
|
||||
case ObDDLTaskStatus::FAIL:
|
||||
if (OB_FAIL(fail())) {
|
||||
LOG_WARN("fail to do clean up", K(ret));
|
||||
}
|
||||
break;
|
||||
case share::ObDDLTaskStatus::SUCCESS:
|
||||
if (OB_FAIL(success())) {
|
||||
LOG_WARN("fail to success", K(ret));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("unexpected drop primary key task state", K(task_status_));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user