[FEAT MERGE] 4.2.4 sql execution feature cp 4.3.4

Co-authored-by: qingsuijiu <642782632@qq.com>
Co-authored-by: jingtaoye35 <1255153887@qq.com>
Co-authored-by: cqliang1995 <cq.liang@outlook.com>
This commit is contained in:
obdev 2024-09-25 07:51:12 +00:00 committed by ob-robot
parent e5dbdc61a4
commit beb9f30a20
177 changed files with 5068 additions and 2651 deletions

View File

@ -115,15 +115,12 @@ public:
}
// sql execute interface
virtual int execute_read(const uint64_t tenant_id, const char *sql,
virtual int execute_read(const uint64_t tenant_id, const ObString &sql,
ObISQLClient::ReadResult &res, bool is_user_sql = false,
const common::ObAddr *sql_exec_addr = nullptr) = 0;
virtual int execute_read(const int64_t cluster_id, const uint64_t tenant_id, const ObString &sql,
ObISQLClient::ReadResult &res, bool is_user_sql = false,
const common::ObAddr *sql_exec_addr = nullptr) = 0;
virtual int execute_write(const uint64_t tenant_id, const char *sql,
int64_t &affected_rows, bool is_user_sql = false,
const common::ObAddr *sql_exec_addr = nullptr) = 0;
virtual int execute_write(const uint64_t tenant_id, const ObString &sql,
int64_t &affected_rows, bool is_user_sql = false,
const common::ObAddr *sql_exec_addr = nullptr) = 0;
@ -137,7 +134,7 @@ public:
const ObTimeZoneInfo *tz_info,
ObObj *result,
bool is_sql) = 0;
virtual int prepare(const char *sql, int64_t param_count, ObIAllocator *allocator = NULL) {
virtual int prepare(const ObString &sql, int64_t param_count, ObIAllocator *allocator = NULL) {
UNUSED(sql);
return OB_NOT_SUPPORTED;
}

View File

@ -128,7 +128,7 @@ public:
virtual DblinkDriverProto get_pool_link_driver_proto() = 0;
// for dblink
virtual int create_dblink_pool(const dblink_param_ctx &param_ctx, const ObAddr &server,
virtual int create_dblink_pool(const dblink_param_ctx &param_ctx, const ObString &host_name, int32_t port,
const ObString &db_tenant, const ObString &db_user,
const ObString &db_pass, const ObString &db_name,
const common::ObString &conn_str,

View File

@ -93,7 +93,7 @@ void ObMySQLConnection::reset()
set_last_error(OB_SUCCESS);
}
int ObMySQLConnection::prepare_statement(ObMySQLPreparedStatement &stmt, const char *sql)
int ObMySQLConnection::prepare_statement(ObMySQLPreparedStatement &stmt, const ObString &sql)
{
int ret = OB_SUCCESS;
if (OB_FAIL(stmt.init(*this, sql, 0))) {
@ -103,23 +103,18 @@ int ObMySQLConnection::prepare_statement(ObMySQLPreparedStatement &stmt, const c
}
int ObMySQLConnection::connect(const char *user, const char *pass, const char *db,
oceanbase::common::ObAddr &addr, int64_t timeout,
const char *host_name, int32_t port, int64_t timeout,
bool read_write_no_timeout /*false*/, int64_t sql_req_level /*0*/)
{
int ret = OB_SUCCESS;
const static int MAX_IP_BUFFER_LEN = common::OB_IP_STR_BUFF;
char host[MAX_IP_BUFFER_LEN];
host[0] = '\0';
// if db is NULL, the default database is used.
if (OB_ISNULL(user) || OB_ISNULL(pass) /*|| OB_ISNULL(db)*/) {
if (OB_ISNULL(user) || OB_ISNULL(pass) || OB_ISNULL(host_name)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid argument", KP(user), KP(pass), KP(db), K(ret));
} else if (!addr.ip_to_string(host, MAX_IP_BUFFER_LEN)) {
ret = OB_BUF_NOT_ENOUGH;
LOG_WARN("fail to get host.", K(addr), K(ret));
LOG_WARN("invalid argument", KP(user), KP(pass), KP(host_name), K(ret));
} else {
close();
LOG_INFO("connecting to mysql server", "ip", host, "port", addr.get_port());
LOG_INFO("connecting to mysql server", "ip", host_name, "port", port);
mysql_init(&mysql_);
timeout_ = timeout;
#ifdef OB_BUILD_TDE_SECURITY
@ -151,11 +146,10 @@ int ObMySQLConnection::connect(const char *user, const char *pass, const char *d
#ifdef OB_BUILD_TDE_SECURITY
mysql_options(&mysql_, MYSQL_OPT_SSL_ENFORCE, &ssl_enforce);
#endif
int32_t port = addr.get_port();
MYSQL *mysql = mysql_real_connect(&mysql_, host, user, pass, db, port, NULL, 0);
MYSQL *mysql = mysql = mysql_real_connect(&mysql_, host_name, user, pass, db, port, NULL, 0);
if (OB_ISNULL(mysql)) {
ret = -mysql_errno(&mysql_);
LOG_WARN("fail to connect to mysql server", K(get_sessid()), KCSTRING(host), KCSTRING(user), KCSTRING(db), K(port),
LOG_WARN("fail to connect to mysql server", K(get_sessid()), KCSTRING(host_name), KCSTRING(user), KCSTRING(db), K(port),
"info", mysql_error(&mysql_), K(ret));
} else {
/*Note: mysql_real_connect() incorrectly reset the MYSQL_OPT_RECONNECT option
@ -185,18 +179,21 @@ int ObMySQLConnection::connect(const char *user, const char *pass, const char *d
char host[MAX_IP_BUFFER_LEN];
host[0] = '\0';
// if db is NULL, the default database is used.
bool is_server_valid = false;
if (OB_ISNULL(user) || OB_ISNULL(pass) /*|| OB_ISNULL(db)*/) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid argument", KP(user), KP(pass), KP(db), K(ret));
} else if (OB_ISNULL(root_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("root_ is NULL", K(ret));
} else if (!root_->get_server().ip_to_string(host, MAX_IP_BUFFER_LEN)) {
} else if (FALSE_IT(is_server_valid = root_->get_server().is_valid())) {
} else if (is_server_valid && !root_->get_server().ip_to_string(host, MAX_IP_BUFFER_LEN)) {
ret = OB_BUF_NOT_ENOUGH;
LOG_WARN("fail to get host.", K(root_->get_server()), K(ret));
} else {
close();
LOG_INFO("connecting to mysql server", "ip", host, "port", root_->get_server().get_port());
LOG_INFO("connecting to mysql server", "ip", host, "port", root_->get_server().get_port(),
"host_name", root_->get_host_name(), "host port", root_->get_port());
mysql_init(&mysql_);
#ifdef OB_BUILD_TDE_SECURITY
int64_t ssl_enforce = 1;
@ -230,8 +227,14 @@ int ObMySQLConnection::connect(const char *user, const char *pass, const char *d
#ifdef OB_BUILD_TDE_SECURITY
mysql_options(&mysql_, MYSQL_OPT_SSL_ENFORCE, &ssl_enforce);
#endif
MYSQL *mysql = NULL;
int32_t port = root_->get_server().get_port();
MYSQL *mysql = mysql_real_connect(&mysql_, host, user, pass, db, port, NULL, 0);
if (is_server_valid) {
mysql = mysql_real_connect(&mysql_, host, user, pass, db, port, NULL, 0);
} else {
port = root_->get_port();
mysql = mysql_real_connect(&mysql_, root_->get_host_name(), user, pass, db, port, NULL, 0);
}
if (OB_ISNULL(mysql)) {
ret = -mysql_errno(&mysql_);
char errmsg[256] = {0};
@ -249,6 +252,7 @@ int ObMySQLConnection::connect(const char *user, const char *pass, const char *d
K(db),
K(host),
K(port),
K(root_->get_host_name()),
K(errmsg));
TRANSLATE_CLIENT_ERR_2(ret, false, errmsg);
}
@ -393,7 +397,7 @@ int ObMySQLConnection::set_timeout_variable(const int64_t query_timeout, const i
} else if (OB_FAIL(create_statement(stmt, OB_SYS_TENANT_ID, sql))) {
LOG_WARN("create statement failed", K(ret));
} else if (OB_FAIL(stmt.execute_update(affect_rows))) {
LOG_WARN("execute sql failed", K(get_server()), KCSTRING(sql), K(ret));
LOG_WARN("execute sql failed", K(get_server()), K(sql), K(ret));
}
}
}
@ -446,7 +450,7 @@ int ObMySQLConnection::init_oceanbase_connection()
} else if (OB_FAIL(stmt.init(*this, sql))) {
LOG_WARN("create statement failed", K(ret));
} else if (OB_FAIL(stmt.execute_update())) {
LOG_WARN("execute sql failed", KCSTRING(sql), K(ret), K_(tenant_id));
LOG_WARN("execute sql failed", K(sql), K(ret), K_(tenant_id));
}
}
return ret;
@ -474,7 +478,7 @@ int ObMySQLConnection::switch_tenant(const uint64_t tenant_id)
}
}
if (OB_FAIL(ret)) {
} else if (OB_FAIL(stmt.init(*this, sql.ptr()))) {
} else if (OB_FAIL(stmt.init(*this, sql.string()))) {
LOG_WARN("create statement failed", K(ret));
} else if (OB_FAIL(stmt.execute_update())) {
LOG_WARN("execute sql failed", K(sql), K(ret), K(tenant_id), K(tenant_id_));
@ -487,13 +491,6 @@ int ObMySQLConnection::switch_tenant(const uint64_t tenant_id)
int ObMySQLConnection::execute_write(const uint64_t tenant_id, const ObString &sql,
int64_t &affected_rows, bool is_user_sql, const common::ObAddr *sql_exec_addr)
{
UNUSEDx(tenant_id, sql, affected_rows, is_user_sql, sql_exec_addr);
return OB_NOT_SUPPORTED;
}
int ObMySQLConnection::execute_write(const uint64_t tenant_id, const char *sql,
int64_t &affected_rows, bool is_user_sql, const common::ObAddr *sql_exec_addr)
{
UNUSED(is_user_sql);
UNUSED(sql_exec_addr);
@ -504,9 +501,9 @@ int ObMySQLConnection::execute_write(const uint64_t tenant_id, const char *sql,
} else {
ObMySQLStatement stmt;
if (OB_FAIL(create_statement(stmt, tenant_id, sql))) {
LOG_WARN("create statement failed", KCSTRING(sql), K(ret));
LOG_WARN("create statement failed", K(sql), K(ret));
} else if (OB_FAIL(stmt.execute_update(affected_rows))) {
LOG_WARN("statement execute update failed", KCSTRING(sql), K(ret));
LOG_WARN("statement execute update failed", K(sql), K(ret));
}
}
return ret;
@ -552,7 +549,7 @@ int ObMySQLConnection::execute_read(const int64_t cluster_id, const uint64_t ten
return OB_NOT_SUPPORTED;
}
int ObMySQLConnection::execute_read(const uint64_t tenant_id, const char *sql,
int ObMySQLConnection::execute_read(const uint64_t tenant_id, const ObString &sql,
ObISQLClient::ReadResult &res, bool is_user_sql, const common::ObAddr *sql_exec_addr)
{
UNUSED(is_user_sql);
@ -565,17 +562,17 @@ int ObMySQLConnection::execute_read(const uint64_t tenant_id, const char *sql,
} else if (OB_FAIL(res.create_handler(read_ctx))) {
LOG_ERROR("create result handler failed", K(ret));
} else if (OB_FAIL(create_statement(read_ctx->stmt_, tenant_id, sql))) {
LOG_WARN("create statement failed", KCSTRING(sql), K(ret));
LOG_WARN("create statement failed", K(sql), K(ret));
} else if (OB_ISNULL(read_ctx->result_ = read_ctx->stmt_.execute_query(res.is_enable_use_result()))) {
ret = get_last_error();
//const int ER_LOCK_WAIT_TIMEOUT = -1205;
if (-1205 == ret) {
LOG_INFO("query failed", K(get_server()), KCSTRING(sql), K(ret));
LOG_INFO("query failed", K(get_server()), K(sql), K(ret));
} else {
LOG_WARN("query failed", K(get_server()), KCSTRING(sql), K(ret));
LOG_WARN("query failed", K(get_server()), K(sql), K(ret));
}
} else {
LOG_DEBUG("query succeed", K(get_server()), KCSTRING(sql), K(ret));
LOG_DEBUG("query succeed", K(get_server()), K(sql), K(ret));
}
return ret;
}
@ -592,7 +589,7 @@ int ObMySQLConnection::get_session_variable(const ObString &name, int64_t &val)
ObMySQLResult *result = NULL;
if (OB_FAIL(sql.append_fmt("select %.*s from dual", name.length(), name.ptr()))) {
LOG_WARN("assign sql failed", K(ret));
} else if (OB_FAIL(create_statement(read_ctx.stmt_, OB_SYS_TENANT_ID, sql.ptr()))) {
} else if (OB_FAIL(create_statement(read_ctx.stmt_, OB_SYS_TENANT_ID, sql.string()))) {
LOG_WARN("create statement failed", K(sql), K(ret));
} else if (OB_ISNULL(read_ctx.result_ = read_ctx.stmt_.execute_query())) {
ret = get_last_error();
@ -618,7 +615,7 @@ int ObMySQLConnection::set_session_variable(const ObString &name, int64_t val)
ObSqlString sql;
if (OB_FAIL(sql.append_fmt("set %.*s = %ld", name.length(), name.ptr(), val))) {
LOG_WARN("assign sql failed", K(ret));
} else if (OB_FAIL(stmt.init(*this, sql.ptr()))) {
} else if (OB_FAIL(stmt.init(*this, sql.string()))) {
LOG_WARN("create statement failed", K(ret));
} else if (OB_FAIL(stmt.execute_update())) {
LOG_WARN("execute sql failed", K(sql), K(ret));
@ -657,7 +654,7 @@ int ObMySQLConnection::set_session_variable(const ObString &name, const ObString
}
if (OB_FAIL(ret)) {
// do nothing
} else if (OB_FAIL(stmt.init(*this, sql.ptr()))) {
} else if (OB_FAIL(stmt.init(*this, sql.string()))) {
LOG_WARN("create statement failed", K(ret), K(sql));
} else if (OB_FAIL(stmt.execute_update())) {
LOG_WARN("execute sql failed", K(sql), K(ret));
@ -699,16 +696,16 @@ int ObMySQLConnection::connect_dblink(const bool use_ssl, int64_t sql_request_le
return ret;
}
int ObMySQLConnection::prepare(const char *sql, int64_t param_count, ObIAllocator *allocator)
int ObMySQLConnection::prepare(const ObString &sql, int64_t param_count, ObIAllocator *allocator)
{
int ret = OB_SUCCESS;
if (OB_FAIL(prepare_proc_stmt(sql, param_count, allocator))) {
LOG_WARN("prepare proc stmt failed", K(ret), KCSTRING(sql));
LOG_WARN("prepare proc stmt failed", K(ret), K(ObString(sql)));
}
return ret;
}
int ObMySQLConnection::prepare_proc_stmt(const char *sql, int64_t param_count, ObIAllocator *allocator)
int ObMySQLConnection::prepare_proc_stmt(const ObString &sql, int64_t param_count, ObIAllocator *allocator)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(allocator)) {
@ -719,7 +716,7 @@ int ObMySQLConnection::prepare_proc_stmt(const char *sql, int64_t param_count, O
ret = OB_NOT_INIT;
LOG_WARN("connection not established. call connect first", K(ret));
} else if (OB_FAIL(create_statement(proc_stmt_, OB_INVALID_TENANT_ID, sql, param_count))) {
LOG_WARN("create statement failed", K(ret), KCSTRING(sql));
LOG_WARN("create statement failed", K(ret), K(ObString(sql)));
}
return ret;
}

View File

@ -51,14 +51,14 @@ public:
ObMySQLConnection();
~ObMySQLConnection();
int connect(const char *user, const char *pass, const char *db,
oceanbase::common::ObAddr &addr, int64_t timeout, bool read_write_no_timeout = false, int64_t sql_req_level = 0);
const char *domin_name, int32_t port, int64_t timeout, bool read_write_no_timeout = false, int64_t sql_req_level = 0);
int connect(const char *user, const char *pass, const char *db, const bool use_ssl, bool read_write_no_timeout = false, int64_t sql_req_level = 0);
void close();
virtual bool is_closed() const;
// use user provided the statement
template<typename T>
int create_statement(T &stmt, const uint64_t tenant_id, const char *sql, int64_t param_count = 0);
int prepare_statement(ObMySQLPreparedStatement &stmt, const char *sql);
int create_statement(T &stmt, const uint64_t tenant_id, const ObString &sql, int64_t param_count = 0);
int prepare_statement(ObMySQLPreparedStatement &stmt, const ObString &sql);
int escape(const char *from, const int64_t from_size, char *to,
const int64_t to_size, int64_t &out_size);
void init(ObServerConnectionPool *root);
@ -70,7 +70,7 @@ public:
void set_last_error(int err_code);
int get_last_error(void) const;
virtual int execute_read(const uint64_t tenant_id, const char *sql,
virtual int execute_read(const uint64_t tenant_id, const ObString &sql,
ObISQLClient::ReadResult &res, bool is_user_sql = false,
const common::ObAddr *sql_exec_addr = nullptr) override;
@ -82,9 +82,6 @@ public:
int64_t &affected_rows, bool is_user_sql = false,
const common::ObAddr *sql_exec_addr = nullptr) override;
virtual int execute_write(const uint64_t tenant_id, const char *sql,
int64_t &affected_rows, bool is_user_sql = false,
const common::ObAddr *sql_exec_addr = nullptr) override;
virtual int execute_proc(const uint64_t tenant_id,
ObIAllocator &allocator,
ParamStore &params,
@ -123,8 +120,8 @@ public:
// dblink.
virtual int connect_dblink(const bool use_ssl, int64_t sql_request_level);
int prepare(const char *sql, int64_t param_count, ObIAllocator *allocator);
int prepare_proc_stmt(const char *sql, int64_t param_count, ObIAllocator *allocator);
int prepare(const ObString &sql, int64_t param_count, ObIAllocator *allocator);
int prepare_proc_stmt(const ObString &sql, int64_t param_count, ObIAllocator *allocator);
int bind_basic_type_by_pos(uint64_t position,
void *param,
int64_t param_size,
@ -199,7 +196,7 @@ inline int64_t ObMySQLConnection::connection_version() const
}
template<typename T>
int ObMySQLConnection::create_statement(T &stmt, const uint64_t tenant_id, const char *sql, int64_t param_count)
int ObMySQLConnection::create_statement(T &stmt, const uint64_t tenant_id, const ObString &sql, int64_t param_count)
{
int ret = OB_SUCCESS;
if (OB_FAIL(switch_tenant(tenant_id))) {

View File

@ -769,7 +769,7 @@ int ObMySQLConnectionPool::escape(const char *from, const int64_t from_size,
}
return ret;
}
int ObMySQLConnectionPool::create_dblink_pool(const dblink_param_ctx &param_ctx, const ObAddr &server,
int ObMySQLConnectionPool::create_dblink_pool(const dblink_param_ctx &param_ctx, const ObString &host_name, int32_t port,
const ObString &db_tenant, const ObString &db_user,
const ObString &db_pass, const ObString &db_name,
const common::ObString &conn_str,
@ -796,14 +796,14 @@ int ObMySQLConnectionPool::create_dblink_pool(const dblink_param_ctx &param_ctx,
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_ERROR("out of memory", K(ret));
} else if (OB_FAIL(dblink_pool->init_dblink(param_ctx.tenant_id_, param_ctx.dblink_id_,
server, db_tenant, db_user, db_pass,
host_name, port, db_tenant, db_user, db_pass,
db_name, conn_str, cluster_str,
this, config_.sqlclient_per_observer_conn_limit_))) {
LOG_WARN("fail to init dblink connection pool", K(ret));
} else if (OB_FAIL(server_list_.push_back(dblink_pool))) {
LOG_WARN("fail to push pool to list", K(ret));
} else {
LOG_DEBUG("new dblink pool created", K(server), K(config_.sqlclient_per_observer_conn_limit_));
LOG_DEBUG("new dblink pool created", K(host_name), K(port), K(config_.sqlclient_per_observer_conn_limit_));
}
}
if (OB_FAIL(ret) && OB_NOT_NULL(dblink_pool)) {

View File

@ -159,7 +159,7 @@ public:
virtual DblinkDriverProto get_pool_link_driver_proto() { return DBLINK_DRV_OB; }
// dblink
virtual int create_dblink_pool(const dblink_param_ctx &param_ctx, const ObAddr &server,
virtual int create_dblink_pool(const dblink_param_ctx &param_ctx, const ObString &host_name, int32_t port,
const ObString &db_tenant, const ObString &db_user,
const ObString &db_pass, const ObString &db_name,
const common::ObString &conn_str,

View File

@ -1095,17 +1095,17 @@ int ObMySQLPreparedStatement::get_ob_type(ObObjType &ob_type, obmysql::EMySQLFie
return ret;
}
int ObMySQLPreparedStatement::init(ObMySQLConnection &conn, const char *sql, int64_t param_count)
int ObMySQLPreparedStatement::init(ObMySQLConnection &conn, const ObString &sql, int64_t param_count)
{
int ret = OB_SUCCESS;
conn_ = &conn;
if (OB_ISNULL(sql)) {
if (sql.empty()) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid sql", KP(sql), K(ret));
LOG_WARN("invalid sql", K(sql), K(ret));
} else if (OB_ISNULL(stmt_ = mysql_stmt_init(conn_->get_handler()))) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_ERROR("fail to init stmt", K(ret));
} else if (0 != mysql_stmt_prepare(stmt_, sql, STRLEN(sql))) {
} else if (0 != mysql_stmt_prepare(stmt_, sql.ptr(), sql.length())) {
ret = -mysql_errno(conn_->get_handler());
LOG_WARN("fail to prepare stmt", "info", mysql_error(conn_->get_handler()), K(ret));
} else if (OB_FAIL(param_.init())) {
@ -1669,7 +1669,7 @@ int ObMySQLProcStatement::process_proc_output_params(ObIAllocator &allocator,
}
int ObMySQLProcStatement::init(ObMySQLConnection &conn,
const char *sql,
const ObString &sql,
int64_t param_count)
{
int ret = OB_SUCCESS;
@ -1679,9 +1679,9 @@ int ObMySQLProcStatement::init(ObMySQLConnection &conn,
conn_ = &conn;
stmt_param_count_ = param_count;
in_out_map_.reset();
if (OB_ISNULL(proc_ = sql)) {
if (OB_ISNULL(proc_ = sql.ptr())) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid sql", KCSTRING(sql), K(ret));
LOG_WARN("invalid sql", K(sql), K(ret));
} else if (OB_ISNULL(conn_) || OB_ISNULL(conn_->get_handler())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("conn_ is NULL", K(ret));
@ -1691,7 +1691,7 @@ int ObMySQLProcStatement::init(ObMySQLConnection &conn,
} else if (OB_ISNULL(stmt_ = mysql_stmt_init(conn_->get_handler()))) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_ERROR("fail to init stmt", K(ret));
} else if (0 != mysql_stmt_prepare_v2(stmt_, sql, STRLEN(sql), &stmt_param_count_)) {
} else if (0 != mysql_stmt_prepare_v2(stmt_, sql.ptr(), sql.length(), &stmt_param_count_)) {
ret = -mysql_errno(conn_->get_handler());
LOG_WARN("fail to prepare stmt", "info", mysql_error(conn_->get_handler()), K(ret));
} else if (OB_FAIL(param_.init())) {

View File

@ -155,7 +155,7 @@ public:
MYSQL_STMT *get_stmt_handler();
MYSQL *get_conn_handler();
virtual int close();
virtual int init(ObMySQLConnection &conn, const char *sql, int64_t param_count);
virtual int init(ObMySQLConnection &conn, const ObString &sql, int64_t param_count);
int bind_param(ObBindParam &param);
int bind_result(ObBindParam &param);
int bind_param_int(const int64_t col_idx, int64_t *out_buf);
@ -215,7 +215,7 @@ public:
in_out_map_.reset();
proc_ = NULL;
}
virtual int init(ObMySQLConnection &conn, const char *sql, int64_t param_count);
virtual int init(ObMySQLConnection &conn, const ObString &sql, int64_t param_count);
virtual int close();
virtual void free_resouce();
virtual int close_mysql_stmt();

View File

@ -435,7 +435,7 @@ int ObDbLinkProxy::switch_dblink_conn_pool(DblinkDriverProto type, ObISQLConnect
return ret;
}
int ObDbLinkProxy::create_dblink_pool(const dblink_param_ctx &param_ctx, const ObAddr &server,
int ObDbLinkProxy::create_dblink_pool(const dblink_param_ctx &param_ctx, const ObString &host_name, int32_t port,
const ObString &db_tenant, const ObString &db_user,
const ObString &db_pass, const ObString &db_name,
const common::ObString &conn_str,
@ -451,10 +451,10 @@ int ObDbLinkProxy::create_dblink_pool(const dblink_param_ctx &param_ctx, const O
LOG_WARN("mysql proxy not inited");
} else if (OB_FAIL(switch_dblink_conn_pool(param_ctx.link_type_, dblink_pool))) {
LOG_WARN("failed to get dblink interface", K(ret));
} else if (OB_FAIL(dblink_pool->create_dblink_pool(param_ctx, server, db_tenant,
} else if (OB_FAIL(dblink_pool->create_dblink_pool(param_ctx, host_name, port, db_tenant,
db_user, db_pass, db_name,
conn_str, cluster_str))) {
LOG_WARN("create dblink pool failed", K(ret), K(param_ctx), K(server),
LOG_WARN("create dblink pool failed", K(ret), K(param_ctx), K(host_name), K(port),
K(db_tenant), K(db_user), K(db_pass), K(db_name));
}
return ret;
@ -531,7 +531,7 @@ int ObDbLinkProxy::execute_init_sql(const sqlclient::dblink_param_ctx &param_ctx
}
}
} else if (DBLINK_DRV_OB == param_ctx.link_type_) {
static sql_ptr_type sql_ptr[] = {
sql_ptr_type sql_ptr[] = {
param_ctx.set_client_charset_cstr_,
param_ctx.set_connection_charset_cstr_,
param_ctx.set_results_charset_cstr_,
@ -609,27 +609,27 @@ int ObDbLinkProxy::release_dblink(/*uint64_t dblink_id,*/ DblinkDriverProto dbli
return ret;
}
int ObDbLinkProxy::dblink_read(ObISQLConnection *dblink_conn, ReadResult &result, const char *sql)
int ObDbLinkProxy::dblink_read(ObISQLConnection *dblink_conn, ReadResult &result, const ObString &sql)
{
int ret = OB_SUCCESS;
result.reset();
if (OB_ISNULL(dblink_conn) || OB_ISNULL(sql)) {
if (OB_ISNULL(dblink_conn) || sql.empty()) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("null ptr", K(ret), KP(dblink_conn), KP(sql));
LOG_WARN("null ptr", K(ret), KP(dblink_conn), K(sql));
} else if (OB_FAIL(dblink_conn->execute_read(OB_INVALID_TENANT_ID, sql, result))) {
LOG_WARN("read from dblink failed", K(ret), K(dblink_conn), KCSTRING(sql));
LOG_WARN("read from dblink failed", K(ret), K(dblink_conn), K(sql));
} else {
LOG_DEBUG("succ to read from dblink", K(sql));
}
return ret;
}
int ObDbLinkProxy::dblink_write(ObISQLConnection *dblink_conn, int64_t &affected_rows, const char *sql)
int ObDbLinkProxy::dblink_write(ObISQLConnection *dblink_conn, int64_t &affected_rows, const ObString &sql)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(dblink_conn) || OB_ISNULL(sql)) {
if (OB_ISNULL(dblink_conn) || sql.empty()) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("null ptr", K(ret), KP(dblink_conn), KP(sql));
LOG_WARN("null ptr", K(ret), KP(dblink_conn), K(sql));
} else if (OB_FAIL(dblink_conn->execute_write(OB_INVALID_TENANT_ID, sql, affected_rows))) {
LOG_WARN("write to dblink failed", K(ret), K(dblink_conn), K(sql));
} else {
@ -652,16 +652,16 @@ int ObDbLinkProxy::dblink_execute_proc(ObISQLConnection *dblink_conn)
int ObDbLinkProxy::dblink_prepare(sqlclient::ObISQLConnection *dblink_conn,
const char *sql,
const ObString &sql,
int64_t param_count,
ObIAllocator *allocator)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(dblink_conn) || OB_ISNULL(sql)) {
if (OB_ISNULL(dblink_conn) || sql.empty()) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("null ptr", K(ret), KP(dblink_conn), KP(sql));
LOG_WARN("null ptr", K(ret), KP(dblink_conn), K(sql));
} else if (OB_FAIL(dblink_conn->prepare(sql, param_count, allocator))) {
LOG_WARN("prepare to dblink failed", K(ret), K(ObString(sql)));
LOG_WARN("prepare to dblink failed", K(ret), K(sql));
}
return ret;
}

View File

@ -203,7 +203,7 @@ public:
virtual bool is_oracle_mode() const override { return true; }
virtual int init(sqlclient::ObDbLinkConnectionPool *pool);
int create_dblink_pool(const sqlclient::dblink_param_ctx &param_ctx,
const ObAddr &server,
const ObString &host_name, int32_t port,
const ObString &db_tenant, const ObString &db_user,
const ObString &db_pass, const ObString &db_name,
const common::ObString &conn_str,
@ -211,8 +211,8 @@ public:
int acquire_dblink(const sqlclient::dblink_param_ctx &param_ctx,
sqlclient::ObISQLConnection *&dblink_conn);
int release_dblink(sqlclient::DblinkDriverProto dblink_type, sqlclient::ObISQLConnection *dblink_conn);
int dblink_read(sqlclient::ObISQLConnection *dblink_conn, ReadResult &result, const char *sql);
int dblink_write(sqlclient::ObISQLConnection *dblink_conn, int64_t &affected_rows, const char *sql);
int dblink_read(sqlclient::ObISQLConnection *dblink_conn, ReadResult &result, const ObString &sql);
int dblink_write(sqlclient::ObISQLConnection *dblink_conn, int64_t &affected_rows, const ObString &sql);
int dblink_execute_proc(sqlclient::ObISQLConnection *dblink_conn);
int dblink_execute_proc(const uint64_t tenant_id,
sqlclient::ObISQLConnection *dblink_conn,
@ -225,7 +225,7 @@ public:
ObObj *result,
bool is_sql);
int dblink_prepare(sqlclient::ObISQLConnection *dblink_conn,
const char *sql,
const ObString &sql,
int64_t param_count,
ObIAllocator *allocator = NULL);
int dblink_bind_basic_type_by_pos(sqlclient::ObISQLConnection *dblink_conn,

View File

@ -29,8 +29,7 @@ namespace sqlclient
ObMySQLStatement::ObMySQLStatement() :
conn_(NULL),
result_(*this),
stmt_(NULL),
sql_str_(NULL)
stmt_(NULL)
{
}
@ -54,11 +53,11 @@ ObMySQLConnection *ObMySQLStatement::get_connection()
return conn_;
}
int ObMySQLStatement::init(ObMySQLConnection &conn, const char *sql, int64_t param_count)
int ObMySQLStatement::init(ObMySQLConnection &conn, const ObString &sql, int64_t param_count)
{
int ret = OB_SUCCESS;
conn_ = &conn;
if (OB_ISNULL(sql)) {
if (sql.empty()) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid sql, sql is null", K(ret));
} else if (OB_ISNULL(stmt_ = conn.get_handler())) {
@ -90,16 +89,16 @@ int ObMySQLStatement::execute_update(int64_t &affected_rows)
int ret = OB_SUCCESS;
int tmp_ret = 0;
const int CR_SERVER_LOST = 2013;
if (OB_ISNULL(conn_) || OB_ISNULL(stmt_) || OB_ISNULL(sql_str_)) {
if (OB_ISNULL(conn_) || OB_ISNULL(stmt_) || sql_str_.empty()) {
ret = OB_ERR_UNEXPECTED;
LOG_ERROR("invalid mysql stmt", K_(conn), KP_(stmt), KP_(sql_str), K(ret));
LOG_ERROR("invalid mysql stmt", K_(conn), KP_(stmt), K_(sql_str), K(ret));
} else if (OB_UNLIKELY(!conn_->usable())) {
ret = -CR_SERVER_LOST;
conn_->set_last_error(ret);
LOG_WARN("conn already failed, should not execute query again!", K(conn_));
} else {
int64_t begin = ObTimeUtility::current_monotonic_raw_time();
if (0 != (tmp_ret = mysql_real_query(stmt_, sql_str_, STRLEN(sql_str_)))) {
if (0 != (tmp_ret = mysql_real_query(stmt_, sql_str_.ptr(), sql_str_.length()))) {
ret = -mysql_errno(stmt_);
char errmsg[256] = {0};
const char *srcmsg = mysql_error(stmt_);
@ -120,7 +119,7 @@ int ObMySQLStatement::execute_update(int64_t &affected_rows)
K(stmt_->host),
K(stmt_->port),
K(errmsg),
K(STRLEN(sql_str_)),
K(sql_str_.length()),
K(sql_str_));
TRANSLATE_CLIENT_ERR(ret, errmsg);
}
@ -142,16 +141,16 @@ ObMySQLResult *ObMySQLStatement::execute_query(bool enable_use_result)
ObMySQLResult *result = NULL;
int ret = OB_SUCCESS;
const int CR_SERVER_LOST = 2013;
if (OB_ISNULL(conn_) || OB_ISNULL(stmt_) || OB_ISNULL(sql_str_)) {
if (OB_ISNULL(conn_) || OB_ISNULL(stmt_) || sql_str_.empty()) {
ret = OB_ERR_UNEXPECTED;
LOG_ERROR("invalid mysql stmt", K_(conn), K_(stmt), KP_(sql_str), K(ret));
LOG_ERROR("invalid mysql stmt", K_(conn), K_(stmt), K(sql_str_), K(ret));
} else if (OB_UNLIKELY(!conn_->usable())) {
ret = -CR_SERVER_LOST;
conn_->set_last_error(ret);
LOG_WARN("conn already failed, should not execute query again", K(conn_));
} else {
int64_t begin = ObTimeUtility::current_monotonic_raw_time();
if (0 != mysql_real_query(stmt_, sql_str_, STRLEN(sql_str_))) {
if (0 != mysql_real_query(stmt_, sql_str_.ptr(), sql_str_.length())) {
ret = -mysql_errno(stmt_);
char errmsg[256] = {0};
const char *srcmsg = mysql_error(stmt_);
@ -162,7 +161,7 @@ ObMySQLResult *ObMySQLStatement::execute_query(bool enable_use_result)
"err_msg", errmsg, K(ret), K(sql_str_));
} else {
LOG_WARN("fail to query server", "host", stmt_->host, "port", stmt_->port, K(conn_->get_sessid()),
"err_msg", errmsg, K(ret), K(STRLEN(sql_str_)), K(sql_str_), K(lbt()));
"err_msg", errmsg, K(ret), K(sql_str_.length()), K(sql_str_));
}
if (OB_SUCCESS == ret) {
ret = OB_ERR_SQL_CLIENT;
@ -177,7 +176,7 @@ ObMySQLResult *ObMySQLStatement::execute_query(bool enable_use_result)
K(stmt_->host),
K(stmt_->port),
K(errmsg),
K(STRLEN(sql_str_)),
K(sql_str_.length()),
K(sql_str_));
TRANSLATE_CLIENT_ERR(ret, errmsg);
}

View File

@ -31,7 +31,7 @@ public:
ObMySQLConnection *get_connection();
MYSQL *get_stmt_handler();
MYSQL *get_conn_handler();
int init(ObMySQLConnection &conn, const char *sql, int64_t param_count = 0);
int init(ObMySQLConnection &conn, const ObString &sql, int64_t param_count = 0);
/*
* close statement
@ -63,7 +63,7 @@ private:
ObMySQLConnection *conn_;
ObMySQLResultImpl result_;
MYSQL *stmt_;
const char *sql_str_;
ObString sql_str_;
};
} //namespace sqlclient
}

View File

@ -26,6 +26,7 @@ ObServerConnectionPool::ObServerConnectionPool() :
connection_pool_ptr_(NULL),
root_(NULL),
dblink_id_(OB_INVALID_ID),
port_(0),
server_(),
pool_lock_(common::ObLatchIds::INNER_CONN_POOL_LOCK),
last_renew_timestamp_(0),
@ -201,7 +202,7 @@ void ObServerConnectionPool::dump()
"max_allowed_conn_count_", max_allowed_conn_count_, "server_not_available_", server_not_available_);
}
int ObServerConnectionPool::init_dblink(uint64_t tenant_id, uint64_t dblink_id, const ObAddr &server,
int ObServerConnectionPool::init_dblink(uint64_t tenant_id, uint64_t dblink_id, const ObString &host_name, int32_t port,
const ObString &db_tenant, const ObString &db_user,
const ObString &db_pass, const ObString &db_name,
const common::ObString &conn_str,
@ -210,22 +211,33 @@ int ObServerConnectionPool::init_dblink(uint64_t tenant_id, uint64_t dblink_id,
{
UNUSED(conn_str);
int ret = OB_SUCCESS;
if (OB_FAIL(init(root, server, max_allowed_conn_count))) {
if (OB_ISNULL(root)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("fail to init server connection pool. root=NULL", K(ret));
} else if (OB_FAIL(dblink_connection_pool_.init())) {
LOG_WARN("fail to init", K(ret));
} else if (OB_INVALID_ID == dblink_id
|| 0 == port
|| db_tenant.empty() || db_user.empty() || db_pass.empty()
|| (!lib::is_oracle_mode() && db_name.empty())
|| OB_UNLIKELY(cluster_str.length() >= OB_MAX_CLUSTER_NAME_LENGTH)
|| OB_UNLIKELY(db_tenant.length() >= OB_MAX_TENANT_NAME_LENGTH)
|| OB_UNLIKELY(db_user.length() >= OB_MAX_USER_NAME_LENGTH)
|| OB_UNLIKELY(db_pass.length() >= OB_MAX_PASSWORD_LENGTH)
|| OB_UNLIKELY(db_name.length() >= OB_MAX_DATABASE_NAME_LENGTH)) {
|| OB_UNLIKELY(db_name.length() >= OB_MAX_DATABASE_NAME_LENGTH)
|| OB_UNLIKELY(host_name.length() > OB_MAX_DOMIN_NAME_LENGTH)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("db param buffer is not enough", K(ret),
K(dblink_id), K(db_tenant), K(db_user), K(db_pass), K(db_name));
K(dblink_id), K(db_tenant), K(db_user), K(db_pass), K(db_name), K(port), K(host_name));
} else {
dblink_id_ = dblink_id;
tenant_id_ = tenant_id;
port_ = port;
root_ = root;
last_renew_timestamp_ = ::oceanbase::common::ObTimeUtility::current_time();
server_not_available_ = false;
max_allowed_conn_count_ = max_allowed_conn_count;
connection_pool_ptr_ = &dblink_connection_pool_;
if (cluster_str.empty()) {
(void)snprintf(db_user_, sizeof(db_user_), "%.*s@%.*s", db_user.length(), db_user.ptr(),
db_tenant.length(), db_tenant.ptr());
@ -235,11 +247,12 @@ int ObServerConnectionPool::init_dblink(uint64_t tenant_id, uint64_t dblink_id,
cluster_str.length(), cluster_str.ptr());
}
(void)snprintf(db_pass_, sizeof(db_pass_), "%.*s", db_pass.length(), db_pass.ptr());
(void)snprintf(host_name_, sizeof(host_name_), "%.*s", host_name.length(), host_name.ptr());
// if db is NULL, the default database is used.
if (!db_name.empty()) {
(void)snprintf(db_name_, sizeof(db_name_), "%.*s", db_name.length(), db_name.ptr());
}
connection_pool_ptr_ = &dblink_connection_pool_;
server_.reset(); //server_ will be invlid, then mysqlconnnection will use host_name_
}
return ret;
}

View File

@ -45,6 +45,8 @@ public:
void set_server_gone(bool gone);
const char *get_db_user() const; const char *get_db_pass() const;
const char *get_db_name() const;
const char *get_host_name() const;
int32_t get_port() const;
common::ObAddr &get_server();
ObMySQLConnectionPool *get_root();
void close_all_connection();
@ -53,7 +55,7 @@ public:
K_(free_conn_count),
K_(busy_conn_count));
// dblink.
int init_dblink(uint64_t tenant_id, uint64_t dblink_id, const ObAddr &server,
int init_dblink(uint64_t tenant_id, uint64_t dblink_id, const ObString &host_name, int32_t port,
const ObString &db_tenant, const ObString &db_user,
const ObString &db_pass, const ObString &db_name,
const common::ObString &conn_str,
@ -73,6 +75,8 @@ private:
char db_user_[OB_MAX_USER_NAME_LENGTH + OB_MAX_TENANT_NAME_LENGTH + OB_MAX_CLUSTER_NAME_LENGTH + 1];
char db_pass_[OB_MAX_PASSWORD_LENGTH];
char db_name_[OB_MAX_DATABASE_NAME_LENGTH];
char host_name_[OB_MAX_DOMIN_NAME_LENGTH + 1]; // used by dblink to connect, instead of using server_ to connect
int32_t port_; // used by dblink to connect, instead of using server_ to connect
common::ObAddr server_; // shared by connections in this pool
common::ObSpinLock pool_lock_;
int64_t last_renew_timestamp_;
@ -81,6 +85,14 @@ private:
bool server_not_available_;
};
inline const char *ObServerConnectionPool::get_host_name() const
{
return host_name_;
}
inline int32_t ObServerConnectionPool::get_port() const
{
return port_;
}
inline void ObServerConnectionPool::set_server_gone(bool gone)
{

View File

@ -20,6 +20,7 @@
#include "lib/checksum/ob_crc64.h"
#include "common/object/ob_object.h"
#include "rpc/obmysql/obsm_struct.h"
#include "lib/compress/zlib/ob_zlib_compressor.h"
namespace oceanbase
{
@ -86,60 +87,56 @@ int Ob20ProtocolProcessor::do_decode(ObSMConnection& conn, ObICSMemPool& pool, c
header20.cp_hdr_.comp_seq_ = pktseq;
header20.cp_hdr_.uncomp_len = pktlen_before_compress;
// 2. decode proto2.0 header
ObMySQLUtil::get_uint2(start, header20.magic_num_);
ObMySQLUtil::get_uint2(start, header20.version_);
ObMySQLUtil::get_uint4(start, header20.connection_id_);
ObMySQLUtil::get_uint3(start, header20.request_id_);
ObMySQLUtil::get_uint1(start, header20.pkt_seq_);
ObMySQLUtil::get_uint4(start, header20.payload_len_);
ObMySQLUtil::get_uint4(start, header20.flag_.flags_);
ObMySQLUtil::get_uint2(start, header20.reserved_);
ObMySQLUtil::get_uint2(start, header20.header_checksum_);
LOG_DEBUG("decode proto20 header succ", K(header20));
// 3. crc16 for header checksum
if (OB_FAIL(do_header_checksum(origin_start, header20))) {
LOG_ERROR("fail to do header checksum", K(header20), K(ret));
} else if (OB_UNLIKELY(OB20_PROTOCOL_MAGIC_NUM != header20.magic_num_)) {
ret = OB_UNKNOWN_PACKET;
LOG_ERROR("invalid magic num", K(OB20_PROTOCOL_MAGIC_NUM),
K(header20.magic_num_), K(sessid), K(ret));
} else if (OB_UNLIKELY(sessid != header20.connection_id_)) {
ret = OB_UNKNOWN_CONNECTION;
LOG_ERROR("connection id mismatch", K(sessid), K_(header20.connection_id), K(ret));
} else if (0 != pktlen_before_compress) {
ret = OB_ERR_UNEXPECTED;
LOG_ERROR("pktlen_before_compress must be 0 here", K(pktlen_before_compress),
K(sessid), K(ret));
} else if (OB_UNLIKELY(OB20_PROTOCOL_VERSION_VALUE != header20.version_)) {
ret = OB_UNKNOWN_PACKET;
LOG_ERROR("invalid version", K(OB20_PROTOCOL_VERSION_VALUE),
K(header20.version_), K(sessid), K(ret));
} else if (OB_UNLIKELY(pktlen !=
(header20.payload_len_ + OB20_PROTOCOL_HEADER_LENGTH + OB20_PROTOCOL_TAILER_LENGTH))) {
// must only contain one ob20 packet
ret = OB_ERR_UNEXPECTED;
LOG_ERROR("invalid pktlen len", K(pktlen), K(header20.payload_len_), K(sessid),
K(OB20_PROTOCOL_HEADER_LENGTH), K(OB20_PROTOCOL_TAILER_LENGTH), K(ret));
} else {
// received packet length, include tailer, but exclude packet header
conn.proto20_pkt_context_.is_comp_packet_ = conn.proxy_cap_flags_.is_ob_protocol_v2_compress();
if (conn.proto20_pkt_context_.is_comp_packet_) {
// do decompress
// received packet length, exclude packet header
uint32_t rpktlen = static_cast<uint32_t>(end - start);
// one packet was not received complete
if ((header20.payload_len_ + OB20_PROTOCOL_TAILER_LENGTH) > rpktlen) {
int64_t delta_len = header20.payload_len_ + OB20_PROTOCOL_TAILER_LENGTH - rpktlen;
if (0 == pktlen) {
ret = OB_INVALID_ARGUMENT;
LOG_ERROR("invalid arugment", K(sessid), K(pktlen), K(pktlen_before_compress), K(ret));
} else if (pktlen > rpktlen) { // one packet was not received complete
int64_t delta_len = pktlen - rpktlen;
// valid packet, but not sufficient data received by easy, tell easy read more.
// go backward with MySQL packet header length
start -= header_size;
next_read_bytes = delta_len;
// if received at least packet completed, do payload checksum
// delat_len == 0, recevied one packet complete
// delta_len < 0, received more than one packet
} else if (OB_FAIL(do_body_checksum(start, header20))) {
LOG_ERROR("fail to do body checksum", K(header20), K(sessid), K(ret));
} else if (OB_FAIL(decode_ob20_body(pool, start, header20, pkt))) {
LOG_ERROR("fail to decode_compressed_body", K(sessid), K(header20), K(ret));
// Attention!! when arrive here, all mysql compress protocols are in command phase
} else if (OB_FAIL(decode_compressed_body(pool, start, pktlen, pktseq, pktlen_before_compress, pkt))) {
LOG_ERROR("fail to decode_compressed_body", K(sessid), K(pktseq), K(ret));
}
} else {
if (OB_FAIL(decode_ob20_header(origin_start, start, end, header20, sessid, true))) {
LOG_ERROR("invalid 20 protocol header", K(header20), K(sessid), K(ret));
} else if (0 != pktlen_before_compress) {
ret = OB_ERR_UNEXPECTED;
LOG_ERROR("pktlen_before_compress must be 0 here",
K(pktlen_before_compress), K(sessid), K(ret));
} else if (OB_UNLIKELY(pktlen !=
(header20.payload_len_ + OB20_PROTOCOL_HEADER_LENGTH + OB20_PROTOCOL_TAILER_LENGTH))) {
// must only contain one ob20 packet
ret = OB_ERR_UNEXPECTED;
LOG_ERROR("invalid pktlen len", K(pktlen), K(header20.payload_len_), K(sessid),
K(OB20_PROTOCOL_HEADER_LENGTH), K(OB20_PROTOCOL_TAILER_LENGTH), K(ret));
} else {
// received packet length, include tailer, but exclude packet header
uint32_t rpktlen = static_cast<uint32_t>(end - start);
// one packet was not received complete
if ((header20.payload_len_ + OB20_PROTOCOL_TAILER_LENGTH) > rpktlen) {
int64_t delta_len = header20.payload_len_ + OB20_PROTOCOL_TAILER_LENGTH - rpktlen;
// valid packet, but not sufficient data received by easy, tell easy read more.
// go backward with MySQL packet header length
start -= header_size;
next_read_bytes = delta_len;
// if received at least packet completed, do payload checksum
// delat_len == 0, recevied one packet complete
// delta_len < 0, received more than one packet
} else if (OB_FAIL(do_body_checksum(start, header20))) {
LOG_ERROR("fail to do body checksum", K(header20), K(sessid), K(ret));
} else if (OB_FAIL(decode_ob20_body(pool, start, header20, pkt))) {
LOG_ERROR("fail to decode_compressed_body", K(sessid), K(header20), K(ret));
}
}
}
} else {
@ -150,7 +147,8 @@ int Ob20ProtocolProcessor::do_decode(ObSMConnection& conn, ObICSMemPool& pool, c
return ret;
}
inline int Ob20ProtocolProcessor::do_header_checksum(const char *origin_start, const Ob20ProtocolHeader &hdr) {
inline int Ob20ProtocolProcessor::do_header_checksum(const char *origin_start,
const Ob20ProtocolHeader &hdr, bool need_check_compress) {
INIT_SUCC(ret);
if (OB_ISNULL(origin_start)) {
ret = OB_INVALID_ARGUMENT;
@ -160,7 +158,7 @@ inline int Ob20ProtocolProcessor::do_header_checksum(const char *origin_start, c
} else {
const char *header_start = origin_start;
// mysql compress header len + proto20 header(except 2 byte checksum)
int64_t check_len = OB20_PROTOCOL_HEADER_LENGTH - 2 + OB_MYSQL_COMPRESSED_HEADER_SIZE;
int64_t check_len = OB20_PROTOCOL_HEADER_LENGTH - 2 + (need_check_compress ? OB_MYSQL_COMPRESSED_HEADER_SIZE : 0);
// 3. crc16 for header checksum
uint16_t local_header_checksum = 0;
@ -198,6 +196,50 @@ inline int Ob20ProtocolProcessor::do_body_checksum(const char* buf, const Ob20Pr
return ret;
}
inline int Ob20ProtocolProcessor::decode_ob20_header(const char*& origin_start, const char*& start, const char* end,
Ob20ProtocolHeader &header20, uint32_t sessid, bool need_check_compress)
{
int ret = OB_SUCCESS;
const int64_t header_size = OB20_PROTOCOL_HEADER_LENGTH;
if ((end - start) >= header_size) {
char* origin = NULL;
if (need_check_compress) {
origin = const_cast<char *>(origin_start);
} else {
origin = const_cast<char *>(start);
}
ObMySQLUtil::get_uint2(start, header20.magic_num_);
ObMySQLUtil::get_uint2(start, header20.version_);
ObMySQLUtil::get_uint4(start, header20.connection_id_);
ObMySQLUtil::get_uint3(start, header20.request_id_);
ObMySQLUtil::get_uint1(start, header20.pkt_seq_);
ObMySQLUtil::get_uint4(start, header20.payload_len_);
ObMySQLUtil::get_uint4(start, header20.flag_.flags_);
ObMySQLUtil::get_uint2(start, header20.reserved_);
ObMySQLUtil::get_uint2(start, header20.header_checksum_);
LOG_DEBUG("decode proto20 header succ", K(header20));
// 3. crc16 for header checksum
if (OB_FAIL(do_header_checksum((const char*)origin, header20, need_check_compress))) {
LOG_ERROR("fail to do header checksum", K(header20), K(ret));
} else if (OB_UNLIKELY(OB20_PROTOCOL_MAGIC_NUM != header20.magic_num_)) {
ret = OB_UNKNOWN_PACKET;
LOG_ERROR("invalid magic num", K(OB20_PROTOCOL_MAGIC_NUM),
K(header20.magic_num_), K(sessid), K(ret));
} else if (OB_UNLIKELY(sessid != header20.connection_id_)) {
ret = OB_UNKNOWN_CONNECTION;
LOG_ERROR("connection id mismatch", K(sessid), K_(header20.connection_id), K(ret));
} else if (OB_UNLIKELY(OB20_PROTOCOL_VERSION_VALUE != header20.version_)) {
ret = OB_UNKNOWN_PACKET;
LOG_ERROR("invalid version", K(OB20_PROTOCOL_VERSION_VALUE),
K(header20.version_), K(sessid), K(ret));
}
}
return ret;
}
inline int Ob20ProtocolProcessor::decode_ob20_body(
ObICSMemPool& pool,
const char*& buf,
@ -356,9 +398,18 @@ int Ob20ProtocolProcessor::decode_new_extra_info(const Ob20ProtocolHeader &hdr,
int Ob20ProtocolProcessor::do_splice(ObSMConnection& conn, ObICSMemPool& pool, void*& pkt, bool& need_decode_more)
{
INIT_SUCC(ret);
if (OB_FAIL(process_ob20_packet(conn.proto20_pkt_context_, conn.mysql_pkt_context_,
conn.pkt_rec_wrapper_, pool, pkt, need_decode_more))) {
LOG_ERROR("fail to process_ob20_packet", K(ret));
if (conn.proto20_pkt_context_.is_comp_packet_) {
// do nothing
if (OB_FAIL(process_compressed_ob20_packet(conn.sessid_,
conn.proto20_pkt_context_, conn.mysql_pkt_context_,
conn.pkt_rec_wrapper_, pool, pkt, need_decode_more))) {
LOG_ERROR("fail to process_compressed_ob20_packet", K(ret));
}
} else {
if (OB_FAIL(process_ob20_packet(conn.proto20_pkt_context_, conn.mysql_pkt_context_,
conn.pkt_rec_wrapper_, pool, pkt, need_decode_more))) {
LOG_ERROR("fail to process_ob20_packet", K(ret));
}
}
return ret;
}
@ -425,47 +476,178 @@ inline int Ob20ProtocolProcessor::process_ob20_packet(ObProto20PktContext& conte
if (OB_FAIL(ret)) {
// do nothing
} else {
context.comp_last_pkt_seq_ = pkt20->get_comp_seq();
context.proto20_last_pkt_seq_ = pkt20->get_seq(); // remember the request proto20 seq
context.proto20_last_request_id_ = pkt20->get_request_id(); // remember the request id
if (need_decode_more) {
context.is_multi_pkt_ = true;
} else {
// If a MySQL package is split into multiple 2.0 protocol packages,
// Only after all the sub-packages have been received and the group package is completed, ipacket is set as a complete MySQL package
// Only then can we set the flag of re-routing
// If a request is divided into multiple MySQL packages, each MySQL package will also set the re-routing flag
ObMySQLRawPacket *input_packet = reinterpret_cast<ObMySQLRawPacket *>(ipacket);
input_packet->set_can_reroute_pkt(pkt20->get_flags().is_proxy_reroute());
input_packet->set_is_weak_read(pkt20->get_flags().is_weak_read());
// need test proxy_switch_route flag.
input_packet->set_proxy_switch_route(pkt20->get_flags().proxy_switch_route());
const int64_t t_len = context.extra_info_.get_total_len();
char *t_buffer = NULL;
if (t_len <= 0) {
// empty extra info, do nothing
} else if (OB_ISNULL(t_buffer = reinterpret_cast<char *>(pool.alloc(t_len)))) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_ERROR("no memory available", "alloc_size", t_len, K(ret));
} else if (OB_FAIL(input_packet->extra_info_.assign(context.extra_info_, t_buffer, t_len))) {
LOG_ERROR("failed to assign extra info", K(ret));
}
} else if (OB_FAIL(after_process_mysql_packet(pool, context, pkt_rec_wrapper, ipacket, need_decode_more, pkt20))) {
LOG_ERROR("failed to do after process mysql packet");
}
}
return ret;
}
input_packet->set_txn_free_route(pkt20->get_flags().txn_free_route());
context.reset();
// set again for sending response
context.proto20_last_pkt_seq_ = pkt20->get_seq();
context.proto20_last_request_id_ = pkt20->get_request_id();
if (pkt_rec_wrapper.enable_proto_dia()) {
pkt_rec_wrapper.record_recieve_obp20_packet(*pkt20, *input_packet);
inline int Ob20ProtocolProcessor::after_process_mysql_packet(
ObICSMemPool& pool, ObProto20PktContext& context,
obmysql::ObPacketRecordWrapper &pkt_rec_wrapper,
void *&ipacket, bool &need_decode_more, Ob20Packet *pkt20)
{
int ret = OB_SUCCESS;
context.comp_last_pkt_seq_ = pkt20->get_comp_seq();
context.proto20_last_pkt_seq_ = pkt20->get_seq(); // remember the request proto20 seq
context.proto20_last_request_id_ = pkt20->get_request_id(); // remember the request id
if (need_decode_more) {
context.is_multi_pkt_ = true;
} else {
// If a MySQL package is split into multiple 2.0 protocol packages,
// Only after all the sub-packages have been received and the group package is completed, ipacket is set as a complete MySQL package
// Only then can we set the flag of re-routing
// If a request is divided into multiple MySQL packages, each MySQL package will also set the re-routing flag
ObMySQLRawPacket *input_packet = reinterpret_cast<ObMySQLRawPacket *>(ipacket);
input_packet->set_can_reroute_pkt(pkt20->get_flags().is_proxy_reroute());
input_packet->set_is_weak_read(pkt20->get_flags().is_weak_read());
// need test proxy_switch_route flag.
input_packet->set_proxy_switch_route(pkt20->get_flags().proxy_switch_route());
const int64_t t_len = context.extra_info_.get_total_len();
char *t_buffer = NULL;
if (t_len <= 0) {
// empty extra info, do nothing
// the allocate action would failed in `load data local` allocator
} else if (OB_ISNULL(t_buffer = reinterpret_cast<char *>(pool.alloc(t_len)))) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_ERROR("no memory available", "alloc_size", t_len, K(ret));
} else if (OB_FAIL(input_packet->extra_info_.assign(context.extra_info_, t_buffer, t_len))) {
LOG_ERROR("failed to assign extra info", K(ret));
}
input_packet->set_txn_free_route(pkt20->get_flags().txn_free_route());
context.reset();
// set again for sending response
context.proto20_last_pkt_seq_ = pkt20->get_seq();
context.proto20_last_request_id_ = pkt20->get_request_id();
if (pkt_rec_wrapper.enable_proto_dia()) {
pkt_rec_wrapper.record_recieve_obp20_packet(*pkt20, *input_packet);
}
}
return ret;
}
inline int Ob20ProtocolProcessor::decode_compressed_packet(
const char *comp_buf, const uint32_t comp_pktlen,
const uint32_t pktlen_before_compress, char *&pkt_body,
const uint32_t pkt_body_size)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(comp_buf) || OB_ISNULL(pkt_body)) {
ret = OB_INVALID_ARGUMENT;
LOG_ERROR("invalid arguement", KP(comp_buf),KP(pkt_body), K(ret));
} else if ((0 == pktlen_before_compress && OB_UNLIKELY(comp_pktlen != pkt_body_size))
|| (0 != pktlen_before_compress && OB_UNLIKELY(pktlen_before_compress != pkt_body_size))) {
ret = OB_ERR_UNEXPECTED;
LOG_ERROR("pkt_body_size is unexpected", K(pktlen_before_compress), K(comp_pktlen),
K(pkt_body_size), K(ret));
} else {
// pktlen_before_compress==0 means do not use compress
if (0 == pktlen_before_compress) {
pkt_body = const_cast<char *>(comp_buf);
} else {
ObZlibCompressor compressor;
int64_t decompress_data_len = 0;
if (OB_FAIL(compressor.decompress(comp_buf, comp_pktlen, pkt_body,
pktlen_before_compress, decompress_data_len))) {
LOG_ERROR("failed to decompress packet", K(ret));
} else if (OB_UNLIKELY(pktlen_before_compress != decompress_data_len)) {
ret = OB_ERR_UNEXPECTED;
LOG_ERROR("failed to decompress packet", K(pktlen_before_compress),
K(decompress_data_len), K(ret));
}
}
}
return ret;
}
inline int Ob20ProtocolProcessor::process_compressed_ob20_packet(uint32_t sessid,
ObProto20PktContext& context, ObMysqlPktContext &mysql_pkt_context,
obmysql::ObPacketRecordWrapper &pkt_rec_wrapper, ObICSMemPool& pool,
void *&ipacket, bool &need_decode_more)
{
int ret = OB_SUCCESS;
need_decode_more = true;
ObMySQLCompressedPacket *iraw_pkt = NULL;
if (OB_ISNULL(iraw_pkt = reinterpret_cast<ObMySQLCompressedPacket*>(ipacket))) {
ret = OB_ERR_UNEXPECTED;
LOG_ERROR("ipacket is null", K(ret));
} else if (context.is_multi_pkt_
&& OB_UNLIKELY(iraw_pkt->get_comp_seq() != static_cast<uint8_t>(context.comp_last_pkt_seq_ + 1))) {
ret = OB_ERR_UNEXPECTED;
LOG_ERROR("comp seq is unexpected", "last_seq", context.comp_last_pkt_seq_,
"comp_seq", iraw_pkt->get_comp_seq(), K(ret));
} else {
char *decompress_data_buf = NULL;
uint32_t decompress_data_size = (0 == iraw_pkt->get_uncomp_len()
? iraw_pkt->get_comp_len()
: iraw_pkt->get_uncomp_len());
int64_t alloc_size = static_cast<int64_t>(decompress_data_size);
if (pkt_rec_wrapper.enable_proto_dia()) {
pkt_rec_wrapper.record_recieve_mysql_pkt_fragment(iraw_pkt->get_comp_len());
}
//in order to reuse optimize memory, we put decompressed data into raw_pkt directly
char *tmp_buffer = NULL;
if (OB_ISNULL(tmp_buffer = reinterpret_cast<char *>(pool.alloc(alloc_size)))) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_ERROR("no memory available", K(alloc_size), K(ret));
} else {
decompress_data_buf = tmp_buffer;
Ob20ProtocolHeader header20;
header20.cp_hdr_.comp_len_ = iraw_pkt->get_comp_len();
header20.cp_hdr_.comp_seq_ = iraw_pkt->get_comp_seq();
header20.cp_hdr_.uncomp_len = iraw_pkt->get_uncomp_len();
if (OB_FAIL(decode_compressed_packet(iraw_pkt->get_cdata(), iraw_pkt->get_comp_len(),
iraw_pkt->get_uncomp_len(), decompress_data_buf,
decompress_data_size))) {
LOG_ERROR("fail to decode_compressed_packet", K(ret));
} else {
const char* start = decompress_data_buf;
// compressed 20 proto skip compress head
if (OB_FAIL(decode_ob20_header(start, start,
start + decompress_data_size, header20, sessid, false))) {
LOG_ERROR("invalid 20 protocol header", K(header20), K(sessid), K(ret));
} else if (OB_FAIL(do_body_checksum(start, header20))) {
LOG_ERROR("fail to do body checksum", K(header20), K(sessid), K(ret));
} else if (OB_FAIL(decode_ob20_body(pool, start, header20, (rpc::ObPacket*&)ipacket))) {
LOG_ERROR("fail to decode_compressed_body", K(sessid), K(header20), K(ret));
} else if (OB_FAIL(process_ob20_packet(context, mysql_pkt_context, pkt_rec_wrapper,
pool, ipacket, need_decode_more))) {
LOG_ERROR("fail to process fragment mysql packet", KP(start),
K(decompress_data_size), K(need_decode_more), K(ret));
} else {
// do nothing
}
}
}
}
return ret;
}
inline int Ob20ProtocolProcessor::decode_compressed_body(ObICSMemPool& pool, const char*& buf,
const uint32_t comp_pktlen, const uint8_t comp_pktseq, const uint32_t pktlen_before_compress,
rpc::ObPacket *&pkt)
{
INIT_SUCC(ret);
const char *pkt_body = buf;
buf += comp_pktlen;
ObMySQLCompressedPacket *cmdpkt = NULL;
if (OB_ISNULL(pkt_body)) {
ret = OB_INVALID_ARGUMENT;
LOG_ERROR("easy callback message null pointer", KP(pkt_body), K(ret));
} else if (OB_ISNULL(cmdpkt =
reinterpret_cast<ObMySQLCompressedPacket*>(pool.alloc(sizeof(ObMySQLCompressedPacket))))) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_ERROR("no memory available, close connection", "alloc_size", sizeof(ObMySQLCompressedPacket), K(ret));
} else {
cmdpkt = new (cmdpkt) ObMySQLCompressedPacket();
cmdpkt->set_content(pkt_body, comp_pktlen, comp_pktseq, pktlen_before_compress);
pkt = cmdpkt;
LOG_DEBUG("decompresse packet succ", KPC(cmdpkt));
}
return ret;
}
} // end of namespace obmysql
} // end of namespace oceanbase

View File

@ -39,7 +39,7 @@ public:
virtual int do_splice(observer::ObSMConnection& conn, ObICSMemPool& pool, void*& pkt, bool& need_decode_more);
private:
int do_header_checksum(const char *origin_start, const Ob20ProtocolHeader &hdr);
int do_header_checksum(const char *origin_start, const Ob20ProtocolHeader &hdr, bool need_check_compress);
int do_body_checksum(const char* buf, const Ob20ProtocolHeader &hdr);
int decode_extra_info(const Ob20ProtocolHeader &hdr,
const char*& payload_start,
@ -51,6 +51,20 @@ private:
int process_ob20_packet(ObProto20PktContext& context, ObMysqlPktContext &mysql_pkt_context,
obmysql::ObPacketRecordWrapper &pkt_rec_wrapper, ObICSMemPool& pool,
void *&ipacket, bool &need_decode_more);
int decode_ob20_header(const char*& origin_start, const char*& start, const char* end,
Ob20ProtocolHeader &header20, uint32_t sessid, bool need_check_compress);
int decode_compressed_packet(const char *comp_buf, const uint32_t comp_pktlen,
const uint32_t pktlen_before_compress, char *&pkt_body, const uint32_t pkt_body_size);
int process_compressed_ob20_packet(uint32_t sessid, ObProto20PktContext& context,
ObMysqlPktContext &mysql_pkt_context,
obmysql::ObPacketRecordWrapper &pkt_rec_wrapper, ObICSMemPool& pool,
void *&ipacket, bool &need_decode_more);
int after_process_mysql_packet(ObICSMemPool& pool, ObProto20PktContext& context,
obmysql::ObPacketRecordWrapper &pkt_rec_wrapper,
void *&ipacket, bool &need_decode_more, Ob20Packet *pkt20);
int decode_compressed_body(ObICSMemPool& pool, const char*& buf,
const uint32_t comp_pktlen, const uint8_t comp_pktseq,
const uint32_t pktlen_before_compress, rpc::ObPacket *&pkt);
Obp20Decoder* svr_decoders_[OBP20_SVR_END-OBP20_PROXY_MAX_TYPE] = {
&trace_info_dcd_,
&sess_info_dcd_,

View File

@ -542,10 +542,18 @@ inline int ObProto20Utils::fill_proto20_header(ObProtoEncodeParam &param) {
ObEasyBuffer easy_buffer(*param.ez_buf_);
ObProto20Context &proto20_context = *param.proto20_context_;
uint32_t compress_len = static_cast<uint32_t>(easy_buffer.read_avail_size() - OB_MYSQL_COMPRESSED_HEADER_SIZE);
uint8_t compress_seq = proto20_context.comp_seq_;
++proto20_context.comp_seq_;
uint32_t compress_len = 0;
uint8_t compress_seq = 0;
uint32_t uncompress_len = 0;
if (param.conn_->proxy_cap_flags_.is_ob_protocol_v2_compress()) {
// do nothing
} else {
compress_len = static_cast<uint32_t>(easy_buffer.read_avail_size() - OB_MYSQL_COMPRESSED_HEADER_SIZE);
compress_seq = proto20_context.comp_seq_;
++proto20_context.comp_seq_;
}
int16_t magic_num = OB20_PROTOCOL_MAGIC_NUM;
uint16_t version = OB20_PROTOCOL_VERSION_VALUE;
uint32_t connid = param.conn_id_;
@ -571,11 +579,14 @@ inline int ObProto20Utils::fill_proto20_header(ObProtoEncodeParam &param) {
} else if (OB_UNLIKELY(compress_len > OB_MYSQL_MAX_PAYLOAD_LENGTH)) {
ret = OB_ERR_UNEXPECTED;
LOG_ERROR("invalid compress_len", K(compress_len), K(OB_MYSQL_MAX_PAYLOAD_LENGTH), K(ret));
} else if (OB_FAIL(ObMySQLUtil::store_int3(start, proto20_context.header_len_, compress_len, pos))) {
} else if (!param.conn_->proxy_cap_flags_.is_ob_protocol_v2_compress()
&& OB_FAIL(ObMySQLUtil::store_int3(start, proto20_context.header_len_, compress_len, pos))) {
LOG_ERROR("fail to store int3", K(ret));
} else if (OB_FAIL(ObMySQLUtil::store_int1(start, proto20_context.header_len_, compress_seq, pos))) {
} else if (!param.conn_->proxy_cap_flags_.is_ob_protocol_v2_compress()
&& OB_FAIL(ObMySQLUtil::store_int1(start, proto20_context.header_len_, compress_seq, pos))) {
LOG_ERROR("fail to store int1", K(ret));
} else if (OB_FAIL(ObMySQLUtil::store_int3(start, proto20_context.header_len_, uncompress_len, pos))) {
} else if (!param.conn_->proxy_cap_flags_.is_ob_protocol_v2_compress()
&& OB_FAIL(ObMySQLUtil::store_int3(start, proto20_context.header_len_, uncompress_len, pos))) {
LOG_ERROR("fail to store int3", K(ret));
} else if (OB_FAIL(ObMySQLUtil::store_int2(start, proto20_context.header_len_, magic_num, pos))) {
LOG_ERROR("fail to store int2", K(ret));

View File

@ -171,6 +171,8 @@ union ObProxyCapabilityFlags
bool is_feedback_proxy_info_support() const { return 1 == cap_flags_.OB_CAP_FEEDBACK_PROXY_SHIFT
&& is_ob_protocol_v2_support(); }
bool is_ob_protocol_v2_compress() const { return 1 == cap_flags_.OB_CAP_OB_PROTOCOL_V2_COMPRESS
&& is_ob_protocol_v2_support(); }
uint64_t capability_;
struct CapabilityFlags
{

View File

@ -81,7 +81,8 @@ static int build_compressed_packet(ObEasyBuffer &src_buf,
ObZlibCompressor compressor;
bool use_real_compress = true;
if (context.use_checksum()) {
compressor.set_compress_level(0);
int64_t com_level = context.conn_->proxy_cap_flags_.is_ob_protocol_v2_compress() ? 6 : 0;
compressor.set_compress_level(com_level);
use_real_compress = !context.is_checksum_off_;
}
int64_t dst_data_size = 0;
@ -126,7 +127,7 @@ static int build_compressed_packet(ObEasyBuffer &src_buf,
}
SERVER_LOG(DEBUG, "succ to build compressed pkt", "comp_len", dst_data_size,
"comp_seq", context.seq_, K(len_before_compress), K(next_compress_size),
K(src_buf), K(dst_buf), K(context));
K(src_buf), K(dst_buf), K(context), K(context.conn_->sessid_));
src_buf.read(next_compress_size);
dst_buf.write(dst_data_size + OB_MYSQL_COMPRESSED_HEADER_SIZE);
++context.seq_;
@ -139,14 +140,19 @@ static int build_compressed_buffer(ObEasyBuffer &orig_send_buf,
ObCompressionContext &context)
{
int ret = OB_SUCCESS;
if (NULL != context.send_buf_) {
if (OB_ISNULL(context.conn_)) {
ret = OB_INVALID_ARGUMENT;
SERVER_LOG(WARN, "conn_ is null", K(context), K(ret));
} else if (NULL != context.send_buf_) {
ObEasyBuffer comp_send_buf(*context.send_buf_);
if (OB_UNLIKELY(!orig_send_buf.is_valid()) || OB_UNLIKELY(!comp_send_buf.is_valid())) {
ret = OB_ERR_UNEXPECTED;
SERVER_LOG(ERROR, "orig_send_buf or comp_send_buf is invalid", K(orig_send_buf), K(comp_send_buf), K(ret));
} else {
const int64_t max_read_step = context.get_max_read_step();
int64_t next_read_size = orig_send_buf.get_next_read_size(context.last_pkt_pos_, max_read_step);
bool is_v2_compress = context.conn_->proxy_cap_flags_.is_ob_protocol_v2_compress();
char * proxy_pos = is_v2_compress ? NULL : context.last_pkt_pos_;
int64_t next_read_size = orig_send_buf.get_next_read_size(proxy_pos, max_read_step);
int64_t last_read_size = 0;
if (next_read_size > (comp_send_buf.write_avail_size() - OB_MYSQL_COMPRESSED_HEADER_SIZE)) {
next_read_size = max_read_step;
@ -155,8 +161,9 @@ static int build_compressed_buffer(ObEasyBuffer &orig_send_buf,
while (OB_SUCC(ret)
&& next_read_size > 0
&& max_comp_pkt_size <= comp_send_buf.write_avail_size()) {
// v2 compress protocol not do this check
//error+ok/ok packet should use last seq
if (context.last_pkt_pos_ == orig_send_buf.read_pos() && context.is_proxy_compress_based()) {
if (!is_v2_compress && context.last_pkt_pos_ == orig_send_buf.read_pos() && context.is_proxy_compress_based()) {
--context.seq_;
}
@ -165,7 +172,7 @@ static int build_compressed_buffer(ObEasyBuffer &orig_send_buf,
} else {
//optimize for multi packet
last_read_size = next_read_size;
next_read_size = orig_send_buf.get_next_read_size(context.last_pkt_pos_, max_read_step);
next_read_size = orig_send_buf.get_next_read_size(proxy_pos, max_read_step);
if (next_read_size > (comp_send_buf.write_avail_size() - OB_MYSQL_COMPRESSED_HEADER_SIZE)) {
next_read_size = max_read_step;
}
@ -325,6 +332,11 @@ int ObMySQLRequestUtils::check_flush_param(ObFlushBufferParam &param)
} else if (OB_UNLIKELY(!param.orig_send_buf_.is_valid())) {
ret = OB_ERR_UNEXPECTED;
SERVER_LOG(ERROR, "orig_send_buf_ is invalid", K(param.orig_send_buf_), K(ret));
} else if (OB_ISNULL(param.comp_context_.conn_)) {
ret = OB_INVALID_ARGUMENT;
SERVER_LOG(WARN, "conn_ is null", K(param.comp_context_), K(ret));
} else if (param.comp_context_.conn_->proxy_cap_flags_.is_ob_protocol_v2_compress()){
// not check last pkt_pos and send_buf_
} else if (!param.comp_context_.use_compress()) {
if (OB_NOT_NULL(param.comp_context_.last_pkt_pos_)
|| OB_NOT_NULL(param.comp_context_.send_buf_)) {
@ -619,7 +631,13 @@ int ObMySQLRequestUtils::flush_compressed_buffer(bool pkt_has_completed, ObCompr
int ret = OB_SUCCESS;
int64_t need_hold_size = 0;
if (comp_context.need_hold_last_pkt(pkt_has_completed)) {
if (OB_ISNULL(comp_context.conn_)) {
ret = OB_INVALID_ARGUMENT;
SERVER_LOG(WARN, "conn_ is null", K(comp_context), K(ret));
} else if (comp_context.conn_->proxy_cap_flags_.is_ob_protocol_v2_compress()){
// do nothing
} else if (comp_context.need_hold_last_pkt(pkt_has_completed)) {
need_hold_size = orig_send_buf.proxy_read_avail_size(comp_context.last_pkt_pos_);
orig_send_buf.write(0 - need_hold_size);
SERVER_LOG(DEBUG, "need hold uncompleted proxy pkt", K(need_hold_size),
@ -641,11 +659,18 @@ int ObMySQLRequestUtils::flush_compressed_buffer(bool pkt_has_completed, ObCompr
}
}
if (OB_SUCC(ret) && false == pkt_has_completed) {
const bool need_reset_last_pkt_pos = (comp_context.last_pkt_pos_ == orig_send_buf.last());
if (OB_FAIL(ret)) {
// do nothing
} else if (false == pkt_has_completed) {
bool need_reset_last_pkt_pos = (comp_context.last_pkt_pos_ == orig_send_buf.last());
init_easy_buf(&orig_send_buf.buf_, reinterpret_cast<char *>(&orig_send_buf.buf_ + 1),
NULL, orig_send_buf.orig_buf_size());
// v2 compression not check
if (comp_context.conn_->proxy_cap_flags_.is_ob_protocol_v2_compress()) {
need_reset_last_pkt_pos = false;
}
if (need_reset_last_pkt_pos) {
if (need_hold_size > 0) {
MEMMOVE(orig_send_buf.last(), comp_context.last_pkt_pos_, need_hold_size);

View File

@ -177,6 +177,7 @@ public:
{
comp_last_pkt_seq_ = 0;
is_multi_pkt_ = false;
is_comp_packet_ = false;
proto20_last_request_id_ = 0;
proto20_last_pkt_seq_ = 0;
extra_info_.reset();
@ -188,6 +189,7 @@ public:
K_(proto20_last_request_id),
K_(proto20_last_pkt_seq),
K_(extra_info),
K_(is_comp_packet),
"used", arena_.used(),
"total", arena_.total());
@ -198,6 +200,8 @@ public:
uint8_t proto20_last_pkt_seq_;
Ob20ExtraInfo extra_info_;
common::ObArenaAllocator arena_;
bool is_comp_packet_;
void set_tenant_id(uint64_t tenant_id)
{
tenant_id_ = tenant_id;
@ -314,7 +318,7 @@ public:
{
int64_t pos = 0;
J_OBJ_START();
J_KV(K_(sessid), K_(type), K_(is_checksum_off), K_(seq), KP_(last_pkt_pos));
J_KV(K_(sessid), K_(type), K_(is_checksum_off), K_(seq), KP_(last_pkt_pos), K_(comp_level));
J_COMMA();
if (NULL != send_buf_) {
J_KV("send_buf", ObEasyBuffer(*send_buf_));
@ -333,6 +337,7 @@ public:
char *last_pkt_pos_;//proxy last pkt(error+ok, eof+ok, ok)'s pos in orig_ezbuf, default is null
uint32_t sessid_;
observer::ObSMConnection *conn_;
int64_t comp_level_;
private:
DISALLOW_COPY_AND_ASSIGN(ObCompressionContext);

View File

@ -86,7 +86,8 @@ public:
obmysql::ObCompressType get_compress_type() {
obmysql::ObCompressType type_ret = obmysql::ObCompressType::NO_COMPRESS;
//unauthed connection, treat it do not use compress
if (is_in_authed_phase() && 1 == cap_flags_.cap_flags_.OB_CLIENT_COMPRESS) {
if (is_in_authed_phase() && (1 == cap_flags_.cap_flags_.OB_CLIENT_COMPRESS
|| proxy_cap_flags_.is_ob_protocol_v2_compress())) {
if (is_proxy_) {
if (1 == proxy_cap_flags_.cap_flags_.OB_CAP_CHECKSUM) {
type_ret = obmysql::ObCompressType::PROXY_CHECKSUM;

View File

@ -14,11 +14,15 @@
#include "rpc/obmysql/packet/ompk_handshake.h"
ObString __attribute__((weak)) get_display_mysql_version_cfg()
{
return ObString((DEFAULT_MYSQL_VERSION_CSTR)); // default server version string for mysql mode
}
using namespace oceanbase::common;
using namespace oceanbase::obmysql;
//FIXME::here we use hard code to avoid security flaw from AliYun. In fact, ob do not use any mysql code
const char *OMPKHandshake::SERVER_VERSION_STR = "5.7.25";
const char *OMPKHandshake::AUTH_PLUGIN_MYSQL_NATIVE_PASSWORD = "mysql_native_password";
const char *OMPKHandshake::AUTH_PLUGIN_MYSQL_OLD_PASSWORD = "mysql_old_password";
const char *OMPKHandshake::AUTH_PLUGIN_MYSQL_CLEAR_PASSWORD = "mysql_clear_password";
@ -29,7 +33,7 @@ OMPKHandshake::OMPKHandshake()
terminated_(0)
{
protocol_version_ = 10; // Protocol::HandshakeV10
server_version_ = ObString::make_string(SERVER_VERSION_STR);
server_version_ = get_display_mysql_version_cfg();
thread_id_ = 1;
memset(scramble_buff_, 'a', 8);
filler_ = 0;
@ -182,8 +186,7 @@ int OMPKHandshake::decode()
ObMySQLUtil::get_uint1(pos, protocol_version_);
int64_t sv_len = strlen(pos);
server_version_.assign_ptr(SERVER_VERSION_STR,
static_cast<ObString::obstr_size_t>(strlen(SERVER_VERSION_STR)));
server_version_ = get_display_mysql_version_cfg();
pos += sv_len + 1;
ObMySQLUtil::get_uint4(pos, thread_id_);

View File

@ -18,6 +18,10 @@
#include "rpc/obmysql/ob_mysql_util.h"
#include "rpc/obmysql/ob_mysql_packet.h"
#define DEFAULT_MYSQL_VERSION_CSTR "5.7.25"
extern ObString get_display_mysql_version_cfg();
namespace oceanbase
{
namespace obmysql
@ -118,7 +122,6 @@ private:
private:
DISALLOW_COPY_AND_ASSIGN(OMPKHandshake);
static const char *SERVER_VERSION_STR;
const static char *AUTH_PLUGIN_MYSQL_NATIVE_PASSWORD; // Secure Password Authentication
const static char *AUTH_PLUGIN_MYSQL_OLD_PASSWORD; // Old Password Authentication

View File

@ -142,7 +142,9 @@ ObMPConnect::ObMPConnect(const ObGlobalContext &gctx)
client_ip_(),
tenant_name_(),
db_name_(),
deser_ret_(OB_SUCCESS)
deser_ret_(OB_SUCCESS),
allocator_(ObModIds::OB_SQL_REQUEST),
asr_mem_pool_(&allocator_)
{
client_ip_buf_[0] = '\0';
user_name_var_[0] = '\0';
@ -684,11 +686,101 @@ int ObMPConnect::load_privilege_info(ObSQLSessionInfo &session)
login_info.db_ = db_name;
}
}
if (OB_SUCC(ret)) {
LOG_TRACE("some important information required for login verification, print it before doing login", K(ret), K(ObString(sizeof(conn->scramble_buf_), conn->scramble_buf_)), K(conn->is_proxy_), K(conn->client_type_), K(hsr_.get_auth_plugin_name()), K(hsr_.get_auth_response()));
if (OB_FAIL(ret)) {
// Do nothing
} else {
login_info.scramble_str_.assign_ptr(conn->scramble_buf_, sizeof(conn->scramble_buf_));
login_info.passwd_ = hsr_.get_auth_response();
login_info.passwd_ = hsr_.get_auth_response();// Assume client is use mysql_native_password
bool is_empty_passwd = false;
if (OB_FAIL(schema_guard.is_user_empty_passwd(login_info, is_empty_passwd))) {
LOG_WARN("failed to check is user account is empty && login_info.passwd_ is empty", K(ret), K(login_info.passwd_));
} else if (!is_empty_passwd && // user account with empty password do not need auth switch, same as MySQL 5.7 and 8.x
OB_CLIENT_NON_STANDARD == conn->client_type_ && // client is not OB's C/JAVA client
!hsr_.get_auth_plugin_name().empty() && // client do not use mysql_native_method
hsr_.get_auth_plugin_name().compare(AUTH_PLUGIN_MYSQL_NATIVE_PASSWORD)) {
// Client is not use mysql_native_password method,
// but observer only support mysql_native_password in user account's authentication,
// so observer need tell client use mysql_native_password method by sending "AuthSwitchRequest"
LOG_TRACE("auth plugin from client is not mysql_native_password, start to auth switch request", K(ret), K(hsr_.get_auth_plugin_name()));
conn->set_auth_switch_phase(); // State of connection turn to auth_switch_phase
OMPKAuthSwitch auth_switch;
auth_switch.set_plugin_name(ObString(AUTH_PLUGIN_MYSQL_NATIVE_PASSWORD));
// "AuthSwitchRequest" carry 20 bit random salt value(MySQL call it scramble) to client which has sent in "Initial Handshake Packet"
auth_switch.set_scramble(ObString(sizeof(conn->scramble_buf_), conn->scramble_buf_));
/*-------------------START-----------------If error occur, disconnect-------------------START-----------------*/
if (OB_FAIL(packet_sender_.response_packet(auth_switch, &session))) {
RPC_LOG(WARN, "failed to send auth switch request packet, disconnect", K(auth_switch), K(ret));
LOG_WARN("failed to send auth switch request packet, disconnect", K(auth_switch), K(ret));
packet_sender_.disable_response(); // The connection is about to be closed, do not need response ok pkt or err pkt, so disable it
disconnect();// If send "AuthSwitchRequest" failed, observer need disconnect with client
} else if (OB_FAIL(packet_sender_.flush_buffer(false/*is_last*/))) { // "AuthSwitchRequest" may not have been sent yet, flush the buffer to ensure it has been sent.
RPC_LOG(WARN, "failed to flush socket buffer while sending auth switch request packet, disconnect", K(auth_switch), K(ret));
LOG_WARN("failed to flush socket buffer while sending auth switch request packet, disconnect", K(auth_switch), K(ret));
packet_sender_.disable_response(); // The connection is about to be closed, do not need response ok pkt or err pkt, so disable it
disconnect();// If send "AuthSwitchRequest" failed, observer need disconnect with client
} else {
LOG_TRACE("suuc to send auth switch request", K(ret));
obmysql::ObMySQLPacket *asr_pkt = NULL;
int64_t start_wait_asr_time = ObTimeUtil::current_time();
int receive_asr_times = 0;
while (OB_SUCC(ret) && OB_ISNULL(asr_pkt)) {
++receive_asr_times;
usleep(10 * 1000); // Sleep 10 ms at every time trying receive auth-switch-response mysql pkt
// TO DO:
// In most unix system, The max TCP Retransmission Timeout is under 240 seconds,
// we need to set a suitable timeout, what should this be?
if (ObTimeUtil::current_time() - start_wait_asr_time > 10000000) {
ret = OB_WAIT_NEXT_TIMEOUT;
RPC_LOG(WARN, "read auth switch response pkt timeout, disconnect", K(ret), K(receive_asr_times));
LOG_WARN("read auth switch response pkt timeout, disconnect", K(ret), K(receive_asr_times));
packet_sender_.disable_response(); // The connection is about to be closed, do not need response ok pkt or err pkt, so disable it
disconnect(); // If receive "AuthSwitchResponse" timeout, observer need disconnect with client
} else if (OB_FAIL(read_packet(asr_mem_pool_, asr_pkt))) {
RPC_LOG(WARN, "failed to read auth switch response pkt, disconnect", K(ret), K(receive_asr_times));
LOG_WARN("failed to read auth switch response pkt, disconnect", K(ret), K(receive_asr_times));
packet_sender_.disable_response(); // The connection is about to be closed, do not need response ok pkt or err pkt, so disable it
disconnect(); // If receive "AuthSwitchResponse" failed, observer need disconnect with client
} else {
LOG_WARN("succ try to read auth switch response pkt", K(ret), K(receive_asr_times), KP(asr_pkt));
}
}
if (OB_FAIL(ret)) {
// Do nothing
} else if (OB_ISNULL(asr_pkt)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("unexpected null ptr, disconnect", K(ret));
packet_sender_.disable_response(); // The connection is about to be closed, do not need response ok pkt or err pkt, so disable it
disconnect(); // If receive "AuthSwitchResponse" failed, observer need disconnect with client
} else {
/*--------------------END------------------if error occur, disconnect--------------------END------------------*/
LOG_TRACE("suuc to receive auth switch response", K(ret));
const obmysql::ObMySQLRawPacket *asr_raw_pkt = reinterpret_cast<const ObMySQLRawPacket*>(asr_pkt);
const char *auth_data = asr_raw_pkt->get_cdata();
const int64_t auth_data_len = asr_raw_pkt->get_clen();
void *auth_buf = NULL;
// Length of authentication response data in AuthSwitchResponse which is using mysql_native_password methon is 20 byte,
// the ObSMConnection::SCRAMBLE_BUF_SIZE is 20
if (ObSMConnection::SCRAMBLE_BUF_SIZE != auth_data_len) {
ret = OB_PASSWORD_WRONG;
LOG_WARN("invalid length of authentication response data", K(ret), K(auth_data_len), K(ObString(auth_data_len, auth_data)));
} else if (OB_ISNULL(auth_buf = asr_mem_pool_.alloc(auth_data_len))) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("alloc auth data buffer for auth switch response failed", K(ret), K(auth_data_len));
} else {
// packet_sender_.release_packet will recycle mem of auth_data, need using mem allocated by asr_mem_pool_ to save it
MEMCPY(auth_buf, auth_data, auth_data_len);
login_info.scramble_str_.assign_ptr(conn->scramble_buf_, sizeof(conn->scramble_buf_));
login_info.passwd_.assign_ptr(static_cast<const char*>(auth_buf), auth_data_len);
}
packet_sender_.release_packet(asr_pkt);
asr_pkt = NULL;
asr_raw_pkt = NULL;
}
}
conn->set_auth_phase(); // State of connection turn to auth_phase
}
}
if (OB_FAIL(ret)) {
} else if (OB_FAIL(schema_guard.check_user_access(login_info, session_priv, ssl_st, user_info))) {
@ -1812,6 +1904,7 @@ int ObMPConnect::check_update_proxy_capability(ObSMConnection &conn) const
} else {
server_proxy_cap_flag.cap_flags_.OB_CAP_FEEDBACK_PROXY_SHIFT = 0;
}
server_proxy_cap_flag.cap_flags_.OB_CAP_OB_PROTOCOL_V2_COMPRESS = 1;
conn.proxy_cap_flags_.capability_ = (server_proxy_cap_flag.capability_ & client_proxy_cap); // if old java client, set it 0
LOG_DEBUG("Negotiated capability",

View File

@ -30,6 +30,24 @@ struct ObSMConnection;
ObString extract_user_name(const ObString &in);
int extract_user_tenant(const ObString &in, ObString &user_name, ObString &tenant_name);
int extract_tenant_id(const ObString &tenant_name, uint64_t &tenant_id);
class AuthSwitchResonseMemPool : public obmysql::ObICSMemPool
{
public:
explicit AuthSwitchResonseMemPool(ObIAllocator *allocator)
: allocator_(allocator)
{}
virtual ~AuthSwitchResonseMemPool() {}
void *alloc(int64_t size) override
{
return allocator_->alloc(size);
}
private:
ObIAllocator *allocator_;
};
class ObMPConnect
: public ObMPBase
{
@ -146,6 +164,8 @@ private:
char proxied_user_name_var_[OB_MAX_USER_NAME_BUF_LENGTH];
char db_name_var_[OB_MAX_DATABASE_NAME_BUF_LENGTH];
int deser_ret_;
ObArenaAllocator allocator_;
AuthSwitchResonseMemPool asr_mem_pool_;
int32_t client_port_;
}; // end of class ObMPConnect

View File

@ -161,13 +161,15 @@ int ObMPPacketSender::do_init(rpc::ObRequest *req,
// init proto20 context
bool is_proto20_supported = (OB_2_0_CS_TYPE == conn->get_cs_protocol_type());
bool is_proto20_compress = conn->proxy_cap_flags_.is_ob_protocol_v2_compress();
if (is_proto20_supported) {
proto20_context_.reset();
proto20_context_.is_proto20_used_ = is_proto20_supported;
proto20_context_.comp_seq_ = comp_seq;
proto20_context_.request_id_ = conn->proto20_pkt_context_.proto20_last_request_id_;
proto20_context_.proto20_seq_ = static_cast<uint8_t>(conn->proto20_pkt_context_.proto20_last_pkt_seq_ + 1);
proto20_context_.header_len_ = OB20_PROTOCOL_HEADER_LENGTH + OB_MYSQL_COMPRESSED_HEADER_SIZE;
// if v2 compress protocol, not add compress head here
proto20_context_.header_len_ = OB20_PROTOCOL_HEADER_LENGTH + (is_proto20_compress ? 0 : OB_MYSQL_COMPRESSED_HEADER_SIZE);
proto20_context_.tailer_len_ = OB20_PROTOCOL_TAILER_LENGTH;
proto20_context_.next_step_ = START_TO_FILL_STEP;
proto20_context_.is_checksum_off_ = false;

View File

@ -911,6 +911,9 @@ OB_INLINE int ObMPQuery::do_process(ObSQLSessionInfo &session,
audit_record.user_client_addr_ = session.get_user_client_addr();
audit_record.user_group_ = THIS_WORKER.get_group_id();
MEMCPY(audit_record.sql_id_, ctx_.sql_id_, (int32_t)sizeof(audit_record.sql_id_));
MEMCPY(audit_record.format_sql_id_, ctx_.format_sql_id_, (int32_t)sizeof(audit_record.format_sql_id_));
audit_record.format_sql_id_[common::OB_MAX_SQL_ID_LENGTH] = '\0';
if (NULL != plan) {
audit_record.plan_type_ = plan->get_plan_type();
audit_record.table_scan_ = plan->contain_table_scan();

View File

@ -1419,16 +1419,6 @@ int ObInnerSQLConnection::commit()
return ret;
}
int ObInnerSQLConnection::execute_write(const uint64_t tenant_id, const char *sql,
int64_t &affected_rows, bool is_user_sql, const common::ObAddr *sql_exec_addr)
{
int ret = OB_SUCCESS;
if (OB_FAIL(execute_write(tenant_id, ObString::make_string(sql), affected_rows, is_user_sql, sql_exec_addr))) {
LOG_WARN("execute_write failed", K(ret), K(tenant_id), K(sql));
}
return ret;
}
int ObInnerSQLConnection::execute_write(const uint64_t tenant_id, const ObString &sql,
int64_t &affected_rows, bool is_user_sql, const common::ObAddr *sql_exec_addr)
{
@ -1618,7 +1608,7 @@ int ObInnerSQLConnection::get_session_timeout_for_rpc(int64_t &query_timeout, in
}
int ObInnerSQLConnection::execute_read(const uint64_t tenant_id,
const char *sql,
const ObString &sql,
ObISQLClient::ReadResult &res,
bool is_user_sql,
const common::ObAddr *sql_exec_addr)

View File

@ -150,15 +150,12 @@ public:
const int32_t group_id = 0);
int destroy(void);
inline void reset() { destroy(); }
virtual int execute_read(const uint64_t tenant_id, const char *sql,
virtual int execute_read(const uint64_t tenant_id, const ObString &sql,
common::ObISQLClient::ReadResult &res, bool is_user_sql = false,
const common::ObAddr *sql_exec_addr = nullptr/* ddl inner sql execution addr */) override;
virtual int execute_read(const int64_t cluster_id, const uint64_t tenant_id, const ObString &sql,
common::ObISQLClient::ReadResult &res, bool is_user_sql = false,
const common::ObAddr *sql_exec_addr = nullptr/* ddl inner sql execution addr */) override;
virtual int execute_write(const uint64_t tenant_id, const char *sql,
int64_t &affected_rows, bool is_user_sql = false,
const common::ObAddr *sql_exec_addr = nullptr/* ddl inner sql execution addr */) override;
virtual int execute_write(const uint64_t tenant_id, const ObString &sql,
int64_t &affected_rows, bool is_user_sql = false,
const common::ObAddr *sql_exec_addr = nullptr) override;

View File

@ -85,12 +85,12 @@ public:
virtual common::sqlclient::ObSQLConnPoolType get_type() override { return common::sqlclient::INNER_POOL; }
virtual common::sqlclient::DblinkDriverProto get_pool_link_driver_proto() override { return common::sqlclient::DBLINK_DRV_OB; }
// for dblink
virtual int create_dblink_pool(const common::sqlclient::dblink_param_ctx &param_ctx, const ObAddr &server,
virtual int create_dblink_pool(const common::sqlclient::dblink_param_ctx &param_ctx, const ObString &host_name, int32_t port,
const ObString &db_tenant, const ObString &db_user,
const ObString &db_pass, const ObString &db_name,
const common::ObString &conn_str,
const common::ObString &cluster_str) override
{ UNUSEDx(param_ctx, server, db_tenant, db_user, db_pass, db_name, conn_str); return OB_SUCCESS; }
{ UNUSEDx(param_ctx, host_name, port, db_tenant, db_user, db_pass, db_name, conn_str); return OB_SUCCESS; }
virtual int acquire_dblink(const sqlclient::dblink_param_ctx &param_ctx, common::sqlclient::ObISQLConnection *&dblink_conn)
{ UNUSEDx(param_ctx, dblink_conn); return OB_SUCCESS; }
virtual int release_dblink(common::sqlclient::ObISQLConnection *dblink_conn)

View File

@ -1104,10 +1104,17 @@ int ObGvSqlAudit::fill_cells(obmysql::ObMySQLRequestRecord &record)
int64_t len = min(record.data_.proxy_user_name_len_, OB_MAX_USER_NAME_LENGTH);
cells[cell_idx].set_varchar(record.data_.proxy_user_name_,
static_cast<ObString::obstr_size_t>(len));
cells[cell_idx].set_collation_type(ObCharset::get_default_collation(
ObCharset::get_default_charset()));
} break;
//format_sql_id
case FORMAT_SQL_ID: {
cells[cell_idx].set_varchar("");
if (OB_MAX_SQL_ID_LENGTH == strlen(record.data_.format_sql_id_)) {
cells[cell_idx].set_varchar(record.data_.format_sql_id_,
static_cast<ObString::obstr_size_t>(OB_MAX_SQL_ID_LENGTH));
} else {
cells[cell_idx].set_varchar("");
}
cells[cell_idx].set_collation_type(ObCharset::get_default_collation(
ObCharset::get_default_charset()));
} break;

View File

@ -268,20 +268,32 @@ int ObTenantVirtualOutline::fill_cells(const ObOutlineInfo *outline_info)
break;
}
case FORMAT_SQL_TEXT : {
ObString str("");
cells[cell_idx].set_lob_value(ObLongTextType, str.ptr(), 0);
cells[cell_idx].set_collation_type(
ObCharset::get_default_collation(ObCharset::get_default_charset()));
ObString format_sql_text;
if (OB_FAIL(ob_write_string(*allocator_, outline_info->get_format_sql_text_str(), format_sql_text))) {
LOG_WARN("fail to deep copy obstring", K(ret),
K(outline_info->get_format_sql_text_str()), K(format_sql_text));
} else {
cells[cell_idx].set_lob_value(ObLongTextType, format_sql_text.ptr(),
static_cast<int32_t>(format_sql_text.length()));
cells[cell_idx].set_collation_type(
ObCharset::get_default_collation(ObCharset::get_default_charset()));
}
break;
}
case FORMAT_SQL_ID : {
cells[cell_idx].set_varchar("");
cells[cell_idx].set_collation_type(
ObCharset::get_default_collation(ObCharset::get_default_charset()));
ObString format_sql_id;
if (OB_FAIL(ob_write_string(*allocator_, outline_info->get_format_sql_id_str(), format_sql_id))) {
LOG_WARN("fail to deep copy obstring", K(ret),
K(outline_info->get_format_sql_id_str()), K(format_sql_id));
} else {
cells[cell_idx].set_varchar(format_sql_id);
cells[cell_idx].set_collation_type(
ObCharset::get_default_collation(ObCharset::get_default_charset()));
}
break;
}
case FORMAT_OUTLINE : {
cells[cell_idx].set_int(static_cast<int64_t>(false));
cells[cell_idx].set_int(static_cast<int64_t>(outline_info->is_format()));
break;
}
default: {

View File

@ -18,7 +18,6 @@
#include "sql/monitor/ob_monitor_info_manager.h"
#include "sql/monitor/ob_phy_plan_monitor_info.h"
#include "share/diagnosis/ob_sql_plan_monitor_node_list.h"
#include "observer/ob_server.h"
#include <algorithm> // std::sort
using namespace oceanbase::observer;
@ -694,7 +693,6 @@ int ObVirtualSqlPlanMonitor::convert_node_to_row(ObMonitorNode &node, ObNewRow *
ret = OB_ERR_UNEXPECTED;
SERVER_LOG(WARN, "cur row cell is NULL", K(ret));
}
uint64_t cpu_khz = OBSERVER.get_cpu_frequency_khz();
for (int64_t cell_idx = 0;
OB_SUCC(ret) && cell_idx < output_column_ids_.count();
++cell_idx) {
@ -733,11 +731,11 @@ int ObVirtualSqlPlanMonitor::convert_node_to_row(ObMonitorNode &node, ObNewRow *
}
case DB_TIME: {
// concept:
cells[cell_idx].set_int(node.db_time_ / cpu_khz);
cells[cell_idx].set_int(node.db_time_);
break;
}
case USER_IO_WAIT_TIME: {
cells[cell_idx].set_int(node.block_time_ / cpu_khz);
cells[cell_idx].set_int(node.block_time_);
break;
}
case FIRST_REFRESH_TIME: {

View File

@ -34587,9 +34587,12 @@ int ObDDLService::check_outline_exist(share::schema::ObOutlineInfo &outline_info
} else if (OB_UNLIKELY(OB_INVALID_ID == outline_info.get_tenant_id()
|| OB_INVALID_ID == outline_info.get_database_id()
|| outline_info.get_name_str().empty()
|| (outline_info.get_signature_str().empty() && !ObOutlineInfo::is_sql_id_valid(outline_info.get_sql_id_str())))) {
|| (!outline_info.is_format() && outline_info.get_signature_str().empty() &&
!ObOutlineInfo::is_sql_id_valid(outline_info.get_sql_id_str()))
|| (outline_info.is_format() && outline_info.get_format_sql_text_str().empty() &&
!ObOutlineInfo::is_sql_id_valid(outline_info.get_format_sql_id_str())))) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid argument", K(outline_info), K(ret));
LOG_WARN("invalid argument", K(outline_info.is_format()), K(outline_info.get_format_sql_text_str().empty()), K(ObOutlineInfo::is_sql_id_valid(outline_info.get_format_sql_id_str())), K(outline_info), K(ret));
} else {
is_update = false;
bool is_outline_exist_with_name = false;
@ -34600,6 +34603,7 @@ int ObDDLService::check_outline_exist(share::schema::ObOutlineInfo &outline_info
outline_info.get_database_id(),
outline_info.get_name_str(),
outline_id,
outline_info.is_format(),
is_outline_exist_with_name))) {
LOG_WARN("failed to check if outline_name exists", K(outline_info), K(ret));
} else {
@ -34608,6 +34612,7 @@ int ObDDLService::check_outline_exist(share::schema::ObOutlineInfo &outline_info
outline_info.get_tenant_id(),
outline_info.get_database_id(),
outline_info.get_signature_str(),
outline_info.is_format(),
is_outline_exist_with_signature_or_sql_id))) {
LOG_WARN("failed to check if signature exist", K(outline_info), K(ret));
}
@ -34615,7 +34620,8 @@ int ObDDLService::check_outline_exist(share::schema::ObOutlineInfo &outline_info
if (OB_FAIL(schema_service_->check_outline_exist_with_sql_id(
outline_info.get_tenant_id(),
outline_info.get_database_id(),
outline_info.get_sql_id_str(),
(outline_info.is_format() ? outline_info.get_format_sql_id_str() : outline_info.get_sql_id_str()),
outline_info.is_format(),
is_outline_exist_with_signature_or_sql_id))) {
LOG_WARN("failed to check if sql id exist", K(outline_info), K(ret));
}
@ -34632,6 +34638,7 @@ int ObDDLService::check_outline_exist(share::schema::ObOutlineInfo &outline_info
outline_info.get_tenant_id(),
outline_info.get_database_id(),
outline_info.get_name_str(),
outline_info.is_format(),
orig_outline))) {
LOG_WARN("failed to get origin outline info", K(outline_info), K(ret));
} else if (OB_ISNULL(orig_outline)) {
@ -34649,9 +34656,11 @@ int ObDDLService::check_outline_exist(share::schema::ObOutlineInfo &outline_info
ret = OB_ERR_OUTLINE_EXIST;
LOG_USER_ERROR(OB_ERR_OUTLINE_EXIST, outline_info.get_name_str().length(), outline_info.get_name_str().ptr());
} else if (is_outline_exist_with_signature_or_sql_id) {
ObString outline_name;
outline_name = outline_info.is_format() ? outline_info.get_format_sql_text_str() : outline_info.get_sql_text_str();
ret = OB_ERR_OUTLINE_EXIST;
LOG_USER_ERROR(OB_ERR_OUTLINE_EXIST, outline_info.get_sql_text_str().length(),
outline_info.get_sql_text_str().ptr());
LOG_USER_ERROR(OB_ERR_OUTLINE_EXIST, outline_name.length(),
outline_name.ptr());
} else {/*do nothing*/}
}
return ret;
@ -34725,6 +34734,7 @@ int ObDDLService::alter_outline_in_trans(const obrpc::ObAlterOutlineArg &arg)
const ObString &database_name = arg.db_name_;
const ObString &outline_name = alter_outline_info.get_name_str();
const ObOutlineInfo *orig_outline_info = NULL;
bool is_format = alter_outline_info.is_format();
if (database_name.empty() || outline_name.empty()) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("database name or outline name is empty", K(alter_outline_info),
@ -34732,6 +34742,7 @@ int ObDDLService::alter_outline_in_trans(const obrpc::ObAlterOutlineArg &arg)
} else if (OB_FAIL(schema_guard.get_outline_info_with_name(tenant_id,
database_name,
outline_name,
is_format,
orig_outline_info))) {
LOG_WARN("failed to get_outline_info_with_name", K(tenant_id),
K(database_name), K(outline_name), K(ret));
@ -34899,7 +34910,7 @@ int ObDDLService::drop_outline(const obrpc::ObDropOutlineArg &arg)
//do nothing
} else if (OB_FAIL(schema_service_->check_outline_exist_with_name(tenant_id, database_id,
outline_name, outline_id,
outline_exist))) {
arg.is_format_, outline_exist))) {
LOG_WARN("check_outline_exist failed", K(tenant_id), K(database_name), K(outline_name), K(ret));
} else if (!outline_exist) {
ret = OB_OUTLINE_NOT_EXIST;

View File

@ -6734,7 +6734,7 @@ int ObRootService::create_outline(const ObCreateOutlineArg &arg)
bool is_update = false;
if (OB_SUCC(ret)) {
if (OB_FAIL(ddl_service_.check_outline_exist(outline_info, is_or_replace, is_update))) {
LOG_WARN("failed to check_outline_exist", K(outline_info), K(ret));
LOG_WARN("failed to check_outline_exist", K(outline_info), K(is_or_replace), K(is_update), K(ret));
}
}

View File

@ -632,6 +632,11 @@ bool ObTTLDutyDurationChecker::check(const ObConfigItem& t) const
return OB_SUCCESS == common::ObTTLUtil::parse(t.str(), duty_duration) && duty_duration.is_valid();
}
bool ObMySQLVersionLengthChecker::check(const ObConfigItem& t) const
{
return STRLEN(t.str()) < 16; // length of MySQL version is less then 16
}
bool ObConfigPublishSchemaModeChecker::check(const ObConfigItem& t) const
{
return 0 == t.case_compare(PUBLISH_SCHEMA_MODE_BEST_EFFORT)

View File

@ -636,6 +636,16 @@ private:
DISALLOW_COPY_AND_ASSIGN(ObTTLDutyDurationChecker);
};
class ObMySQLVersionLengthChecker : public ObConfigChecker {
public:
ObMySQLVersionLengthChecker()
{}
virtual ~ObMySQLVersionLengthChecker(){};
bool check(const ObConfigItem& t) const;
private:
DISALLOW_COPY_AND_ASSIGN(ObMySQLVersionLengthChecker);
};
class ObConfigPublishSchemaModeChecker
: public ObConfigChecker
{

View File

@ -61,8 +61,9 @@ SQL_MONITOR_STATNAME_DEF(SSTABLE_INSERT_ROW_COUNT, sql_monitor_statname::INT, "s
SQL_MONITOR_STATNAME_DEF(SSTABLE_INSERT_CG_ROW_COUNT, sql_monitor_statname::INT, "sstable insert cg_row count", "sstable insert cg row count")
// Table Scan stat
SQL_MONITOR_STATNAME_DEF(IO_READ_BYTES, sql_monitor_statname::CAPACITY, "total io bytes read from disk", "total io bytes read from storage")
SQL_MONITOR_STATNAME_DEF(TOTAL_READ_BYTES, sql_monitor_statname::CAPACITY, "total bytes processed by storage", "total bytes processed by storage, including memtable")
SQL_MONITOR_STATNAME_DEF(TOTAL_READ_ROW_COUNT, sql_monitor_statname::INT, "total rows processed by storage", "total rows processed by storage, including memtable")
SQL_MONITOR_STATNAME_DEF(SSSTORE_READ_BYTES, sql_monitor_statname::CAPACITY, "total bytes processed by ssstore", "total bytes processed by ssstore")
SQL_MONITOR_STATNAME_DEF(SSSTORE_READ_ROW_COUNT, sql_monitor_statname::INT, "total rows processed by ssstore", "total rows processed by ssstore")
SQL_MONITOR_STATNAME_DEF(MEMSTORE_READ_ROW_COUNT, sql_monitor_statname::INT, "total rows processed by memstore", "total rows processed by memstore")
//end
SQL_MONITOR_STATNAME_DEF(MONITOR_STATNAME_END, sql_monitor_statname::INVALID, "monitor end", "monitor stat name end")

View File

@ -14,6 +14,9 @@
#include "share/diagnosis/ob_sql_plan_monitor_node_list.h"
#include "lib/rc/ob_rc.h"
#include "share/ob_thread_mgr.h"
#include "common/ob_smart_call.h"
#include "sql/engine/ob_operator.h"
#include "observer/ob_server.h"
using namespace oceanbase::common;
using namespace oceanbase::sql;
@ -21,21 +24,6 @@ using namespace oceanbase::lib;
const char *ObPlanMonitorNodeList::MOD_LABEL = "SqlPlanMon";
int ObMonitorNode::add_rt_monitor_node(ObMonitorNode *node)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(node) ||
OB_NOT_NULL(node->prev_) ||
OB_NOT_NULL(node->next_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("unexpected node", K(node));
} else {
next_ = node;
node->prev_ = this;
}
return ret;
}
ObPlanMonitorNodeList::ObPlanMonitorNodeList() :
inited_(false),
destroyed_(false),
@ -135,8 +123,9 @@ int ObPlanMonitorNodeList::submit_node(ObMonitorNode &node)
LOG_WARN("fail alloc mem", K(mem_size), K(ret));
} else {
deep_cp_node = new(buf) ObMonitorNode(node);
deep_cp_node->covert_to_static_node();
int64_t req_id = 0;
if(OB_FAIL(queue_.push(deep_cp_node, req_id))) {
if (OB_FAIL(queue_.push(deep_cp_node, req_id))) {
//sql audit槽位已满时会push失败, 依赖后台线程进行淘汰获得可用槽位
if (REACH_TIME_INTERVAL(2 * 1000 * 1000)) {
SERVER_LOG(WARN, "push into queue failed", K(get_size_used()), K(get_size()), K(ret));
@ -190,12 +179,38 @@ int ObPlanMonitorNodeList::ObMonitorNodeTraverseCall::operator() (
ObMonitorNode *> &entry)
{
int ret = OB_SUCCESS;
ObMonitorNode *head = entry.second;
while (OB_NOT_NULL(head) && OB_SUCC(ret)) {
if (OB_FAIL(node_array_.push_back(*head))) {
ObMonitorNode *node = entry.second;
if (OB_ISNULL(node)) {
// do nothing
} else if (OB_FAIL(recursive_add_node_to_array(*node))) {
LOG_WARN("fail to recursive add node to array", K(ret), KPC(node));
}
return ret;
}
int ObPlanMonitorNodeList::ObMonitorNodeTraverseCall::recursive_add_node_to_array(
ObMonitorNode &node)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(node.op_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("node.op_ is null", K(ret));
}
for (int i = 0; OB_SUCC(ret) && i < node.op_->get_child_cnt(); ++i) {
ObOperator *child_op = node.op_->get_child(i);
if (OB_ISNULL(child_op)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("operator child is nullptr", K(ret), KPC(node.op_), K(i));
} else if (OB_FAIL(SMART_CALL(
recursive_add_node_to_array(child_op->get_monitor_info())))) {
LOG_WARN("fail to recursive add node to array", K(ret), K(node), K(i));
}
}
if (OB_SUCC(ret)) {
if (OB_FAIL(node_array_.push_back(node))) {
LOG_WARN("fail to push back mointor node", K(ret));
} else {
head = head->next_;
node_array_.at(node_array_.count() - 1).covert_to_static_node();
}
}
return ret;
@ -213,6 +228,43 @@ void ObMonitorNode::update_tempseg(int64_t delta_size)
workarea_max_tempseg_ = MAX(workarea_tempseg_, workarea_max_tempseg_);
}
uint64_t ObMonitorNode::calc_db_time()
{
int64_t db_time = 0;
if (OB_NOT_NULL(op_)) {
db_time = op_->total_time_;
int64_t cur_time = rdtsc();
if (op_->cpu_begin_level_ > 0) {
db_time += cur_time - op_->cpu_begin_time_;
}
for (int32_t i = 0; i < op_->get_child_cnt(); ++i) {
ObOperator *child_op = op_->get_child(i);
if (OB_NOT_NULL(child_op)) {
db_time -= child_op->total_time_;
if (child_op->cpu_begin_level_ > 0) {
db_time -= (cur_time - child_op->cpu_begin_time_);
}
} else {
int ret = OB_ERR_UNEXPECTED;
LOG_WARN("operator child is nullptr", K(ret), KPC(op_), K(i));
}
}
if (db_time < 0) {
db_time = 0;
}
}
return (uint64_t)db_time;
}
void ObMonitorNode::covert_to_static_node()
{
db_time_ = calc_db_time();
uint64_t cpu_khz = OBSERVER.get_cpu_frequency_khz();
db_time_ = db_time_ * 1000 / cpu_khz;
block_time_ = block_time_ * 1000 / cpu_khz;
op_ = nullptr;
}
void ObSqlPlanMonitorRecycleTask::runTimerTask()
{
if (node_list_) {

View File

@ -28,6 +28,7 @@ namespace oceanbase
{
namespace sql
{
class ObOperator;
// 用于统计一段代码的执行时间
class TimingGuard
@ -47,7 +48,7 @@ private:
int64_t begin_;
};
class ObMonitorNode final : public common::ObDLinkBase<ObMonitorNode>
class ObMonitorNode
{
friend class ObPlanMonitorNodeList;
typedef common::ObCurTraceId::TraceId TraceId;
@ -59,6 +60,7 @@ public:
output_batches_(0),
skipped_rows_count_(0),
op_type_(PHY_INVALID),
op_(nullptr),
rt_node_id_(OB_INVALID_ID),
open_time_(0),
first_row_time_(0),
@ -100,6 +102,7 @@ public:
*this = that;
return common::OB_SUCCESS;
}
void set_op(ObOperator *op) { op_ = op; }
void set_operator_type(ObPhyOperatorType type) { op_type_ = type; }
void set_operator_id(int64_t op_id) { op_id_ = op_id; }
void set_tenant_id(int64_t tenant_id) { tenant_id_ = tenant_id; }
@ -112,10 +115,11 @@ public:
const TraceId& get_trace_id() const { return trace_id_; }
int64_t get_thread_id() { return thread_id_; }
int64_t get_rt_node_id() { return rt_node_id_;}
int add_rt_monitor_node(ObMonitorNode *node);
void set_rich_format(bool v) { enable_rich_format_ = v; }
void update_memory(int64_t delta_size);
void update_tempseg(int64_t delta_size);
uint64_t calc_db_time();
void covert_to_static_node();
TO_STRING_KV(K_(tenant_id), K_(op_id), "op_name", get_operator_name(), K_(thread_id));
public:
int64_t tenant_id_;
@ -124,6 +128,7 @@ public:
int64_t output_batches_; // for batch
int64_t skipped_rows_count_; // for batch
ObPhyOperatorType op_type_;
ObOperator *op_;
private:
int64_t thread_id_;
TraceId trace_id_;
@ -198,8 +203,9 @@ public:
public:
ObMonitorNodeTraverseCall(common::ObIArray<ObMonitorNode> &node_array) :
node_array_(node_array), ret_(OB_SUCCESS) {}
int operator() (common::hash::HashMapPair<ObMonitorNodeKey,
ObMonitorNode *> &entry);
int operator() (common::hash::HashMapPair<ObMonitorNodeKey,
ObMonitorNode *> &entry);
int recursive_add_node_to_array(ObMonitorNode &node);
common::ObIArray<ObMonitorNode> &node_array_;
int ret_;
};

File diff suppressed because one or more lines are too long

View File

@ -1692,7 +1692,7 @@ int ObInnerTableSchema::dba_ob_outlines_schema(ObTableSchema &table_schema)
table_schema.set_collation_type(ObCharset::get_default_collation(ObCharset::get_default_charset()));
if (OB_SUCC(ret)) {
if (OB_FAIL(table_schema.set_view_definition(R"__( SELECT B.GMT_CREATE AS CREATE_TIME, B.GMT_MODIFIED AS MODIFY_TIME, A.TENANT_ID, A.DATABASE_ID, A.OUTLINE_ID, A.DATABASE_NAME, A.OUTLINE_NAME, A.VISIBLE_SIGNATURE, A.SQL_TEXT, A.OUTLINE_TARGET, A.OUTLINE_SQL, A.SQL_ID, A.OUTLINE_CONTENT FROM oceanbase.__tenant_virtual_outline A, oceanbase.__all_outline B WHERE A.OUTLINE_ID = B.OUTLINE_ID )__"))) {
if (OB_FAIL(table_schema.set_view_definition(R"__( SELECT B.GMT_CREATE AS CREATE_TIME, B.GMT_MODIFIED AS MODIFY_TIME, A.TENANT_ID, A.DATABASE_ID, A.OUTLINE_ID, A.DATABASE_NAME, A.OUTLINE_NAME, A.VISIBLE_SIGNATURE, A.SQL_TEXT, A.OUTLINE_TARGET, A.OUTLINE_SQL, A.SQL_ID, A.OUTLINE_CONTENT FROM oceanbase.__tenant_virtual_outline A, oceanbase.__all_outline B WHERE A.OUTLINE_ID = B.OUTLINE_ID AND B.FORMAT_OUTLINE = 0 )__"))) {
LOG_ERROR("fail to set view_definition", K(ret));
}
}

View File

@ -1045,6 +1045,57 @@ int ObInnerTableSchema::v_ob_cgroup_config_schema(ObTableSchema &table_schema)
return ret;
}
int ObInnerTableSchema::dba_ob_format_outlines_schema(ObTableSchema &table_schema)
{
int ret = OB_SUCCESS;
uint64_t column_id = OB_APP_MIN_COLUMN_ID - 1;
//generated fields:
table_schema.set_tenant_id(OB_SYS_TENANT_ID);
table_schema.set_tablegroup_id(OB_INVALID_ID);
table_schema.set_database_id(OB_SYS_DATABASE_ID);
table_schema.set_table_id(OB_DBA_OB_FORMAT_OUTLINES_TID);
table_schema.set_rowkey_split_pos(0);
table_schema.set_is_use_bloomfilter(false);
table_schema.set_progressive_merge_num(0);
table_schema.set_rowkey_column_num(0);
table_schema.set_load_type(TABLE_LOAD_TYPE_IN_DISK);
table_schema.set_table_type(SYSTEM_VIEW);
table_schema.set_index_type(INDEX_TYPE_IS_NOT);
table_schema.set_def_type(TABLE_DEF_TYPE_INTERNAL);
if (OB_SUCC(ret)) {
if (OB_FAIL(table_schema.set_table_name(OB_DBA_OB_FORMAT_OUTLINES_TNAME))) {
LOG_ERROR("fail to set table_name", K(ret));
}
}
if (OB_SUCC(ret)) {
if (OB_FAIL(table_schema.set_compress_func_name(OB_DEFAULT_COMPRESS_FUNC_NAME))) {
LOG_ERROR("fail to set compress_func_name", K(ret));
}
}
table_schema.set_part_level(PARTITION_LEVEL_ZERO);
table_schema.set_charset_type(ObCharset::get_default_charset());
table_schema.set_collation_type(ObCharset::get_default_collation(ObCharset::get_default_charset()));
if (OB_SUCC(ret)) {
if (OB_FAIL(table_schema.set_view_definition(R"__( SELECT B.GMT_CREATE AS CREATE_TIME, B.GMT_MODIFIED AS MODIFY_TIME, A.TENANT_ID, A.DATABASE_ID, A.OUTLINE_ID, A.DATABASE_NAME, A.OUTLINE_NAME, A.VISIBLE_SIGNATURE, A.FORMAT_SQL_TEXT, A.OUTLINE_TARGET, A.OUTLINE_SQL, A.FORMAT_SQL_ID, A.OUTLINE_CONTENT FROM oceanbase.__tenant_virtual_outline A, oceanbase.__all_outline B WHERE A.OUTLINE_ID = B.OUTLINE_ID AND B.FORMAT_OUTLINE != 0 )__"))) {
LOG_ERROR("fail to set view_definition", K(ret));
}
}
table_schema.set_index_using_type(USING_BTREE);
table_schema.set_row_store_type(ENCODING_ROW_STORE);
table_schema.set_store_format(OB_STORE_FORMAT_DYNAMIC_MYSQL);
table_schema.set_progressive_merge_round(1);
table_schema.set_storage_format_version(3);
table_schema.set_tablet_id(0);
table_schema.set_micro_index_clustered(false);
table_schema.set_max_used_column_id(column_id);
return ret;
}
int ObInnerTableSchema::procs_priv_schema(ObTableSchema &table_schema)
{
int ret = OB_SUCCESS;

File diff suppressed because one or more lines are too long

View File

@ -637,6 +637,57 @@ int ObInnerTableSchema::dba_ob_import_table_task_history_ora_schema(ObTableSchem
return ret;
}
int ObInnerTableSchema::dba_ob_format_outlines_ora_schema(ObTableSchema &table_schema)
{
int ret = OB_SUCCESS;
uint64_t column_id = OB_APP_MIN_COLUMN_ID - 1;
//generated fields:
table_schema.set_tenant_id(OB_SYS_TENANT_ID);
table_schema.set_tablegroup_id(OB_INVALID_ID);
table_schema.set_database_id(OB_ORA_SYS_DATABASE_ID);
table_schema.set_table_id(OB_DBA_OB_FORMAT_OUTLINES_ORA_TID);
table_schema.set_rowkey_split_pos(0);
table_schema.set_is_use_bloomfilter(false);
table_schema.set_progressive_merge_num(0);
table_schema.set_rowkey_column_num(0);
table_schema.set_load_type(TABLE_LOAD_TYPE_IN_DISK);
table_schema.set_table_type(SYSTEM_VIEW);
table_schema.set_index_type(INDEX_TYPE_IS_NOT);
table_schema.set_def_type(TABLE_DEF_TYPE_INTERNAL);
if (OB_SUCC(ret)) {
if (OB_FAIL(table_schema.set_table_name(OB_DBA_OB_FORMAT_OUTLINES_ORA_TNAME))) {
LOG_ERROR("fail to set table_name", K(ret));
}
}
if (OB_SUCC(ret)) {
if (OB_FAIL(table_schema.set_compress_func_name(OB_DEFAULT_COMPRESS_FUNC_NAME))) {
LOG_ERROR("fail to set compress_func_name", K(ret));
}
}
table_schema.set_part_level(PARTITION_LEVEL_ZERO);
table_schema.set_charset_type(ObCharset::get_default_charset());
table_schema.set_collation_type(ObCharset::get_default_collation(ObCharset::get_default_charset()));
if (OB_SUCC(ret)) {
if (OB_FAIL(table_schema.set_view_definition(R"__( SELECT CAST(B.GMT_CREATE AS TIMESTAMP(6)) AS CREATE_TIME, CAST(B.GMT_MODIFIED AS TIMESTAMP(6)) AS MODIFY_TIME, A.TENANT_ID, A.DATABASE_ID, A.OUTLINE_ID, A.DATABASE_NAME, A.OUTLINE_NAME, A.VISIBLE_SIGNATURE, A.FORMAT_SQL_TEXT, A.OUTLINE_TARGET, A.OUTLINE_SQL, A.FORMAT_SQL_ID, A.OUTLINE_CONTENT FROM SYS.TENANT_VIRTUAL_OUTLINE_AGENT A, SYS.ALL_VIRTUAL_OUTLINE_REAL_AGENT B WHERE A.OUTLINE_ID = B.OUTLINE_ID AND B.FORMAT_OUTLINE != 0; )__"))) {
LOG_ERROR("fail to set view_definition", K(ret));
}
}
table_schema.set_index_using_type(USING_BTREE);
table_schema.set_row_store_type(ENCODING_ROW_STORE);
table_schema.set_store_format(OB_STORE_FORMAT_DYNAMIC_MYSQL);
table_schema.set_progressive_merge_round(1);
table_schema.set_storage_format_version(3);
table_schema.set_tablet_id(0);
table_schema.set_micro_index_clustered(false);
table_schema.set_max_used_column_id(column_id);
return ret;
}
int ObInnerTableSchema::dba_ob_transfer_partition_tasks_ora_schema(ObTableSchema &table_schema)
{
int ret = OB_SUCCESS;

File diff suppressed because one or more lines are too long

View File

@ -2304,7 +2304,7 @@ int ObInnerTableSchema::dba_ob_outlines_ora_schema(ObTableSchema &table_schema)
table_schema.set_collation_type(ObCharset::get_default_collation(ObCharset::get_default_charset()));
if (OB_SUCC(ret)) {
if (OB_FAIL(table_schema.set_view_definition(R"__(SELECT CAST(B.GMT_CREATE AS TIMESTAMP(6)) AS CREATE_TIME, CAST(B.GMT_MODIFIED AS TIMESTAMP(6)) AS MODIFY_TIME, A.TENANT_ID, A.DATABASE_ID, A.OUTLINE_ID, A.DATABASE_NAME, A.OUTLINE_NAME, A.VISIBLE_SIGNATURE, A.SQL_TEXT, A.OUTLINE_TARGET, A.OUTLINE_SQL, A.SQL_ID, A.OUTLINE_CONTENT FROM SYS.TENANT_VIRTUAL_OUTLINE_AGENT A, SYS.ALL_VIRTUAL_OUTLINE_REAL_AGENT B WHERE A.OUTLINE_ID = B.OUTLINE_ID )__"))) {
if (OB_FAIL(table_schema.set_view_definition(R"__(SELECT CAST(B.GMT_CREATE AS TIMESTAMP(6)) AS CREATE_TIME, CAST(B.GMT_MODIFIED AS TIMESTAMP(6)) AS MODIFY_TIME, A.TENANT_ID, A.DATABASE_ID, A.OUTLINE_ID, A.DATABASE_NAME, A.OUTLINE_NAME, A.VISIBLE_SIGNATURE, A.SQL_TEXT, A.OUTLINE_TARGET, A.OUTLINE_SQL, A.SQL_ID, A.OUTLINE_CONTENT FROM SYS.TENANT_VIRTUAL_OUTLINE_AGENT A, SYS.ALL_VIRTUAL_OUTLINE_REAL_AGENT B WHERE A.OUTLINE_ID = B.OUTLINE_ID AND B.FORMAT_OUTLINE = 0 )__"))) {
LOG_ERROR("fail to set view_definition", K(ret));
}
}

View File

@ -1776,6 +1776,7 @@ public:
static int v_ob_tenant_runtime_info_schema(share::schema::ObTableSchema &table_schema);
static int gv_ob_cgroup_config_schema(share::schema::ObTableSchema &table_schema);
static int v_ob_cgroup_config_schema(share::schema::ObTableSchema &table_schema);
static int dba_ob_format_outlines_schema(share::schema::ObTableSchema &table_schema);
static int procs_priv_schema(share::schema::ObTableSchema &table_schema);
static int dba_ob_aux_statistics_schema(share::schema::ObTableSchema &table_schema);
static int cdb_ob_aux_statistics_schema(share::schema::ObTableSchema &table_schema);
@ -2131,6 +2132,7 @@ public:
static int dba_ob_import_table_job_history_ora_schema(share::schema::ObTableSchema &table_schema);
static int dba_ob_import_table_tasks_ora_schema(share::schema::ObTableSchema &table_schema);
static int dba_ob_import_table_task_history_ora_schema(share::schema::ObTableSchema &table_schema);
static int dba_ob_format_outlines_ora_schema(share::schema::ObTableSchema &table_schema);
static int dba_ob_transfer_partition_tasks_ora_schema(share::schema::ObTableSchema &table_schema);
static int dba_ob_transfer_partition_task_history_ora_schema(share::schema::ObTableSchema &table_schema);
static int user_users_schema(share::schema::ObTableSchema &table_schema);
@ -4736,6 +4738,7 @@ const schema_create_func sys_view_schema_creators [] = {
ObInnerTableSchema::v_ob_tenant_runtime_info_schema,
ObInnerTableSchema::gv_ob_cgroup_config_schema,
ObInnerTableSchema::v_ob_cgroup_config_schema,
ObInnerTableSchema::dba_ob_format_outlines_schema,
ObInnerTableSchema::procs_priv_schema,
ObInnerTableSchema::dba_ob_aux_statistics_schema,
ObInnerTableSchema::cdb_ob_aux_statistics_schema,
@ -5091,6 +5094,7 @@ const schema_create_func sys_view_schema_creators [] = {
ObInnerTableSchema::dba_ob_import_table_job_history_ora_schema,
ObInnerTableSchema::dba_ob_import_table_tasks_ora_schema,
ObInnerTableSchema::dba_ob_import_table_task_history_ora_schema,
ObInnerTableSchema::dba_ob_format_outlines_ora_schema,
ObInnerTableSchema::dba_ob_transfer_partition_tasks_ora_schema,
ObInnerTableSchema::dba_ob_transfer_partition_task_history_ora_schema,
ObInnerTableSchema::user_users_schema,
@ -6539,6 +6543,7 @@ const uint64_t tenant_space_tables [] = {
OB_DBA_OB_IMPORT_TABLE_TASK_HISTORY_TID,
OB_GV_OB_CGROUP_CONFIG_TID,
OB_V_OB_CGROUP_CONFIG_TID,
OB_DBA_OB_FORMAT_OUTLINES_TID,
OB_PROCS_PRIV_TID,
OB_DBA_OB_AUX_STATISTICS_TID,
OB_DBA_INDEX_USAGE_TID,
@ -6873,6 +6878,7 @@ const uint64_t tenant_space_tables [] = {
OB_DBA_OB_IMPORT_TABLE_JOB_HISTORY_ORA_TID,
OB_DBA_OB_IMPORT_TABLE_TASKS_ORA_TID,
OB_DBA_OB_IMPORT_TABLE_TASK_HISTORY_ORA_TID,
OB_DBA_OB_FORMAT_OUTLINES_ORA_TID,
OB_DBA_OB_TRANSFER_PARTITION_TASKS_ORA_TID,
OB_DBA_OB_TRANSFER_PARTITION_TASK_HISTORY_ORA_TID,
OB_USER_USERS_TID,
@ -9264,6 +9270,7 @@ const char* const tenant_space_table_names [] = {
OB_DBA_OB_IMPORT_TABLE_TASK_HISTORY_TNAME,
OB_GV_OB_CGROUP_CONFIG_TNAME,
OB_V_OB_CGROUP_CONFIG_TNAME,
OB_DBA_OB_FORMAT_OUTLINES_TNAME,
OB_PROCS_PRIV_TNAME,
OB_DBA_OB_AUX_STATISTICS_TNAME,
OB_DBA_INDEX_USAGE_TNAME,
@ -9598,6 +9605,7 @@ const char* const tenant_space_table_names [] = {
OB_DBA_OB_IMPORT_TABLE_JOB_HISTORY_ORA_TNAME,
OB_DBA_OB_IMPORT_TABLE_TASKS_ORA_TNAME,
OB_DBA_OB_IMPORT_TABLE_TASK_HISTORY_ORA_TNAME,
OB_DBA_OB_FORMAT_OUTLINES_ORA_TNAME,
OB_DBA_OB_TRANSFER_PARTITION_TASKS_ORA_TNAME,
OB_DBA_OB_TRANSFER_PARTITION_TASK_HISTORY_ORA_TNAME,
OB_USER_USERS_TNAME,
@ -13594,10 +13602,10 @@ static inline int get_sys_table_lob_aux_schema(const uint64_t tid,
const int64_t OB_CORE_TABLE_COUNT = 4;
const int64_t OB_SYS_TABLE_COUNT = 304;
const int64_t OB_VIRTUAL_TABLE_COUNT = 851;
const int64_t OB_SYS_VIEW_COUNT = 963;
const int64_t OB_SYS_TENANT_TABLE_COUNT = 2123;
const int64_t OB_SYS_VIEW_COUNT = 965;
const int64_t OB_SYS_TENANT_TABLE_COUNT = 2125;
const int64_t OB_CORE_SCHEMA_VERSION = 1;
const int64_t OB_BOOTSTRAP_SCHEMA_VERSION = 2126;
const int64_t OB_BOOTSTRAP_SCHEMA_VERSION = 2128;
} // end namespace share
} // end namespace oceanbase

View File

@ -1476,6 +1476,7 @@ const uint64_t OB_GV_OB_TENANT_RUNTIME_INFO_TID = 21477; // "GV$OB_TENANT_RUNTIM
const uint64_t OB_V_OB_TENANT_RUNTIME_INFO_TID = 21478; // "V$OB_TENANT_RUNTIME_INFO"
const uint64_t OB_GV_OB_CGROUP_CONFIG_TID = 21479; // "GV$OB_CGROUP_CONFIG"
const uint64_t OB_V_OB_CGROUP_CONFIG_TID = 21480; // "V$OB_CGROUP_CONFIG"
const uint64_t OB_DBA_OB_FORMAT_OUTLINES_TID = 21485; // "DBA_OB_FORMAT_OUTLINES"
const uint64_t OB_PROCS_PRIV_TID = 21486; // "procs_priv"
const uint64_t OB_DBA_OB_AUX_STATISTICS_TID = 21497; // "DBA_OB_AUX_STATISTICS"
const uint64_t OB_CDB_OB_AUX_STATISTICS_TID = 21498; // "CDB_OB_AUX_STATISTICS"
@ -1831,6 +1832,7 @@ const uint64_t OB_DBA_OB_IMPORT_TABLE_JOBS_ORA_TID = 25264; // "DBA_OB_IMPORT_TA
const uint64_t OB_DBA_OB_IMPORT_TABLE_JOB_HISTORY_ORA_TID = 25265; // "DBA_OB_IMPORT_TABLE_JOB_HISTORY_ORA"
const uint64_t OB_DBA_OB_IMPORT_TABLE_TASKS_ORA_TID = 25266; // "DBA_OB_IMPORT_TABLE_TASKS_ORA"
const uint64_t OB_DBA_OB_IMPORT_TABLE_TASK_HISTORY_ORA_TID = 25267; // "DBA_OB_IMPORT_TABLE_TASK_HISTORY_ORA"
const uint64_t OB_DBA_OB_FORMAT_OUTLINES_ORA_TID = 25272; // "DBA_OB_FORMAT_OUTLINES_ORA"
const uint64_t OB_DBA_OB_TRANSFER_PARTITION_TASKS_ORA_TID = 25275; // "DBA_OB_TRANSFER_PARTITION_TASKS_ORA"
const uint64_t OB_DBA_OB_TRANSFER_PARTITION_TASK_HISTORY_ORA_TID = 25276; // "DBA_OB_TRANSFER_PARTITION_TASK_HISTORY_ORA"
const uint64_t OB_USER_USERS_TID = 25278; // "USER_USERS"
@ -4323,6 +4325,7 @@ const char *const OB_GV_OB_TENANT_RUNTIME_INFO_TNAME = "GV$OB_TENANT_RUNTIME_INF
const char *const OB_V_OB_TENANT_RUNTIME_INFO_TNAME = "V$OB_TENANT_RUNTIME_INFO";
const char *const OB_GV_OB_CGROUP_CONFIG_TNAME = "GV$OB_CGROUP_CONFIG";
const char *const OB_V_OB_CGROUP_CONFIG_TNAME = "V$OB_CGROUP_CONFIG";
const char *const OB_DBA_OB_FORMAT_OUTLINES_TNAME = "DBA_OB_FORMAT_OUTLINES";
const char *const OB_PROCS_PRIV_TNAME = "procs_priv";
const char *const OB_DBA_OB_AUX_STATISTICS_TNAME = "DBA_OB_AUX_STATISTICS";
const char *const OB_CDB_OB_AUX_STATISTICS_TNAME = "CDB_OB_AUX_STATISTICS";
@ -4678,6 +4681,7 @@ const char *const OB_DBA_OB_IMPORT_TABLE_JOBS_ORA_TNAME = "DBA_OB_IMPORT_TABLE_J
const char *const OB_DBA_OB_IMPORT_TABLE_JOB_HISTORY_ORA_TNAME = "DBA_OB_IMPORT_TABLE_JOB_HISTORY";
const char *const OB_DBA_OB_IMPORT_TABLE_TASKS_ORA_TNAME = "DBA_OB_IMPORT_TABLE_TASKS";
const char *const OB_DBA_OB_IMPORT_TABLE_TASK_HISTORY_ORA_TNAME = "DBA_OB_IMPORT_TABLE_TASK_HISTORY";
const char *const OB_DBA_OB_FORMAT_OUTLINES_ORA_TNAME = "DBA_OB_FORMAT_OUTLINES";
const char *const OB_DBA_OB_TRANSFER_PARTITION_TASKS_ORA_TNAME = "DBA_OB_TRANSFER_PARTITION_TASKS";
const char *const OB_DBA_OB_TRANSFER_PARTITION_TASK_HISTORY_ORA_TNAME = "DBA_OB_TRANSFER_PARTITION_TASK_HISTORY";
const char *const OB_USER_USERS_TNAME = "USER_USERS";

74
src/share/inner_table/ob_inner_table_schema_def.py Normal file → Executable file
View File

@ -17199,6 +17199,7 @@ def_table_schema(
flt_trace_id as FLT_TRACE_ID,
pl_trace_id as PL_TRACE_ID,
plsql_exec_time as PLSQL_EXEC_TIME,
format_sql_id as FORMAT_SQL_ID,
stmt_type as STMT_TYPE,
total_memstore_read_row_count as TOTAL_MEMSTORE_READ_ROW_COUNT,
total_ssstore_read_row_count as TOTAL_SSSTORE_READ_ROW_COUNT,
@ -17609,6 +17610,7 @@ def_table_schema(
FLT_TRACE_ID,
PL_TRACE_ID,
PLSQL_EXEC_TIME,
FORMAT_SQL_ID,
stmt_type as STMT_TYPE,
TOTAL_MEMSTORE_READ_ROW_COUNT,
TOTAL_SSSTORE_READ_ROW_COUNT,
@ -27231,7 +27233,7 @@ def_table_schema(
A.SQL_ID,
A.OUTLINE_CONTENT
FROM oceanbase.__tenant_virtual_outline A, oceanbase.__all_outline B
WHERE A.OUTLINE_ID = B.OUTLINE_ID
WHERE A.OUTLINE_ID = B.OUTLINE_ID AND B.FORMAT_OUTLINE = 0
""".replace("\n", " "),
normal_columns = [
@ -34134,7 +34136,35 @@ WHERE SVR_IP=HOST_IP() AND SVR_PORT=RPC_PORT()
#21482: CDB_WR_SYSTEM_EVENT
#21483: DBA_WR_EVENT_NAME
#21484: CDB_WR_EVENT_NAME
#21485: DBA_OB_FORMAT_OUTLINES
def_table_schema(
owner = 'guoyun.lgy',
table_name = 'DBA_OB_FORMAT_OUTLINES',
table_id = '21485',
table_type = 'SYSTEM_VIEW',
gm_columns = [],
in_tenant_space = True,
rowkey_columns = [],
view_definition = """
SELECT
B.GMT_CREATE AS CREATE_TIME,
B.GMT_MODIFIED AS MODIFY_TIME,
A.TENANT_ID,
A.DATABASE_ID,
A.OUTLINE_ID,
A.DATABASE_NAME,
A.OUTLINE_NAME,
A.VISIBLE_SIGNATURE,
A.FORMAT_SQL_TEXT,
A.OUTLINE_TARGET,
A.OUTLINE_SQL,
A.FORMAT_SQL_ID,
A.OUTLINE_CONTENT
FROM oceanbase.__tenant_virtual_outline A, oceanbase.__all_outline B
WHERE A.OUTLINE_ID = B.OUTLINE_ID AND B.FORMAT_OUTLINE != 0
""".replace("\n", " "),
normal_columns = [
],
)
def_table_schema(
owner = 'mingye.swj',
@ -51582,6 +51612,7 @@ def_table_schema(
WHEN 'USER_TAB_PRIVS' THEN ''
WHEN 'STMT_AUDIT_OPTION_MAP' THEN ''
WHEN 'DBA_OB_OUTLINES' THEN ''
WHEN 'DBA_OB_FORMAT_OUTLINES' THEN ''
WHEN 'GV$OB_SQL_AUDIT' THEN ''
WHEN 'V$OB_SQL_AUDIT' THEN ''
WHEN 'DBA_AUDIT_SESSION' THEN ''
@ -56694,7 +56725,39 @@ def_table_schema(
# 25269: DBA_WR_SYSTEM_EVENT
# 25270: DBA_WR_EVENT_NAME
# 25271: DBA_SCHEDULER_RUNNING_JOBS
# 25272: DBA_OB_FORMAT_OUTLINES
def_table_schema(
owner = 'guoyun.lgy',
table_name = 'DBA_OB_FORMAT_OUTLINES',
name_postfix = '_ORA',
database_id = 'OB_ORA_SYS_DATABASE_ID',
table_id = '25272',
table_type = 'SYSTEM_VIEW',
gm_columns = [],
in_tenant_space = True,
rowkey_columns = [],
view_definition = """
SELECT
CAST(B.GMT_CREATE AS TIMESTAMP(6)) AS CREATE_TIME,
CAST(B.GMT_MODIFIED AS TIMESTAMP(6)) AS MODIFY_TIME,
A.TENANT_ID,
A.DATABASE_ID,
A.OUTLINE_ID,
A.DATABASE_NAME,
A.OUTLINE_NAME,
A.VISIBLE_SIGNATURE,
A.FORMAT_SQL_TEXT,
A.OUTLINE_TARGET,
A.OUTLINE_SQL,
A.FORMAT_SQL_ID,
A.OUTLINE_CONTENT
FROM SYS.TENANT_VIRTUAL_OUTLINE_AGENT A, SYS.ALL_VIRTUAL_OUTLINE_REAL_AGENT B
WHERE A.OUTLINE_ID = B.OUTLINE_ID AND B.FORMAT_OUTLINE != 0;
""".replace("\n", " "),
normal_columns = [
],
)
# 25273: DBA_WR_SQLSTAT
# 25274: DBA_WR_SYS_TIME_MODEL
def_table_schema(
@ -58195,6 +58258,7 @@ def_table_schema(
flt_trace_id as FLT_TRACE_ID,
pl_trace_id as PL_TRACE_ID,
plsql_exec_time as PLSQL_EXEC_TIME,
format_sql_id as FORMAT_SQL_ID,
stmt_type as STMT_TYPE,
total_memstore_read_row_count as TOTAL_MEMSTORE_READ_ROW_COUNT,
total_ssstore_read_row_count as TOTAL_SSSTORE_READ_ROW_COUNT,
@ -58309,6 +58373,7 @@ TX_STATE_VERSION,
FLT_TRACE_ID,
PL_TRACE_ID,
PLSQL_EXEC_TIME,
FORMAT_SQL_ID,
STMT_TYPE,
TOTAL_MEMSTORE_READ_ROW_COUNT,
TOTAL_SSSTORE_READ_ROW_COUNT,
@ -63732,7 +63797,7 @@ def_table_schema(
A.SQL_ID,
A.OUTLINE_CONTENT
FROM SYS.TENANT_VIRTUAL_OUTLINE_AGENT A, SYS.ALL_VIRTUAL_OUTLINE_REAL_AGENT B
WHERE A.OUTLINE_ID = B.OUTLINE_ID
WHERE A.OUTLINE_ID = B.OUTLINE_ID AND B.FORMAT_OUTLINE = 0
""".replace("\n", " ")
)
@ -66204,6 +66269,7 @@ def_table_schema(
# * # 100001: __all_table
################################################################################
################################################################################
# Lob Table (50000, 70000)
################################################################################

View File

@ -2171,6 +2171,7 @@
# 21478: V$OB_TENANT_RUNTIME_INFO
# 21479: GV$OB_CGROUP_CONFIG
# 21480: V$OB_CGROUP_CONFIG
# 21485: DBA_OB_FORMAT_OUTLINES
# 21486: procs_priv
# 21497: DBA_OB_AUX_STATISTICS
# 21498: CDB_OB_AUX_STATISTICS
@ -2526,6 +2527,7 @@
# 25265: DBA_OB_IMPORT_TABLE_JOB_HISTORY
# 25266: DBA_OB_IMPORT_TABLE_TASKS
# 25267: DBA_OB_IMPORT_TABLE_TASK_HISTORY
# 25272: DBA_OB_FORMAT_OUTLINES
# 25275: DBA_OB_TRANSFER_PARTITION_TASKS
# 25276: DBA_OB_TRANSFER_PARTITION_TASK_HISTORY
# 25278: USER_USERS

View File

@ -24,6 +24,7 @@
#include "share/schema/ob_schema_getter_guard.h"
#include "storage/tx/ob_trans_define.h"
#include "sql/engine/cmd/ob_load_data_parser.h"
#include "share/diagnosis/ob_sql_plan_monitor_node_list.h"
namespace oceanbase
{
@ -160,6 +161,87 @@ struct ObLimitParam
OB_UNIS_VERSION(1);
};
struct ObTSCMonitorInfo
{
int64_t* io_read_bytes_;
int64_t* ssstore_read_bytes_;
int64_t* ssstore_read_row_cnt_;
int64_t* memstore_read_row_cnt_;
ObTSCMonitorInfo()
: io_read_bytes_(nullptr),
ssstore_read_bytes_(nullptr),
ssstore_read_row_cnt_(nullptr),
memstore_read_row_cnt_(nullptr) {}
ObTSCMonitorInfo(int64_t* io_read_bytes,
int64_t* ssstore_read_bytes,
int64_t* ssstore_read_row_cnt,
int64_t* memstore_read_row_cnt)
: io_read_bytes_(io_read_bytes),
ssstore_read_bytes_(ssstore_read_bytes),
ssstore_read_row_cnt_(ssstore_read_row_cnt),
memstore_read_row_cnt_(memstore_read_row_cnt) {}
void init(int64_t* io_read_bytes,
int64_t* ssstore_read_bytes,
int64_t* ssstore_read_row_cnt,
int64_t* memstore_read_row_cnt)
{
io_read_bytes_ = io_read_bytes;
ssstore_read_bytes_ = ssstore_read_bytes;
ssstore_read_row_cnt_ = ssstore_read_row_cnt;
memstore_read_row_cnt_ = memstore_read_row_cnt;
}
void add_io_read_bytes(int64_t io_read_bytes) {
if (OB_NOT_NULL(io_read_bytes_)) {
*io_read_bytes_ += io_read_bytes;
}
}
void add_ssstore_read_bytes(int64_t ssstore_read_bytes) {
if (OB_NOT_NULL(ssstore_read_bytes_)) {
*ssstore_read_bytes_ += ssstore_read_bytes;
}
}
void add_ssstore_read_row_cnt(int64_t ssstore_read_row_cnt) {
if (OB_NOT_NULL(ssstore_read_row_cnt_)) {
*ssstore_read_row_cnt_ += ssstore_read_row_cnt;
}
}
void add_memstore_read_row_cnt(int64_t memstore_read_row_cnt) {
if (OB_NOT_NULL(memstore_read_row_cnt_)) {
*memstore_read_row_cnt_ += memstore_read_row_cnt;
}
}
void reset_stat()
{
if (OB_NOT_NULL(io_read_bytes_)) {
*io_read_bytes_ = 0;
}
if (OB_NOT_NULL(ssstore_read_bytes_)) {
*ssstore_read_bytes_ = 0;
}
if (OB_NOT_NULL(ssstore_read_row_cnt_)) {
*ssstore_read_row_cnt_ = 0;
}
if (OB_NOT_NULL(memstore_read_row_cnt_)) {
*memstore_read_row_cnt_ = 0;
}
}
DEFINE_TO_STRING(
OB_ISNULL(io_read_bytes_) ? J_KV(K(io_read_bytes_)) : J_KV(K(*io_read_bytes_));
OB_ISNULL(ssstore_read_bytes_) ? J_KV(K(ssstore_read_bytes_)) : J_KV(K(*ssstore_read_bytes_));
OB_ISNULL(ssstore_read_row_cnt_) ? J_KV(K(ssstore_read_row_cnt_)) : J_KV(K(*ssstore_read_row_cnt_));
OB_ISNULL(memstore_read_row_cnt_) ? J_KV(K(memstore_read_row_cnt_)) : J_KV(K(*memstore_read_row_cnt_));
)
};
struct ObTableScanStatistic
{
//storage access row cnt before filter
@ -176,6 +258,8 @@ struct ObTableScanStatistic
int64_t block_cache_hit_cnt_;
int64_t block_cache_miss_cnt_;
int64_t rowkey_prefix_;
ObTSCMonitorInfo *tsc_monitor_info_;
ObTableScanStatistic()
: access_row_cnt_(0),
out_row_cnt_(0),
@ -188,8 +272,10 @@ struct ObTableScanStatistic
row_cache_miss_cnt_(0),
block_cache_hit_cnt_(0),
block_cache_miss_cnt_(0),
rowkey_prefix_(0)
rowkey_prefix_(0),
tsc_monitor_info_(nullptr)
{}
OB_INLINE void reset()
{
access_row_cnt_ = 0;
@ -205,6 +291,7 @@ struct ObTableScanStatistic
block_cache_miss_cnt_ = 0;
rowkey_prefix_ = 0;
}
OB_INLINE void reset_cache_stat()
{
bf_filter_cnt_ = 0;
@ -216,6 +303,7 @@ struct ObTableScanStatistic
block_cache_hit_cnt_ = 0;
block_cache_miss_cnt_ = 0;
}
TO_STRING_KV(
K_(access_row_cnt),
K_(out_row_cnt),
@ -226,7 +314,8 @@ struct ObTableScanStatistic
K_(row_cache_miss_cnt),
K_(fuse_row_cache_hit_cnt),
K_(fuse_row_cache_miss_cnt),
K_(rowkey_prefix));
K_(rowkey_prefix),
KPC_(tsc_monitor_info));
};
static const int64_t OB_DEFAULT_FILTER_EXPR_COUNT = 4;

View File

@ -6423,11 +6423,22 @@ bool ObBatchGetRoleResult::is_valid() const
bool ObCreateOutlineArg::is_valid() const
{
return OB_INVALID_ID != outline_info_.get_tenant_id()
bool ret = (OB_INVALID_ID != outline_info_.get_tenant_id())
&& !outline_info_.get_name_str().empty()
&& !(outline_info_.get_signature_str().empty() && !ObOutlineInfo::is_sql_id_valid(outline_info_.get_sql_id_str()))
&& (!outline_info_.get_outline_content_str().empty() || outline_info_.has_outline_params())
&& !(outline_info_.get_sql_text_str().empty() && !ObOutlineInfo::is_sql_id_valid(outline_info_.get_sql_id_str()));
&& (!outline_info_.get_outline_content_str().empty() || outline_info_.has_outline_params());
if (!outline_info_.is_format()) {
ret = ret && !(outline_info_.get_sql_text_str().empty() &&
!ObOutlineInfo::is_sql_id_valid(outline_info_.get_sql_id_str()))
&& !(outline_info_.get_signature_str().empty() &&
!ObOutlineInfo::is_sql_id_valid(outline_info_.get_sql_id_str()));
} else {
ret = ret && !(outline_info_.get_format_sql_text_str().empty() &&
!ObOutlineInfo::is_sql_id_valid(outline_info_.get_format_sql_id_str()))
&& !(outline_info_.get_signature_str().empty() &&
!ObOutlineInfo::is_sql_id_valid(outline_info_.get_format_sql_id_str()));
}
return ret;
}
OB_SERIALIZE_MEMBER((ObCreateOutlineArg, ObDDLArg),
@ -6458,6 +6469,22 @@ OB_SERIALIZE_MEMBER((ObDropOutlineArg, ObDDLArg),
outline_name_,
is_format_);
int ObDropOutlineArg::assign(const ObDropOutlineArg &other)
{
int ret = OB_SUCCESS;
if (OB_FAIL(ObDDLArg::assign(other))) {
LOG_WARN("fail to assign ddl arg", KR(ret));
} else {
tenant_id_ = other.tenant_id_;
db_name_ = other.db_name_;
outline_name_ = other.outline_name_;
is_format_ = other.is_format_;
}
return ret;
}
bool ObCreateDbLinkArg::is_valid() const
{
return OB_INVALID_ID != dblink_info_.get_tenant_id()
@ -6466,7 +6493,8 @@ bool ObCreateDbLinkArg::is_valid() const
&& !dblink_info_.get_dblink_name().empty()
&& !dblink_info_.get_tenant_name().empty()
&& !dblink_info_.get_user_name().empty()
&& dblink_info_.get_host_addr().is_valid()
&& ((!dblink_info_.get_host_name().empty() && 0 != dblink_info_.get_host_port()) ||
dblink_info_.get_host_addr().is_valid())
&& (!dblink_info_.get_password().empty() || !dblink_info_.get_encrypted_password().empty());
}

View File

@ -7186,6 +7186,7 @@ public:
virtual ~ObDropOutlineArg() {}
bool is_valid() const;
virtual bool is_allow_when_upgrade() const { return true; }
int assign(const ObDropOutlineArg &other);
TO_STRING_KV(K_(tenant_id), K_(db_name), K_(outline_name), K_(is_format));
uint64_t tenant_id_;

View File

@ -1772,6 +1772,9 @@ DEF_BOOL(_ob_enable_direct_load, OB_CLUSTER_PARAMETER, "True",
DEF_BOOL(enable_dblink, OB_CLUSTER_PARAMETER, "True",
"Enable or disable dblink",
ObParameterAttr(Section::OBSERVER, Source::DEFAULT, EditLevel::DYNAMIC_EFFECTIVE));
DEF_STR_WITH_CHECKER(_display_mysql_version, OB_CLUSTER_PARAMETER, "5.7.25", common::ObMySQLVersionLengthChecker,
"dynamic mysql version of mysql mode observer",
ObParameterAttr(Section::OBSERVER, Source::DEFAULT, EditLevel::DYNAMIC_EFFECTIVE));
DEF_BOOL(_px_join_skew_handling, OB_TENANT_PARAMETER, "False",
"enables skew handling for parallel joins. The default value is True.",
ObParameterAttr(Section::OBSERVER, Source::DEFAULT, EditLevel::DYNAMIC_EFFECTIVE));

View File

@ -126,6 +126,7 @@ int ObDbLinkSqlService::add_normal_columns(const ObDbLinkBaseInfo &dblink_info,
uint64_t compat_version = 0;
bool is_oracle_mode = false;
uint64_t tenant_id = dblink_info.get_tenant_id();
bool support_domin_name = false;
if (OB_FAIL(GET_MIN_DATA_VERSION(tenant_id, compat_version))) {
LOG_WARN("fail to get data version", KR(ret), K(tenant_id));
} else if (OB_FAIL(ObCompatModeGetter::check_is_oracle_mode_with_tenant_id(tenant_id, is_oracle_mode))) {
@ -133,20 +134,49 @@ int ObDbLinkSqlService::add_normal_columns(const ObDbLinkBaseInfo &dblink_info,
} else if (compat_version < DATA_VERSION_4_2_0_0 && !is_oracle_mode) {
ret = OB_NOT_SUPPORTED;
LOG_WARN("mysql dblink is not supported when MIN_DATA_VERSION is below DATA_VERSION_4_2_0_0", K(ret));
} else if (!dblink_info.get_host_addr().ip_to_string(ip_buf, sizeof(ip_buf))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("failed to ip to string", K(ret), K(dblink_info.get_host_addr()));
} else if (FALSE_IT(host_ip.assign_ptr(ip_buf, static_cast<int32_t>(STRLEN(ip_buf))))) {
// nothing.
} else if (!dblink_info.get_reverse_host_addr().ip_to_string(reverse_ip_buf, sizeof(reverse_ip_buf))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("failed to reverse_ip to string", K(ret), K(dblink_info.get_reverse_host_addr()));
} else if (FALSE_IT(reverse_host_ip.assign_ptr(reverse_ip_buf, static_cast<int32_t>(STRLEN(reverse_ip_buf))))) {
// nothing.
} else {
support_domin_name = compat_version >= DATA_VERSION_4_3_4_0 ||
(compat_version >= MOCK_DATA_VERSION_4_2_1_8 && compat_version < DATA_VERSION_4_2_2_0) ||
(compat_version >= MOCK_DATA_VERSION_4_2_5_0 && compat_version < DATA_VERSION_4_3_0_0);
}
if (OB_FAIL(ret)) {
// do nothing
} else if (!support_domin_name) {
if (!dblink_info.get_host_addr().ip_to_string(ip_buf, sizeof(ip_buf))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("failed to ip to string", K(ret), K(dblink_info.get_host_addr()));
} else if (FALSE_IT(host_ip.assign_ptr(ip_buf, static_cast<int32_t>(STRLEN(ip_buf))))) {
} else if (OB_FAIL(dml.add_column("host_ip", host_ip))) {
LOG_WARN("failed to add host_ip columns", K(ret));
} else if (OB_FAIL(dml.add_column("host_port", dblink_info.get_host_addr().get_port()))) {
LOG_WARN("failed to add host_port columns", K(ret));
} else if (!dblink_info.get_reverse_host_addr().ip_to_string(reverse_ip_buf, sizeof(reverse_ip_buf))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("failed to reverse_ip to string", K(ret), K(dblink_info.get_reverse_host_addr()));
} else if (FALSE_IT(reverse_host_ip.assign_ptr(reverse_ip_buf, static_cast<int32_t>(STRLEN(reverse_ip_buf))))) {
// nothing.
} else if (compat_version >= DATA_VERSION_4_1_0_0) {
if (OB_FAIL(dml.add_column("reverse_host_ip", reverse_host_ip))) {
LOG_WARN("failed to add reverse_host_ip columns", K(ret));
} else if (OB_FAIL(dml.add_column("reverse_host_port", dblink_info.get_reverse_host_addr().get_port()))) {
LOG_WARN("failed to add reverse_host_port columns", K(ret));
}
}
} else {
if (OB_FAIL(dml.add_column("host_ip", dblink_info.get_host_name()))) {
LOG_WARN("failed to add host_ip columns", K(ret));
} else if (OB_FAIL(dml.add_column("host_port", dblink_info.get_host_port()))) {
LOG_WARN("failed to add host_port columns", K(ret));
} else if (OB_FAIL(dml.add_column("reverse_host_ip", dblink_info.get_reverse_host_name()))) {
LOG_WARN("failed to add reverse_host_ip columns", K(ret));
} else if (OB_FAIL(dml.add_column("reverse_host_port", dblink_info.get_reverse_host_port()))) {
LOG_WARN("failed to add reverse_host_port columns", K(ret));
}
}
if (OB_FAIL(ret)) {
// do nothing
} else if (OB_FAIL(dml.add_column("dblink_name", ObHexEscapeSqlStr(dblink_info.get_dblink_name())))
|| OB_FAIL(dml.add_column("owner_id", extract_owner_id))
|| OB_FAIL(dml.add_column("host_ip", host_ip))
|| OB_FAIL(dml.add_column("host_port", dblink_info.get_host_port()))
|| OB_FAIL(dml.add_column("cluster_name", dblink_info.get_cluster_name()))
|| OB_FAIL(dml.add_column("tenant_name", dblink_info.get_tenant_name()))
|| OB_FAIL(dml.add_column("user_name", dblink_info.get_user_name()))
@ -169,57 +199,48 @@ int ObDbLinkSqlService::add_normal_columns(const ObDbLinkBaseInfo &dblink_info,
const ObString &reverse_user_name = dblink_info.get_reverse_user_name();
const ObString &reverse_password = dblink_info.get_reverse_password();
const ObString &password = dblink_info.get_password();
uint64_t compat_version = 0;
uint64_t tenant_id = dblink_info.get_tenant_id();
if (OB_FAIL(GET_MIN_DATA_VERSION(tenant_id, compat_version))) { //compat_version < DATA_VERSION_4_1_0_0
LOG_WARN("fail to get data version", KR(ret), K(tenant_id));
} else {
if (compat_version < DATA_VERSION_4_1_0_0) {
if (!encrypted_password.empty() ||
0 != reverse_host_port ||
!reverse_cluster_name.empty() ||
!reverse_tenant_name.empty() ||
!reverse_user_name.empty() ||
!reverse_password.empty()) {
ret = OB_NOT_SUPPORTED;
LOG_WARN("some column of dblink_info is not empty when MIN_DATA_VERSION is below DATA_VERSION_4_1_0_0", K(ret),
K(encrypted_password),
K(reverse_host_port),
K(reverse_cluster_name),
K(reverse_tenant_name),
K(reverse_user_name),
K(reverse_password));
} else if (password.empty()) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("password can not be empty when MIN_DATA_VERSION is below DATA_VERSION_4_1_0_0", K(ret), K(password));
}
} else if (encrypted_password.empty()) {
if (compat_version < DATA_VERSION_4_1_0_0) {
if (!encrypted_password.empty() ||
0 != reverse_host_port ||
!reverse_cluster_name.empty() ||
!reverse_tenant_name.empty() ||
!reverse_user_name.empty() ||
!reverse_password.empty()) {
ret = OB_NOT_SUPPORTED;
LOG_WARN("some column of dblink_info is not empty when MIN_DATA_VERSION is below DATA_VERSION_4_1_0_0", K(ret),
K(encrypted_password),
K(reverse_host_port),
K(reverse_cluster_name),
K(reverse_tenant_name),
K(reverse_user_name),
K(reverse_password));
} else if (password.empty()) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("encrypted_password is invalid when MIN_DATA_VERSION is DATA_VERSION_4_1_0_0 or above", K(ret), K(encrypted_password));
} else if (!password.empty()) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("password need be empty when MIN_DATA_VERSION is DATA_VERSION_4_1_0_0 or above", K(ret), K(password));
} else if (OB_FAIL(dml.add_column("encrypted_password", encrypted_password))
|| OB_FAIL(dml.add_column("reverse_host_ip", reverse_host_ip))
|| OB_FAIL(dml.add_column("reverse_host_port", dblink_info.get_reverse_host_port()))
|| OB_FAIL(dml.add_column("reverse_cluster_name", dblink_info.get_reverse_cluster_name()))
|| OB_FAIL(dml.add_column("reverse_tenant_name", dblink_info.get_reverse_tenant_name()))
|| OB_FAIL(dml.add_column("reverse_user_name", dblink_info.get_reverse_user_name()))
|| OB_FAIL(dml.add_column("reverse_password", dblink_info.get_reverse_password()))) {
LOG_WARN("failed to add encrypted_password column", K(ret), K(encrypted_password));
}
if (OB_FAIL(ret)) {
// do nothing
} else if (compat_version < DATA_VERSION_4_2_0_0) {
if (!dblink_info.get_database_name().empty()) {
ret = OB_NOT_SUPPORTED;
LOG_WARN("some column of dblink_info is not empty when MIN_DATA_VERSION is below DATA_VERSION_4_2_0_0", K(ret), K(dblink_info.get_database_name()));
}
} else if (OB_FAIL(dml.add_column("database_name", dblink_info.get_database_name()))) {
LOG_WARN("failed to add normal database_name", K(dblink_info.get_database_name()), K(ret));
LOG_WARN("password can not be empty when MIN_DATA_VERSION is below DATA_VERSION_4_1_0_0", K(ret), K(password));
}
} else if (encrypted_password.empty()) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("encrypted_password is invalid when MIN_DATA_VERSION is DATA_VERSION_4_1_0_0 or above", K(ret), K(encrypted_password));
} else if (!password.empty()) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("password need be empty when MIN_DATA_VERSION is DATA_VERSION_4_1_0_0 or above", K(ret), K(password));
} else if (OB_FAIL(dml.add_column("encrypted_password", encrypted_password))
|| OB_FAIL(dml.add_column("reverse_cluster_name", dblink_info.get_reverse_cluster_name()))
|| OB_FAIL(dml.add_column("reverse_tenant_name", dblink_info.get_reverse_tenant_name()))
|| OB_FAIL(dml.add_column("reverse_user_name", dblink_info.get_reverse_user_name()))
|| OB_FAIL(dml.add_column("reverse_password", dblink_info.get_reverse_password()))) {
LOG_WARN("failed to add encrypted_password column", K(ret), K(encrypted_password));
}
if (OB_FAIL(ret)) {
// do nothing
} else if (compat_version < DATA_VERSION_4_2_0_0) {
if (!dblink_info.get_database_name().empty()) {
ret = OB_NOT_SUPPORTED;
LOG_WARN("some column of dblink_info is not empty when MIN_DATA_VERSION is below DATA_VERSION_4_2_0_0", K(ret), K(dblink_info.get_database_name()));
}
} else if (OB_FAIL(dml.add_column("database_name", dblink_info.get_database_name()))) {
LOG_WARN("failed to add normal database_name", K(dblink_info.get_database_name()), K(ret));
}
}
return ret;
}

View File

@ -2832,6 +2832,7 @@ int ObMultiVersionSchemaService::check_outline_exist_with_name(const uint64_t te
const uint64_t database_id,
const common::ObString &outline_name,
uint64_t &outline_id,
bool is_format,
bool &exist)
{
int ret = OB_SUCCESS;
@ -2855,6 +2856,7 @@ int ObMultiVersionSchemaService::check_outline_exist_with_name(const uint64_t te
tenant_id,
database_id,
outline_name,
is_format,
outline_id,
exist))) {
LOG_WARN("failed to check outline name exist", K(tenant_id), K(database_id), K(outline_name),
@ -2867,6 +2869,7 @@ int ObMultiVersionSchemaService::check_outline_exist_with_name(const uint64_t te
int ObMultiVersionSchemaService::check_outline_exist_with_sql(const uint64_t tenant_id,
const uint64_t database_id,
const common::ObString &paramlized_sql,
bool is_format,
bool &exist)
{
@ -2888,6 +2891,7 @@ int ObMultiVersionSchemaService::check_outline_exist_with_sql(const uint64_t ten
tenant_id,
database_id,
paramlized_sql,
is_format,
exist))) {
LOG_WARN("failed to check outline sql exist", K(tenant_id), K(database_id),
K(paramlized_sql), K(ret));
@ -3095,6 +3099,7 @@ int ObMultiVersionSchemaService::check_label_se_component_long_name_exist(const
int ObMultiVersionSchemaService::check_outline_exist_with_sql_id(const uint64_t tenant_id,
const uint64_t database_id,
const common::ObString &sql_id,
bool is_format,
bool &exist)
{
@ -3116,6 +3121,7 @@ int ObMultiVersionSchemaService::check_outline_exist_with_sql_id(const uint64_t
tenant_id,
database_id,
sql_id,
is_format,
exist))) {
LOG_WARN("failed to check outline sql exist", K(tenant_id), K(database_id),
K(sql_id), K(ret));

View File

@ -293,10 +293,12 @@ public:
const uint64_t database_id,
const common::ObString &outline_name,
uint64_t &outline_id,
bool is_format,
bool &exist) ;
int check_outline_exist_with_sql(const uint64_t tenant_id,
const uint64_t database_id,
const common::ObString &paramlized_sql,
bool is_format,
bool &exist) ;
int check_synonym_exist(const uint64_t tenant_id,
const uint64_t database_id,
@ -314,6 +316,7 @@ public:
int check_outline_exist_with_sql_id(const uint64_t tenant_id,
const uint64_t database_id,
const common::ObString &sql_id,
bool is_format,
bool &exist) ;
int check_procedure_exist(uint64_t tenant_id, uint64_t database_id,

View File

@ -60,12 +60,15 @@ ObSimpleOutlineSchema &ObSimpleOutlineSchema::operator =(const ObSimpleOutlineSc
outline_id_ = other.outline_id_;
schema_version_ = other.schema_version_;
database_id_ = other.database_id_;
format_outline_ = other.format_outline_;
if (OB_FAIL(deep_copy_str(other.name_, name_))) {
LOG_WARN("Fail to deep copy outline name", K(ret));
} else if (OB_FAIL(deep_copy_str(other.signature_, signature_))) {
LOG_WARN("Fail to deep copy signature", K(ret));
} else if (OB_FAIL(deep_copy_str(other.sql_id_, sql_id_))) {
LOG_WARN("Fail to deep copy sql_id", K(ret));
} else if (OB_FAIL(deep_copy_str(other.format_sql_id_, format_sql_id_))) {
LOG_WARN("Fail to deep copy sql_id", K(ret));
}
if (OB_FAIL(ret)) {
@ -86,6 +89,8 @@ bool ObSimpleOutlineSchema::operator ==(const ObSimpleOutlineSchema &other) cons
database_id_ == other.database_id_ &&
name_ == other.name_ &&
signature_ == other.signature_ &&
format_outline_ == other.format_outline_ &&
format_sql_id_ == other.format_sql_id_ &&
sql_id_ == other.sql_id_) {
ret = true;
}
@ -100,9 +105,11 @@ void ObSimpleOutlineSchema::reset()
outline_id_ = OB_INVALID_ID;
schema_version_ = OB_INVALID_VERSION;
database_id_ = OB_INVALID_ID;
format_outline_ = false;
name_.reset();
signature_.reset();
sql_id_.reset();
format_sql_id_.reset();
}
bool ObSimpleOutlineSchema::is_valid() const
@ -113,7 +120,8 @@ bool ObSimpleOutlineSchema::is_valid() const
schema_version_ < 0 ||
OB_INVALID_ID == database_id_ ||
name_.empty() ||
(signature_.empty() && sql_id_.empty())) {
(!is_format() && signature_.empty() && sql_id_.empty()) ||
(is_format() && signature_.empty() && format_sql_id_.empty())) {
ret = false;
}
return ret;
@ -127,6 +135,7 @@ int64_t ObSimpleOutlineSchema::get_convert_size() const
convert_size += name_.length() + 1;
convert_size += signature_.length() + 1;
convert_size += sql_id_.length() + 1;
convert_size += format_sql_id_.length() + 1;
return convert_size;
}
@ -361,7 +370,8 @@ int ObOutlineMgr::add_outline(const ObSimpleOutlineSchema &outline_schema)
if (OB_SUCC(ret)) {
ObOutlineNameHashWrapper name_wrapper(new_outline_schema->get_tenant_id(),
new_outline_schema->get_database_id(),
new_outline_schema->get_name_str());
new_outline_schema->get_name_str(),
new_outline_schema->is_format());
hash_ret = outline_name_map_.set_refactored(name_wrapper, new_outline_schema,
over_write);
if (OB_SUCCESS != hash_ret && OB_HASH_EXIST != hash_ret) {
@ -375,7 +385,8 @@ int ObOutlineMgr::add_outline(const ObSimpleOutlineSchema &outline_schema)
if (0 != new_outline_schema->get_signature_str().length()) {
ObOutlineSignatureHashWrapper outline_signature_wrapper(new_outline_schema->get_tenant_id(),
new_outline_schema->get_database_id(),
new_outline_schema->get_signature_str());
new_outline_schema->get_signature_str(),
new_outline_schema->is_format());
hash_ret = signature_map_.set_refactored(outline_signature_wrapper,
new_outline_schema, over_write);
if (OB_SUCCESS != hash_ret && OB_HASH_EXIST != hash_ret) {
@ -387,14 +398,18 @@ int ObOutlineMgr::add_outline(const ObSimpleOutlineSchema &outline_schema)
} else {
ObOutlineSqlIdHashWrapper outline_sql_id_wrapper(new_outline_schema->get_tenant_id(),
new_outline_schema->get_database_id(),
new_outline_schema->get_sql_id_str());
new_outline_schema->is_format() ? new_outline_schema->get_format_sql_id_str()
: new_outline_schema->get_sql_id_str(),
new_outline_schema->is_format());
hash_ret = sql_id_map_.set_refactored(outline_sql_id_wrapper,
new_outline_schema, over_write);
if (OB_SUCCESS != hash_ret && OB_HASH_EXIST != hash_ret) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("build outline signature hashmap failed", K(ret), K(hash_ret),
"outline_id", new_outline_schema->get_outline_id(),
"outline_sql_id", new_outline_schema->get_sql_id_str());
"outline_sql_id", new_outline_schema->get_sql_id_str(),
"format outline", new_outline_schema->get_format_sql_id_str(),
"is_format", new_outline_schema->is_format());
}
}
}
@ -467,7 +482,8 @@ int ObOutlineMgr::del_outline(const ObTenantOutlineId &outline)
if (OB_SUCC(ret)) {
ObOutlineNameHashWrapper name_wrapper(schema_to_del->get_tenant_id(),
schema_to_del->get_database_id(),
schema_to_del->get_name_str());
schema_to_del->get_name_str(),
schema_to_del->is_format());
hash_ret = outline_name_map_.erase_refactored(name_wrapper);
if (OB_SUCCESS != hash_ret) {
ret = OB_ERR_UNEXPECTED;
@ -476,14 +492,16 @@ int ObOutlineMgr::del_outline(const ObTenantOutlineId &outline)
K(hash_ret),
"tenant_id", schema_to_del->get_tenant_id(),
"database_id", schema_to_del->get_database_id(),
"name", schema_to_del->get_name());
"name", schema_to_del->get_name(),
"is format", schema_to_del->is_format());
}
}
if (OB_SUCC(ret)) {
if (0 != schema_to_del->get_signature_str().length()) {
ObOutlineSignatureHashWrapper outline_signature_wrapper(schema_to_del->get_tenant_id(),
schema_to_del->get_database_id(),
schema_to_del->get_signature_str());
schema_to_del->get_signature_str(),
schema_to_del->is_format());
hash_ret = signature_map_.erase_refactored(outline_signature_wrapper);
if (OB_SUCCESS != hash_ret) {
ret = OB_ERR_UNEXPECTED;
@ -492,12 +510,15 @@ int ObOutlineMgr::del_outline(const ObTenantOutlineId &outline)
K(hash_ret),
"tenant_id", schema_to_del->get_tenant_id(),
"database_id", schema_to_del->get_database_id(),
"signature", schema_to_del->get_signature());
"signature", schema_to_del->get_signature(),
"is format", schema_to_del->is_format());
}
} else {
ObOutlineSqlIdHashWrapper outline_sql_id_wrapper(schema_to_del->get_tenant_id(),
schema_to_del->get_database_id(),
schema_to_del->get_sql_id_str());
schema_to_del->get_database_id(),
schema_to_del->is_format() ? schema_to_del->get_format_sql_id_str()
: schema_to_del->get_sql_id_str(),
schema_to_del->is_format());
hash_ret = sql_id_map_.erase_refactored(outline_sql_id_wrapper);
if (OB_SUCCESS != hash_ret) {
ret = OB_ERR_UNEXPECTED;
@ -506,7 +527,9 @@ int ObOutlineMgr::del_outline(const ObTenantOutlineId &outline)
K(hash_ret),
"tenant_id", schema_to_del->get_tenant_id(),
"database_id", schema_to_del->get_database_id(),
"sql_id", schema_to_del->get_sql_id_str());
"sql_id", schema_to_del->get_sql_id_str(),
"format outline", schema_to_del->get_format_sql_id_str(),
"is format", schema_to_del->is_format());
}
}
}
@ -569,6 +592,7 @@ int ObOutlineMgr::get_outline_schema_with_name(
const uint64_t tenant_id,
const uint64_t database_id,
const ObString &name,
const bool is_format,
const ObSimpleOutlineSchema *&outline_schema) const
{
int ret = OB_SUCCESS;
@ -584,7 +608,7 @@ int ObOutlineMgr::get_outline_schema_with_name(
LOG_WARN("invalid argument", K(ret), K(tenant_id), K(database_id), K(name));
} else {
ObSimpleOutlineSchema *tmp_schema = NULL;
const ObOutlineNameHashWrapper name_wrapper(tenant_id, database_id, name);
const ObOutlineNameHashWrapper name_wrapper(tenant_id, database_id, name, is_format);
int hash_ret = outline_name_map_.get_refactored(name_wrapper, tmp_schema);
if (OB_SUCCESS == hash_ret) {
if (OB_ISNULL(tmp_schema)) {
@ -603,6 +627,7 @@ int ObOutlineMgr::get_outline_schema_with_signature(
const uint64_t tenant_id,
const uint64_t database_id,
const ObString &signature,
const bool is_format,
const ObSimpleOutlineSchema *&outline_schema) const
{
int ret = OB_SUCCESS;
@ -619,7 +644,7 @@ int ObOutlineMgr::get_outline_schema_with_signature(
} else {
ObSimpleOutlineSchema *tmp_schema = NULL;
const ObOutlineSignatureHashWrapper outline_signature_wrapper(tenant_id, database_id,
signature);
signature, is_format);
int hash_ret = signature_map_.get_refactored(outline_signature_wrapper, tmp_schema);
if (OB_SUCCESS == hash_ret) {
if (OB_ISNULL(tmp_schema)) {
@ -638,6 +663,7 @@ int ObOutlineMgr::get_outline_schema_with_sql_id(
const uint64_t tenant_id,
const uint64_t database_id,
const ObString &sql_id,
const bool is_format,
const ObSimpleOutlineSchema *&outline_schema) const
{
int ret = OB_SUCCESS;
@ -654,7 +680,7 @@ int ObOutlineMgr::get_outline_schema_with_sql_id(
} else {
ObSimpleOutlineSchema *tmp_schema = NULL;
const ObOutlineSqlIdHashWrapper outline_sql_id_wrapper(tenant_id, database_id,
sql_id);
sql_id, is_format);
int hash_ret = sql_id_map_.get_refactored(outline_sql_id_wrapper, tmp_schema);
if (OB_SUCCESS == hash_ret) {
if (OB_ISNULL(tmp_schema)) {
@ -820,7 +846,8 @@ int ObOutlineMgr::rebuild_outline_hashmap()
if (OB_SUCC(ret)) {
ObOutlineNameHashWrapper name_wrapper(outline_schema->get_tenant_id(),
outline_schema->get_database_id(),
outline_schema->get_name_str());
outline_schema->get_name_str(),
outline_schema->is_format());
hash_ret = outline_name_map_.set_refactored(name_wrapper, outline_schema,
over_write);
if (OB_SUCCESS != hash_ret) {
@ -834,7 +861,8 @@ int ObOutlineMgr::rebuild_outline_hashmap()
if (0 != outline_schema->get_signature_str().length()) {
ObOutlineSignatureHashWrapper outline_signature_wrapper(outline_schema->get_tenant_id(),
outline_schema->get_database_id(),
outline_schema->get_signature_str());
outline_schema->get_signature_str(),
outline_schema->is_format());
hash_ret = signature_map_.set_refactored(outline_signature_wrapper,
outline_schema, over_write);
if (OB_SUCCESS != hash_ret) {
@ -844,9 +872,12 @@ int ObOutlineMgr::rebuild_outline_hashmap()
"signature", outline_schema->get_signature());
}
} else {
ObOutlineSqlIdHashWrapper outline_signature_wrapper(outline_schema->get_tenant_id(),
outline_schema->get_database_id(),
outline_schema->get_sql_id_str());
outline_schema->is_format() ? outline_schema->get_format_sql_id_str()
: outline_schema->get_sql_id_str(),
outline_schema->is_format());
hash_ret = sql_id_map_.set_refactored(outline_signature_wrapper,
outline_schema, over_write);
if (OB_SUCCESS != hash_ret) {

View File

@ -40,7 +40,9 @@ public:
K_(schema_version),
K_(database_id),
K_(name),
K_(signature));
K_(signature),
K_(format_sql_id),
K_(format_outline));
virtual void reset();
inline bool is_valid() const;
inline int64_t get_convert_size() const;
@ -52,6 +54,8 @@ public:
inline int64_t get_schema_version() const { return schema_version_; }
inline void set_database_id(const uint64_t database_id) { database_id_ = database_id; }
inline uint64_t get_database_id() const { return database_id_; }
int set_format_sql_id(const char *sql_id) { return deep_copy_str(sql_id, format_sql_id_); }
int set_format_sql_id(const common::ObString &sql_id) { return deep_copy_str(sql_id, format_sql_id_); }
inline int set_name(const common::ObString &name)
{ return deep_copy_str(name, name_); }
inline const char *get_name() const { return extract_str(name_); }
@ -64,8 +68,12 @@ public:
inline const char *get_sql_id() const { return extract_str(sql_id_); }
inline const common::ObString &get_signature_str() const { return signature_; }
inline const common::ObString &get_sql_id_str() const { return sql_id_; }
inline const char *get_format_sql_id() const { return extract_str(format_sql_id_); }
inline const common::ObString &get_format_sql_id_str() const { return format_sql_id_; }
inline ObTenantOutlineId get_tenant_outline_id() const
{ return ObTenantOutlineId(tenant_id_, outline_id_); }
void set_format_outline(bool is_format) { format_outline_ = is_format;}
inline bool is_format() const { return format_outline_; }
private:
uint64_t tenant_id_;
@ -75,6 +83,8 @@ private:
common::ObString name_;
common::ObString signature_;
common::ObString sql_id_;
common::ObString format_sql_id_;
bool format_outline_;
};
template<class T, class V>
@ -106,6 +116,7 @@ struct ObGetOutlineKeyV3<ObOutlineNameHashWrapper, ObSimpleOutlineSchema *>
name_wrap.set_tenant_id(outline_schema->get_tenant_id());
name_wrap.set_database_id(outline_schema->get_database_id());
name_wrap.set_name(outline_schema->get_name_str());
name_wrap.set_is_format(outline_schema->is_format());
}
return name_wrap;
}
@ -121,6 +132,7 @@ struct ObGetOutlineKeyV3<ObOutlineSignatureHashWrapper, ObSimpleOutlineSchema *>
sql_wrap.set_tenant_id(outline_schema->get_tenant_id());
sql_wrap.set_database_id(outline_schema->get_database_id());
sql_wrap.set_signature(outline_schema->get_signature_str());
sql_wrap.set_is_format(outline_schema->is_format());
}
return sql_wrap;
}
@ -133,9 +145,12 @@ struct ObGetOutlineKeyV3<ObOutlineSqlIdHashWrapper, ObSimpleOutlineSchema *>
{
ObOutlineSqlIdHashWrapper sql_wrap;
if (!OB_ISNULL(outline_schema)) {
ObString sql_id = outline_schema->is_format() ? outline_schema->get_format_sql_id_str()
: outline_schema->get_sql_id_str();
sql_wrap.set_tenant_id(outline_schema->get_tenant_id());
sql_wrap.set_database_id(outline_schema->get_database_id());
sql_wrap.set_sql_id(outline_schema->get_sql_id_str());
sql_wrap.set_sql_id(sql_id);
sql_wrap.set_is_format(outline_schema->is_format());
}
return sql_wrap;
}
@ -176,14 +191,17 @@ public:
int get_outline_schema_with_name(const uint64_t tenant_id,
const uint64_t database_id,
const common::ObString &name,
const bool is_format,
const ObSimpleOutlineSchema *&outline_schema) const;
int get_outline_schema_with_signature(const uint64_t tenant_id,
const uint64_t database_id,
const common::ObString &signature,
const bool is_format,
const ObSimpleOutlineSchema *&outline_schema) const;
int get_outline_schema_with_sql_id(const uint64_t tenant_id,
const uint64_t database_id,
const common::ObString &sql_id,
const bool is_format,
const ObSimpleOutlineSchema *&outline_schema) const;
int get_outline_schemas_in_tenant(const uint64_t tenant_id,
common::ObIArray<const ObSimpleOutlineSchema *> &outline_schemas) const;

View File

@ -35,7 +35,10 @@ int ObOutlineSqlService::insert_outline(const ObOutlineInfo &outline_info,
int ret = OB_SUCCESS;
if (!outline_info.is_valid()) {
ret = OB_INVALID_ARGUMENT;
SHARE_SCHEMA_LOG(WARN, "outline_info is invalid", K(outline_info), K(ret));
SHARE_SCHEMA_LOG(WARN, "outline_info is invalid", K(outline_info), K(ret),
K(outline_info.is_format()),
K(outline_info.get_format_sql_text_str().empty()),
K(ObOutlineInfo::is_sql_id_valid(outline_info.get_format_sql_id_str())));
} else {
if (OB_FAIL(add_outline(sql_client, outline_info))) {
LOG_WARN("failed to add outline", K(ret));
@ -71,10 +74,21 @@ int ObOutlineSqlService::replace_outline(const ObOutlineInfo &outline_info,
uint64_t outline_id = outline_info.get_outline_id();
ObString outline_params_hex_str;
ObArenaAllocator allocator(ObModIds::OB_SCHEMA);
uint64_t compat_version = 0;
// modify __all_outline table
if (OB_SUCC(ret)) {
if (OB_FAIL(outline_info.get_hex_str_from_outline_params(outline_params_hex_str, allocator))) {
LOG_WARN("fail to get_hex_str_from_outline_params", K(ret));
} else if (OB_FAIL(GET_MIN_DATA_VERSION(tenant_id, compat_version))) {
LOG_WARN("fail to get data version", KR(ret), K(tenant_id));
} else if (!is_formatoutline_compat(compat_version) &&
(!outline_info.get_format_sql_text_str().empty()
|| !outline_info.get_format_sql_id_str().empty()
|| outline_info.is_format())) {
ret = OB_NOT_SUPPORTED;
LOG_WARN("format outline is not suppported when tenant's data version is below 4.3.4.0", KR(ret),
K(outline_info.is_format()), K(outline_info.get_format_sql_text_str().empty()),
K(outline_info.get_format_sql_id_str().empty()));
}
if (OB_SUCC(ret)) {
@ -88,11 +102,23 @@ int ObOutlineSqlService::replace_outline(const ObOutlineInfo &outline_info,
|| OB_FAIL(dml.add_column("outline_params", ObHexEscapeSqlStr(outline_params_hex_str)))
|| OB_FAIL(dml.add_column("sql_text", outline_info.get_sql_text_str().empty() ? ObString::make_string("") : ObHexEscapeSqlStr(outline_info.get_sql_text_str())))
|| OB_FAIL(dml.add_column("sql_id", outline_info.get_sql_id_str().empty() ? ObString::make_string("") : ObHexEscapeSqlStr(outline_info.get_sql_id_str())))
|| (is_formatoutline_compat(compat_version) &&
OB_FAIL(dml.add_column("format_sql_text",
outline_info.get_format_sql_text_str().empty() ?
ObString::make_string("") :
ObHexEscapeSqlStr(outline_info.get_format_sql_text_str()))))
|| (is_formatoutline_compat(compat_version) &&
OB_FAIL(dml.add_column("format_sql_id",
outline_info.get_format_sql_id_str().empty() ?
ObString::make_string("") :
ObHexEscapeSqlStr(outline_info.get_format_sql_id_str()))))
|| OB_FAIL(dml.add_column("version", ObHexEscapeSqlStr(outline_info.get_version_str())))
|| OB_FAIL(dml.add_column("schema_version", outline_info.get_schema_version()))
|| OB_FAIL(dml.add_column("outline_target", ObHexEscapeSqlStr(
outline_info.get_outline_target_str().empty() ? ObString::make_string("")
: outline_info.get_outline_target_str())))
|| (is_formatoutline_compat(compat_version) &&
OB_FAIL(dml.add_column("format_outline", outline_info.is_format())))
|| OB_FAIL(dml.add_gmt_modified())) {
LOG_WARN("add column failed", K(ret));
}
@ -147,12 +173,20 @@ int ObOutlineSqlService::alter_outline(const ObOutlineInfo &outline_info,
uint64_t tenant_id = outline_info.get_tenant_id();
const uint64_t exec_tenant_id = ObSchemaUtils::get_exec_tenant_id(tenant_id);
uint64_t outline_id = outline_info.get_outline_id();
uint64_t compat_version = 0;
ObString outline_params_hex_str;
ObArenaAllocator allocator(ObModIds::OB_SCHEMA);
// modify __all_outline table
if (OB_SUCC(ret)) {
if (OB_FAIL(outline_info.get_hex_str_from_outline_params(outline_params_hex_str, allocator))) {
LOG_WARN("fail to get_hex_str_from_max_concurrent_param", K(ret));
} else if (OB_FAIL(GET_MIN_DATA_VERSION(exec_tenant_id, compat_version))) {
LOG_WARN("fail to get data version", KR(ret), K(tenant_id));
} else if (!is_formatoutline_compat(compat_version) &&
!outline_info.get_format_sql_text_str().empty()) {
ret = OB_NOT_SUPPORTED;
LOG_WARN("format outline is not suppported when tenant's data version is below 4.3.4.0", KR(ret),
K(outline_info.get_format_sql_text_str().empty()));
}
// outline_content is described by sql_test here.
@ -165,7 +199,13 @@ int ObOutlineSqlService::alter_outline(const ObOutlineInfo &outline_info,
outline_info.get_outline_content_str().empty() ? ObString::make_string("")
: outline_info.get_outline_content_str())))
|| OB_FAIL(dml.add_column("outline_params", ObHexEscapeSqlStr(outline_params_hex_str)))
|| OB_FAIL(dml.add_column("sql_text", ObHexEscapeSqlStr(outline_info.get_sql_text_str())))
|| OB_FAIL(dml.add_column("sql_text", ObHexEscapeSqlStr(
outline_info.get_sql_text_str().empty() ? ObString::make_string("")
: outline_info.get_sql_text_str())))
|| (is_formatoutline_compat(compat_version) &&
OB_FAIL(dml.add_column("format_sql_text",
outline_info.get_format_sql_text_str().empty() ? ObString::make_string("")
: ObHexEscapeSqlStr(outline_info.get_format_sql_text_str()))))
|| OB_FAIL(dml.add_column("schema_version", outline_info.get_schema_version()))
|| OB_FAIL(dml.add_gmt_modified())) {
LOG_WARN("add column failed", K(ret));
@ -282,6 +322,7 @@ int ObOutlineSqlService::add_outline(common::ObISQLClient &sql_client,
int ret = OB_SUCCESS;
ObSqlString sql;
ObSqlString values;
uint64_t compat_version = 0;
const char *tname[] = {OB_ALL_OUTLINE_TNAME, OB_ALL_OUTLINE_HISTORY_TNAME};
ObString max_outline_params_hex_str;
ObArenaAllocator allocator(ObModIds::OB_SCHEMA);
@ -289,7 +330,18 @@ int ObOutlineSqlService::add_outline(common::ObISQLClient &sql_client,
const uint64_t exec_tenant_id = ObSchemaUtils::get_exec_tenant_id(tenant_id);
if (OB_FAIL(outline_info.get_hex_str_from_outline_params(max_outline_params_hex_str, allocator))) {
LOG_WARN("fail to get_hex_str_from_outline_params", K(ret));
} else if (OB_FAIL(GET_MIN_DATA_VERSION(exec_tenant_id, compat_version))) {
LOG_WARN("fail to get data version", KR(ret), K(exec_tenant_id));
} else if (!is_formatoutline_compat(compat_version) &&
(!outline_info.get_format_sql_text_str().empty()
|| !outline_info.get_format_sql_id_str().empty()
|| outline_info.is_format())) {
ret = OB_NOT_SUPPORTED;
LOG_WARN("format outline is not suppported when tenant's data version is below 4.3.4.0", KR(ret),
K(outline_info.is_format()), K(outline_info.get_format_sql_text_str().empty()),
K(outline_info.get_format_sql_id_str().empty()));
}
for (int64_t i = 0; OB_SUCC(ret) && i < ARRAYSIZEOF(tname); i++) {
if (only_history && 0 == STRCMP(tname[i], OB_ALL_OUTLINE_TNAME)) {
continue;
@ -322,6 +374,14 @@ int ObOutlineSqlService::add_outline(common::ObISQLClient &sql_client,
max_outline_params_hex_str.length(), "outline_params");
SQL_COL_APPEND_ESCAPE_STR_VALUE(sql, values, outline_info.get_outline_target(),
outline_info.get_outline_target_str().length(), "outline_target");
if (is_formatoutline_compat(compat_version)) {
SQL_COL_APPEND_ESCAPE_STR_VALUE(sql, values, outline_info.get_format_sql_id(),
outline_info.get_format_sql_id_str().length(), "format_sql_id");
SQL_COL_APPEND_ESCAPE_STR_VALUE(sql, values, outline_info.get_format_sql_text(),
outline_info.get_format_sql_text_str().length(), "format_sql_text");
SQL_COL_APPEND_VALUE(sql, values, outline_info.is_format(), "format_outline", "%d");
}
if (0 == STRCMP(tname[i], OB_ALL_OUTLINE_HISTORY_TNAME)) {
SQL_COL_APPEND_VALUE(sql, values, "false", "is_deleted", "%s");
}

View File

@ -50,6 +50,9 @@ public:
const int64_t new_schema_version,
common::ObISQLClient &sql_client,
const common::ObString *ddl_stmt_str = NULL);
static bool is_formatoutline_compat(uint64_t compat_version) {
return compat_version < DATA_VERSION_4_3_0_0 || compat_version >= DATA_VERSION_4_3_4_0;
}
private:
int add_outline(common::ObISQLClient &sql_client, const ObOutlineInfo &outline_info,
const bool only_history = false);

View File

@ -2870,6 +2870,53 @@ int ObSchemaGetterGuard::check_activate_all_role_var(const uint64_t tenant_id, b
return ret;
}
int ObSchemaGetterGuard::is_user_empty_passwd(const ObUserLoginInfo &login_info, bool &is_empty_passwd_account) {
int ret = OB_SUCCESS;
lib::Worker::CompatMode compat_mode = lib::Worker::CompatMode::INVALID;
uint64_t tenant_id = OB_INVALID_ID;
is_empty_passwd_account = false;
if (OB_FAIL(get_tenant_id(login_info.tenant_name_,tenant_id))) {
LOG_WARN("Invalid tenant", "tenant_name", login_info.tenant_name_, KR(ret));
} else if (OB_FAIL(check_tenant_schema_guard(tenant_id))) {
LOG_WARN("fail to check tenant schema guard", KR(ret), K_(tenant_id));
} else if (OB_FAIL(get_tenant_compat_mode(tenant_id, compat_mode))) {
LOG_WARN("fail to get tenant compat mode", K(ret));
} else {
const int64_t DEFAULT_SAME_USERNAME_COUNT = 4;
ObSEArray<const ObUserInfo *, DEFAULT_SAME_USERNAME_COUNT> users_info;
if (OB_FAIL(get_user_info(tenant_id, login_info.user_name_, users_info))) {
LOG_WARN("get user info failed", KR(ret), K(tenant_id), K(login_info));
} else if (users_info.empty()) {
ret = OB_PASSWORD_WRONG;
LOG_WARN("No tenant user", K(login_info), KR(ret));
} else {
const ObUserInfo *user_info = NULL;
const ObUserInfo *matched_user_info = NULL;
for (int64_t i = 0; i < users_info.count() && OB_SUCC(ret); ++i) {
user_info = users_info.at(i);
if (NULL == user_info) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("user info is null", K(login_info), KR(ret));
} else if (user_info->is_role() && lib::Worker::CompatMode::ORACLE == compat_mode) {
ret = OB_PASSWORD_WRONG;
LOG_INFO("password error", "tenant_name", login_info.tenant_name_,
"user_name", login_info.user_name_,
"client_ip_", login_info.client_ip_, KR(ret));
} else if (!obsys::ObNetUtil::is_match(login_info.client_ip_, user_info->get_host_name_str())) {
LOG_TRACE("account not matched, try next", KPC(user_info), K(login_info));
} else {
matched_user_info = user_info;
if (0 == login_info.passwd_.length() && 0 == user_info->get_passwd_str().length()) {
is_empty_passwd_account = true;
break;
}
}
}
}
}
return ret;
}
// for privilege
int ObSchemaGetterGuard::check_user_access(
const ObUserLoginInfo &login_info,
@ -6501,6 +6548,7 @@ int ObSchemaGetterGuard::check_outline_exist_with_name(
const uint64_t tenant_id,
const uint64_t database_id,
const common::ObString &name,
const bool is_format,
uint64_t &outline_id,
bool &exist)
{
@ -6524,7 +6572,7 @@ int ObSchemaGetterGuard::check_outline_exist_with_name(
} else {
const ObSimpleOutlineSchema *schema = NULL;
if (OB_FAIL(mgr->outline_mgr_.get_outline_schema_with_name(tenant_id, database_id,
name, schema))) {
name, is_format, schema))) {
LOG_WARN("get outline schema failed", KR(ret),
K(tenant_id), K(database_id), K(name));
} else if (NULL != schema) {
@ -6540,6 +6588,7 @@ int ObSchemaGetterGuard::check_outline_exist_with_sql_id(
const uint64_t tenant_id,
const uint64_t database_id,
const common::ObString &sql_id,
const bool is_format,
bool &exist)
{
int ret= OB_SUCCESS;
@ -6561,7 +6610,7 @@ int ObSchemaGetterGuard::check_outline_exist_with_sql_id(
} else {
const ObSimpleOutlineSchema *schema = NULL;
if (OB_FAIL(mgr->outline_mgr_.get_outline_schema_with_sql_id(tenant_id, database_id,
sql_id, schema))) {
sql_id, is_format, schema))) {
LOG_WARN("get outline schema failed", KR(ret),
K(tenant_id), K(database_id), K(sql_id));
} else if (NULL != schema) {
@ -6576,6 +6625,7 @@ int ObSchemaGetterGuard::check_outline_exist_with_sql(
const uint64_t tenant_id,
const uint64_t database_id,
const common::ObString &paramlized_sql,
const bool is_format,
bool &exist)
{
int ret= OB_SUCCESS;
@ -6597,7 +6647,7 @@ int ObSchemaGetterGuard::check_outline_exist_with_sql(
} else {
const ObSimpleOutlineSchema *schema = NULL;
if (OB_FAIL(mgr->outline_mgr_.get_outline_schema_with_signature(tenant_id, database_id,
paramlized_sql, schema))) {
paramlized_sql, is_format, schema))) {
LOG_WARN("get outline schema failed", KR(ret),
K(tenant_id), K(database_id), K(paramlized_sql));
} else if (NULL != schema) {
@ -7020,6 +7070,7 @@ int ObSchemaGetterGuard::get_outline_info_with_name(
const uint64_t tenant_id,
const uint64_t database_id,
const common::ObString &name,
const bool is_format,
const ObOutlineInfo *&outline_info)
{
int ret = OB_SUCCESS;
@ -7040,7 +7091,7 @@ int ObSchemaGetterGuard::get_outline_info_with_name(
} else if (OB_FAIL(check_lazy_guard(tenant_id, mgr))) {
LOG_WARN("fail to check lazy guard", KR(ret), K(tenant_id));
} else if (OB_FAIL(mgr->outline_mgr_.get_outline_schema_with_name(tenant_id,
database_id, name, simple_outline))) {
database_id, name, is_format, simple_outline))) {
LOG_WARN("get simple outline failed", KR(ret), K(tenant_id), K(database_id), K(name));
} else if (NULL == simple_outline) {
LOG_INFO("outline not exist", K(tenant_id), K(database_id), K(name));
@ -7062,6 +7113,7 @@ int ObSchemaGetterGuard::get_outline_info_with_name(
const uint64_t tenant_id,
const ObString &db_name,
const ObString &outline_name,
const bool is_format,
const ObOutlineInfo *&outline_info)
{
int ret = OB_SUCCESS;
@ -7087,7 +7139,7 @@ int ObSchemaGetterGuard::get_outline_info_with_name(
} else if (OB_INVALID_ID == database_id) {
// do-nothing
} else if (OB_FAIL(mgr->outline_mgr_.get_outline_schema_with_name(tenant_id,
database_id, outline_name, simple_outline))) {
database_id, outline_name, is_format, simple_outline))) {
LOG_WARN("get simple outline failed", KR(ret), K(tenant_id), K(database_id), K(outline_name));
} else if (NULL == simple_outline) {
LOG_TRACE("outline not exist", K(tenant_id), K(database_id), K(outline_name));
@ -7108,6 +7160,7 @@ int ObSchemaGetterGuard::get_outline_info_with_signature(
const uint64_t tenant_id,
const uint64_t database_id,
const common::ObString &signature,
const bool is_format,
const ObOutlineInfo *&outline_info)
{
int ret = OB_SUCCESS;
@ -7128,10 +7181,10 @@ int ObSchemaGetterGuard::get_outline_info_with_signature(
} else if (OB_FAIL(check_lazy_guard(tenant_id, mgr))) {
LOG_WARN("fail to check lazy guard", KR(ret), K(tenant_id));
} else if (OB_FAIL(mgr->outline_mgr_.get_outline_schema_with_signature(tenant_id,
database_id, signature, simple_outline))) {
database_id, signature, is_format, simple_outline))) {
LOG_WARN("get simple outline failed", KR(ret), K(tenant_id), K(database_id), K(signature));
} else if (NULL == simple_outline) {
LOG_TRACE("outline not exist", K(tenant_id), K(database_id), K(signature));
LOG_TRACE("outline not exist", K(tenant_id), K(is_format), K(database_id), K(signature));
} else if (OB_FAIL(get_schema(OUTLINE_SCHEMA,
simple_outline->get_tenant_id(),
simple_outline->get_outline_id(),
@ -7695,6 +7748,7 @@ int ObSchemaGetterGuard::get_outline_info_with_sql_id(
const uint64_t tenant_id,
const uint64_t database_id,
const common::ObString &sql_id,
const bool is_format,
const ObOutlineInfo *&outline_info)
{
int ret = OB_SUCCESS;
@ -7715,10 +7769,10 @@ int ObSchemaGetterGuard::get_outline_info_with_sql_id(
} else if (OB_FAIL(check_lazy_guard(tenant_id, mgr))) {
LOG_WARN("fail to check lazy guard", KR(ret), K(tenant_id));
} else if (OB_FAIL(mgr->outline_mgr_.get_outline_schema_with_sql_id(tenant_id,
database_id, sql_id, simple_outline))) {
database_id, sql_id, is_format, simple_outline))) {
LOG_WARN("get simple outline failed", KR(ret), K(tenant_id), K(database_id), K(sql_id));
} else if (NULL == simple_outline) {
LOG_DEBUG("outline not exist", K(tenant_id), K(database_id), K(sql_id));
LOG_TRACE("outline not exist", K(tenant_id), K(database_id), K(sql_id));
} else if (OB_FAIL(get_schema(OUTLINE_SCHEMA,
simple_outline->get_tenant_id(),
simple_outline->get_outline_id(),

View File

@ -470,6 +470,7 @@ public:
// for readonly
int verify_read_only(const uint64_t tenant_id, const ObStmtNeedPrivs &stmt_need_privs);
int is_user_empty_passwd(const ObUserLoginInfo &login_info, bool &is_empty_passwd_account);
int check_user_access(const ObUserLoginInfo &login_info,
ObSessionPrivInfo &s_priv,
SSL *ssl_st,
@ -637,27 +638,33 @@ public:
int check_outline_exist_with_name(const uint64_t tenant_id,
const uint64_t database_id,
const common::ObString &outline_name,
const bool is_format,
uint64_t &outline_id,
bool &exist);
int check_outline_exist_with_sql(const uint64_t tenant_id,
const uint64_t database_id,
const common::ObString &paramlized_sql,
const bool is_format,
bool &exist);
int check_outline_exist_with_sql_id(const uint64_t tenant_id,
const uint64_t database_id,
const common::ObString &sql_id,
const bool is_format,
bool &exist) ;
int get_outline_info_with_name(const uint64_t tenant_id,
const uint64_t database_id,
const common::ObString &name,
const bool is_format,
const ObOutlineInfo *&outline_info);
int get_outline_info_with_name(const uint64_t tenant_id,
const common::ObString &db_name,
const common::ObString &outline_name,
const bool is_format,
const ObOutlineInfo *&outline_info);
int get_outline_info_with_signature(const uint64_t tenant_id,
const uint64_t database_id,
const common::ObString &signature,
const bool is_format,
const ObOutlineInfo *&outline_info);
//package
int check_package_exist(uint64_t tenant_id, uint64_t database_id,
@ -776,6 +783,7 @@ public:
int get_outline_info_with_sql_id(const uint64_t tenant_id,
const uint64_t database_id,
const common::ObString &sql_id,
const bool is_format,
const ObOutlineInfo *&outline_info) ;
//about user define function
int check_udf_exist_with_name(const uint64_t tenant_id,

View File

@ -2388,6 +2388,7 @@ int ObSchemaRetrieveUtils::fill_outline_schema(
is_deleted = false;
int ret = common::OB_SUCCESS;
outline_info.set_tenant_id(tenant_id);
bool ignore_column_error = true;
EXTRACT_INT_FIELD_TO_CLASS_MYSQL_WITH_TENANT_ID(result, outline_id, outline_info, tenant_id);
EXTRACT_INT_FIELD_MYSQL(result, "is_deleted", is_deleted, bool);
if (!is_deleted) {
@ -2407,6 +2408,12 @@ int ObSchemaRetrieveUtils::fill_outline_schema(
EXTRACT_INT_FIELD_TO_CLASS_MYSQL(result, format, outline_info, ObHintFormat);
EXTRACT_VARCHAR_FIELD_TO_CLASS_MYSQL(result, outline_params, outline_info);
EXTRACT_VARCHAR_FIELD_TO_CLASS_MYSQL(result, outline_target, outline_info);
EXTRACT_VARCHAR_FIELD_TO_CLASS_MYSQL_WITH_DEFAULT_VALUE(
result, format_sql_text, outline_info, true, ignore_column_error, ObString::make_string(""));
EXTRACT_VARCHAR_FIELD_TO_CLASS_MYSQL_WITH_DEFAULT_VALUE(
result, format_sql_id, outline_info, true, ignore_column_error, ObString::make_string(""));
EXTRACT_INT_FIELD_TO_CLASS_MYSQL_WITH_DEFAULT_VALUE(
result, format_outline, outline_info, bool, true, ignore_column_error, false);
}
return ret;
}
@ -4560,6 +4567,7 @@ int ObSchemaRetrieveUtils::fill_outline_schema(
bool &is_deleted)
{
int ret = common::OB_SUCCESS;
bool ignore_column_error = true;
outline_schema.reset();
is_deleted = false;
@ -4573,6 +4581,10 @@ int ObSchemaRetrieveUtils::fill_outline_schema(
EXTRACT_VARCHAR_FIELD_TO_CLASS_MYSQL(result, signature, outline_schema);
EXTRACT_VARCHAR_FIELD_TO_CLASS_MYSQL_WITH_DEFAULT_VALUE(
result, sql_id, outline_schema, true, ObSchemaService::g_ignore_column_retrieve_error_, ObString::make_string(""));
EXTRACT_VARCHAR_FIELD_TO_CLASS_MYSQL_WITH_DEFAULT_VALUE(
result, format_sql_id, outline_schema, true, ignore_column_error, ObString::make_string(""));
EXTRACT_INT_FIELD_TO_CLASS_MYSQL_WITH_DEFAULT_VALUE(
result, format_outline, outline_schema, bool, true, ignore_column_error, false);
}
return ret;
}

View File

@ -9411,7 +9411,8 @@ int ObSchemaServiceSQLImpl::get_link_table_schema(const ObDbLinkSchema *dblink_s
LOG_WARN("unexpected null", K(ret), KP(dblink_schema));
} else if (sql::DblinkGetConnType::DBLINK_POOL == conn_type &&
OB_FAIL(dblink_proxy_->create_dblink_pool(param_ctx,
dblink_schema->get_host_addr(),
dblink_schema->get_host_name(),
dblink_schema->get_host_port(),
dblink_schema->get_tenant_name(),
dblink_schema->get_user_name(),
dblink_schema->get_plain_password(),

View File

@ -10607,6 +10607,7 @@ void ObOutlineInfo::reset()
format_ = HINT_NORMAL;
format_outline_ = false;
outline_params_wrapper_.destroy();
format_outline_ = false;
ObSchema::reset();
}
@ -10634,11 +10635,16 @@ bool ObOutlineInfo::is_valid() const
bool valid_ret = true;
if (!ObSchema::is_valid()) {
valid_ret = false;
} else if (name_.empty() || !((!signature_.empty() && !sql_text_.empty() && sql_id_.empty())
|| (signature_.empty() && sql_text_.empty() && is_sql_id_valid(sql_id_)))
} else if (name_.empty()
|| owner_.empty() || version_.empty()
|| (outline_content_.empty() && !has_outline_params())) {
valid_ret = false;
} else if (!is_format() && !((!signature_.empty() && !sql_text_.empty() && sql_id_.empty())
|| (signature_.empty() && sql_text_.empty() && is_sql_id_valid(sql_id_)))) {
valid_ret = false;
} else if (is_format() && !(((format_sql_text_.empty() && is_sql_id_valid(format_sql_id_))
|| (!format_sql_text_.empty() && format_sql_id_.empty())))) {
valid_ret = false;
} else if (OB_INVALID_ID == tenant_id_ || OB_INVALID_ID == database_id_ || OB_INVALID_ID == outline_id_) {
valid_ret = false;
} else if (schema_version_ <= 0) {
@ -10652,11 +10658,15 @@ bool ObOutlineInfo::is_valid_for_replace() const
bool valid_ret = true;
if (!ObSchema::is_valid()) {
valid_ret = false;
} else if (name_.empty() || !((!signature_.empty() && !sql_text_.empty() && sql_id_.empty())
|| (signature_.empty() && sql_text_.empty() && is_sql_id_valid(sql_id_)))
|| owner_.empty() || version_.empty()
} else if (name_.empty() || owner_.empty() || version_.empty()
|| (outline_content_.empty() && !has_outline_params())) {
valid_ret = false;
} else if (!is_format() && !((!signature_.empty() && !sql_text_.empty() && sql_id_.empty()) ||
(signature_.empty() && sql_text_.empty() && is_sql_id_valid(sql_id_)))) {
valid_ret = false;
} else if (is_format() && !((!signature_.empty() && !format_sql_text_.empty() && sql_id_.empty()) ||
(signature_.empty() && format_sql_text_.empty() && is_sql_id_valid(format_sql_id_)))) {
valid_ret = false;
} else if (OB_INVALID_ID == tenant_id_ || OB_INVALID_ID == database_id_
|| OB_INVALID_ID == outline_id_) {
valid_ret = false;
@ -10820,6 +10830,7 @@ OB_DEF_DESERIALIZE(ObOutlineInfo)
LOG_WARN("Fail to deep copy outline_content", K(ret));
} else if (OB_FAIL(deep_copy_str(sql_text, sql_text_))) {
LOG_WARN("Fail to deep copy sql_text", K(ret));
} else if (OB_FAIL(deep_copy_str(outline_target, outline_target_))) {
LOG_WARN("Fail to deep copy outline target", K(ret));
} else if (OB_FAIL(deep_copy_str(owner, owner_))) {
@ -11071,12 +11082,6 @@ int ObDbLinkBaseInfo::dblink_decrypt(common::ObString &src, common::ObString &ds
return ret;
}
int ObDbLinkBaseInfo::set_host_ip(const common::ObString &host_ip)
{
bool bret = host_addr_.set_ip_addr(host_ip, 0);
return bret ? common::OB_SUCCESS : common::OB_ERR_UNEXPECTED;
}
OB_SERIALIZE_MEMBER(ObDbLinkInfo,
tenant_id_,
owner_id_,

View File

@ -5910,11 +5910,15 @@ public:
int set_signature(const common::ObString &sig) { return deep_copy_str(sig, signature_); }
int set_sql_id(const char *sql_id) { return deep_copy_str(sql_id, sql_id_); }
int set_sql_id(const common::ObString &sql_id) { return deep_copy_str(sql_id, sql_id_); }
int set_format_sql_id(const char *sql_id) { return deep_copy_str(sql_id, format_sql_id_); }
int set_format_sql_id(const common::ObString &sql_id) { return deep_copy_str(sql_id, format_sql_id_); }
int set_outline_params(const common::ObString &outline_params_str);
int set_outline_content(const char *content) { return deep_copy_str(content, outline_content_); }
int set_outline_content(const common::ObString &content) { return deep_copy_str(content, outline_content_); }
int set_sql_text(const char *sql) { return deep_copy_str(sql, sql_text_); }
int set_sql_text(const common::ObString &sql) { return deep_copy_str(sql, sql_text_); }
int set_format_sql_text(const char *sql) { return deep_copy_str(sql, format_sql_text_); }
int set_format_sql_text(const common::ObString &sql) { return deep_copy_str(sql, format_sql_text_); }
int set_outline_target(const char *target) { return deep_copy_str(target, outline_target_); }
int set_outline_target(const common::ObString &target) { return deep_copy_str(target, outline_target_); }
int set_owner(const char *owner) { return deep_copy_str(owner, owner_); }
@ -5926,6 +5930,7 @@ public:
void set_compatible(const bool compatible) { compatible_ = compatible;}
void set_enabled(const bool enabled) { enabled_ = enabled;}
void set_format(const ObHintFormat hint_format) { format_ = hint_format;}
void set_format_outline(bool is_format) { format_outline_ = is_format;}
inline uint64_t get_tenant_id() const { return tenant_id_; }
inline uint64_t get_owner_id() const { return owner_id_; }
@ -5941,12 +5946,17 @@ public:
inline const char *get_signature() const { return extract_str(signature_); }
inline const char *get_sql_id() const { return extract_str(sql_id_); }
inline const common::ObString &get_sql_id_str() const { return sql_id_; }
inline const char *get_format_sql_id() const { return extract_str(format_sql_id_); }
inline const common::ObString &get_format_sql_id_str() const { return format_sql_id_; }
inline const common::ObString &get_signature_str() const { return signature_; }
inline const char *get_outline_content() const { return extract_str(outline_content_); }
inline const common::ObString &get_outline_content_str() const { return outline_content_; }
inline const char *get_sql_text() const { return extract_str(sql_text_); }
inline const common::ObString &get_sql_text_str() const { return sql_text_; }
inline common::ObString &get_sql_text_str() { return sql_text_; }
inline const char *get_format_sql_text() const { return extract_str(format_sql_text_); }
inline const common::ObString &get_format_sql_text_str() const { return format_sql_text_; }
inline common::ObString &get_format_sql_text_str() { return format_sql_text_; }
inline const char *get_outline_target() const { return extract_str(outline_target_); }
inline const common::ObString &get_outline_target_str() const { return outline_target_; }
inline common::ObString &get_outline_target_str() { return outline_target_; }
@ -6030,11 +6040,15 @@ public:
inline int set_user_name(const common::ObString &name) { return deep_copy_str(name, user_name_); }
inline int set_password(const common::ObString &password) { return deep_copy_str(password, password_); }
inline int set_encrypted_password(const common::ObString &encrypted_password) { return deep_copy_str(encrypted_password, encrypted_password_); }
inline int set_host_name(const common::ObString &host_name) { return deep_copy_str(host_name, host_name_); }
inline int set_reverse_host_name(const common::ObString &host_name) { return deep_copy_str(host_name, reverse_host_name_); }
int do_encrypt_password();
int set_plain_password(const common::ObString &plain_password) { return deep_copy_str(plain_password, plain_password_); }
inline void set_host_addr(const common::ObAddr &addr) { host_addr_ = addr; }
int set_host_ip(const common::ObString &host_ip);
inline void set_host_port(const int32_t host_port) { host_addr_.set_port(host_port); }
inline int set_host_ip(const common::ObString &host_ip) { return set_host_name(host_ip); }
inline void set_host_port(const int32_t host_port) { host_port_ = host_port; }
inline int set_reverse_host_ip(const common::ObString &host_ip) { return set_reverse_host_name(host_ip); }
inline void set_reverse_host_port(const int32_t reverse_host_port) { reverse_host_port_ = reverse_host_port; }
inline int set_database_name(const common::ObString &name) { return deep_copy_str(name, database_name_); }
inline int set_reverse_cluster_name(const common::ObString &name) { return deep_copy_str(name, reverse_cluster_name_); }
inline int set_reverse_tenant_name(const common::ObString &name) { return deep_copy_str(name, reverse_tenant_name_); }
@ -6043,8 +6057,6 @@ public:
int do_encrypt_reverse_password();
inline int set_plain_reverse_password(const common::ObString &password) { return deep_copy_str(password, plain_reverse_password_); }
inline void set_reverse_host_addr(const common::ObAddr &addr) { reverse_host_addr_ = addr; }
inline int set_reverse_host_ip(const common::ObString &host_ip) { reverse_host_addr_.set_ip_addr(host_ip, 0); return common::OB_SUCCESS; }
inline void set_reverse_host_port(const int32_t host_port) { reverse_host_addr_.set_port(host_port); }
inline int set_authusr(const common::ObString &str) { return deep_copy_str(str, authusr_); }
inline int set_authpwd(const common::ObString &str) { return deep_copy_str(str, authpwd_); }
inline int set_passwordx(const common::ObString &str) { return deep_copy_str(str, passwordx_); }
@ -6066,7 +6078,8 @@ public:
int do_decrypt_password();
inline const common::ObString &get_plain_password() const { return plain_password_; }
inline const common::ObAddr &get_host_addr() const { return host_addr_; }
inline int32_t get_host_port() const { return host_addr_.get_port(); }
inline const common::ObString &get_host_name() const { return host_name_; }
inline int32_t get_host_port() const { return host_port_; }
inline const common::ObString &get_database_name() const { return database_name_; }
inline const common::ObString &get_reverse_cluster_name() const { return reverse_cluster_name_; }
inline const common::ObString &get_reverse_tenant_name() const { return reverse_tenant_name_; }
@ -6075,7 +6088,8 @@ public:
int do_decrypt_reverse_password();
inline const common::ObString &get_plain_reverse_password() const { return plain_reverse_password_; }
inline const common::ObAddr &get_reverse_host_addr() const { return reverse_host_addr_; }
inline int32_t get_reverse_host_port() const { return reverse_host_addr_.get_port(); }
inline const common::ObString &get_reverse_host_name() const { return reverse_host_name_; }
inline int32_t get_reverse_host_port() const { return reverse_host_port_; }
inline int64_t get_driver_proto() const { return driver_proto_; }
@ -6116,7 +6130,7 @@ protected:
common::ObString tenant_name_;
common::ObString user_name_;
common::ObString password_; // only encrypt when write to sys table.
common::ObAddr host_addr_;
common::ObAddr host_addr_; // discarded
int64_t driver_proto_; // type of dblink, ob2ob, ob2oracle
int64_t flag_; // flag of dblink;
common::ObString service_name_; // oracle instance name, ex: SID=ORCL, 128
@ -6689,10 +6703,11 @@ class ObOutlineNameHashWrapper
public:
ObOutlineNameHashWrapper() : tenant_id_(common::OB_INVALID_ID),
database_id_(common::OB_INVALID_ID),
name_() {}
name_(),
is_format_(false) {}
ObOutlineNameHashWrapper(const uint64_t tenant_id, const uint64_t database_id,
const common::ObString &name_)
: tenant_id_(tenant_id), database_id_(database_id), name_(name_)
const common::ObString &name_, bool is_format)
: tenant_id_(tenant_id), database_id_(database_id), name_(name_), is_format_(is_format)
{}
~ObOutlineNameHashWrapper() {}
inline uint64_t hash() const;
@ -6704,10 +6719,13 @@ public:
inline uint64_t get_tenant_id() const { return tenant_id_; }
inline uint64_t get_database_id() const { return database_id_; }
inline const common::ObString &get_name() const { return name_; }
inline void set_is_format(bool is_format) { is_format_ = is_format; }
inline bool is_format() const { return is_format_; }
private:
uint64_t tenant_id_;
uint64_t database_id_;
common::ObString name_;
bool is_format_;
};
inline uint64_t ObOutlineNameHashWrapper::hash() const
@ -6716,12 +6734,14 @@ inline uint64_t ObOutlineNameHashWrapper::hash() const
hash_ret = common::murmurhash(&tenant_id_, sizeof(uint64_t), 0);
hash_ret = common::murmurhash(&database_id_, sizeof(uint64_t), hash_ret);
hash_ret = common::murmurhash(name_.ptr(), name_.length(), hash_ret);
hash_ret = common::murmurhash(&is_format_, sizeof(bool), hash_ret);
return hash_ret;
}
inline bool ObOutlineNameHashWrapper::operator ==(const ObOutlineNameHashWrapper &rv) const
{
return (tenant_id_ == rv.tenant_id_) && (database_id_ == rv.database_id_) && (name_ == rv.name_);
return (tenant_id_ == rv.tenant_id_) && (database_id_ == rv.database_id_)
&& (name_ == rv.name_) && (is_format_ == rv.is_format_);
}
class ObOutlineSignatureHashWrapper
@ -6729,10 +6749,11 @@ class ObOutlineSignatureHashWrapper
public:
ObOutlineSignatureHashWrapper() : tenant_id_(common::OB_INVALID_ID),
database_id_(common::OB_INVALID_ID),
signature_() {}
signature_(),
is_format_(false) {}
ObOutlineSignatureHashWrapper(const uint64_t tenant_id, const uint64_t database_id,
const common::ObString &signature)
: tenant_id_(tenant_id), database_id_(database_id), signature_(signature)
const common::ObString &signature, bool is_format)
: tenant_id_(tenant_id), database_id_(database_id), signature_(signature), is_format_(is_format)
{}
~ObOutlineSignatureHashWrapper() {}
inline uint64_t hash() const;
@ -6744,10 +6765,13 @@ public:
inline uint64_t get_tenant_id() const { return tenant_id_; }
inline uint64_t get_database_id() const { return database_id_; }
inline const common::ObString &get_signature() const { return signature_; }
inline void set_is_format(bool is_format) { is_format_ = is_format; }
inline bool is_format() const { return is_format_; }
private:
uint64_t tenant_id_;
uint64_t database_id_;
common::ObString signature_;
bool is_format_;
};
class ObOutlineSqlIdHashWrapper
@ -6755,10 +6779,11 @@ class ObOutlineSqlIdHashWrapper
public:
ObOutlineSqlIdHashWrapper() : tenant_id_(common::OB_INVALID_ID),
database_id_(common::OB_INVALID_ID),
sql_id_() {}
sql_id_(),
is_format_(false) {}
ObOutlineSqlIdHashWrapper(const uint64_t tenant_id, const uint64_t database_id,
const common::ObString &sql_id)
: tenant_id_(tenant_id), database_id_(database_id), sql_id_(sql_id)
const common::ObString &sql_id, bool is_format)
: tenant_id_(tenant_id), database_id_(database_id), sql_id_(sql_id), is_format_(is_format)
{}
~ObOutlineSqlIdHashWrapper() {}
inline uint64_t hash() const;
@ -6770,10 +6795,13 @@ public:
inline uint64_t get_tenant_id() const { return tenant_id_; }
inline uint64_t get_database_id() const { return database_id_; }
inline const common::ObString &get_sql_id() const { return sql_id_; }
inline void set_is_format(bool is_format) { is_format_ = is_format; }
inline bool is_format() const { return is_format_; }
private:
uint64_t tenant_id_;
uint64_t database_id_;
common::ObString sql_id_;
bool is_format_;
};
inline uint64_t ObOutlineSqlIdHashWrapper::hash() const
@ -6782,13 +6810,14 @@ inline uint64_t ObOutlineSqlIdHashWrapper::hash() const
hash_ret = common::murmurhash(&tenant_id_, sizeof(uint64_t), 0);
hash_ret = common::murmurhash(&database_id_, sizeof(uint64_t), hash_ret);
hash_ret = common::murmurhash(sql_id_.ptr(), sql_id_.length(), hash_ret);
hash_ret = common::murmurhash(&is_format_, sizeof(bool), hash_ret);
return hash_ret;
}
inline bool ObOutlineSqlIdHashWrapper::operator ==(const ObOutlineSqlIdHashWrapper &rv) const
{
return (tenant_id_ == rv.tenant_id_) && (database_id_ == rv.database_id_)
&& (sql_id_ == rv.sql_id_);
&& (sql_id_ == rv.sql_id_) && (is_format_ == rv.is_format_);
}
inline uint64_t ObOutlineSignatureHashWrapper::hash() const
@ -6797,13 +6826,14 @@ inline uint64_t ObOutlineSignatureHashWrapper::hash() const
hash_ret = common::murmurhash(&tenant_id_, sizeof(uint64_t), 0);
hash_ret = common::murmurhash(&database_id_, sizeof(uint64_t), hash_ret);
hash_ret = common::murmurhash(signature_.ptr(), signature_.length(), hash_ret);
hash_ret = common::murmurhash(&is_format_, sizeof(bool), hash_ret);
return hash_ret;
}
inline bool ObOutlineSignatureHashWrapper::operator ==(const ObOutlineSignatureHashWrapper &rv) const
{
return (tenant_id_ == rv.tenant_id_) && (database_id_ == rv.database_id_)
&& (signature_ == rv.signature_);
&& (signature_ == rv.signature_) && (is_format_ == rv.is_format_);
}
class ObSysTableChecker

View File

@ -432,6 +432,7 @@ enum ObSysVarClassType
SYS_VAR_INNODB_SYNC_DEBUG = 10324,
SYS_VAR_DEFAULT_COLLATION_FOR_UTF8MB4 = 10325,
SYS_VAR__ENABLE_OLD_CHARSET_AGGREGATION = 10326,
SYS_VAR_ENABLE_SQL_PLAN_MONITOR = 10327,
SYS_VAR_INSERT_ID = 10328,
SYS_VAR_JOIN_BUFFER_SIZE = 10329,
SYS_VAR_MAX_JOIN_SIZE = 10330,

View File

@ -427,6 +427,7 @@ namespace share
static const char* const OB_SV_INNODB_SYNC_DEBUG = "innodb_sync_debug";
static const char* const OB_SV_DEFAULT_COLLATION_FOR_UTF8MB4 = "default_collation_for_utf8mb4";
static const char* const OB_SV__ENABLE_OLD_CHARSET_AGGREGATION = "_enable_old_charset_aggregation";
static const char* const OB_SV_ENABLE_SQL_PLAN_MONITOR = "enable_sql_plan_monitor";
static const char* const OB_SV_INSERT_ID = "insert_id";
static const char* const OB_SV_JOIN_BUFFER_SIZE = "join_buffer_size";
static const char* const OB_SV_MAX_JOIN_SIZE = "max_join_size";

View File

@ -618,6 +618,7 @@ const char *ObSysVarFactory::SYS_VAR_NAMES_SORTED_BY_NAME[] = {
"disabled_storage_engines",
"disconnect_on_expired_password",
"div_precision_increment",
"enable_sql_plan_monitor",
"enforce_gtid_consistency",
"eq_range_index_dive_limit",
"error_count",
@ -1229,6 +1230,7 @@ const ObSysVarClassType ObSysVarFactory::SYS_VAR_IDS_SORTED_BY_NAME[] = {
SYS_VAR_DISABLED_STORAGE_ENGINES,
SYS_VAR_DISCONNECT_ON_EXPIRED_PASSWORD,
SYS_VAR_DIV_PRECISION_INCREMENT,
SYS_VAR_ENABLE_SQL_PLAN_MONITOR,
SYS_VAR_ENFORCE_GTID_CONSISTENCY,
SYS_VAR_EQ_RANGE_INDEX_DIVE_LIMIT,
SYS_VAR_ERROR_COUNT,
@ -2149,6 +2151,7 @@ const char *ObSysVarFactory::SYS_VAR_NAMES_SORTED_BY_ID[] = {
"innodb_sync_debug",
"default_collation_for_utf8mb4",
"_enable_old_charset_aggregation",
"enable_sql_plan_monitor",
"insert_id",
"join_buffer_size",
"max_join_size",
@ -2961,6 +2964,7 @@ int ObSysVarFactory::create_all_sys_vars()
+ sizeof(ObSysVarInnodbSyncDebug)
+ sizeof(ObSysVarDefaultCollationForUtf8mb4)
+ sizeof(ObSysVarEnableOldCharsetAggregation)
+ sizeof(ObSysVarEnableSqlPlanMonitor)
+ sizeof(ObSysVarInsertId)
+ sizeof(ObSysVarJoinBufferSize)
+ sizeof(ObSysVarMaxJoinSize)
@ -6865,6 +6869,15 @@ int ObSysVarFactory::create_all_sys_vars()
ptr = (void *)((char *)ptr + sizeof(ObSysVarEnableOldCharsetAggregation));
}
}
if (OB_SUCC(ret)) {
if (OB_ISNULL(sys_var_ptr = new (ptr)ObSysVarEnableSqlPlanMonitor())) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_ERROR("fail to new ObSysVarEnableSqlPlanMonitor", K(ret));
} else {
store_buf_[ObSysVarsToIdxMap::get_store_idx(static_cast<int64_t>(SYS_VAR_ENABLE_SQL_PLAN_MONITOR))] = sys_var_ptr;
ptr = (void *)((char *)ptr + sizeof(ObSysVarEnableSqlPlanMonitor));
}
}
if (OB_SUCC(ret)) {
if (OB_ISNULL(sys_var_ptr = new (ptr)ObSysVarInsertId())) {
ret = OB_ALLOCATE_MEMORY_FAILED;
@ -13169,6 +13182,17 @@ int ObSysVarFactory::create_sys_var(ObIAllocator &allocator_, ObSysVarClassType
}
break;
}
case SYS_VAR_ENABLE_SQL_PLAN_MONITOR: {
void *ptr = NULL;
if (OB_ISNULL(ptr = allocator_.alloc(sizeof(ObSysVarEnableSqlPlanMonitor)))) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_ERROR("fail to alloc memory", K(ret), K(sizeof(ObSysVarEnableSqlPlanMonitor)));
} else if (OB_ISNULL(sys_var_ptr = new (ptr)ObSysVarEnableSqlPlanMonitor())) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_ERROR("fail to new ObSysVarEnableSqlPlanMonitor", K(ret));
}
break;
}
case SYS_VAR_INSERT_ID: {
void *ptr = NULL;
if (OB_ISNULL(ptr = allocator_.alloc(sizeof(ObSysVarInsertId)))) {

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -6034,12 +6034,11 @@
"base_value": "0",
"data_type": "bool",
"info": "To set whether the SQL for the current session is logged into the SQL plan monitor.",
"flags": "SESSION",
"flags": "SESSION | INFLUENCE_PLAN",
"publish_version": "",
"info_cn": "",
"background_cn": "",
"ref_url": "",
"placeholder": true
"ref_url": ""
},
"insert_id": {
"id": 10328,

View File

@ -27,7 +27,8 @@ ObDASExtraData::ObDASExtraData()
result_iter_(),
has_more_(false),
need_check_output_datum_(false),
enable_rich_format_(false)
enable_rich_format_(false),
tsc_monitor_info_(nullptr)
{
}
@ -78,6 +79,12 @@ int ObDASExtraData::fetch_result()
} else {
LOG_TRACE("das fetch task result", KR(ret), K(req), K(result_));
has_more_ = result_.has_more();
if (OB_NOT_NULL(tsc_monitor_info_)) {
tsc_monitor_info_->add_io_read_bytes(result_.io_read_bytes_);
tsc_monitor_info_->add_ssstore_read_bytes(result_.ssstore_read_bytes_);
tsc_monitor_info_->add_ssstore_read_row_cnt(result_.ssstore_read_row_cnt_);
tsc_monitor_info_->add_memstore_read_row_cnt(result_.memstore_read_row_cnt_);
}
}
return ret;
}

View File

@ -38,6 +38,7 @@ public:
void erase_task_result();
void set_has_more(const bool has_more) { has_more_ = has_more; }
void set_need_check_output_datum(bool v) { need_check_output_datum_ = v; }
void set_tsc_monitor_info(ObTSCMonitorInfo *tsc_monitor_info) { tsc_monitor_info_ = tsc_monitor_info; }
TO_STRING_KV(KPC_(output_exprs));
private:
int fetch_result();
@ -54,6 +55,7 @@ private:
bool has_more_;
bool need_check_output_datum_;
bool enable_rich_format_;
ObTSCMonitorInfo *tsc_monitor_info_;
};
} // namespace sql
} // namespace oceanbase

View File

@ -497,7 +497,7 @@ int ObDASInsertResult::get_next_row(ObDatumRow *&row)
return ret;
}
int ObDASInsertResult::link_extra_result(ObDASExtraData &extra_result)
int ObDASInsertResult::link_extra_result(ObDASExtraData &extra_result, ObIDASTaskOp *task_op)
{
UNUSED(extra_result);
return OB_NOT_IMPLEMENT;

View File

@ -119,7 +119,7 @@ public:
virtual int reuse() override;
virtual int get_next_row(blocksstable::ObDatumRow *&row) override;
virtual void reset();
virtual int link_extra_result(ObDASExtraData &extra_result) override;
virtual int link_extra_result(ObDASExtraData &extra_result, ObIDASTaskOp *task_op) override;
int init_result_newrow_iter(const ObjMetaFixedArray *output_types);
ObDASWriteBuffer &get_result_buffer() { return result_buffer_; }
int64_t get_affected_rows() const { return affected_rows_; }

View File

@ -31,6 +31,9 @@ int ObDASBaseAccessP<pcode>::init()
int ret = OB_SUCCESS;
ObDASTaskArg &task = RpcProcessor::arg_;
ObDASBaseAccessP<pcode>::get_das_factory() = &das_factory_;
memset(monitor_val_, 0, sizeof(monitor_val_));
tsc_monitor_info_.init(&monitor_val_[0], &monitor_val_[1], &monitor_val_[2], &monitor_val_[3]);
das_remote_info_.tsc_monitor_info_ = &tsc_monitor_info_;
das_remote_info_.exec_ctx_ = &exec_ctx_;
das_remote_info_.frame_info_ = &frame_info_;
task.set_remote_info(&das_remote_info_);
@ -299,7 +302,11 @@ int ObDASSyncFetchP::process()
} else if (OB_ISNULL(das = MTL(ObDataAccessService *))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("das is null", KR(ret), KP(das));
} else if (OB_FAIL(das->get_task_res_mgr().iterator_task_result(res))) {
} else if (OB_FAIL(das->get_task_res_mgr().iterator_task_result(res,
res.io_read_bytes_,
res.ssstore_read_bytes_,
res.ssstore_read_row_cnt_,
res.memstore_read_row_cnt_))) {
if (OB_UNLIKELY(OB_ENTRY_NOT_EXIST == ret)) {
// After server reboot, the hash map containing task results was gone.
// We need to retry for such cases.

View File

@ -58,6 +58,9 @@ protected:
ObExprFrameInfo frame_info_;
share::schema::ObSchemaGetterGuard schema_guard_;
ObDASRemoteInfo das_remote_info_;
//tsc monitor info
int64_t monitor_val_[4];
ObTSCMonitorInfo tsc_monitor_info_;
};
class ObDASSyncAccessP final : public ObDASBaseAccessP<obrpc::OB_DAS_SYNC_ACCESS> {

View File

@ -214,6 +214,7 @@ int ObDASScanOp::swizzling_remote_task(ObDASRemoteInfo *remote_info)
snapshot_ = &remote_info->snapshot_;
scan_rtdef_->stmt_allocator_.set_alloc(&CURRENT_CONTEXT->get_arena_allocator());
scan_rtdef_->scan_allocator_.set_alloc(&CURRENT_CONTEXT->get_arena_allocator());
scan_rtdef_->tsc_monitor_info_ = remote_info->tsc_monitor_info_;
if (OB_FAIL(scan_rtdef_->init_pd_op(*remote_info->exec_ctx_, *scan_ctdef_))) {
LOG_WARN("init scan pushdown operator failed", K(ret));
} else {
@ -233,6 +234,7 @@ int ObDASScanOp::swizzling_remote_task(ObDASRemoteInfo *remote_info)
ObDASScanRtDef *related_rtdef = static_cast<ObDASScanRtDef*>(related_rtdefs_.at(i));
related_rtdef->stmt_allocator_.set_alloc(&CURRENT_CONTEXT->get_arena_allocator());
related_rtdef->scan_allocator_.set_alloc(&CURRENT_CONTEXT->get_arena_allocator());
related_rtdef->tsc_monitor_info_ = remote_info->tsc_monitor_info_;
if (OB_FAIL(related_rtdef->init_pd_op(*remote_info->exec_ctx_, *related_ctdef))) {
LOG_WARN("init related rtdef pushdown operator failed", K(ret));
} else {
@ -290,6 +292,7 @@ int ObDASScanOp::init_scan_param()
scan_param_.fb_snapshot_ = scan_rtdef_->fb_snapshot_;
scan_param_.fb_read_tx_uncommitted_ = scan_rtdef_->fb_read_tx_uncommitted_;
scan_param_.is_mds_query_ = false;
scan_param_.main_table_scan_stat_.tsc_monitor_info_ = scan_rtdef_->tsc_monitor_info_;
if (scan_rtdef_->is_for_foreign_check_) {
scan_param_.trans_desc_ = trans_desc_;
}
@ -829,6 +832,8 @@ int ObDASScanOp::decode_task_result(ObIDASTaskResult *task_result)
#if !defined(NDEBUG)
CK(typeid(*task_result) == typeid(ObDASScanResult));
CK(task_id_ == task_result->get_task_id());
CK(OB_NOT_NULL(scan_rtdef_));
CK(OB_NOT_NULL(scan_rtdef_->tsc_monitor_info_));
#endif
if (need_check_output_datum()) {
reset_access_datums_ptr();
@ -840,6 +845,14 @@ int ObDASScanOp::decode_task_result(ObIDASTaskResult *task_result)
} else {
result_ = scan_result;
LOG_DEBUG("decode task result", K(*scan_result));
// Aggregate the remote TSC statistical information into the local monitor node.
if (OB_NOT_NULL(scan_rtdef_->tsc_monitor_info_)) {
ObTSCMonitorInfo &tsc_monitor_info = *scan_rtdef_->tsc_monitor_info_;
tsc_monitor_info.add_io_read_bytes(scan_result->get_io_read_bytes());
tsc_monitor_info.add_ssstore_read_bytes(scan_result->get_ssstore_read_bytes());
tsc_monitor_info.add_ssstore_read_row_cnt(scan_result->get_ssstore_read_row_cnt());
tsc_monitor_info.add_memstore_read_row_cnt(scan_result->get_memstore_read_row_cnt());
}
}
return ret;
}
@ -942,6 +955,13 @@ int ObDASScanOp::fill_task_result(ObIDASTaskResult &task_result, bool &has_more,
} else {
memory_limit -= datum_store.get_mem_used();
}
if (OB_SUCC(ret) && OB_NOT_NULL(scan_rtdef_->tsc_monitor_info_)) {
scan_result.add_io_read_bytes(*scan_rtdef_->tsc_monitor_info_->io_read_bytes_);
scan_result.add_ssstore_read_bytes(*scan_rtdef_->tsc_monitor_info_->ssstore_read_bytes_);
scan_result.add_ssstore_read_row_cnt(*scan_rtdef_->tsc_monitor_info_->ssstore_read_row_cnt_);
scan_result.add_memstore_read_row_cnt(*scan_rtdef_->tsc_monitor_info_->memstore_read_row_cnt_);
scan_rtdef_->tsc_monitor_info_->reset_stat();
}
return ret;
}
@ -955,14 +975,14 @@ int ObDASScanOp::fill_extra_result()
if (OB_ISNULL(output_result_iter)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("output result iter is null", K(ret));
} else if (OB_FAIL(result_mgr.save_task_result(task_id_,
&result_output,
&eval_ctx,
*output_result_iter,
remain_row_cnt_,
scan_ctdef_,
scan_rtdef_,
*this))) {
} else if (OB_FAIL(result_mgr.save_task_result(task_id_,
&result_output,
&eval_ctx,
*output_result_iter,
remain_row_cnt_,
scan_ctdef_,
scan_rtdef_,
*this))) {
LOG_WARN("save task result failed", KR(ret), K(task_id_));
}
return ret;
@ -1567,11 +1587,14 @@ int ObDASScanResult::reuse()
return ret;
}
int ObDASScanResult::link_extra_result(ObDASExtraData &extra_result)
int ObDASScanResult::link_extra_result(ObDASExtraData &extra_result, ObIDASTaskOp *task_op)
{
extra_result.set_output_info(output_exprs_, eval_ctx_);
extra_result.set_need_check_output_datum(need_check_output_datum_);
extra_result_ = &extra_result;
ObTSCMonitorInfo *tsc_monitor_info =
static_cast<ObDASScanRtDef *>(task_op->get_rtdef())->tsc_monitor_info_;
extra_result.set_tsc_monitor_info(tsc_monitor_info);
return OB_SUCCESS;
}
@ -1911,6 +1934,7 @@ OB_INLINE int ObLocalIndexLookupOp::init_scan_param()
scan_param_.fb_read_tx_uncommitted_ = lookup_rtdef_->fb_read_tx_uncommitted_;
scan_param_.ls_id_ = ls_id_;
scan_param_.tablet_id_ = tablet_id_;
scan_param_.main_table_scan_stat_.tsc_monitor_info_ = lookup_rtdef_->tsc_monitor_info_;
if (lookup_rtdef_->is_for_foreign_check_) {
scan_param_.trans_desc_ = tx_desc_;
}

View File

@ -161,12 +161,15 @@ public:
scan_allocator_("TableScanAlloc"),
sample_info_(nullptr),
is_for_foreign_check_(false),
tsc_monitor_info_(nullptr),
key_ranges_(),
ss_key_ranges_(),
mbr_filters_()
{ }
virtual ~ObDASScanRtDef();
bool enable_rich_format() const { return scan_flag_.enable_rich_format_; }
INHERIT_TO_STRING_KV("ObDASBaseRtDef", ObDASBaseRtDef,
K_(tenant_schema_version),
K_(limit_param),
@ -179,10 +182,12 @@ public:
K_(tx_lock_timeout),
K_(sql_mode),
K_(scan_flag),
K_(tsc_monitor_info),
K_(key_ranges),
K_(ss_key_ranges),
K_(mbr_filters));
int init_pd_op(ObExecContext &exec_ctx, const ObDASScanCtDef &scan_ctdef);
storage::ObRow2ExprsProjector *p_row2exprs_projector_;
ObPushdownOperator *p_pd_expr_op_;
int64_t tenant_schema_version_;
@ -202,6 +207,7 @@ public:
common::ObWrapperAllocatorWithAttr scan_allocator_;
const common::SampleInfo *sample_info_; //Block(Row)SampleScan, only support local das scan
bool is_for_foreign_check_;
ObTSCMonitorInfo *tsc_monitor_info_;
common::ObSEArray<common::ObNewRange, 1> key_ranges_;
common::ObSEArray<common::ObNewRange, 1> ss_key_ranges_;
common::ObSEArray<common::ObSpatialMBR, 1> mbr_filters_;
@ -339,10 +345,18 @@ public:
virtual int get_next_row() override;
virtual int get_next_rows(int64_t &count, int64_t capacity) override;
virtual void reset() override;
virtual int link_extra_result(ObDASExtraData &extra_result) override;
virtual int link_extra_result(ObDASExtraData &extra_result, ObIDASTaskOp *task_op) override;
int init_result_iter(const ExprFixedArray *output_exprs, ObEvalCtx *eval_ctx);
ObChunkDatumStore &get_datum_store() { return datum_store_; }
ObTempRowStore &get_vec_row_store() { return vec_row_store_; }
void add_io_read_bytes(int64_t io_read_bytes) { io_read_bytes_ += io_read_bytes; }
int64_t get_io_read_bytes() { return io_read_bytes_; }
void add_ssstore_read_bytes(int64_t ssstore_read_bytes) { ssstore_read_bytes_ += ssstore_read_bytes; }
int64_t get_ssstore_read_bytes() { return ssstore_read_bytes_; }
void add_ssstore_read_row_cnt(int64_t ssstore_read_row_cnt) { ssstore_read_row_cnt_ += ssstore_read_row_cnt; }
int64_t get_ssstore_read_row_cnt() { return ssstore_read_row_cnt_; }
void add_memstore_read_row_cnt(int64_t memstore_read_row_cnt) { memstore_read_row_cnt_ += memstore_read_row_cnt; }
int64_t get_memstore_read_row_cnt() { return memstore_read_row_cnt_; }
INHERIT_TO_STRING_KV("ObIDASTaskResult", ObIDASTaskResult,
K_(datum_store),
KPC_(output_exprs),

View File

@ -100,7 +100,8 @@ public:
user_id_(0),
session_id_(0),
plan_id_(0),
plan_hash_(0)
plan_hash_(0),
tsc_monitor_info_(nullptr)
{
sql_id_[0] = '\0';
}
@ -136,6 +137,8 @@ public:
uint64_t plan_id_;
private:
uint64_t plan_hash_; // no use!!!
public:
ObTSCMonitorInfo *tsc_monitor_info_;
};
class ObIDASTaskOp
@ -343,7 +346,7 @@ public:
virtual ~ObIDASTaskResult() { }
virtual int init(const ObIDASTaskOp &task_op, common::ObIAllocator &alloc) = 0;
virtual int reuse() = 0;
virtual int link_extra_result(ObDASExtraData &extra_result)
virtual int link_extra_result(ObDASExtraData &extra_result, ObIDASTaskOp *task_op)
{
UNUSED(extra_result);
return common::OB_NOT_IMPLEMENT;
@ -622,6 +625,7 @@ private:
bool has_more_;
bool enable_rich_format_;
ObTempRowStore vec_row_store_;
public:
int64_t io_read_bytes_;
int64_t ssstore_read_bytes_;
int64_t ssstore_read_row_cnt_;

View File

@ -43,6 +43,10 @@ ObDASTCB::ObDASTCB()
vec_stored_row_arr_(NULL),
vec_row_store_(),
vec_result_iter_(),
io_read_bytes_(0),
ssstore_read_bytes_(0),
ssstore_read_row_cnt_(0),
memstore_read_row_cnt_(0),
tcb_lock_()
{
}
@ -130,7 +134,7 @@ int ObDASTaskResultMgr::save_task_result(int64_t task_id,
common::ObNewRowIterator &result,
int64_t read_rows,
const ObDASScanCtDef *scan_ctdef,
const ObDASScanRtDef * scan_rtdef,
ObDASScanRtDef *scan_rtdef,
ObDASScanOp & scan_op)
{
int ret = OB_SUCCESS;
@ -280,6 +284,13 @@ int ObDASTaskResultMgr::save_task_result(int64_t task_id,
}
}
if (OB_SUCC(ret)) {
if (OB_NOT_NULL(scan_rtdef->tsc_monitor_info_)) {
tcb->io_read_bytes_ += *scan_rtdef->tsc_monitor_info_->io_read_bytes_;
tcb->ssstore_read_bytes_ += *scan_rtdef->tsc_monitor_info_->ssstore_read_bytes_;
tcb->ssstore_read_row_cnt_ += *scan_rtdef->tsc_monitor_info_->ssstore_read_row_cnt_;
tcb->memstore_read_row_cnt_ += *scan_rtdef->tsc_monitor_info_->memstore_read_row_cnt_;
scan_rtdef->tsc_monitor_info_->reset_stat();
}
if (OB_FAIL(tcb_map_.insert_and_get(tcb_info, tcb))) {
LOG_WARN("insert das tcb failed", KR(ret));
} else {
@ -449,7 +460,11 @@ int ObDASTaskResultMgr::erase_task_result(int64_t task_id)
return ret;
}
int ObDASTaskResultMgr::iterator_task_result(ObDASDataFetchRes &res)
int ObDASTaskResultMgr::iterator_task_result(ObDASDataFetchRes &res,
int64_t &io_read_bytes,
int64_t &ssstore_read_bytes,
int64_t &ssstore_read_row_cnt,
int64_t &memstore_read_row_cnt)
{
int ret = OB_SUCCESS;
bool has_more = false;
@ -481,6 +496,12 @@ int ObDASTaskResultMgr::iterator_task_result(ObDASDataFetchRes &res)
OZ (fetch_result_by_normal(tcb, res, has_more));
}
if (OB_SUCC(ret)) {
if (tcb->packet_cnt_ == 0) {
io_read_bytes += tcb->io_read_bytes_;
ssstore_read_bytes += tcb->ssstore_read_bytes_;
ssstore_read_row_cnt += tcb->ssstore_read_row_cnt_;
memstore_read_row_cnt += tcb->memstore_read_row_cnt_;
}
tcb->packet_cnt_++;
}
int save_ret = ret;

View File

@ -37,7 +37,11 @@ public:
K_(expire_ts),
K_(packet_cnt),
K_(is_reading),
K_(is_exiting));
K_(is_exiting),
K_(io_read_bytes),
K_(ssstore_read_bytes),
K_(ssstore_read_row_cnt),
K_(memstore_read_row_cnt));
int register_reading();
int unregister_reading();
@ -62,6 +66,10 @@ public:
ObTempRowStore vec_row_store_;
ObTempRowStore::Iterator vec_result_iter_;
int64_t io_read_bytes_;
int64_t ssstore_read_bytes_;
int64_t ssstore_read_row_cnt_;
int64_t memstore_read_row_cnt_;
private:
common::ObSpinLock tcb_lock_; //用于控制资源资源释放的时序,保证并发访问的安全
};
@ -140,11 +148,15 @@ public:
common::ObNewRowIterator &result,
int64_t read_rows,
const ObDASScanCtDef *scan_ctdef,
const ObDASScanRtDef * scan_rtdef,
ObDASScanRtDef *scan_rtdef,
ObDASScanOp &scan_op);
int erase_task_result(int64_t task_id);
//从中间结果管理器中获取一个block大小的结果,默认为2M大小
int iterator_task_result(ObDASDataFetchRes &res);
int iterator_task_result(ObDASDataFetchRes &res,
int64_t &io_read_bytes,
int64_t &ssstore_read_bytes,
int64_t &ssstore_read_row_cnt,
int64_t &memstore_read_row_cnt);
int remove_expired_results();
private:
int save_task_result_by_vector(int64_t &read_rows,

View File

@ -661,7 +661,7 @@ int ObDataAccessService::process_task_resp(ObDASRef &das_ref, const ObDASTaskRes
} else if (task_resp.has_more()
&& OB_FAIL(setup_extra_result(das_ref, task_resp, task_op, extra_result))) {
LOG_WARN("setup extra result failed", KR(ret));
} else if (task_resp.has_more() && OB_FAIL(op_result->link_extra_result(*extra_result))) {
} else if (task_resp.has_more() && OB_FAIL(op_result->link_extra_result(*extra_result, task_op))) {
LOG_WARN("link extra result failed", K(ret));
}
// even if trans result have a failure. It only take effect on the last valid op result.

View File

@ -347,6 +347,22 @@ int ObDblinkService::get_local_session_vars(sql::ObSQLSessionInfo *session_info,
return ret;
}
int ObDblinkService::get_spell_collation_type(ObSQLSessionInfo *session, ObCollationType &spell_coll) {
int ret = OB_SUCCESS;
common::ObCharsetType database_cs = ObCharsetType::CHARSET_UTF8MB4;
if (OB_ISNULL(session)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("unexpected null ptr", K(ret));
} else if (lib::is_oracle_mode()) {
spell_coll = session->get_nls_collation();
} else if (OB_FAIL(session->get_character_set_database(database_cs))) {
LOG_WARN("failed to get character_set_database", K(ret));
} else {
spell_coll = ObCharset::get_default_collation_by_mode(database_cs, false);
}
return ret;
}
ObReverseLink::ObReverseLink()
: user_(),
tenant_(),
@ -356,7 +372,9 @@ ObReverseLink::ObReverseLink()
self_addr_(),
tx_id_(0),
tm_sessid_(0),
is_close_(true)
is_close_(true),
host_name_(),
port_(0)
{
}
@ -376,7 +394,9 @@ OB_DEF_SERIALIZE(ObReverseLink)
addr_,
self_addr_,
tx_id_,
tm_sessid_);
tm_sessid_,
host_name_,
port_);
return ret;
}
@ -393,7 +413,9 @@ OB_DEF_DESERIALIZE(ObReverseLink)
addr_,
self_addr_,
tx_id_,
tm_sessid_);
tm_sessid_,
host_name_,
port_);
if (OB_FAIL(ret)) {
} else if (FALSE_IT(tmp_len = user_.length())) {
} else if (OB_ISNULL(tmp_buf = static_cast<char *>(allocator_.alloc(tmp_len)))) {
@ -430,6 +452,15 @@ OB_DEF_DESERIALIZE(ObReverseLink)
MEMCPY(tmp_buf, passwd_.ptr(), tmp_len);
passwd_.assign(tmp_buf, static_cast<int32_t>(tmp_len));
}
if (OB_FAIL(ret)) {
} else if (FALSE_IT(tmp_len = host_name_.length())) {
} else if (OB_ISNULL(tmp_buf = static_cast<char *>(allocator_.alloc(tmp_len)))) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("failed to alloc tmp_buf", K(ret), K(tmp_len));
} else {
MEMCPY(tmp_buf, host_name_.ptr(), tmp_len);
host_name_.assign(tmp_buf, static_cast<int32_t>(tmp_len));
}
return ret;
}
@ -444,7 +475,9 @@ OB_DEF_SERIALIZE_SIZE(ObReverseLink)
addr_,
self_addr_,
tx_id_,
tm_sessid_);
tm_sessid_,
host_name_,
port_);
return len;
}
@ -465,10 +498,11 @@ int ObReverseLink::open(int64_t session_sql_req_level)
|| OB_UNLIKELY(cluster_.length() >= OB_MAX_CLUSTER_NAME_LENGTH)
|| OB_UNLIKELY(tenant_.length() >= OB_MAX_TENANT_NAME_LENGTH)
|| OB_UNLIKELY(user_.length() >= OB_MAX_USER_NAME_LENGTH)
|| OB_UNLIKELY(passwd_.length() >= OB_MAX_PASSWORD_LENGTH)) {
|| OB_UNLIKELY(passwd_.length() >= OB_MAX_PASSWORD_LENGTH)
|| OB_UNLIKELY(host_name_.length() >= OB_MAX_DOMIN_NAME_LENGTH)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid argument", K(ret),
K(cluster_), K(tenant_), K(user_), K(passwd_));
K(cluster_), K(tenant_), K(user_), K(passwd_), K(host_name_));
} else if (OB_FAIL(ObDblinkService::get_local_session_vars(session_info_, allocator_, param_ctx))) {
LOG_WARN("failed to get local session vars", K(ret));
} else {
@ -481,9 +515,10 @@ int ObReverseLink::open(int64_t session_sql_req_level)
cluster_.length(), cluster_.ptr());
}
(void)snprintf(db_pass_, sizeof(db_pass_), "%.*s", passwd_.length(), passwd_.ptr());
(void)snprintf(host_name_cstr_, sizeof(host_name_), "%.*s", host_name_.length(), host_name_.ptr());
LOG_DEBUG("open reverse link connection", K(ret), K(db_user_), K(db_pass_), K(addr_));
param_ctx.link_type_ = common::sqlclient::DBLINK_DRV_OB;
if (OB_FAIL(reverse_conn_.connect(db_user_, db_pass_, "", addr_, 10, true, session_sql_req_level))) { //just set connect timeout to 10s, read and write have not timeout
if (OB_FAIL(reverse_conn_.connect(db_user_, db_pass_, "", host_name_cstr_, port_, 10, true, session_sql_req_level))) { //just set connect timeout to 10s, read and write have not timeout
LOG_WARN("failed to open reverse link connection", K(ret), K(db_user_), K(db_pass_), K(addr_));
} else if (OB_FAIL(reverse_conn_.set_timeout_variable(LONG_QUERY_TIMEOUT, common::sqlclient::ObMySQLConnectionPool::DEFAULT_TRANSACTION_TIMEOUT_US))) {
LOG_WARN("failed to set reverse link connection's timeout", K(ret));
@ -501,7 +536,7 @@ int ObReverseLink::open(int64_t session_sql_req_level)
return ret;
}
int ObReverseLink::read(const char *sql, ObISQLClient::ReadResult &res)
int ObReverseLink::read(const ObString &sql, ObISQLClient::ReadResult &res)
{
int ret = OB_SUCCESS;
if (is_close_) {

View File

@ -60,6 +60,7 @@ public:
const char *&set_results_charset);
static int get_set_transaction_isolation_cstr(sql::ObSQLSessionInfo *session_info,
const char *&set_isolation_level);
static int get_spell_collation_type(ObSQLSessionInfo *session, ObCollationType &spell_coll);
public:
static const char *SET_ISOLATION_LEVEL_READ_COMMITTED;
static const char *SET_ISOLATION_LEVEL_REPEATABLE_READ;
@ -97,6 +98,8 @@ public:
inline void set_passwd(ObString name) { passwd_ = name; }
inline void set_addr(common::ObAddr addr) { addr_ = addr; }
inline void set_self_addr(common::ObAddr addr) { self_addr_ = addr; }
inline void set_host_name(ObString host_name) { host_name_ = host_name; }
inline void set_port(int32_t port) { port_ = port; }
inline void set_tx_id(int64_t tx_id) { tx_id_ = tx_id; }
inline void set_tm_sessid(uint32_t tm_sessid) { tm_sessid_ = tm_sessid; }
inline void set_session_info(sql::ObSQLSessionInfo *session_info) { session_info_ = session_info; }
@ -106,11 +109,13 @@ public:
const ObString &get_passwd() { return passwd_; }
const common::ObAddr &get_addr() { return addr_; }
const common::ObAddr &get_self_addr() { return self_addr_; }
const ObString &get_host_name() { return host_name_; }
int32_t get_port() { return port_; }
int64_t get_tx_id() { return tx_id_; }
uint32_t get_tm_sessid() { return tm_sessid_; }
int open(int64_t session_sql_req_level);
int read(const char *sql, ObISQLClient::ReadResult &res);
int read(const ObString &sql, ObISQLClient::ReadResult &res);
int ping();
int close();
TO_STRING_KV(K_(user),
@ -121,7 +126,9 @@ public:
K_(self_addr),
K_(tx_id),
K_(tm_sessid),
K_(is_close));
K_(is_close),
K_(host_name),
K_(port));
public:
static const char *SESSION_VARIABLE;
static const int64_t VARI_LENGTH;
@ -141,6 +148,9 @@ private:
common::sqlclient::ObMySQLConnection reverse_conn_; // ailing.lcq to do, ObReverseLink can be used by serval connection, not just one
char db_user_[OB_MAX_USER_NAME_LENGTH + OB_MAX_TENANT_NAME_LENGTH + OB_MAX_CLUSTER_NAME_LENGTH];
char db_pass_[OB_MAX_PASSWORD_LENGTH];
char host_name_cstr_[OB_MAX_DOMIN_NAME_LENGTH + 1]; // used by dblink to connect, instead of using server_ to connect
ObString host_name_;
int32_t port_; // used by dblink to connect, instead of using server_ to connect
sql::ObSQLSessionInfo *session_info_; // reverse link belongs to which session
};

View File

@ -55,6 +55,7 @@ int ObOutlineExecutor::generate_outline_info2(ObExecContext &ctx,
outline_info.set_tenant_id(ctx.get_my_session()->get_effective_tenant_id());
outline_info.set_outline_content(create_outline_stmt->get_hint());
outline_info.set_sql_id(create_outline_stmt->get_sql_id());
outline_info.set_format_sql_id(create_outline_stmt->get_format_sql_id());
if (create_outline_stmt->get_max_concurrent() >= 0) {
ObMaxConcurrentParam concurrent_param(&ctx.get_allocator());
@ -90,13 +91,23 @@ int ObOutlineExecutor::generate_outline_info1(ObExecContext &ctx,
bool has_questionmark_in_outline_sql = false;
ObString outline;
ObString outline_key;
ObString &outline_sql = outline_info.get_sql_text_str();
ObString &outline_sql = outline_info.is_format() ?
outline_info.get_format_sql_text_str() : outline_info.get_sql_text_str();
int64_t max_concurrent = ObGlobalHint::UNSET_MAX_CONCURRENT;
const ObQueryHint *query_hint = NULL;
char* buf = NULL;
int32_t len = 0;
int32_t pos = 0;
ObMaxConcurrentParam concurrent_param(&ctx.get_allocator());
bool has_in_expr = false;
int64_t in_expr_pos = 0;
buf = (char *)ctx.get_allocator().alloc(outline_sql.length());
if (OB_ISNULL(ctx.get_my_session())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("invalid ctx", K(ret));
} else if (NULL == buf) {
SQL_PC_LOG(WARN, "fail to alloc buf", K(outline_sql.length()));
ret = OB_ALLOCATE_MEMORY_FAILED;
} else if (OB_ISNULL(outline_stmt) || OB_ISNULL(outline_stmt->get_query_ctx())
|| OB_ISNULL(query_hint = &outline_stmt->get_query_ctx()->get_query_hint())) {
ret = OB_ERR_UNEXPECTED;
@ -105,14 +116,25 @@ int ObOutlineExecutor::generate_outline_info1(ObExecContext &ctx,
outline_sql, outline_key,
concurrent_param.fixed_param_store_,
FP_PARAMERIZE_AND_FILTER_HINT_MODE,
has_questionmark_in_outline_sql))) {
has_questionmark_in_outline_sql,
outline_info.is_format()))) {
LOG_WARN("fail to get outline key", "outline_sql", outline_sql, K(ret));
} else if (OB_FAIL(ObSqlParameterization::search_in_expr_pos(outline_info.get_format_sql_text_str().ptr(),
outline_info.get_format_sql_text_str().length(),
in_expr_pos, has_in_expr))) {
LOG_WARN("failed to search in expr", K(ret), K(outline_info.get_format_sql_text_str()));
} else if (FALSE_IT(max_concurrent = query_hint->get_global_hint().max_concurrent_)) {
} else if (OB_UNLIKELY(has_questionmark_in_outline_sql && query_hint->has_hint_exclude_concurrent())) {
ret = OB_INVALID_OUTLINE;
LOG_USER_ERROR(OB_INVALID_OUTLINE, "sql text should have no ? when there is no concurrent limit");
LOG_WARN("outline should have no ? when there is no concurrent limit",
K(outline_sql), K(ret));
} else if (OB_UNLIKELY(max_concurrent > ObGlobalHint::UNSET_MAX_CONCURRENT && has_in_expr
&& concurrent_param.fixed_param_store_.count() > 0 && outline_info.is_format())) {
ret = OB_INVALID_OUTLINE;
LOG_USER_ERROR(OB_INVALID_OUTLINE, "format outline with in expr not support concurrent limit, recommend to use normal outline");
LOG_WARN("format outline with in expr can not have const param",
"outline_format_sql_text", outline_info.get_format_sql_text_str(), K(ret));
} else if (OB_FAIL(get_outline(ctx, outline_stmt, outline))) {
LOG_WARN("fail to get outline", K(ret));
} else {
@ -134,7 +156,8 @@ int ObOutlineExecutor::generate_outline_info1(ObExecContext &ctx,
target_sql, target_key,
target_param.fixed_param_store_,
FP_PARAMERIZE_AND_FILTER_HINT_MODE,
has_questionmark_in_target_sql))) {
has_questionmark_in_target_sql,
outline_info.is_format()))) {
LOG_WARN("fail to get outline key", K(target_sql), K(ret));
} else if (target_key != outline_key || has_questionmark_in_target_sql != has_questionmark_in_outline_sql) {
@ -157,7 +180,8 @@ int ObOutlineExecutor::generate_outline_info1(ObExecContext &ctx,
target_sql, target_key_with_hint,
target_param_with_hint.fixed_param_store_,
FP_MODE,
has_questionmark_in_target_sql))) {
has_questionmark_in_target_sql,
outline_info.is_format()))) {
LOG_WARN("fail to get outline key", K(target_sql), K(ret));
} else {
//replace outline_key with target_key derived from to_clause with index not filtered

View File

@ -67,13 +67,16 @@ int ObLinkDmlOp::send_reverse_link_info(transaction::ObTransID &tx_id)
const oceanbase::common::ObString &tenant_name = dblink_schema_->get_reverse_tenant_name();
const oceanbase::common::ObString &cluster_name = dblink_schema_->get_reverse_cluster_name();
const oceanbase::common::ObString &passwd = dblink_schema_->get_plain_reverse_password();
const oceanbase::common::ObString &host_name = dblink_schema_->get_reverse_host_name();
const int32_t port = dblink_schema_->get_reverse_host_port();
const oceanbase::common::ObAddr &addr = dblink_schema_->get_reverse_host_addr();
if (user_name.empty() ||
tenant_name.empty() ||
passwd.empty() ||
!addr.is_valid()) {
host_name.empty() ||
port == 0) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("reverse link has invalid credentials", K(ret), K(user_name), K(tenant_name), K(passwd.empty()), K(addr));
LOG_WARN("reverse link has invalid credentials", K(ret), K(user_name), K(tenant_name), K(passwd.empty()), K(host_name), K(port));
LOG_USER_ERROR(OB_ERR_UNEXPECTED, "check if the database link was created with local credentials");
} else {
ObReverseLink reverse_link_info;
@ -81,7 +84,9 @@ int ObLinkDmlOp::send_reverse_link_info(transaction::ObTransID &tx_id)
reverse_link_info.set_tenant(tenant_name);
reverse_link_info.set_cluster(cluster_name);
reverse_link_info.set_passwd(passwd);
reverse_link_info.set_addr(addr);
reverse_link_info.set_addr(addr);// discard
reverse_link_info.set_host_name(host_name);
reverse_link_info.set_port(port);
common::ObAddr local_addr = GCTX.self_addr();
local_addr.set_port(ObServerConfig::get_instance().mysql_port);
reverse_link_info.set_self_addr(local_addr);
@ -111,13 +116,13 @@ int ObLinkDmlOp::send_reverse_link_info(transaction::ObTransID &tx_id)
return ret;
}
int ObLinkDmlOp::inner_execute_link_stmt(const char *link_stmt)
int ObLinkDmlOp::inner_execute_link_stmt(const ObString &link_stmt)
{
int ret = OB_SUCCESS;
ObSQLSessionInfo *session = ctx_.get_my_session();
if (OB_ISNULL(dblink_proxy_) || OB_ISNULL(dblink_conn_) || OB_ISNULL(link_stmt) || OB_ISNULL(session)) {
if (OB_ISNULL(dblink_proxy_) || OB_ISNULL(dblink_conn_) || link_stmt.empty() || OB_ISNULL(session)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("dblink_proxy or link_stmt is NULL", K(ret), KP(dblink_proxy_), KP(link_stmt), KP(dblink_conn_), KP(session));
LOG_WARN("dblink_proxy or link_stmt is NULL", K(ret), KP(dblink_proxy_), K(link_stmt), KP(dblink_conn_), KP(session));
} else if (MY_SPEC.is_reverse_link_ && OB_FAIL(send_reverse_link_info(session->get_dblink_context().get_tx_id()))) {
LOG_WARN("failed to send reverse link info", K(ret), K(link_stmt));
} else if (OB_FAIL(dblink_proxy_->dblink_write(dblink_conn_, affected_rows_, link_stmt))) {

View File

@ -39,7 +39,7 @@ public:
virtual int inner_rescan() override;
virtual void reset();
int inner_execute_link_stmt(const char *link_stmt);
int inner_execute_link_stmt(const ObString &link_stmt);
int send_reverse_link_info(transaction::ObTransID &tx_id);
private:

View File

@ -106,6 +106,7 @@ ObLinkOp::ObLinkOp(ObExecContext &exec_ctx, const ObOpSpec &spec, ObOpInput *inp
allocator_(exec_ctx.get_allocator()),
stmt_buf_(NULL),
stmt_buf_len_(STMT_BUF_BLOCK),
stmt_buf_pos_(0),
next_sql_req_level_(0),
link_type_(DBLINK_DRV_OB),
in_xa_transaction_(false),
@ -147,7 +148,8 @@ int ObLinkOp::init_dblink()
link_type_))) {
LOG_WARN("failed to init dblink param ctx", K(ret), K(dblink_param_ctx_), K(dblink_id_), K(link_type_));
} else if (OB_FAIL(dblink_proxy_->create_dblink_pool(dblink_param_ctx_,
dblink_schema_->get_host_addr(),
dblink_schema_->get_host_name(),
dblink_schema_->get_host_port(),
dblink_schema_->get_tenant_name(),
dblink_schema_->get_user_name(),
dblink_schema_->get_plain_password(),
@ -185,8 +187,8 @@ int ObLinkOp::execute_link_stmt(const ObString &link_stmt_fmt,
param_store,
reverse_link))) {
LOG_WARN("failed to gen link stmt", K(ret), K(link_stmt_fmt));
} else if (OB_FAIL(inner_execute_link_stmt(stmt_buf_))) {
LOG_WARN("failed to execute link stmt", K(ret));
} else if (OB_FAIL(inner_execute_link_stmt(ObString(stmt_buf_pos_, stmt_buf_)))) {
LOG_WARN("failed to execute link stmt", K(ret), K(stmt_buf_pos_), K(stmt_buf_));
}
return ret;
}
@ -206,6 +208,7 @@ int ObLinkOp::combine_link_stmt(const ObString &link_stmt_fmt,
int64_t stmt_fmt_next_param_pos = (next_param < param_infos.count() ?
param_infos.at(next_param).pos_ : link_stmt_fmt.length());
char proxy_route_ip_port_str[proxy_route_ip_port_size_] = { 0 };
ObCollationType spell_coll = CS_TYPE_INVALID;
if (OB_NOT_NULL(reverse_link)) {
if (OB_FAIL(reverse_link->get_self_addr().ip_port_to_string(proxy_route_ip_port_str,
proxy_route_ip_port_size_))) {
@ -217,6 +220,9 @@ int ObLinkOp::combine_link_stmt(const ObString &link_stmt_fmt,
}
}
link_stmt_pos += reserve_proxy_route_space;
if (OB_SUCC(ret) && param_infos.count() && OB_FAIL(ObDblinkService::get_spell_collation_type(ctx_.get_my_session(), spell_coll))) {
LOG_WARN("failed to get spell collation type", K(ret));
}
while (OB_SUCC(ret) && stmt_fmt_pos < link_stmt_fmt.length()) {
// copy from link_stmt_fmt.
if (stmt_fmt_pos < stmt_fmt_next_param_pos) {
@ -244,11 +250,7 @@ int ObLinkOp::combine_link_stmt(const ObString &link_stmt_fmt,
obj_print_params.ob_obj_type_ = ObObjType(param_type_value);
obj_print_params.print_null_string_value_ = 1;
}
if (DBLINK_DRV_OCI == link_type_) {
// Ensure that when oceanbase connects to oracle,
// the target character set of param is the same as that of oci connection.
obj_print_params.cs_type_ = ctx_.get_my_session()->get_nls_collation();
}
obj_print_params.cs_type_ = spell_coll;
obj_print_params.need_cast_expr_ = true;
obj_print_params.print_const_expr_type_ = true;
while (OB_SUCC(ret) && link_stmt_pos == saved_stmt_pos) {
@ -316,7 +318,10 @@ int ObLinkOp::combine_link_stmt(const ObString &link_stmt_fmt,
stmt_buf_ += head_comment_length_ + reserve_proxy_route_space;
link_stmt_pos -= head_comment_length_ + reserve_proxy_route_space;
}
LOG_TRACE("succ to combine link sql", K(stmt_buf_), K(link_stmt_pos));
if (OB_SUCC(ret)) {
stmt_buf_pos_ = link_stmt_pos;
}
LOG_WARN("succ to combine link sql", KP(stmt_buf_), K(stmt_buf_pos_), K(ObString(stmt_buf_pos_, stmt_buf_)));
}
return ret;
}

View File

@ -57,7 +57,7 @@ public:
const common::ObIArray<ObParamPosIdx> &param_infos,
const ObParamStore &param_store,
ObReverseLink *reverse_link = NULL);
virtual int inner_execute_link_stmt(const char *link_stmt) = 0;
virtual int inner_execute_link_stmt(const ObString &sql) = 0;
protected:
int combine_link_stmt(const common::ObString &link_stmt_fmt,
const common::ObIArray<ObParamPosIdx> &param_infos,
@ -77,6 +77,7 @@ protected:
common::ObIAllocator &allocator_;
char *stmt_buf_;
int64_t stmt_buf_len_;
int64_t stmt_buf_pos_;
int64_t next_sql_req_level_;
static const int64_t STMT_BUF_BLOCK;
common::sqlclient::DblinkDriverProto link_type_;

View File

@ -95,7 +95,7 @@ int calc_digest_text(ObIAllocator &allocator,
charsets4parser))) {
LOG_WARN("fail to parameterize syntax tree", K(sql_str), K(ret));
} else {
digest_str = pc_ctx.sql_ctx_.spm_ctx_.bl_key_.constructed_sql_;
digest_str = pc_ctx.sql_ctx_.spm_ctx_.bl_key_.format_sql_;
}
} else {
digest_str = queries.at(i);

View File

@ -281,7 +281,6 @@ int ObOpSpec::create_op_input_recursive(ObExecContext &exec_ctx) const
int ObOpSpec::create_operator(ObExecContext &exec_ctx, ObOperator *&op) const
{
int ret = OB_SUCCESS;
ObMonitorNode *pre_node = nullptr;
// Do some sanity check,
// we no longer need to check the validity of those pointers in ObOperator.
if (OB_ISNULL(GET_MY_SESSION(exec_ctx))
@ -291,8 +290,6 @@ int ObOpSpec::create_operator(ObExecContext &exec_ctx, ObOperator *&op) const
LOG_WARN("invalid argument", K(ret));
} else if (OB_FAIL(create_operator_recursive(exec_ctx, op))) {
LOG_WARN("create operator recursive failed", K(ret));
} else if (OB_FAIL(link_sql_plan_monitor_node_recursive(exec_ctx, pre_node))) {
LOG_WARN("fail to link sql plan monitor node recursive", K(ret));
} else if (OB_FAIL(create_exec_feedback_node_recursive(exec_ctx))) {
LOG_WARN("fail to create exec feedback node", K(ret));
}
@ -359,6 +356,7 @@ int ObOpSpec::create_operator_recursive(ObExecContext &exec_ctx, ObOperator *&op
LOG_WARN("create operator failed", K(ret), KP(kit->op_), K(*this));
} else {
op = kit->op_;
op->get_monitor_info().set_op(op);
op->get_monitor_info().set_operator_id(id_);
op->get_monitor_info().set_operator_type(type_);
op->get_monitor_info().set_plan_depth(plan_depth_);
@ -396,33 +394,6 @@ int ObOpSpec::create_operator_recursive(ObExecContext &exec_ctx, ObOperator *&op
return ret;
}
int ObOpSpec::link_sql_plan_monitor_node_recursive(ObExecContext &exec_ctx, ObMonitorNode *&pre_node) const
{
int ret = OB_SUCCESS;
ObOperatorKit *kit = exec_ctx.get_operator_kit(id_);
if (OB_ISNULL(kit) || OB_ISNULL(kit->op_)) {
LOG_TRACE("operator kit is NULL", K(ret));
} else if (OB_NOT_NULL(kit->op_->get_monitor_info().get_next()) ||
OB_NOT_NULL(kit->op_->get_monitor_info().get_prev())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("cur monitor info is unexpected", K(ret));
} else if (OB_ISNULL(pre_node)) {
pre_node = &(kit->op_->get_monitor_info());
} else {
pre_node->add_rt_monitor_node(&(kit->op_->get_monitor_info()));
pre_node = &(kit->op_->get_monitor_info());
}
for (int i = 0; OB_SUCC(ret) && i < child_cnt_; ++i) {
if (nullptr == children_[i]) {
continue;
} else if (OB_FAIL(SMART_CALL(children_[i]->link_sql_plan_monitor_node_recursive(
exec_ctx, pre_node)))) {
LOG_WARN("fail to link sql plan monitor", K(ret));
}
}
return ret;
}
int ObOpSpec::create_exec_feedback_node_recursive(ObExecContext &exec_ctx) const
{
int ret = OB_SUCCESS;
@ -520,6 +491,7 @@ ObOperator::ObOperator(ObExecContext &exec_ctx, const ObOpSpec &spec, ObOpInput
fb_node_idx_(OB_INVALID_INDEX),
io_event_observer_(op_monitor_info_),
cpu_begin_time_(0),
cpu_begin_level_(0),
total_time_(0),
batch_reach_end_(false),
row_reach_end_(false),
@ -1129,14 +1101,14 @@ int ObOperator::setup_op_feedback_info()
ObExecFeedbackInfo &fb_info = ctx_.get_feedback_info();
common::ObIArray<ObExecFeedbackNode> &nodes = fb_info.get_feedback_nodes();
int64_t &total_db_time = fb_info.get_total_db_time();
total_db_time += op_monitor_info_.db_time_;
uint64_t db_time = op_monitor_info_.calc_db_time();
uint64_t cpu_khz = OBSERVER.get_cpu_frequency_khz();
db_time = db_time * 1000 / cpu_khz;
total_db_time += db_time;
if (fb_node_idx_ >= 0 && fb_node_idx_ < nodes.count()) {
uint64_t cpu_khz = OBSERVER.get_cpu_frequency_khz();
ObExecFeedbackNode &node = nodes.at(fb_node_idx_);
node.block_time_ = op_monitor_info_.block_time_;
node.block_time_ /= cpu_khz;
node.db_time_ = op_monitor_info_.db_time_;
node.db_time_ /= cpu_khz;
node.block_time_ = op_monitor_info_.block_time_ * 1000 / cpu_khz;;
node.db_time_ = db_time;
node.op_close_time_ = op_monitor_info_.close_time_;
node.op_first_row_time_ = op_monitor_info_.first_row_time_;
node.op_last_row_time_ = op_monitor_info_.last_row_time_;
@ -1206,11 +1178,9 @@ int ObOperator::get_next_row()
} else if (OB_UNLIKELY(get_spec().is_vectorized())) {
// Operator itself supports vectorization, while parent operator does NOT.
// Use vectorize method to get next row.
end_cpu_time_counting();
if (OB_FAIL(get_next_row_vectorizely())) {
// do nothing
}
begin_cpu_time_counting();
} else {
if (OB_UNLIKELY(!startup_passed_)) {
bool filtered = false;
@ -1437,13 +1407,11 @@ int ObOperator::get_next_batch(const int64_t max_row_cnt, const ObBatchRows *&ba
}
}
} else {
end_cpu_time_counting();
// Operator does NOT support vectorization, while its parent does. Return
// the batch with only 1 row
if (OB_FAIL(get_next_batch_with_onlyone_row())) {
// do nothing
}
begin_cpu_time_counting();
}
if (OB_SUCC(ret)) {
if (OB_UNLIKELY(spec_.need_check_output_datum_) && brs_checker_ && !brs_.end_ && brs_.size_ > 0) {
@ -1665,9 +1633,9 @@ int ObOperator::filter_batch_rows(const ObExprPtrIArray &exprs,
int ObOperator::drain_exch()
{
int ret = OB_SUCCESS;
uint64_t cpu_begin_time = rdtsc();
begin_cpu_time_counting();
ret = do_drain_exch();
total_time_ += (rdtsc() - cpu_begin_time);
end_cpu_time_counting();
return ret;
}

View File

@ -301,7 +301,6 @@ private:
int create_op_input_recursive(ObExecContext &exec_ctx) const;
// assign spec ptr to ObOpKitStore
int assign_spec_ptr_recursive(ObExecContext &exec_ctx) const;
int link_sql_plan_monitor_node_recursive(ObExecContext &exec_ctx, ObMonitorNode *&pre_node) const;
int create_exec_feedback_node_recursive(ObExecContext &exec_ctx) const;
// Data members are accessed in ObOperator class, exposed for convenience.
public:
@ -489,6 +488,7 @@ public:
{ fb_node_idx_ = idx; }
bool is_operator_end() { return batch_reach_end_ || row_reach_end_ ; }
TO_STRING_KV(K(spec_));
protected:
virtual int do_drain_exch();
int init_skip_vector();
@ -619,11 +619,17 @@ protected:
inline void begin_cpu_time_counting()
{
cpu_begin_time_ = rdtsc();
if (cpu_begin_level_ == 0) {
cpu_begin_time_ = rdtsc();
}
++cpu_begin_level_;
}
inline void end_cpu_time_counting()
{
total_time_ += (rdtsc() - cpu_begin_time_);
--cpu_begin_level_;
if (cpu_begin_level_ == 0) {
total_time_ += (rdtsc() - cpu_begin_time_);
}
}
inline void begin_ash_line_id_reg()
{
@ -644,7 +650,9 @@ protected:
#ifdef ENABLE_DEBUG_LOG
inline int init_dummy_mem_context(uint64_t tenant_id);
#endif
public:
uint64_t cpu_begin_time_; // start of counting cpu time
uint64_t cpu_begin_level_; // level of counting cpu time
uint64_t total_time_; // total time cost on this op, including io & cpu time
protected:
bool batch_reach_end_;

View File

@ -722,6 +722,7 @@ public:
bool use_rich_format_;
ObSubSchemaCtx subschema_ctx_;
bool disable_auto_memory_mgr_;
private:
common::ObFixedArray<ObLocalSessionVar, common::ObIAllocator> all_local_session_vars_;
public:

View File

@ -241,9 +241,9 @@ int ObPxTransmitOp::inner_open()
int ObPxTransmitOp::transmit()
{
int64_t cpu_begin_time = rdtsc();
begin_cpu_time_counting();
int ret = do_transmit();
total_time_ += (rdtsc() - cpu_begin_time_);
end_cpu_time_counting();
return ret;
}

View File

@ -430,6 +430,8 @@ int ObGranuleUtil::compute_total_task_count(const ObParallelBlockRangeTaskParams
// default value of expected_task_load_ is 128 MB
int64_t expected_task_load = max(params.expected_task_load_, min_task_access_size);
LOG_TRACE("compute task count: ", K(total_access_size), K(expected_task_load));
// lower bound size: dop*128M*13
int64_t lower_bound_size = params.parallelism_ * expected_task_load * params.min_task_count_per_thread_;
// hight bound size: dop*128M*100

View File

@ -244,7 +244,8 @@ int ObRemoteSequenceExecutor::init_dblink_connection(ObExecContext &ctx)
link_type_))) {
LOG_WARN("failed to init dblink param ctx", K(ret));
} else if (OB_FAIL(dblink_proxy->create_dblink_pool(param_ctx,
dblink_schema->get_host_addr(),
dblink_schema->get_host_name(),
dblink_schema->get_host_port(),
dblink_schema->get_tenant_name(),
dblink_schema->get_user_name(),
dblink_schema->get_plain_password(),

Some files were not shown because too many files have changed in this diff Show More