forked from oceanbase/seekdb
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathob_catalog_executor.cpp
More file actions
95 lines (90 loc) · 3.5 KB
/
Copy pathob_catalog_executor.cpp
File metadata and controls
95 lines (90 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* Copyright (c) 2025 OceanBase.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define USING_LOG_PREFIX SQL_ENG
#include "sql/engine/cmd/ob_catalog_executor.h"
#include "sql/resolver/ddl/ob_catalog_stmt.h"
#include "share/schema/ob_schema_struct.h"
#include "share/ob_rpc_struct.h"
#include "share/ob_common_rpc_proxy.h"
#include "sql/engine/ob_exec_context.h"
namespace oceanbase
{
using namespace common;
namespace sql
{
int ObCatalogExecutor::execute(ObExecContext &ctx, ObCatalogStmt &stmt)
{
int ret = OB_SUCCESS;
ObTaskExecutorCtx *task_exec_ctx = NULL;
obrpc::ObCommonRpcProxy *common_rpc_proxy = NULL;
ObString null_string;
uint64_t catalog_id = 0;
uint64_t drop_catalog_id = 0;
ObSQLSessionInfo *session = NULL;
ObObj obj;
stmt.get_ddl_arg().ddl_stmt_str_ = stmt.get_query_ctx()->get_sql_stmt();
if (OB_ISNULL(task_exec_ctx = GET_TASK_EXECUTOR_CTX(ctx))) {
ret = OB_NOT_INIT;
LOG_WARN("get task executor context failed");
} else if (OB_ISNULL(common_rpc_proxy = task_exec_ctx->get_common_rpc())) {
ret = OB_NOT_INIT;
LOG_WARN("get common rpc proxy failed");
} else if (OB_FAIL(common_rpc_proxy->handle_catalog_ddl(stmt.get_ddl_arg()))) {
LOG_WARN("handle catalog ddl error", K(ret));
}
if (OB_SUCC(ret) && OB_DDL_DROP_CATALOG == stmt.get_ddl_arg().ddl_type_) {
drop_catalog_id = stmt.get_ddl_arg().schema_.get_catalog_id();
obj.set_uint64(OB_INTERNAL_CATALOG_ID);
if (OB_ISNULL(session = ctx.get_my_session())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret));
} else if (OB_FAIL(session->get_sys_variable(share::SYS_VAR__CURRENT_DEFAULT_CATALOG, catalog_id))) {
LOG_WARN("failed to get current default catalog id", K(ret));
} else if (catalog_id == drop_catalog_id && OB_INVALID_ID != drop_catalog_id) {
// drop current default catalog, set catalog null
if (OB_FAIL(session->update_sys_variable(share::SYS_VAR__CURRENT_DEFAULT_CATALOG, obj))) {
LOG_WARN("failed to update sys var", K(ret));
} else if (OB_FAIL(ctx.get_my_session()->set_default_database(null_string))) {
LOG_WARN("failed to set default database", K(ret));
} else {
ctx.get_my_session()->set_database_id(OB_INVALID_ID);
}
}
}
return ret;
}
int ObSetCatalogExecutor::execute(ObExecContext &ctx, ObCatalogStmt &stmt)
{
int ret = OB_SUCCESS;
ObSQLSessionInfo *session = NULL;
ObObj obj;
ObString null_string;
if (OB_ISNULL(session = ctx.get_my_session())) {
ret = OB_NOT_INIT;
LOG_WARN("session is NULL", K(ret));
} else if (OB_FALSE_IT(obj.set_uint64(stmt.get_ddl_arg().schema_.get_catalog_id()))) {
// do nothing
} else if (OB_FAIL(session->update_sys_variable(share::SYS_VAR__CURRENT_DEFAULT_CATALOG, obj))) {
LOG_WARN("failed to update sys var", K(ret));
} else if (OB_FAIL(ctx.get_my_session()->set_default_database(null_string))) {
LOG_WARN("failed to set default database", K(ret));
} else {
ctx.get_my_session()->set_database_id(OB_INVALID_ID);
}
return ret;
}
}
}