support tenant role interface
This commit is contained in:
@ -276,6 +276,14 @@ int ObTenantRecoveryReportor::load_tenant_info_()
|
|||||||
sql_proxy_, false, tenant_info))) {
|
sql_proxy_, false, tenant_info))) {
|
||||||
LOG_WARN("failed to load tenant info", KR(ret), K(tenant_id_));
|
LOG_WARN("failed to load tenant info", KR(ret), K(tenant_id_));
|
||||||
} else {
|
} else {
|
||||||
|
/**
|
||||||
|
* Only need to refer to tenant role, no need to refer to switchover status.
|
||||||
|
* tenant_role is primary only in <primary, normal switchoverstatus>.
|
||||||
|
* When switch to standby starts, it will change to <standby, prepare switch to standby>.
|
||||||
|
* During the master switch process, some LS may be in RO state.
|
||||||
|
* This also ensures the consistency of tenant_role cache and the tenant role field in all_tenant_info
|
||||||
|
*/
|
||||||
|
MTL_SET_TENANT_ROLE(tenant_info.get_tenant_role().value());
|
||||||
SpinWLockGuard guard(lock_);
|
SpinWLockGuard guard(lock_);
|
||||||
if (OB_FAIL(tenant_info_.assign(tenant_info))) {
|
if (OB_FAIL(tenant_info_.assign(tenant_info))) {
|
||||||
LOG_WARN("failed to assign tenant info", KR(ret), K(tenant_info));
|
LOG_WARN("failed to assign tenant info", KR(ret), K(tenant_info));
|
||||||
@ -309,6 +317,7 @@ int ObTenantRecoveryReportor::get_tenant_info(share::ObAllTenantInfo &tenant_inf
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int ObTenantRecoveryReportor::update_replayable_point_()
|
int ObTenantRecoveryReportor::update_replayable_point_()
|
||||||
{
|
{
|
||||||
int ret = OB_SUCCESS;
|
int ret = OB_SUCCESS;
|
||||||
|
|||||||
@ -50,7 +50,7 @@ ObTenantRole::ObTenantRole(const ObString &str)
|
|||||||
} else {
|
} else {
|
||||||
for (int64_t i = 0; i < ARRAYSIZEOF(TENANT_ROLE_ARRAY); i++) {
|
for (int64_t i = 0; i < ARRAYSIZEOF(TENANT_ROLE_ARRAY); i++) {
|
||||||
if (0 == str.case_compare(TENANT_ROLE_ARRAY[i])) {
|
if (0 == str.case_compare(TENANT_ROLE_ARRAY[i])) {
|
||||||
value_ = i;
|
value_ = static_cast<ObTenantRole::Role>(i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -61,5 +61,15 @@ ObTenantRole::ObTenantRole(const ObString &str)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define GEN_IS_TENANT_ROLE(TENANT_ROLE_VALUE, TENANT_ROLE) \
|
||||||
|
bool is_##TENANT_ROLE##_tenant(const ObTenantRole::Role value) { return TENANT_ROLE_VALUE == value; }
|
||||||
|
|
||||||
|
GEN_IS_TENANT_ROLE(ObTenantRole::Role::INVALID_TENANT, invalid)
|
||||||
|
GEN_IS_TENANT_ROLE(ObTenantRole::Role::PRIMARY_TENANT, primary)
|
||||||
|
GEN_IS_TENANT_ROLE(ObTenantRole::Role::STANDBY_TENANT, standby)
|
||||||
|
GEN_IS_TENANT_ROLE(ObTenantRole::Role::RESTORE_TENANT, restore)
|
||||||
|
#undef GEN_IS_TENANT_ROLE
|
||||||
|
|
||||||
|
|
||||||
} // share
|
} // share
|
||||||
} // oceanbase
|
} // oceanbase
|
||||||
|
|||||||
@ -26,25 +26,28 @@ class ObTenantRole
|
|||||||
OB_UNIS_VERSION(1);
|
OB_UNIS_VERSION(1);
|
||||||
public:
|
public:
|
||||||
// Tenant Role
|
// Tenant Role
|
||||||
static const int64_t INVALID_TENANT = 0;
|
enum Role
|
||||||
static const int64_t PRIMARY_TENANT = 1;
|
{
|
||||||
static const int64_t STANDBY_TENANT = 2;
|
INVALID_TENANT = 0,
|
||||||
static const int64_t RESTORE_TENANT = 3;
|
PRIMARY_TENANT = 1,
|
||||||
static const int64_t MAX_TENANT = 4;
|
STANDBY_TENANT = 2,
|
||||||
|
RESTORE_TENANT = 3,
|
||||||
|
MAX_TENANT = 4,
|
||||||
|
};
|
||||||
public:
|
public:
|
||||||
ObTenantRole() : value_(INVALID_TENANT) {}
|
ObTenantRole() : value_(INVALID_TENANT) {}
|
||||||
explicit ObTenantRole(const int64_t value) : value_(value) {}
|
explicit ObTenantRole(const Role value) : value_(value) {}
|
||||||
explicit ObTenantRole(const ObString &str);
|
explicit ObTenantRole(const ObString &str);
|
||||||
~ObTenantRole() { reset(); }
|
~ObTenantRole() { reset(); }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void reset() { value_ = INVALID_TENANT; }
|
void reset() { value_ = INVALID_TENANT; }
|
||||||
bool is_valid() const { return INVALID_TENANT != value_; }
|
bool is_valid() const { return INVALID_TENANT != value_; }
|
||||||
int64_t value() const { return value_; }
|
Role value() const { return value_; }
|
||||||
const char* to_str() const;
|
const char* to_str() const;
|
||||||
|
|
||||||
// assignment
|
// assignment
|
||||||
ObTenantRole &operator=(const int64_t value) { value_ = value; return *this; }
|
ObTenantRole &operator=(const Role value) { value_ = value; return *this; }
|
||||||
|
|
||||||
// compare operator
|
// compare operator
|
||||||
bool operator == (const ObTenantRole &other) const { return value_ == other.value_; }
|
bool operator == (const ObTenantRole &other) const { return value_ == other.value_; }
|
||||||
@ -57,9 +60,18 @@ public:
|
|||||||
|
|
||||||
TO_STRING_KV(K_(value));
|
TO_STRING_KV(K_(value));
|
||||||
private:
|
private:
|
||||||
int64_t value_;
|
Role value_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define GEN_IS_TENANT_ROLE_DECLARE(TENANT_ROLE_VALUE, TENANT_ROLE) \
|
||||||
|
bool is_##TENANT_ROLE##_tenant(const ObTenantRole::Role value);
|
||||||
|
|
||||||
|
GEN_IS_TENANT_ROLE_DECLARE(ObTenantRole::Role::INVALID_TENANT, invalid)
|
||||||
|
GEN_IS_TENANT_ROLE_DECLARE(ObTenantRole::Role::PRIMARY_TENANT, primary)
|
||||||
|
GEN_IS_TENANT_ROLE_DECLARE(ObTenantRole::Role::STANDBY_TENANT, standby)
|
||||||
|
GEN_IS_TENANT_ROLE_DECLARE(ObTenantRole::Role::RESTORE_TENANT, restore)
|
||||||
|
#undef GEN_IS_TENANT_ROLE_DECLARE
|
||||||
|
|
||||||
static const ObTenantRole INVALID_TENANT_ROLE(ObTenantRole::INVALID_TENANT);
|
static const ObTenantRole INVALID_TENANT_ROLE(ObTenantRole::INVALID_TENANT);
|
||||||
static const ObTenantRole PRIMARY_TENANT_ROLE(ObTenantRole::PRIMARY_TENANT);
|
static const ObTenantRole PRIMARY_TENANT_ROLE(ObTenantRole::PRIMARY_TENANT);
|
||||||
static const ObTenantRole STANDBY_TENANT_ROLE(ObTenantRole::STANDBY_TENANT);
|
static const ObTenantRole STANDBY_TENANT_ROLE(ObTenantRole::STANDBY_TENANT);
|
||||||
|
|||||||
@ -51,7 +51,7 @@ ObTenantSwitchoverStatus::ObTenantSwitchoverStatus(const ObString &str)
|
|||||||
} else {
|
} else {
|
||||||
for (int64_t i = 0; i < ARRAYSIZEOF(TENANT_SWITCHOVER_ARRAY); i++) {
|
for (int64_t i = 0; i < ARRAYSIZEOF(TENANT_SWITCHOVER_ARRAY); i++) {
|
||||||
if (0 == str.case_compare(TENANT_SWITCHOVER_ARRAY[i])) {
|
if (0 == str.case_compare(TENANT_SWITCHOVER_ARRAY[i])) {
|
||||||
value_ = i;
|
value_ = static_cast<ObTenantSwitchoverStatus::Status>(i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,22 +26,25 @@ class ObTenantSwitchoverStatus
|
|||||||
OB_UNIS_VERSION(1);
|
OB_UNIS_VERSION(1);
|
||||||
public:
|
public:
|
||||||
// Tenant Switchover Status
|
// Tenant Switchover Status
|
||||||
static const int64_t INVALID_STATUS = 0;
|
enum Status
|
||||||
static const int64_t NORMAL_STATUS = 1;
|
{
|
||||||
static const int64_t SWITCHING_STATUS = 2;
|
INVALID_STATUS = 0,
|
||||||
static const int64_t PREPARE_FLASHBACK_STATUS = 3;
|
NORMAL_STATUS = 1,
|
||||||
static const int64_t FLASHBACK_STATUS = 4;
|
SWITCHING_STATUS = 2,
|
||||||
static const int64_t MAX_STATUS = 5;
|
PREPARE_FLASHBACK_STATUS = 3,
|
||||||
|
FLASHBACK_STATUS = 4,
|
||||||
|
MAX_STATUS = 5,
|
||||||
|
};
|
||||||
public:
|
public:
|
||||||
ObTenantSwitchoverStatus() : value_(INVALID_STATUS) {}
|
ObTenantSwitchoverStatus() : value_(INVALID_STATUS) {}
|
||||||
explicit ObTenantSwitchoverStatus(const int64_t value) : value_(value) {}
|
explicit ObTenantSwitchoverStatus(const ObTenantSwitchoverStatus::Status value) : value_(value) {}
|
||||||
explicit ObTenantSwitchoverStatus(const ObString &str);
|
explicit ObTenantSwitchoverStatus(const ObString &str);
|
||||||
~ObTenantSwitchoverStatus() { reset(); }
|
~ObTenantSwitchoverStatus() { reset(); }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void reset() { value_ = INVALID_STATUS; }
|
void reset() { value_ = INVALID_STATUS; }
|
||||||
bool is_valid() const { return INVALID_STATUS != value_; }
|
bool is_valid() const { return INVALID_STATUS != value_; }
|
||||||
int64_t value() const { return value_; }
|
ObTenantSwitchoverStatus::Status value() const { return value_; }
|
||||||
const char* to_str() const;
|
const char* to_str() const;
|
||||||
|
|
||||||
// compare operator
|
// compare operator
|
||||||
@ -49,7 +52,7 @@ public:
|
|||||||
bool operator != (const ObTenantSwitchoverStatus &other) const { return value_ != other.value_; }
|
bool operator != (const ObTenantSwitchoverStatus &other) const { return value_ != other.value_; }
|
||||||
|
|
||||||
// assignment
|
// assignment
|
||||||
ObTenantSwitchoverStatus &operator=(const int64_t value)
|
ObTenantSwitchoverStatus &operator=(const ObTenantSwitchoverStatus::Status value)
|
||||||
{
|
{
|
||||||
value_ = value;
|
value_ = value;
|
||||||
return *this;
|
return *this;
|
||||||
@ -67,7 +70,7 @@ IS_TENANT_STATUS(FLASHBACK_STATUS, flashback)
|
|||||||
|
|
||||||
TO_STRING_KV(K_(value));
|
TO_STRING_KV(K_(value));
|
||||||
private:
|
private:
|
||||||
int64_t value_;
|
ObTenantSwitchoverStatus::Status value_;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const ObTenantSwitchoverStatus NORMAL_SWITCHOVER_STATUS(ObTenantSwitchoverStatus::NORMAL_STATUS);
|
static const ObTenantSwitchoverStatus NORMAL_SWITCHOVER_STATUS(ObTenantSwitchoverStatus::NORMAL_STATUS);
|
||||||
|
|||||||
@ -41,6 +41,7 @@ ObTenantBase::ObTenantBase(const uint64_t id, bool enable_tenant_ctx_check)
|
|||||||
inited_(false),
|
inited_(false),
|
||||||
created_(false),
|
created_(false),
|
||||||
mtl_init_ctx_(nullptr),
|
mtl_init_ctx_(nullptr),
|
||||||
|
tenant_role_value_(share::ObTenantRole::Role::PRIMARY_TENANT),
|
||||||
cgroups_(nullptr),
|
cgroups_(nullptr),
|
||||||
enable_tenant_ctx_check_(enable_tenant_ctx_check),
|
enable_tenant_ctx_check_(enable_tenant_ctx_check),
|
||||||
thread_count_(0)
|
thread_count_(0)
|
||||||
@ -55,6 +56,7 @@ ObTenantBase &ObTenantBase::operator=(const ObTenantBase &ctx)
|
|||||||
}
|
}
|
||||||
id_ = ctx.id_;
|
id_ = ctx.id_;
|
||||||
mtl_init_ctx_ = ctx.mtl_init_ctx_;
|
mtl_init_ctx_ = ctx.mtl_init_ctx_;
|
||||||
|
tenant_role_value_ = ctx.tenant_role_value_;
|
||||||
#define CONSTRUCT_MEMBER_TMP2(IDX) \
|
#define CONSTRUCT_MEMBER_TMP2(IDX) \
|
||||||
m##IDX##_ = ctx.m##IDX##_;
|
m##IDX##_ = ctx.m##IDX##_;
|
||||||
#define CONSTRUCT_MEMBER2(UNUSED, IDX) CONSTRUCT_MEMBER_TMP2(IDX)
|
#define CONSTRUCT_MEMBER2(UNUSED, IDX) CONSTRUCT_MEMBER_TMP2(IDX)
|
||||||
@ -382,7 +384,6 @@ int ObTenantBase::update_thread_cnt(double tenant_unit_cpu)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ObTenantEnv::set_tenant(ObTenantBase *ctx)
|
void ObTenantEnv::set_tenant(ObTenantBase *ctx)
|
||||||
{
|
{
|
||||||
if (ctx != nullptr && ctx->id_ == OB_INVALID_TENANT_ID) {
|
if (ctx != nullptr && ctx->id_ == OB_INVALID_TENANT_ID) {
|
||||||
|
|||||||
@ -21,6 +21,7 @@
|
|||||||
#include "lib/thread/threads.h"
|
#include "lib/thread/threads.h"
|
||||||
#include "lib/thread/thread_mgr.h"
|
#include "lib/thread/thread_mgr.h"
|
||||||
#include "lib/allocator/ob_malloc.h"
|
#include "lib/allocator/ob_malloc.h"
|
||||||
|
#include "share/ob_tenant_role.h"//ObTenantRole
|
||||||
|
|
||||||
namespace oceanbase
|
namespace oceanbase
|
||||||
{
|
{
|
||||||
@ -207,6 +208,12 @@ namespace detector
|
|||||||
|
|
||||||
// 获取租户ID
|
// 获取租户ID
|
||||||
#define MTL_ID() share::ObTenantEnv::get_tenant_local()->id()
|
#define MTL_ID() share::ObTenantEnv::get_tenant_local()->id()
|
||||||
|
// 获取是否为主租户
|
||||||
|
#define MTL_IS_PRIMARY_TENANT() share::ObTenantEnv::get_tenant()->is_primary_tenant()
|
||||||
|
// 更新租户role
|
||||||
|
#define MTL_SET_TENANT_ROLE(tenant_role) share::ObTenantEnv::get_tenant()->set_tenant_role(tenant_role)
|
||||||
|
// 获取租户role
|
||||||
|
#define MTL_GET_TENANT_ROLE() share::ObTenantEnv::get_tenant()->get_tenant_role()
|
||||||
// 获取租户模块
|
// 获取租户模块
|
||||||
#define MTL_CTX() (share::ObTenantEnv::get_tenant())
|
#define MTL_CTX() (share::ObTenantEnv::get_tenant())
|
||||||
// 获取租户初始化参数,仅在初始化时使用
|
// 获取租户初始化参数,仅在初始化时使用
|
||||||
@ -339,6 +346,28 @@ public:
|
|||||||
|
|
||||||
const ObTenantModuleInitCtx *get_mtl_init_ctx() const { return mtl_init_ctx_; }
|
const ObTenantModuleInitCtx *get_mtl_init_ctx() const { return mtl_init_ctx_; }
|
||||||
|
|
||||||
|
void set_tenant_role(const share::ObTenantRole::Role tenant_role_value)
|
||||||
|
{
|
||||||
|
(void)ATOMIC_STORE(&tenant_role_value_, tenant_role_value);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
share::ObTenantRole::Role get_tenant_role() const
|
||||||
|
{
|
||||||
|
return ATOMIC_LOAD(&tenant_role_value_);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description:
|
||||||
|
* Only when it is clear that it is a standby/restore tenant, it returns not primary tenant.
|
||||||
|
* The correct value can be obtained after the tenant role loaded in subsequent retry.
|
||||||
|
* @return whether allow strong consistency read write
|
||||||
|
*/
|
||||||
|
bool is_primary_tenant()
|
||||||
|
{
|
||||||
|
return share::is_primary_tenant(ATOMIC_LOAD(&tenant_role_value_));
|
||||||
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
T get() { return inner_get(Identity<T>()); }
|
T get() { return inner_get(Identity<T>()); }
|
||||||
|
|
||||||
@ -409,6 +438,7 @@ protected:
|
|||||||
bool inited_;
|
bool inited_;
|
||||||
bool created_;
|
bool created_;
|
||||||
share::ObTenantModuleInitCtx *mtl_init_ctx_;
|
share::ObTenantModuleInitCtx *mtl_init_ctx_;
|
||||||
|
share::ObTenantRole::Role tenant_role_value_;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
common::hash::ObHashSet<int64_t> tg_set_;
|
common::hash::ObHashSet<int64_t> tg_set_;
|
||||||
|
|||||||
@ -28,9 +28,9 @@ namespace sql
|
|||||||
|
|
||||||
ObExprToOutfileRow::ObExprToOutfileRow(ObIAllocator &alloc)
|
ObExprToOutfileRow::ObExprToOutfileRow(ObIAllocator &alloc)
|
||||||
: ObStringExprOperator(alloc, T_OP_TO_OUTFILE_ROW, N_TO_OUTFILE_ROW, MORE_THAN_ZERO, INTERNAL_IN_MYSQL_MODE)
|
: ObStringExprOperator(alloc, T_OP_TO_OUTFILE_ROW, N_TO_OUTFILE_ROW, MORE_THAN_ZERO, INTERNAL_IN_MYSQL_MODE)
|
||||||
{
|
{
|
||||||
need_charset_convert_ = false;
|
need_charset_convert_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ObExprToOutfileRow::~ObExprToOutfileRow()
|
ObExprToOutfileRow::~ObExprToOutfileRow()
|
||||||
{
|
{
|
||||||
@ -105,9 +105,9 @@ int ObExprToOutfileRow::extend_buffer(ObExprOutFileInfo &out_info,
|
|||||||
LOG_WARN("fail to allocate memory", K(ret), K(old_len), K(new_len));
|
LOG_WARN("fail to allocate memory", K(ret), K(old_len), K(new_len));
|
||||||
} else {
|
} else {
|
||||||
out_info.buf_len_ = new_len;
|
out_info.buf_len_ = new_len;
|
||||||
out_info.tmp_buf_len_ = new_len;
|
out_info.tmp_buf_len_ = new_len;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ObExprToOutfileRow::calc_outfile_info(const ObExpr &expr,
|
int ObExprToOutfileRow::calc_outfile_info(const ObExpr &expr,
|
||||||
@ -145,9 +145,9 @@ int ObExprToOutfileRow::calc_outfile_info(const ObExpr &expr,
|
|||||||
OZ(extract_fisrt_wchar_from_varhcar(out_info.field_, out_info.wchar_field_));
|
OZ(extract_fisrt_wchar_from_varhcar(out_info.field_, out_info.wchar_field_));
|
||||||
OZ(extract_fisrt_wchar_from_varhcar(out_info.line_, out_info.wchar_line_));
|
OZ(extract_fisrt_wchar_from_varhcar(out_info.line_, out_info.wchar_line_));
|
||||||
OZ(extract_fisrt_wchar_from_varhcar(out_info.enclose_, out_info.wchar_enclose_));
|
OZ(extract_fisrt_wchar_from_varhcar(out_info.enclose_, out_info.wchar_enclose_));
|
||||||
OZ(extract_fisrt_wchar_from_varhcar(out_info.escape_, out_info.wchar_escape_));
|
OZ(extract_fisrt_wchar_from_varhcar(out_info.escape_, out_info.wchar_escape_));
|
||||||
OZ(extend_buffer(out_info, allocator));
|
OZ(extend_buffer(out_info, allocator));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ObExprToOutfileRow::to_outfile_str(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &expr_datum)
|
int ObExprToOutfileRow::to_outfile_str(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &expr_datum)
|
||||||
|
|||||||
Reference in New Issue
Block a user