patch 4.0
This commit is contained in:
@ -23,18 +23,22 @@ using namespace oceanbase;
|
||||
using namespace sql;
|
||||
using namespace observer;
|
||||
using namespace common;
|
||||
namespace oceanbase {
|
||||
namespace observer {
|
||||
struct ObGetAllOperatorStatOp {
|
||||
explicit ObGetAllOperatorStatOp(common::ObIArray<ObOperatorStat>* key_array) : key_array_(key_array)
|
||||
{}
|
||||
ObGetAllOperatorStatOp() : key_array_(NULL)
|
||||
{}
|
||||
void reset()
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace observer
|
||||
{
|
||||
struct ObGetAllOperatorStatOp
|
||||
{
|
||||
explicit ObGetAllOperatorStatOp(common::ObIArray<ObOperatorStat> *key_array)
|
||||
: key_array_(key_array)
|
||||
{
|
||||
key_array_ = NULL;
|
||||
}
|
||||
int set_key_array(common::ObIArray<ObOperatorStat>* key_array)
|
||||
ObGetAllOperatorStatOp()
|
||||
: key_array_(NULL)
|
||||
{
|
||||
}
|
||||
void reset() { key_array_ = NULL; }
|
||||
int set_key_array(common::ObIArray<ObOperatorStat> *key_array)
|
||||
{
|
||||
int ret = common::OB_SUCCESS;
|
||||
if (NULL == key_array) {
|
||||
@ -45,46 +49,45 @@ struct ObGetAllOperatorStatOp {
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
int operator()(common::hash::HashMapPair<ObCacheObjID, ObCacheObject*>& entry)
|
||||
int operator()(common::hash::HashMapPair<ObCacheObjID, ObILibCacheObject *> &entry)
|
||||
{
|
||||
int ret = common::OB_SUCCESS;
|
||||
if (NULL == key_array_) {
|
||||
ret = common::OB_NOT_INIT;
|
||||
SERVER_LOG(WARN, "invalid argument", K(ret));
|
||||
} else if (OB_ISNULL(entry.second)) {
|
||||
ret = common::OB_ERR_UNEXPECTED;
|
||||
SERVER_LOG(WARN, "entry value is nullptr", K(ret));
|
||||
} else {
|
||||
ObOperatorStat stat;
|
||||
ObPhysicalPlan* plan = NULL;
|
||||
if (entry.second->is_sql_crsr()) {
|
||||
if (OB_ISNULL(plan = dynamic_cast<ObPhysicalPlan*>(entry.second))) {
|
||||
ObPhysicalPlan *plan = NULL;
|
||||
if (ObLibCacheNameSpace::NS_CRSR == entry.second->get_ns()) {
|
||||
if (OB_ISNULL(plan = dynamic_cast<ObPhysicalPlan *>(entry.second))) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
SERVER_LOG(WARN, "unexpected null plan", K(ret), K(plan));
|
||||
}
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < plan->op_stats_.count(); i++) {
|
||||
if (OB_FAIL(plan->op_stats_.get_op_stat_accumulation(plan, i, stat))) {
|
||||
for (int64_t i = 0; i < plan->op_stats_.count() && OB_SUCC(ret); i++) {
|
||||
if (OB_FAIL(plan->op_stats_.get_op_stat_accumulation(plan,
|
||||
i, stat))) {
|
||||
SERVER_LOG(WARN, "fail to get op stat accumulation", K(ret), K(i));
|
||||
} else if (OB_FAIL(key_array_->push_back(stat))) {
|
||||
SERVER_LOG(WARN, "fail to push back plan_id", K(ret));
|
||||
}
|
||||
} // for end
|
||||
} // for end
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
common::ObIArray<ObOperatorStat>* key_array_;
|
||||
common::ObIArray<ObOperatorStat> *key_array_;
|
||||
};
|
||||
|
||||
ObVirtualSqlPlanStatistics::ObVirtualSqlPlanStatistics()
|
||||
: pcm_(NULL),
|
||||
tenant_id_array_(),
|
||||
operator_stat_array_(),
|
||||
tenant_id_(0),
|
||||
tenant_id_array_idx_(0),
|
||||
operator_stat_array_idx_(OB_INVALID_ID)
|
||||
{}
|
||||
:pcm_(NULL),
|
||||
tenant_id_array_(),
|
||||
operator_stat_array_(),
|
||||
tenant_id_(0),
|
||||
tenant_id_array_idx_(0),
|
||||
operator_stat_array_idx_(OB_INVALID_ID)
|
||||
{
|
||||
}
|
||||
|
||||
ObVirtualSqlPlanStatistics::~ObVirtualSqlPlanStatistics()
|
||||
{
|
||||
@ -110,23 +113,23 @@ int ObVirtualSqlPlanStatistics::inner_open()
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
SERVER_LOG(WARN, "invalid key range", K(ret), K(key_ranges_.count()));
|
||||
} else {
|
||||
ObNewRange& range = key_ranges_.at(0);
|
||||
if (OB_UNLIKELY(range.get_start_key().get_obj_cnt() != 5 || range.get_end_key().get_obj_cnt() != 5)) {
|
||||
ObNewRange &range = key_ranges_.at(0);
|
||||
if (OB_UNLIKELY(range.get_start_key().get_obj_cnt() != 5
|
||||
|| range.get_end_key().get_obj_cnt() != 5)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
SERVER_LOG(WARN,
|
||||
"unexpected # of rowkey columns",
|
||||
K(ret),
|
||||
"size of start key",
|
||||
range.get_start_key().get_obj_cnt(),
|
||||
"size of end key",
|
||||
range.get_end_key().get_obj_cnt());
|
||||
SERVER_LOG(WARN, "unexpected # of rowkey columns",
|
||||
K(ret),
|
||||
"size of start key", range.get_start_key().get_obj_cnt(),
|
||||
"size of end key", range.get_end_key().get_obj_cnt());
|
||||
} else {
|
||||
ObObj tenant_id_low = range.get_start_key().get_obj_ptr()[0];
|
||||
ObObj tenant_id_high = range.get_end_key().get_obj_ptr()[0];
|
||||
if (tenant_id_low.is_min_value() && tenant_id_high.is_max_value()) {
|
||||
if (tenant_id_low.is_min_value()
|
||||
&& tenant_id_high.is_max_value()) {
|
||||
start_tenant_id = OB_SYS_TENANT_ID;
|
||||
end_tenant_id = OB_SYS_TENANT_ID;
|
||||
} else if (tenant_id_low.get_type() != ObIntType || tenant_id_high.get_type() != ObIntType) {
|
||||
} else if (tenant_id_low.get_type() != ObIntType
|
||||
|| tenant_id_high.get_type() != ObIntType) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
SERVER_LOG(WARN, "invalid tenant id", K(ret), K(tenant_id_low), K(tenant_id_high));
|
||||
} else {
|
||||
@ -134,13 +137,10 @@ int ObVirtualSqlPlanStatistics::inner_open()
|
||||
end_tenant_id = tenant_id_high.get_int();
|
||||
if (start_tenant_id != end_tenant_id) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
SERVER_LOG(WARN,
|
||||
"invalid tenant id range, can only search one tenant",
|
||||
K(ret),
|
||||
K(start_tenant_id),
|
||||
K(end_tenant_id));
|
||||
SERVER_LOG(WARN, "invalid tenant id range, can only search one tenant",
|
||||
K(ret), K(start_tenant_id), K(end_tenant_id));
|
||||
} else if (OB_SYS_TENANT_ID == start_tenant_id) {
|
||||
// sys tenamt can query any plan cache
|
||||
//查询租户为系统租户,可以查询所有的plan cache
|
||||
if (OB_FAIL(get_all_tenant_id())) {
|
||||
SERVER_LOG(WARN, "fail to get all tenant id", K(ret));
|
||||
}
|
||||
@ -167,13 +167,13 @@ int ObVirtualSqlPlanStatistics::get_all_tenant_id()
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObVirtualSqlPlanStatistics::get_row_from_specified_tenant(uint64_t tenant_id, bool& is_end)
|
||||
int ObVirtualSqlPlanStatistics::get_row_from_specified_tenant(uint64_t tenant_id, bool &is_end)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
// !!! Must have an ObReqTimeGuard before any plan cache references
|
||||
// !!! 引用plan cache资源之前必须加ObReqTimeGuard
|
||||
ObReqTimeGuard req_timeinfo_guard;
|
||||
is_end = false;
|
||||
sql::ObPlanCache* plan_cache = NULL;
|
||||
sql::ObPlanCache *plan_cache = NULL;
|
||||
if (OB_INVALID_ID == static_cast<uint64_t>(operator_stat_array_idx_)) {
|
||||
if (OB_UNLIKELY(NULL == pcm_)) {
|
||||
ret = OB_NOT_INIT;
|
||||
@ -182,9 +182,8 @@ int ObVirtualSqlPlanStatistics::get_row_from_specified_tenant(uint64_t tenant_id
|
||||
operator_stat_array_idx_ = 0;
|
||||
SERVER_LOG(WARN, "plan cache is null", K(ret));
|
||||
} else {
|
||||
ObPlanCache::PlanStatMap& plan_stats = plan_cache->get_plan_stat_map();
|
||||
ObGetAllOperatorStatOp operator_stat_op(&operator_stat_array_);
|
||||
if (OB_FAIL(plan_stats.foreach_refactored(operator_stat_op))) {
|
||||
if (OB_FAIL(plan_cache->foreach_cache_obj(operator_stat_op))) {
|
||||
SERVER_LOG(WARN, "fail to traverse id2stat_map");
|
||||
} else {
|
||||
operator_stat_array_idx_ = 0;
|
||||
@ -203,32 +202,35 @@ int ObVirtualSqlPlanStatistics::get_row_from_specified_tenant(uint64_t tenant_id
|
||||
operator_stat_array_.reset();
|
||||
} else {
|
||||
is_end = false;
|
||||
ObOperatorStat& opstat = operator_stat_array_.at(operator_stat_array_idx_);
|
||||
ObOperatorStat &opstat = operator_stat_array_.at(operator_stat_array_idx_);
|
||||
++operator_stat_array_idx_;
|
||||
if (OB_FAIL(fill_cells(opstat))) {
|
||||
SERVER_LOG(WARN, "fail to fill cells", K(opstat), K(tenant_id));
|
||||
}
|
||||
}
|
||||
}
|
||||
SERVER_LOG(DEBUG, "add plan from a tenant", K(ret), K(tenant_id));
|
||||
SERVER_LOG(DEBUG,
|
||||
"add plan from a tenant",
|
||||
K(ret),
|
||||
K(tenant_id));
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObVirtualSqlPlanStatistics::fill_cells(const ObOperatorStat& pstat)
|
||||
int ObVirtualSqlPlanStatistics::fill_cells(const ObOperatorStat &pstat)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
const int64_t col_count = output_column_ids_.count();
|
||||
ObObj* cells = cur_row_.cells_;
|
||||
ObObj *cells = cur_row_.cells_;
|
||||
ObString ipstr;
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < col_count; ++i) {
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < col_count; ++i) {
|
||||
uint64_t col_id = output_column_ids_.at(i);
|
||||
switch (col_id) {
|
||||
// tenant id
|
||||
switch(col_id) {
|
||||
//tenant id
|
||||
case TENANT_ID: {
|
||||
cells[i].set_int(tenant_id_array_.at(tenant_id_array_idx_));
|
||||
break;
|
||||
}
|
||||
// ip
|
||||
//ip
|
||||
case SVR_IP: {
|
||||
// ip
|
||||
ipstr.reset();
|
||||
@ -240,13 +242,13 @@ int ObVirtualSqlPlanStatistics::fill_cells(const ObOperatorStat& pstat)
|
||||
}
|
||||
break;
|
||||
}
|
||||
// port
|
||||
//port
|
||||
case SVR_PORT: {
|
||||
// svr_port
|
||||
cells[i].set_int(GCTX.self_addr_.get_port());
|
||||
cells[i].set_int(GCTX.self_addr().get_port());
|
||||
break;
|
||||
}
|
||||
// plan id
|
||||
//plan id
|
||||
case PLAN_ID: {
|
||||
cells[i].set_int(pstat.plan_id_);
|
||||
break;
|
||||
@ -299,15 +301,20 @@ int ObVirtualSqlPlanStatistics::fill_cells(const ObOperatorStat& pstat)
|
||||
}
|
||||
default: {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
SERVER_LOG(WARN, "invalid column id", K(ret), K(i), K(output_column_ids_), K(col_id));
|
||||
SERVER_LOG(WARN,
|
||||
"invalid column id",
|
||||
K(ret),
|
||||
K(i),
|
||||
K(output_column_ids_),
|
||||
K(col_id));
|
||||
break;
|
||||
}
|
||||
}
|
||||
} // end for
|
||||
} // end for
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObVirtualSqlPlanStatistics::inner_get_next_row(common::ObNewRow*& row)
|
||||
int ObVirtualSqlPlanStatistics::inner_get_next_row(common::ObNewRow *&row)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
bool is_sub_end = false;
|
||||
@ -320,24 +327,26 @@ int ObVirtualSqlPlanStatistics::inner_get_next_row(common::ObNewRow*& row)
|
||||
ret = OB_ITER_END;
|
||||
tenant_id_array_idx_ = 0;
|
||||
} else {
|
||||
if (OB_FAIL(get_row_from_specified_tenant(tenant_id_array_.at(tenant_id_array_idx_), is_sub_end))) {
|
||||
if (OB_FAIL(get_row_from_specified_tenant(tenant_id_array_.at(tenant_id_array_idx_),
|
||||
is_sub_end))) {
|
||||
SERVER_LOG(WARN,
|
||||
"fail to insert plan by tenant id",
|
||||
K(ret),
|
||||
"tenant id",
|
||||
tenant_id_array_.at(tenant_id_array_idx_),
|
||||
K(tenant_id_array_idx_));
|
||||
"fail to insert plan by tenant id",
|
||||
K(ret),
|
||||
"tenant id",
|
||||
tenant_id_array_.at(tenant_id_array_idx_),
|
||||
K(tenant_id_array_idx_));
|
||||
} else {
|
||||
if (is_sub_end) {
|
||||
++tenant_id_array_idx_;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (is_sub_end && OB_SUCCESS == ret);
|
||||
} while(is_sub_end && OB_SUCCESS == ret);
|
||||
if (OB_SUCC(ret)) {
|
||||
row = &cur_row_;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
} // end namespace observer
|
||||
} // end namespace oceanbase
|
||||
} //end namespace observer
|
||||
} //end namespace oceanbase
|
||||
|
||||
|
||||
Reference in New Issue
Block a user