patch 4.0
This commit is contained in:
@ -11,6 +11,7 @@
|
||||
*/
|
||||
|
||||
#define USING_LOG_PREFIX SHARE
|
||||
#include "lib/mysqlclient/ob_isql_connection_pool.h"
|
||||
#include "lib/mysqlclient/ob_mysql_connection.h"
|
||||
#include "lib/mysqlclient/ob_isql_connection_pool.h"
|
||||
#include "lib/mysqlclient/ob_mysql_proxy.h"
|
||||
@ -20,7 +21,7 @@
|
||||
#include "share/inner_table/ob_inner_table_schema_constants.h"
|
||||
#include "share/schema/ob_schema_service_sql_impl.h"
|
||||
#include "observer/ob_server_struct.h"
|
||||
#include "storage/ob_tenant_config_mgr.h"
|
||||
#include "observer/omt/ob_multi_tenant.h"
|
||||
|
||||
using namespace oceanbase::common;
|
||||
using namespace oceanbase::sql;
|
||||
@ -29,33 +30,56 @@ using namespace oceanbase::common::sqlclient;
|
||||
using namespace oceanbase::share::schema;
|
||||
|
||||
ObCompatModeGetter::ObCompatModeGetter() : id_mode_map_(), sql_proxy_(NULL), is_inited_(false)
|
||||
{}
|
||||
{
|
||||
}
|
||||
ObCompatModeGetter::~ObCompatModeGetter()
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
|
||||
ObCompatModeGetter& ObCompatModeGetter::instance()
|
||||
ObCompatModeGetter &ObCompatModeGetter::instance()
|
||||
{
|
||||
static ObCompatModeGetter the_compat_mode_getter;
|
||||
return the_compat_mode_getter;
|
||||
}
|
||||
|
||||
int ObCompatModeGetter::get_tenant_mode(const uint64_t tenant_id, ObWorker::CompatMode& mode)
|
||||
int ObCompatModeGetter::get_tenant_mode(const uint64_t tenant_id, lib::Worker::CompatMode& mode)
|
||||
{
|
||||
return instance().get_tenant_compat_mode(tenant_id, mode);
|
||||
}
|
||||
|
||||
int ObCompatModeGetter::check_is_oracle_mode_with_tenant_id(const uint64_t tenant_id, bool& is_oracle_mode)
|
||||
int ObCompatModeGetter::get_table_compat_mode(
|
||||
const uint64_t tenant_id,
|
||||
const int64_t table_id,
|
||||
lib::Worker::CompatMode& mode)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObWorker::CompatMode compat_mode = ObWorker::CompatMode::INVALID;
|
||||
if (OB_UNLIKELY(
|
||||
OB_INVALID_TENANT_ID == tenant_id
|
||||
|| table_id <= 0)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid tenant_id or table_id", KR(ret), K(tenant_id), K(table_id));
|
||||
} else if (is_inner_table(table_id)) {
|
||||
mode = (is_ora_virtual_table(table_id)
|
||||
|| is_ora_sys_view_table(table_id)) ?
|
||||
lib::Worker::CompatMode::ORACLE :
|
||||
lib::Worker::CompatMode::MYSQL;
|
||||
} else {
|
||||
ret = instance().get_tenant_compat_mode(tenant_id, mode);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObCompatModeGetter::check_is_oracle_mode_with_tenant_id(const uint64_t tenant_id, bool &is_oracle_mode)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
lib::Worker::CompatMode compat_mode = lib::Worker::CompatMode::INVALID;
|
||||
|
||||
if (OB_FAIL(instance().get_tenant_compat_mode(tenant_id, compat_mode))) {
|
||||
LOG_WARN("fail to get tenant mode", K(ret));
|
||||
} else if (ObWorker::CompatMode::ORACLE == compat_mode) {
|
||||
} else if (lib::Worker::CompatMode::ORACLE == compat_mode) {
|
||||
is_oracle_mode = true;
|
||||
} else if (ObWorker::CompatMode::MYSQL == compat_mode) {
|
||||
} else if (lib::Worker::CompatMode::MYSQL == compat_mode) {
|
||||
is_oracle_mode = false;
|
||||
} else {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
@ -65,13 +89,34 @@ int ObCompatModeGetter::check_is_oracle_mode_with_tenant_id(const uint64_t tenan
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObCompatModeGetter::init(common::ObMySQLProxy* proxy)
|
||||
int ObCompatModeGetter::check_is_oracle_mode_with_table_id(
|
||||
const uint64_t tenant_id,
|
||||
const int64_t table_id,
|
||||
bool &is_oracle_mode)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
lib::Worker::CompatMode compat_mode = lib::Worker::CompatMode::INVALID;
|
||||
if (OB_FAIL(instance().get_table_compat_mode(tenant_id, table_id, compat_mode))) {
|
||||
LOG_WARN("fail to get tenant mode", KR(ret), K(tenant_id), K(table_id));
|
||||
} else if (lib::Worker::CompatMode::ORACLE == compat_mode) {
|
||||
is_oracle_mode = true;
|
||||
} else if (lib::Worker::CompatMode::MYSQL == compat_mode) {
|
||||
is_oracle_mode = false;
|
||||
} else {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("compat_mode should not be INVALID", KR(ret), K(tenant_id), K(table_id));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObCompatModeGetter::init(common::ObMySQLProxy *proxy)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (IS_INIT) {
|
||||
ret = OB_INIT_TWICE;
|
||||
} else if (OB_FAIL(id_mode_map_.create(
|
||||
bucket_num, ObModIds::OB_HASH_BUCKET_TENANT_COMPAT_MODE, ObModIds::OB_HASH_NODE_TENANT_COMPAT_MODE))) {
|
||||
} else if (OB_FAIL(id_mode_map_.create(bucket_num,
|
||||
ObModIds::OB_HASH_BUCKET_TENANT_COMPAT_MODE,
|
||||
ObModIds::OB_HASH_NODE_TENANT_COMPAT_MODE))) {
|
||||
LOG_WARN("create hash table failed", K(ret));
|
||||
} else {
|
||||
sql_proxy_ = proxy;
|
||||
@ -87,7 +132,7 @@ void ObCompatModeGetter::destroy()
|
||||
}
|
||||
}
|
||||
|
||||
int ObCompatModeGetter::get_tenant_compat_mode(const uint64_t tenant_id, ObWorker::CompatMode& mode)
|
||||
int ObCompatModeGetter::get_tenant_compat_mode(const uint64_t tenant_id, lib::Worker::CompatMode &mode)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObCompatibilityMode tmp_mode = ObCompatibilityMode::MYSQL_MODE;
|
||||
@ -95,24 +140,32 @@ int ObCompatModeGetter::get_tenant_compat_mode(const uint64_t tenant_id, ObWorke
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("tenant id is invalid", K(ret), K(tenant_id), K(lbt()));
|
||||
} else if (OB_SYS_TENANT_ID == tenant_id) {
|
||||
mode = ObWorker::CompatMode::MYSQL;
|
||||
mode = lib::Worker::CompatMode::MYSQL;
|
||||
} else if (OB_GTS_TENANT_ID == tenant_id) {
|
||||
mode = ObWorker::CompatMode::MYSQL;
|
||||
mode = lib::Worker::CompatMode::MYSQL;
|
||||
} else if (is_meta_tenant(tenant_id)) {
|
||||
mode = lib::Worker::CompatMode::MYSQL;
|
||||
} else if (OB_HASH_NOT_EXIST == (ret = id_mode_map_.get_refactored(tenant_id, mode))) {
|
||||
bool is_exist = false;
|
||||
int overwrite = 1;
|
||||
// First take from the local persistent tenant information
|
||||
if (OB_FAIL(storage::ObTenantConfigMgr::get_instance().get_compat_mode(tenant_id, mode))) {
|
||||
if (ret != OB_ENTRY_NOT_EXIST) {
|
||||
LOG_WARN("failed to get compat mode", K(ret), K(tenant_id));
|
||||
|
||||
if (! ObSchemaService::g_liboblog_mode_) {
|
||||
//先从本地tenant信息里拿
|
||||
if (OB_FAIL(GCTX.omt_->get_compat_mode(tenant_id, mode))) {
|
||||
if (ret != OB_TENANT_NOT_IN_SERVER) {
|
||||
LOG_WARN("failed to get compat mode", K(ret), K(tenant_id));
|
||||
} else {
|
||||
ret = OB_SUCCESS;
|
||||
}
|
||||
} else {
|
||||
ret = OB_SUCCESS;
|
||||
is_exist = true;
|
||||
ret = id_mode_map_.set_refactored(tenant_id, mode, overwrite);
|
||||
}
|
||||
} else {
|
||||
is_exist = true;
|
||||
ret = id_mode_map_.set_refactored(tenant_id, mode, overwrite);
|
||||
ret = OB_SUCCESS;
|
||||
}
|
||||
// cant get it locally, go to the schema to get it
|
||||
|
||||
//如果本地拿不到,再去schema里拿
|
||||
if (OB_SUCC(ret) && !is_exist) {
|
||||
if (OB_ISNULL(sql_proxy_)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
@ -121,10 +174,10 @@ int ObCompatModeGetter::get_tenant_compat_mode(const uint64_t tenant_id, ObWorke
|
||||
LOG_WARN("failed to fetch tenant compat mode", K(ret), K(tenant_id), K(lbt()));
|
||||
} else {
|
||||
if (tmp_mode == ObCompatibilityMode::MYSQL_MODE) {
|
||||
mode = ObWorker::CompatMode::MYSQL;
|
||||
mode = lib::Worker::CompatMode::MYSQL;
|
||||
ret = id_mode_map_.set_refactored(tenant_id, mode, overwrite);
|
||||
} else if (tmp_mode == ObCompatibilityMode::ORACLE_MODE) {
|
||||
mode = ObWorker::CompatMode::ORACLE;
|
||||
mode = lib::Worker::CompatMode::ORACLE;
|
||||
ret = id_mode_map_.set_refactored(tenant_id, mode, overwrite);
|
||||
} else {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
@ -137,14 +190,15 @@ int ObCompatModeGetter::get_tenant_compat_mode(const uint64_t tenant_id, ObWorke
|
||||
}
|
||||
|
||||
// only for unittest
|
||||
int ObCompatModeGetter::set_tenant_compat_mode(const uint64_t tenant_id, ObWorker::CompatMode& mode)
|
||||
int ObCompatModeGetter::set_tenant_compat_mode(const uint64_t tenant_id, lib::Worker::CompatMode &mode)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int overwrite = 1;
|
||||
if (OB_UNLIKELY(OB_INVALID_ID == tenant_id)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("tenant id is invalid", K(ret), K(tenant_id));
|
||||
} else if (ObWorker::CompatMode::MYSQL != mode && ObWorker::CompatMode::ORACLE != mode) {
|
||||
} else if (lib::Worker::CompatMode::MYSQL != mode &&
|
||||
lib::Worker::CompatMode::ORACLE != mode) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid tenant compat mode", K(ret), K(tenant_id), K(mode));
|
||||
} else if (OB_FAIL(id_mode_map_.set_refactored(tenant_id, mode, overwrite))) {
|
||||
@ -164,3 +218,5 @@ int ObCompatModeGetter::reset_compat_getter_map()
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user