[Bugfix] fix coredump when do inner sql for user name in sql audit, cause by request use after free
This commit is contained in:
parent
2cdeaddd8c
commit
c1d8e1ad80
@ -281,13 +281,12 @@ int ObTableApiProcessorBase::check_user_access(const ObString &credential_str)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int64_t pos = 0;
|
||||
ObTableApiSessGuard guard;
|
||||
const ObTableApiCredential *sess_credetial = nullptr;
|
||||
if (OB_FAIL(serialization::decode(credential_str.ptr(), credential_str.length(), pos, credential_))) {
|
||||
LOG_WARN("failed to serialize credential", K(ret), K(pos));
|
||||
} else if (OB_FAIL(TABLEAPI_SESS_POOL_MGR->get_sess_info(credential_, guard))) {
|
||||
} else if (OB_FAIL(TABLEAPI_SESS_POOL_MGR->get_sess_info(credential_, sess_guard_))) {
|
||||
LOG_WARN("fail to get session info", K(ret), K_(credential));
|
||||
} else if (OB_FAIL(guard.get_credential(sess_credetial))) {
|
||||
} else if (OB_FAIL(sess_guard_.get_credential(sess_credetial))) {
|
||||
LOG_WARN("fail to get credential", K(ret));
|
||||
} else if (sess_credetial->hash_val_ != credential_.hash_val_) {
|
||||
ret = OB_KV_CREDENTIAL_NOT_MATCH;
|
||||
@ -300,7 +299,7 @@ int ObTableApiProcessorBase::check_user_access(const ObString &credential_str)
|
||||
} else if (sess_credetial->cluster_id_ != credential_.cluster_id_) {
|
||||
ret = OB_ERR_NO_PRIVILEGE;
|
||||
LOG_WARN("invalid credential cluster id", K(ret), K_(credential), K(*sess_credetial));
|
||||
} else if (OB_FAIL(check_mode(guard.get_sess_info()))) {
|
||||
} else if (OB_FAIL(check_mode(sess_guard_.get_sess_info()))) {
|
||||
LOG_WARN("fail to check mode", K(ret));
|
||||
} else {
|
||||
LOG_DEBUG("user can access", K_(credential));
|
||||
@ -689,59 +688,21 @@ static int set_audit_name(const char *info_name, char *&audit_name, int64_t &aud
|
||||
|
||||
void ObTableApiProcessorBase::end_audit()
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
|
||||
// credential info
|
||||
audit_record_.tenant_id_ = credential_.tenant_id_;
|
||||
audit_record_.effective_tenant_id_ = credential_.tenant_id_;
|
||||
audit_record_.user_id_ = credential_.user_id_;
|
||||
audit_record_.db_id_ = credential_.database_id_;
|
||||
|
||||
// update tenant_name, user_name, database_name
|
||||
int ret = OB_SUCCESS;
|
||||
share::schema::ObSchemaGetterGuard schema_guard;
|
||||
if (OB_FAIL(gctx_.schema_service_->get_tenant_schema_guard(credential_.tenant_id_, schema_guard))) {
|
||||
SERVER_LOG(WARN, "fail to get schema guard", K(ret), "tenant_id", credential_.tenant_id_);
|
||||
} else {
|
||||
{ // set tenant name, ignore ret
|
||||
const share::schema::ObSimpleTenantSchema *tenant_info = NULL;
|
||||
if(OB_FAIL(schema_guard.get_tenant_info(credential_.tenant_id_, tenant_info))) {
|
||||
SERVER_LOG(WARN, "fail to get tenant info", K(ret), K(credential_.tenant_id_));
|
||||
} else if (OB_ISNULL(tenant_info)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
SERVER_LOG(WARN, "tenant info is null", K(ret));
|
||||
} else if (OB_FAIL(set_audit_name(tenant_info->get_tenant_name(),
|
||||
audit_record_.tenant_name_, audit_record_.tenant_name_len_, audit_allocator_))){
|
||||
SERVER_LOG(WARN, "fail to set tenant name", K(ret), "tenant_name", tenant_info->get_tenant_name());
|
||||
}
|
||||
}
|
||||
|
||||
{ // set user name, ignore ret
|
||||
ret = OB_SUCCESS;
|
||||
const share::schema::ObUserInfo *user_info = NULL;
|
||||
if(OB_FAIL(schema_guard.get_user_info(credential_.tenant_id_, credential_.user_id_, user_info))) {
|
||||
SERVER_LOG(WARN, "fail to get user info", K(ret), K(credential_));
|
||||
} else if (OB_ISNULL(user_info)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
SERVER_LOG(WARN, "user info is null", K(ret));
|
||||
} else if (OB_FAIL(set_audit_name(user_info->get_user_name(),
|
||||
audit_record_.user_name_, audit_record_.user_name_len_, audit_allocator_))) {
|
||||
SERVER_LOG(WARN, "fail to set user name", K(ret), "user_name", user_info->get_user_name());
|
||||
}
|
||||
}
|
||||
|
||||
{ // set database name, ignore ret
|
||||
ret = OB_SUCCESS;
|
||||
const share::schema::ObSimpleDatabaseSchema *database_info = NULL;
|
||||
if(OB_FAIL(schema_guard.get_database_schema(credential_.tenant_id_, credential_.database_id_, database_info))) {
|
||||
SERVER_LOG(WARN, "fail to get database info", K(ret), K(credential_));
|
||||
} else if (OB_ISNULL(database_info)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
SERVER_LOG(WARN, "database info is null", K(ret));
|
||||
} else if (OB_FAIL(set_audit_name(database_info->get_database_name(),
|
||||
audit_record_.db_name_, audit_record_.db_name_len_, audit_allocator_))) {
|
||||
SERVER_LOG(WARN, "fail to set database name", K(ret), "database_name", database_info->get_database_name());
|
||||
}
|
||||
}
|
||||
}
|
||||
// tenant name/user name/database name
|
||||
audit_record_.tenant_name_ = const_cast<char *>(sess_guard_.get_tenant_name().ptr());
|
||||
audit_record_.tenant_name_len_ = sess_guard_.get_tenant_name().length();
|
||||
audit_record_.user_name_ = const_cast<char *>(sess_guard_.get_user_name().ptr());
|
||||
audit_record_.user_name_len_ = sess_guard_.get_user_name().length();
|
||||
audit_record_.db_name_ = const_cast<char *>(sess_guard_.get_database_name().ptr());
|
||||
audit_record_.db_name_len_ = sess_guard_.get_database_name().length();
|
||||
|
||||
// append request string to query_sql
|
||||
if (NULL != request_string_ && request_string_len_ > 0) {
|
||||
|
@ -182,6 +182,7 @@ protected:
|
||||
storage::ObAccessService *access_service_;
|
||||
share::ObLocationService *location_service_;
|
||||
table::ObTableApiCredential credential_;
|
||||
table::ObTableApiSessGuard sess_guard_;
|
||||
int32_t stat_event_type_;
|
||||
int64_t audit_row_count_;
|
||||
bool need_audit_;
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "observer/omt/ob_multi_tenant.h"
|
||||
|
||||
using namespace oceanbase::share;
|
||||
using namespace oceanbase::share::schema;
|
||||
using namespace oceanbase::common;
|
||||
using namespace oceanbase::lib;
|
||||
|
||||
@ -41,7 +42,7 @@ int ObTableApiSessPoolMgr::start()
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
|
||||
if (!is_inited_) {
|
||||
if (IS_NOT_INIT) {
|
||||
ret = OB_NOT_INIT;
|
||||
LOG_WARN("table api session pool mgr isn't inited", K(ret));
|
||||
} else if (OB_FAIL(TG_SCHEDULE(MTL(omt::ObSharedTimer*)->get_tg_id(),
|
||||
@ -274,7 +275,12 @@ int ObTableApiSessPool::init(int64_t hash_bucket/* = SESS_POOL_DEFAULT_BUCKET_NU
|
||||
MTL_ID()))) {
|
||||
LOG_WARN("fail to init sess pool", K(ret), K(hash_bucket), K(MTL_ID()));
|
||||
} else {
|
||||
is_inited_ = true;
|
||||
const ObMemAttr attr(MTL_ID(), "TbSessPool");
|
||||
if (OB_FAIL(allocator_.init(ObMallocAllocator::get_instance(), OB_MALLOC_MIDDLE_BLOCK_SIZE, attr))) {
|
||||
LOG_WARN("fail to init allocator", K(ret));
|
||||
} else {
|
||||
is_inited_ = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -305,6 +311,8 @@ void ObTableApiSessPool::destroy()
|
||||
}
|
||||
} else if (OB_NOT_NULL(del_node)) {
|
||||
del_node->destroy();
|
||||
allocator_.free(del_node);
|
||||
del_node = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -313,12 +321,14 @@ void ObTableApiSessPool::destroy()
|
||||
DLIST_FOREACH(node, retired_nodes_) {
|
||||
if (OB_NOT_NULL(node)) {
|
||||
node->destroy();
|
||||
allocator_.free(node);
|
||||
node = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
retired_nodes_.clear();
|
||||
key_node_map_.destroy();
|
||||
allocator_.reset(); // when mtl_destroy, all worker thread has beed existed, no need to lock allocator
|
||||
allocator_.reset();
|
||||
is_inited_ = false;
|
||||
LOG_INFO("ObTableApiSessPool destroy successfully", K(MTL_ID()));
|
||||
}
|
||||
@ -335,7 +345,7 @@ void ObTableApiSessPool::destroy()
|
||||
int ObTableApiSessPool::retire_session_node()
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int64_t cur_time = ObTimeUtility::current_time();
|
||||
int64_t cur_time = ObTimeUtility::fast_current_time();
|
||||
ObTableApiSessForeachOp op;
|
||||
|
||||
if (OB_FAIL(key_node_map_.foreach_refactored(op))) {
|
||||
@ -388,7 +398,7 @@ int ObTableApiSessPool::evict_retired_sess()
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int64_t delete_count = 0;
|
||||
int64_t cur_time = ObTimeUtility::current_time();
|
||||
int64_t cur_time = ObTimeUtility::fast_current_time();
|
||||
ObLockGuard<ObSpinLock> guard(retired_nodes_lock_); // lock retired_nodes_
|
||||
|
||||
DLIST_FOREACH_REMOVESAFE_X(node, retired_nodes_, delete_count < BACKCROUND_TASK_DELETE_SESS_NUM) {
|
||||
@ -402,7 +412,6 @@ int ObTableApiSessPool::evict_retired_sess()
|
||||
ObTableApiSessNode *rm_node = retired_nodes_.remove(node);
|
||||
if (OB_NOT_NULL(rm_node)) {
|
||||
rm_node->~ObTableApiSessNode();
|
||||
ObLockGuard<ObSpinLock> alloc_guard(allocator_lock_); // lock allocator_
|
||||
allocator_.free(rm_node);
|
||||
rm_node = nullptr;
|
||||
delete_count++;
|
||||
@ -498,7 +507,7 @@ int ObTableApiSessPool::get_sess_info(ObTableApiCredential &credential, ObTableA
|
||||
}
|
||||
|
||||
if (OB_SUCC(ret) && OB_NOT_NULL(sess_node)) {
|
||||
int64_t cur_time = ObTimeUtility::current_time();
|
||||
int64_t cur_time = ObTimeUtility::fast_current_time();
|
||||
ATOMIC_STORE(&sess_node->last_active_ts_, cur_time);
|
||||
}
|
||||
|
||||
@ -508,7 +517,6 @@ int ObTableApiSessPool::get_sess_info(ObTableApiCredential &credential, ObTableA
|
||||
int ObTableApiSessPool::create_node_safe(ObTableApiCredential &credential, ObTableApiSessNode *&node)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObLockGuard<ObSpinLock> alloc_guard(allocator_lock_); // lock allocator_
|
||||
ObTableApiSessNode *tmp_node = nullptr;
|
||||
void *buf = nullptr;
|
||||
|
||||
@ -524,6 +532,13 @@ int ObTableApiSessPool::create_node_safe(ObTableApiCredential &credential, ObTab
|
||||
}
|
||||
}
|
||||
|
||||
if (OB_FAIL(ret) && OB_NOT_NULL(tmp_node)) {
|
||||
tmp_node->~ObTableApiSessNode();
|
||||
allocator_.free(tmp_node);
|
||||
tmp_node = nullptr;
|
||||
node = nullptr;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -539,9 +554,14 @@ int ObTableApiSessPool::create_and_add_node_safe(ObTableApiCredential &credentia
|
||||
LOG_WARN("fail to add sess node to hash map", K(ret), K(credential), K(*node));
|
||||
} else {
|
||||
ret = OB_SUCCESS; // replace error code
|
||||
// other thread has set_refactored, free current node
|
||||
node->~ObTableApiSessNode();
|
||||
allocator_.free(node);
|
||||
node = nullptr;
|
||||
}
|
||||
// this node has been set by other thread, free it
|
||||
ObLockGuard<ObSpinLock> alloc_guard(allocator_lock_); // lock allocator_
|
||||
}
|
||||
|
||||
if (OB_FAIL(ret) && OB_NOT_NULL(node)) {
|
||||
node->~ObTableApiSessNode();
|
||||
allocator_.free(node);
|
||||
node = nullptr;
|
||||
@ -560,7 +580,7 @@ int ObTableApiSessPool::update_sess(ObTableApiCredential &credential)
|
||||
int ret = OB_SUCCESS;
|
||||
ObTableApiSessNode *node = nullptr;
|
||||
const uint64_t key = credential.hash_val_;
|
||||
int64_t cur_time = ObTimeUtility::current_time();
|
||||
int64_t cur_time = ObTimeUtility::fast_current_time();
|
||||
|
||||
if (OB_FAIL(get_sess_node(key, node))) {
|
||||
if (OB_HASH_NOT_EXIST == ret) { // not exist, create
|
||||
@ -608,7 +628,7 @@ int ObTableApiSessNodeVal::init_sess_info()
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
|
||||
if (!is_inited_) {
|
||||
if (IS_NOT_INIT) {
|
||||
share::schema::ObSchemaGetterGuard schema_guard;
|
||||
const ObTenantSchema *tenant_schema = nullptr;
|
||||
if (OB_FAIL(GCTX.schema_service_->get_tenant_schema_guard(tenant_id_, schema_guard))) {
|
||||
@ -667,8 +687,42 @@ int ObTableApiSessNode::init()
|
||||
LOG_WARN("unexpected null mem context ", K(ret));
|
||||
} else {
|
||||
mem_ctx_ = tmp_mem_ctx;
|
||||
last_active_ts_ = ObTimeUtility::fast_current_time();
|
||||
is_inited_ = true;
|
||||
ObSchemaGetterGuard schema_guard;
|
||||
const uint64_t tenant_id = credential_.tenant_id_;
|
||||
const uint64_t user_id = credential_.user_id_;
|
||||
const uint64_t database_id = credential_.database_id_;
|
||||
if (OB_FAIL(GCTX.schema_service_->get_tenant_schema_guard(tenant_id, schema_guard))) {
|
||||
LOG_WARN("fail to get schema guard", K(ret), K(tenant_id));
|
||||
} else {
|
||||
const ObSimpleTenantSchema *tenant_info = nullptr;
|
||||
const ObUserInfo *user_info = nullptr;
|
||||
const ObSimpleDatabaseSchema *db_info = nullptr;
|
||||
if (OB_FAIL(schema_guard.get_tenant_info(tenant_id, tenant_info))) {
|
||||
LOG_WARN("fail to get tenant info", K(ret), K(tenant_id));
|
||||
} else if (OB_ISNULL(tenant_info)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("tenant info is null", K(ret));
|
||||
} else if (OB_FAIL(schema_guard.get_user_info(tenant_id, user_id, user_info))) {
|
||||
LOG_WARN("fail to get user info", K(ret), K(tenant_id), K(user_id));
|
||||
} else if (OB_ISNULL(user_info)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("user info is null", K(ret));
|
||||
} else if (OB_FAIL(schema_guard.get_database_schema(tenant_id, database_id, db_info))) {
|
||||
LOG_WARN("fail to get database info", K(ret), K(tenant_id), K(database_id));
|
||||
} else if (OB_ISNULL(db_info)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("database info is null", K(ret));
|
||||
} else if (OB_FAIL(ob_write_string(mem_ctx_->get_arena_allocator(), tenant_info->get_tenant_name(), tenant_name_))) {
|
||||
LOG_WARN("fail to deep copy tenant name", K(ret));
|
||||
} else if (OB_FAIL(ob_write_string(mem_ctx_->get_arena_allocator(), user_info->get_user_name(), user_name_))) {
|
||||
LOG_WARN("fail to deep copy user name", K(ret));
|
||||
} else if (OB_FAIL(ob_write_string(mem_ctx_->get_arena_allocator(), db_info->get_database_name(), db_name_))) {
|
||||
LOG_WARN("fail to deep copy database name", K(ret));
|
||||
} else {
|
||||
last_active_ts_ = ObTimeUtility::fast_current_time();
|
||||
is_inited_ = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (OB_FAIL(ret) && OB_NOT_NULL(mem_ctx_)) {
|
||||
@ -707,6 +761,7 @@ void ObTableApiSessNode::destroy()
|
||||
}
|
||||
if (OB_NOT_NULL(mem_ctx_)) {
|
||||
DESTROY_CONTEXT(mem_ctx_);
|
||||
mem_ctx_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,7 +93,7 @@ public:
|
||||
static const int64_t SESS_UPDATE_TIME_INTERVAL = 5 * 1000 * 1000; // the update interval cannot exceed 5 seconds
|
||||
public:
|
||||
explicit ObTableApiSessPool()
|
||||
: allocator_("TbSessPool", OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID()),
|
||||
: allocator_(MTL_ID()),
|
||||
is_inited_(false),
|
||||
last_update_ts_(0)
|
||||
{}
|
||||
@ -108,14 +108,12 @@ public:
|
||||
int evict_retired_sess();
|
||||
int create_node_safe(ObTableApiCredential &credential, ObTableApiSessNode *&node);
|
||||
int move_node_to_retired_list(ObTableApiSessNode *node);
|
||||
common::ObIAllocator& get_allocator() { return allocator_; };
|
||||
private:
|
||||
int replace_sess_node_safe(ObTableApiCredential &credential);
|
||||
int create_and_add_node_safe(ObTableApiCredential &credential);
|
||||
int get_sess_node(uint64_t key, ObTableApiSessNode *&node);
|
||||
private:
|
||||
common::ObArenaAllocator allocator_;
|
||||
ObSpinLock allocator_lock_; // for lock allocator_
|
||||
common::ObFIFOAllocator allocator_;
|
||||
bool is_inited_;
|
||||
CacheKeyNodeMap key_node_map_;
|
||||
// 已经淘汰的node,等待被后台删除
|
||||
@ -198,6 +196,9 @@ public:
|
||||
OB_INLINE const ObTableApiCredential& get_credential() const { return credential_; }
|
||||
OB_INLINE int64_t get_last_active_ts() const { return last_active_ts_; }
|
||||
int remove_unused_sess();
|
||||
OB_INLINE const ObString& get_tenant_name() const { return tenant_name_; }
|
||||
OB_INLINE const ObString& get_database_name() const { return db_name_; }
|
||||
OB_INLINE const ObString& get_user_name() const { return user_name_; }
|
||||
private:
|
||||
int extend_and_get_sess_val(ObTableApiSessGuard &guard);
|
||||
private:
|
||||
@ -206,6 +207,9 @@ private:
|
||||
SessList sess_lists_;
|
||||
int64_t last_active_ts_;
|
||||
ObTableApiCredential credential_;
|
||||
ObString tenant_name_;
|
||||
ObString db_name_;
|
||||
ObString user_name_;
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(ObTableApiSessNode);
|
||||
};
|
||||
@ -224,11 +228,13 @@ public:
|
||||
~ObTableApiSessGuard()
|
||||
{
|
||||
if (OB_NOT_NULL(sess_node_val_)) {
|
||||
sess_node_val_->get_sess_info().get_trans_result().reset();
|
||||
sess_node_val_->reset_tx_desc();
|
||||
sess_node_val_->give_back_to_free_list();
|
||||
sess_node_val_ = nullptr;
|
||||
}
|
||||
}
|
||||
TO_STRING_KV(KPC_(sess_node_val));
|
||||
public:
|
||||
ObTableApiSessNodeVal* get_sess_node_val() const { return sess_node_val_; }
|
||||
sql::ObSQLSessionInfo& get_sess_info() { return sess_node_val_->get_sess_info(); }
|
||||
@ -245,6 +251,30 @@ public:
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
OB_INLINE const ObString get_tenant_name() const
|
||||
{
|
||||
ObString tenant_name = ObString::make_empty_string();
|
||||
if (OB_NOT_NULL(sess_node_val_) && OB_NOT_NULL(sess_node_val_->owner_node_)) {
|
||||
tenant_name = sess_node_val_->owner_node_->get_tenant_name();
|
||||
}
|
||||
return tenant_name;
|
||||
}
|
||||
OB_INLINE const ObString get_database_name() const
|
||||
{
|
||||
ObString database_name = ObString::make_empty_string();
|
||||
if (OB_NOT_NULL(sess_node_val_) && OB_NOT_NULL(sess_node_val_->owner_node_)) {
|
||||
database_name = sess_node_val_->owner_node_->get_database_name();
|
||||
}
|
||||
return database_name;
|
||||
}
|
||||
OB_INLINE const ObString get_user_name() const
|
||||
{
|
||||
ObString user_name = ObString::make_empty_string();
|
||||
if (OB_NOT_NULL(sess_node_val_) && OB_NOT_NULL(sess_node_val_->owner_node_)) {
|
||||
user_name = sess_node_val_->owner_node_->get_user_name();
|
||||
}
|
||||
return user_name;
|
||||
}
|
||||
private:
|
||||
ObTableApiSessNodeVal *sess_node_val_;
|
||||
};
|
||||
|
@ -50,6 +50,7 @@ public:
|
||||
}
|
||||
private:
|
||||
void create_credential(uint64_t user_id, ObTableApiCredential *&cred);
|
||||
int create_and_add_node(ObTableApiCredential &cred);
|
||||
private:
|
||||
ObArenaAllocator allocator_;
|
||||
ObTableApiCredential *mock_cred_;
|
||||
@ -70,6 +71,43 @@ void TestTableSessPool::create_credential(uint64_t user_id, ObTableApiCredential
|
||||
cred->hash(cred->hash_val_);
|
||||
}
|
||||
|
||||
int TestTableSessPool::create_and_add_node(ObTableApiCredential &cred)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObTableApiSessNode *tmp_node = nullptr;
|
||||
void *buf = nullptr;
|
||||
|
||||
if (OB_FAIL(TABLEAPI_SESS_POOL_MGR->create_session_pool_safe())) {
|
||||
} else if (OB_ISNULL(buf = allocator_.alloc(sizeof(ObTableApiSessNode)))) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
} else {
|
||||
tmp_node = new (buf) ObTableApiSessNode(cred);
|
||||
MemoryContext tmp_mem_ctx = nullptr;
|
||||
ContextParam param;
|
||||
param.set_mem_attr(MTL_ID(), "TbSessNod", ObCtxIds::DEFAULT_CTX_ID)
|
||||
.set_properties(lib::ALLOC_THREAD_SAFE);
|
||||
if (OB_FAIL(ROOT_CONTEXT->CREATE_CONTEXT(tmp_mem_ctx, param))) {
|
||||
} else if (OB_ISNULL(tmp_mem_ctx)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
} else {
|
||||
tmp_node->mem_ctx_ = tmp_mem_ctx;
|
||||
tmp_node->last_active_ts_ = ObTimeUtility::fast_current_time();
|
||||
tmp_node->is_inited_ = true;
|
||||
if (OB_FAIL(TABLEAPI_SESS_POOL_MGR->pool_->key_node_map_.set_refactored(cred.hash_val_, tmp_node))) {
|
||||
if (OB_HASH_EXIST != ret) {
|
||||
} else {
|
||||
ret = OB_SUCCESS; // replace error code
|
||||
}
|
||||
tmp_node->~ObTableApiSessNode();
|
||||
allocator_.free(tmp_node);
|
||||
tmp_node = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
TEST_F(TestTableSessPool, test_mgr_init)
|
||||
{
|
||||
ObTableApiSessPoolMgr mgr;
|
||||
@ -119,7 +157,7 @@ TEST_F(TestTableSessPool, mgr_get_session)
|
||||
ObTableApiSessPoolMgr *mgr = TABLEAPI_SESS_POOL_MGR;
|
||||
|
||||
// first time will create a new node
|
||||
ASSERT_EQ(OB_SUCCESS, mgr->update_sess(*mock_cred_));
|
||||
ASSERT_EQ(OB_SUCCESS, create_and_add_node(*mock_cred_));
|
||||
ASSERT_NE(nullptr, mgr->pool_);
|
||||
ASSERT_TRUE(mgr->pool_->is_inited_);
|
||||
ASSERT_EQ(1, mgr->pool_->key_node_map_.size());
|
||||
@ -149,56 +187,11 @@ TEST_F(TestTableSessPool, mgr_get_session)
|
||||
mgr->destroy();
|
||||
}
|
||||
|
||||
TEST_F(TestTableSessPool, mgr_update_session)
|
||||
{
|
||||
ASSERT_EQ(OB_SYS_TENANT_ID, MTL_ID());
|
||||
ObTableApiSessPoolMgr *mgr = TABLEAPI_SESS_POOL_MGR;
|
||||
// first time will create a new node
|
||||
ASSERT_EQ(OB_SUCCESS, mgr->update_sess(*mock_cred_));
|
||||
ASSERT_NE(nullptr, mgr->pool_);
|
||||
ASSERT_TRUE(mgr->pool_->is_inited_);
|
||||
ASSERT_EQ(1, mgr->pool_->key_node_map_.size());
|
||||
ASSERT_EQ(0, mgr->pool_->retired_nodes_.size_);
|
||||
ObTableApiSessNode *node;
|
||||
ASSERT_EQ(OB_SUCCESS, mgr->pool_->get_sess_node(mock_cred_->hash_val_, node));
|
||||
ASSERT_NE(nullptr, node);
|
||||
ASSERT_TRUE(node->sess_lists_.free_list_.is_empty());
|
||||
ASSERT_TRUE(node->sess_lists_.used_list_.is_empty());
|
||||
ASSERT_NE(0, node->last_active_ts_);
|
||||
// second time will do replace
|
||||
ObTableApiCredential *new_cred = nullptr;
|
||||
create_credential(1, new_cred);
|
||||
ASSERT_NE(nullptr, new_cred);
|
||||
ASSERT_EQ(OB_SUCCESS, mgr->update_sess(*new_cred));
|
||||
ASSERT_NE(nullptr, mgr->pool_);
|
||||
ASSERT_TRUE(mgr->pool_->is_inited_);
|
||||
ASSERT_EQ(1, mgr->pool_->key_node_map_.size());
|
||||
ASSERT_EQ(0, mgr->pool_->retired_nodes_.size_);
|
||||
ASSERT_EQ(OB_SUCCESS, mgr->pool_->get_sess_node(new_cred->hash_val_, node));
|
||||
ASSERT_NE(nullptr, node);
|
||||
ASSERT_TRUE(node->sess_lists_.free_list_.is_empty());
|
||||
ASSERT_TRUE(node->sess_lists_.used_list_.is_empty());
|
||||
ASSERT_NE(0, node->last_active_ts_);
|
||||
// update another key is 2 node.
|
||||
create_credential(2, new_cred);
|
||||
ASSERT_NE(nullptr, new_cred);
|
||||
ASSERT_EQ(OB_SUCCESS, mgr->update_sess(*new_cred));
|
||||
ASSERT_NE(nullptr, mgr->pool_);
|
||||
ASSERT_TRUE(mgr->pool_->is_inited_);
|
||||
ASSERT_EQ(2, mgr->pool_->key_node_map_.size());
|
||||
ASSERT_EQ(0, mgr->pool_->retired_nodes_.size_);
|
||||
ASSERT_EQ(OB_SUCCESS, mgr->pool_->get_sess_node(new_cred->hash_val_, node));
|
||||
ASSERT_NE(nullptr, node);
|
||||
ASSERT_TRUE(node->sess_lists_.free_list_.is_empty());
|
||||
ASSERT_TRUE(node->sess_lists_.used_list_.is_empty());
|
||||
ASSERT_NE(0, node->last_active_ts_);
|
||||
}
|
||||
|
||||
TEST_F(TestTableSessPool, mgr_destroy)
|
||||
{
|
||||
ASSERT_EQ(OB_SYS_TENANT_ID, MTL_ID());
|
||||
ObTableApiSessPoolMgr *mgr = TABLEAPI_SESS_POOL_MGR;
|
||||
ASSERT_EQ(OB_SUCCESS, mgr->update_sess(*mock_cred_));
|
||||
ASSERT_EQ(OB_SUCCESS, create_and_add_node(*mock_cred_));
|
||||
ASSERT_NE(nullptr, mgr->pool_);
|
||||
ObTableApiSessNode *node;
|
||||
ASSERT_EQ(OB_SUCCESS, mgr->pool_->get_sess_node(mock_cred_->hash_val_, node));
|
||||
@ -213,7 +206,7 @@ TEST_F(TestTableSessPool, mgr_sess_recycle)
|
||||
{
|
||||
ASSERT_EQ(OB_SYS_TENANT_ID, MTL_ID());
|
||||
ObTableApiSessPoolMgr *mgr = TABLEAPI_SESS_POOL_MGR;
|
||||
ASSERT_EQ(OB_SUCCESS, mgr->update_sess(*mock_cred_));
|
||||
ASSERT_EQ(OB_SUCCESS, create_and_add_node(*mock_cred_));
|
||||
ASSERT_NE(nullptr, mgr->pool_);
|
||||
|
||||
// add mock val to node
|
||||
|
Loading…
x
Reference in New Issue
Block a user