提交 518fd355 编写于 作者: L ls0 提交者: LINGuanRen

fix alloc local session with same sid leads memory damage

上级 21163c4f
......@@ -109,10 +109,13 @@ int ObDesExecContext::create_my_session(uint64_t tenant_id)
LOG_ERROR("no more memory to create sql session info");
} else {
local_session = new (local_session) ObSQLSessionInfo();
uint32_t tmp_sid = 123456789;
uint32_t tmp_sid = 0;
uint64_t tmp_proxy_sessid = proxy_sid;
uint32_t tmp_version = 0;
uint64_t tmp_proxy_sessid = 1234567890;
if (OB_FAIL(local_session->init(tmp_version, tmp_sid, tmp_proxy_sessid, NULL))) {
bool session_in_mgr = false;
if (OB_FAIL(GCTX.session_mgr_->create_sessid(tmp_sid, session_in_mgr))) {
LOG_WARN("failed to mock session id", K(ret));
} else if (OB_FAIL(local_session->init(tmp_version, tmp_sid, tmp_proxy_sessid, NULL))) {
LOG_WARN("my session init failed", K(ret));
local_session->~ObSQLSessionInfo();
} else {
......
......@@ -282,11 +282,11 @@ int ObSQLSessionMgr::inc_session_ref(const ObSQLSessionInfo* my_session)
// |Mask| Server Id | Local Seq |
// +----+------------------------------+--------------------------------+
//
// MASK: 1 means session_id is generated by observer, 0 means by proxy.
// MASK: 1 means session_id is generated by observer, 0 means in_mgr = false.
// Server Id: generated by root server, and unique in cluster.
// Local Seq: max session number in an observer.
//
int ObSQLSessionMgr::create_sessid(uint32_t& sessid)
int ObSQLSessionMgr::create_sessid(uint32_t &sessid, bool in_mgr)
{
int ret = OB_SUCCESS;
int tmp_ret = OB_SUCCESS;
......@@ -297,6 +297,9 @@ int ObSQLSessionMgr::create_sessid(uint32_t& sessid)
if (server_id > MAX_SERVER_ID) {
ret = OB_ERR_UNEXPECTED;
LOG_ERROR("server id maybe invalid", K(ret), K(server_id));
} else if (!in_mgr) {
sessid = (GETTID() | LOCAL_SESSID_TAG);
sessid |= static_cast<uint32_t>(server_id << LOCAL_SEQ_LEN); // set observer
} else if (0 == server_id) {
local_seq = (ATOMIC_FAA(&abnormal_seq, 1) & MAX_LOCAL_SEQ);
uint32_t max_local_seq = MAX_LOCAL_SEQ;
......@@ -307,7 +310,7 @@ int ObSQLSessionMgr::create_sessid(uint32_t& sessid)
} else { /*do nothing*/
}
if (OB_SUCC(ret)) {
if (OB_SUCC(ret) && in_mgr) {
sessid = local_seq | SERVER_SESSID_TAG; // set observer sessid mark
sessid |= static_cast<uint32_t>(server_id << LOCAL_SEQ_LEN); // set observer
// high bit is reserved for server id
......
......@@ -47,6 +47,7 @@ public:
static const uint32_t NON_DURABLE_VALUE = 0;
static const uint32_t MAX_VERSION = UINT8_MAX; // 255
static const uint32_t SERVER_SESSID_TAG = 1ULL << 31;
static const uint32_t LOCAL_SESSID_TAG = 0; // used for sessions overflow
typedef SessionInfoKey Key;
explicit ObSQLSessionMgr(storage::ObPartitionService* partition_service)
: // null_callback_(),
......@@ -121,11 +122,11 @@ public:
}
static int is_need_clear_sessid(const observer::ObSMConnection* conn, bool& is_need);
int fetch_first_sessid();
int create_sessid(uint32_t& sessid);
// in_mgr = false means fail back to local session allocating, avoid remote/distribute executing fail
int create_sessid(uint32_t& sessid, bool in_mgr = true);
int mark_sessid_used(uint32_t sess_id);
int mark_sessid_unused(uint32_t sess_id);
// inline ObNullEndTransCallback &get_null_callback() { return null_callback_; }
private:
int create_session_by_version(
uint64_t tenant_id, uint32_t sessid, uint64_t proxy_sessid, ObSQLSessionInfo*& sess_info, uint32_t& out_version);
int get_avaiable_local_seq(uint32_t& local_seq);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册