Add a db_id field to the virtual table related to automatic memory management.

This commit is contained in:
obdev
2024-02-27 06:48:37 +00:00
committed by ob-robot
parent e950dd7145
commit 0715f57e39
16 changed files with 124 additions and 13 deletions

View File

@ -66,6 +66,11 @@ uint64_t ObSqlWorkAreaProfile::get_session_id()
return session_id_;
}
uint64_t ObSqlWorkAreaProfile::get_db_id()
{
return db_id_;
}
int ObSqlWorkAreaProfile::set_exec_info(ObExecContext &exec_ctx)
{
int ret = OB_SUCCESS;
@ -82,6 +87,10 @@ int ObSqlWorkAreaProfile::set_exec_info(ObExecContext &exec_ctx)
sql_id_[OB_MAX_SQL_ID_LENGTH] = '\0';
}
}
ObSQLSessionInfo *sql_session = exec_ctx.get_my_session();
if (OB_NOT_NULL(sql_session)) {
db_id_ = sql_session->get_database_id();
}
return ret;
}
@ -737,6 +746,7 @@ int ObTenantSqlMemoryManager::new_and_fill_workarea_stat(
wa_stat->workarea_key_.set_sql_id(profile.get_sql_id());
wa_stat->workarea_key_.set_plan_id(profile.get_plan_id());
wa_stat->workarea_key_.set_operator_id(profile.get_operator_id());
wa_stat->workarea_key_.set_database_id(profile.get_db_id());
wa_stat->op_type_ = profile.get_operator_type();
if (OB_FAIL(fill_workarea_stat(*wa_stat, profile))) {
LOG_WARN("failed to fill workarea stat", K(ret));
@ -767,7 +777,8 @@ int ObTenantSqlMemoryManager::collect_workarea_stat(ObSqlWorkAreaProfile &profil
if (profile.has_exec_ctx()) {
ObSqlWorkAreaStat::WorkareaKey workarea_key(
profile.get_plan_id(),
profile.get_operator_id());
profile.get_operator_id(),
profile.get_db_id());
workarea_key.set_sql_id(profile.get_sql_id());
bool need_insert = false;
if (OB_FAIL(try_fill_workarea_stat(workarea_key, profile, need_insert))) {
@ -1320,6 +1331,7 @@ int ObTenantSqlMemoryManager::get_all_active_workarea(
profile_info.sql_exec_id_ = profile->get_exec_id();
profile_info.set_sql_id(profile->get_sql_id());
profile_info.session_id_ = profile->get_session_id();
profile_info.database_id_ = profile->get_db_id();
if (OB_FAIL(wa_actives.push_back(profile_info))) {
LOG_WARN("failed to push back profile", K(ret));
}

View File

@ -39,7 +39,7 @@ public:
random_id_(0), type_(type), op_type_(PHY_INVALID), op_id_(UINT64_MAX), exec_ctx_(nullptr),
min_size_(0), row_count_(0), input_size_(0), bucket_size_(0),
chunk_size_(0), cache_size_(-1), one_pass_size_(0), expect_size_(OB_INVALID_ID),
global_bound_size_(INT64_MAX), dop_(-1), plan_id_(-1), exec_id_(-1), sql_id_(),
global_bound_size_(INT64_MAX), dop_(-1), plan_id_(-1), exec_id_(-1), sql_id_(), db_id_(-1),
session_id_(-1), max_bound_(INT64_MAX), delta_size_(0), data_size_(0),
max_mem_used_(0), mem_used_(0),
pre_mem_used_(0), dumped_size_(0), data_ratio_(0.5), active_time_(0), number_pass_(0),
@ -145,6 +145,7 @@ public:
uint64_t get_exec_id();
const char* get_sql_id();
uint64_t get_session_id();
uint64_t get_db_id();
OB_INLINE bool need_profiled()
{
@ -180,6 +181,7 @@ private:
int64_t plan_id_;
int64_t exec_id_;
char sql_id_[common::OB_MAX_SQL_ID_LENGTH + 1];
uint64_t db_id_;
int64_t session_id_;
// 取 min(cache_size, global_bound_size)
// sort场景,在global_bound_size比较大情况下,sort理论上有data和extra内存,data应该是one-pass size
@ -219,14 +221,14 @@ public:
active_avg_time_(0), max_temp_size_(0), last_temp_size_(0), is_auto_policy_(false)
{}
public:
// key: (sql_id, plan_id, operator_id) 可以确认相同执行的统计
// key: (sql_id, plan_id, operator_id, database_id) 可以确认相同执行的统计
struct WorkareaKey {
WorkareaKey(uint64_t plan_id, uint64_t operator_id) :
plan_id_(plan_id), operator_id_(operator_id)
WorkareaKey(uint64_t plan_id, uint64_t operator_id, uint64_t database_id) :
plan_id_(plan_id), operator_id_(operator_id), database_id_(database_id)
{
sql_id_[0] = '\0';
}
WorkareaKey() : plan_id_(UINT64_MAX), operator_id_(UINT64_MAX)
WorkareaKey() : plan_id_(UINT64_MAX), operator_id_(UINT64_MAX), database_id_(UINT64_MAX)
{
sql_id_[0] = '\0';
}
@ -240,12 +242,14 @@ public:
}
void set_plan_id(uint64_t plan_id) { plan_id_ = plan_id; }
void set_operator_id(uint64_t op_id) { operator_id_ = op_id; }
void set_database_id(uint64_t database_id) { database_id_ = database_id; }
void assign(const WorkareaKey &other)
{
strncpy(sql_id_, other.sql_id_, common::OB_MAX_SQL_ID_LENGTH + 1);
plan_id_ = other.plan_id_;
operator_id_ = other.operator_id_;
database_id_ = other.database_id_;
}
WorkareaKey &operator=(const WorkareaKey &other)
{
@ -255,6 +259,7 @@ public:
int64_t hash() const
{
uint64_t val = common::murmurhash(&plan_id_, sizeof(plan_id_), 0);
val = common::murmurhash(&database_id_, sizeof(database_id_), val);
return common::murmurhash(&operator_id_, sizeof(operator_id_), val);
}
int hash(uint64_t &hash_val) const
@ -266,13 +271,15 @@ public:
bool operator==(const WorkareaKey &other) const
{
return plan_id_ == other.plan_id_ && operator_id_ == other.operator_id_
&& 0 == MEMCMP(sql_id_, other.sql_id_, strlen(sql_id_));
&& 0 == MEMCMP(sql_id_, other.sql_id_, strlen(sql_id_))
&& database_id_ == other.database_id_;
}
TO_STRING_KV(K_(sql_id), K_(plan_id), K_(operator_id));
TO_STRING_KV(K_(sql_id), K_(plan_id), K_(operator_id), K_(database_id));
public:
char sql_id_[common::OB_MAX_SQL_ID_LENGTH + 1]; // sql id
uint64_t plan_id_; // plan id
uint64_t operator_id_; // operator id
uint64_t database_id_; // database id
}; // end WorkareaKey
OB_INLINE void set_seqno(int64_t seqno) { seqno_ = seqno; }
@ -281,6 +288,7 @@ public:
OB_INLINE const char* get_sql_id() const { return workarea_key_.sql_id_; }
OB_INLINE uint64_t get_plan_id() const { return workarea_key_.plan_id_; }
OB_INLINE uint64_t get_operator_id() const { return workarea_key_.operator_id_; }
OB_INLINE uint64_t get_database_id() const { return workarea_key_.database_id_; }
OB_INLINE ObPhyOperatorType get_op_type() const { return op_type_; }
OB_INLINE int64_t get_est_cache_size() const { return est_cache_size_; }
OB_INLINE int64_t get_est_one_pass_size() const { return est_one_pass_size_; }
@ -331,7 +339,8 @@ class ObSqlWorkareaProfileInfo
{
public:
ObSqlWorkareaProfileInfo() :
profile_(ObSqlWorkAreaType::MAX_TYPE), plan_id_(0), sql_exec_id_(0), session_id_(0)
profile_(ObSqlWorkAreaType::MAX_TYPE), plan_id_(0),
sql_exec_id_(0), session_id_(0), database_id_(0)
{
sql_id_[0] = '\0';
}
@ -343,6 +352,7 @@ public:
plan_id_ = other.plan_id_;
sql_exec_id_ = other.sql_exec_id_;
session_id_ = other.session_id_;
database_id_ = other.database_id_;
}
ObSqlWorkareaProfileInfo &operator=(const ObSqlWorkareaProfileInfo &other)
@ -366,6 +376,7 @@ public:
uint64_t plan_id_;
uint64_t sql_exec_id_;
uint64_t session_id_;
uint64_t database_id_;
};
class ObSqlWorkAreaIntervalStat