add stats for xa
This commit is contained in:
@ -11,6 +11,7 @@
|
||||
*/
|
||||
|
||||
#include "ob_xa_ctx_mgr.h"
|
||||
#include "ob_xa_service.h"
|
||||
//#include "ob_xa_ctx.h"
|
||||
|
||||
namespace oceanbase
|
||||
@ -21,6 +22,16 @@ using namespace common;
|
||||
namespace transaction
|
||||
{
|
||||
|
||||
void XACtxAlloc::free_value(ObXACtx* ctx)
|
||||
{
|
||||
if (NULL != ctx) {
|
||||
ctx->destroy();
|
||||
op_reclaim_free(ctx);
|
||||
ctx = NULL;
|
||||
MTL(ObXAService *)->get_xa_statistics().dec_ctx_count();
|
||||
}
|
||||
}
|
||||
|
||||
int ObXACtxMgr::init()
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
@ -172,7 +183,7 @@ int ObXACtxMgr::get_xa_ctx_(const ObTransID &trans_id, bool &alloc, ObXACtx*& ct
|
||||
} else {
|
||||
ctx = tmp_ctx;
|
||||
inc_total_ctx_count();
|
||||
ObXAStatistics::get_instance().inc_ctx_count();
|
||||
MTL(ObXAService *)->get_xa_statistics().inc_ctx_count();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,15 +32,7 @@ class XACtxAlloc
|
||||
{
|
||||
public:
|
||||
ObXACtx* alloc_value() { return NULL; }
|
||||
void free_value(ObXACtx* ctx)
|
||||
{
|
||||
if (NULL != ctx) {
|
||||
ctx->destroy();
|
||||
op_reclaim_free(ctx);
|
||||
ctx = NULL;
|
||||
ObXAStatistics::get_instance().dec_ctx_count();
|
||||
}
|
||||
}
|
||||
void free_value(ObXACtx* ctx);
|
||||
XACtxHashNode* alloc_node(ObXACtx* node)
|
||||
{
|
||||
UNUSED(node);
|
||||
|
@ -108,8 +108,10 @@ int ObXAService::xa_start_for_tm_promotion(const int64_t flags,
|
||||
|
||||
if (OB_FAIL(ret)) {
|
||||
TRANS_LOG(WARN, "xa start for dblink promotion failed", K(ret), K(xid), K(flags));
|
||||
xa_statistics_.inc_failure_dblink_promotion();
|
||||
} else {
|
||||
TRANS_LOG(INFO, "xa start for dblink promtion", K(ret), K(xid), K(flags));
|
||||
xa_statistics_.inc_success_dblink_promotion();
|
||||
}
|
||||
|
||||
return ret;
|
||||
@ -240,8 +242,10 @@ int ObXAService::xa_start_for_tm(const int64_t flags,
|
||||
|
||||
if (OB_FAIL(ret)) {
|
||||
TRANS_LOG(WARN, "xa start for dblink failed", K(ret), K(xid), K(flags));
|
||||
xa_statistics_.inc_failure_dblink();
|
||||
} else {
|
||||
TRANS_LOG(INFO, "xa start for dblink", K(ret), K(xid), K(flags));
|
||||
xa_statistics_.inc_success_dblink();
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -426,12 +426,46 @@ void ObXATimeoutTask::runTimerTask()
|
||||
}
|
||||
}
|
||||
|
||||
void ObXAStatistics::reset()
|
||||
{
|
||||
ATOMIC_STORE(&total_standby_clearup_count_, 0);
|
||||
ATOMIC_STORE(&total_success_xa_start_, 0);
|
||||
ATOMIC_STORE(&total_failure_xa_start_, 0);
|
||||
ATOMIC_STORE(&total_success_xa_prepare_, 0);
|
||||
ATOMIC_STORE(&total_failure_xa_prepare_, 0);
|
||||
ATOMIC_STORE(&total_success_xa_1pc_commit_, 0);
|
||||
ATOMIC_STORE(&total_failure_xa_1pc_commit_, 0);
|
||||
ATOMIC_STORE(&total_success_xa_2pc_commit_, 0);
|
||||
ATOMIC_STORE(&total_failure_xa_2pc_commit_, 0);
|
||||
ATOMIC_STORE(&total_xa_rollback_, 0);
|
||||
ATOMIC_STORE(&total_success_dblink_promotion_, 0);
|
||||
ATOMIC_STORE(&total_failure_dblink_promotion_, 0);
|
||||
ATOMIC_STORE(&total_success_dblink_, 0);
|
||||
ATOMIC_STORE(&total_failure_dblink_, 0);
|
||||
}
|
||||
|
||||
void ObXAStatistics::print_statistics(int64_t cur_ts)
|
||||
{
|
||||
const int64_t last_stat_ts = ATOMIC_LOAD(&last_stat_ts_);
|
||||
if (cur_ts - last_stat_ts >= STAT_INTERVAL) {
|
||||
if (ATOMIC_BCAS(&last_stat_ts_, last_stat_ts, cur_ts)) {
|
||||
TRANS_LOG(INFO, "xa statistics", K(*this));
|
||||
TRANS_LOG(INFO, "xa statistics",
|
||||
"total_active_xa_ctx_count", ATOMIC_LOAD(&total_active_xa_ctx_count_),
|
||||
"total_standby_clearup_count", ATOMIC_LOAD(&total_standby_clearup_count_),
|
||||
"total_success_xa_start", ATOMIC_LOAD(&total_success_xa_start_),
|
||||
"total_failure_xa_start", ATOMIC_LOAD(&total_failure_xa_start_),
|
||||
"total_success_xa_prepare", ATOMIC_LOAD(&total_success_xa_prepare_),
|
||||
"total_failure_xa_prepare", ATOMIC_LOAD(&total_failure_xa_prepare_),
|
||||
"total_success_xa_1pc_commit", ATOMIC_LOAD(&total_success_xa_1pc_commit_),
|
||||
"total_failure_xa_1pc_commit", ATOMIC_LOAD(&total_failure_xa_1pc_commit_),
|
||||
"total_success_xa_2pc_commit", ATOMIC_LOAD(&total_success_xa_2pc_commit_),
|
||||
"total_failure_xa_2pc_commit", ATOMIC_LOAD(&total_failure_xa_2pc_commit_),
|
||||
"total_failure_xa_rollback", ATOMIC_LOAD(&total_xa_rollback_),
|
||||
"total_success_dblink_promotion", ATOMIC_LOAD(&total_success_dblink_promotion_),
|
||||
"total_failure_dblink_promotion", ATOMIC_LOAD(&total_failure_dblink_promotion_),
|
||||
"total_success_dblink", ATOMIC_LOAD(&total_success_dblink_),
|
||||
"total_failure_dblink", ATOMIC_LOAD(&total_failure_dblink_));
|
||||
reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -280,29 +280,57 @@ public:
|
||||
class ObXAStatistics
|
||||
{
|
||||
public:
|
||||
static ObXAStatistics &get_instance()
|
||||
ObXAStatistics() : last_stat_ts_(0), total_active_xa_ctx_count_(0)
|
||||
{
|
||||
static ObXAStatistics xa_statistics_;
|
||||
return xa_statistics_;
|
||||
reset();
|
||||
}
|
||||
~ObXAStatistics() {}
|
||||
public:
|
||||
void reset();
|
||||
void inc_ctx_count() { ATOMIC_INC(&total_active_xa_ctx_count_); }
|
||||
void dec_ctx_count() { ATOMIC_DEC(&total_active_xa_ctx_count_); }
|
||||
void inc_cleanup_tx_count() { ATOMIC_INC(&total_standby_clearup_count_); }
|
||||
void inc_success_xa_start() { ATOMIC_INC(&total_success_xa_start_); }
|
||||
void inc_failure_xa_start() { ATOMIC_INC(&total_failure_xa_start_); }
|
||||
void inc_success_xa_prepare() { ATOMIC_INC(&total_success_xa_prepare_); }
|
||||
void inc_failure_xa_prepare() { ATOMIC_INC(&total_failure_xa_prepare_); }
|
||||
void inc_success_xa_1pc_commit() { ATOMIC_INC(&total_success_xa_1pc_commit_); }
|
||||
void inc_failure_xa_1pc_commit() { ATOMIC_INC(&total_failure_xa_1pc_commit_); }
|
||||
void inc_success_xa_2pc_commit() { ATOMIC_INC(&total_success_xa_2pc_commit_); }
|
||||
void inc_failure_xa_2pc_commit() { ATOMIC_INC(&total_failure_xa_2pc_commit_); }
|
||||
void inc_xa_rollback() { ATOMIC_INC(&total_xa_rollback_); }
|
||||
void inc_success_dblink_promotion() { ATOMIC_INC(&total_success_dblink_promotion_); }
|
||||
void inc_failure_dblink_promotion() { ATOMIC_INC(&total_failure_dblink_promotion_); }
|
||||
void inc_success_dblink() { ATOMIC_INC(&total_success_dblink_); }
|
||||
void inc_failure_dblink() { ATOMIC_INC(&total_failure_dblink_); }
|
||||
void print_statistics(int64_t cur_ts);
|
||||
public:
|
||||
TO_STRING_KV(K_(total_active_xa_ctx_count), K_(total_standby_clearup_count));
|
||||
TO_STRING_KV(K_(total_active_xa_ctx_count), K_(total_standby_clearup_count),
|
||||
K_(total_success_xa_start), K_(total_failure_xa_start),
|
||||
K_(total_success_xa_prepare), K_(total_failure_xa_prepare),
|
||||
K_(total_success_xa_1pc_commit), K_(total_failure_xa_1pc_commit),
|
||||
K_(total_success_xa_2pc_commit), K_(total_failure_xa_2pc_commit),
|
||||
K_(total_xa_rollback),
|
||||
K_(total_success_dblink_promotion), K_(total_failure_dblink_promotion),
|
||||
K_(total_success_dblink), K_(total_failure_dblink));
|
||||
|
||||
private:
|
||||
ObXAStatistics() : last_stat_ts_(0), total_active_xa_ctx_count_(0),
|
||||
total_standby_clearup_count_(0) {}
|
||||
DISALLOW_COPY_AND_ASSIGN(ObXAStatistics);
|
||||
private:
|
||||
static const int64_t STAT_INTERVAL = 10 * 1000 * 1000;
|
||||
private:
|
||||
int64_t last_stat_ts_;
|
||||
int64_t total_active_xa_ctx_count_;
|
||||
int64_t total_standby_clearup_count_;
|
||||
int64_t total_success_xa_start_;
|
||||
int64_t total_failure_xa_start_;
|
||||
int64_t total_success_xa_prepare_;
|
||||
int64_t total_failure_xa_prepare_;
|
||||
int64_t total_success_xa_1pc_commit_;
|
||||
int64_t total_failure_xa_1pc_commit_;
|
||||
int64_t total_success_xa_2pc_commit_;
|
||||
int64_t total_failure_xa_2pc_commit_;
|
||||
int64_t total_xa_rollback_;
|
||||
int64_t total_success_dblink_promotion_;
|
||||
int64_t total_failure_dblink_promotion_;
|
||||
int64_t total_success_dblink_;
|
||||
int64_t total_failure_dblink_;
|
||||
};
|
||||
|
||||
}//transaction
|
||||
|
@ -308,7 +308,7 @@ int ObXAService::insert_record_for_standby(const uint64_t tenant_id,
|
||||
} else if (OB_FAIL(mysql_proxy->write(exec_tenant_id, sql.ptr(), affected_rows))) {
|
||||
TRANS_LOG(WARN, "execute insert record sql failed", KR(ret), K(exec_tenant_id), K(tenant_id));
|
||||
} else {
|
||||
ObXAStatistics::get_instance().inc_cleanup_tx_count();
|
||||
xa_statistics_.inc_cleanup_tx_count();
|
||||
TRANS_LOG(INFO, "execute insert record sql success", K(exec_tenant_id), K(tenant_id),
|
||||
K(sql), K(affected_rows));
|
||||
}
|
||||
@ -1006,8 +1006,10 @@ int ObXAService::xa_start(const ObXATransID &xid,
|
||||
tx_desc->set_xa_start_addr(GCONF.self_addr_);
|
||||
}
|
||||
if (OB_FAIL(ret)) {
|
||||
xa_statistics_.inc_failure_xa_start();
|
||||
TRANS_LOG(WARN, "xa start failed", K(ret), K(xid), K(flags), K(timeout_seconds));
|
||||
} else {
|
||||
xa_statistics_.inc_success_xa_start();
|
||||
TRANS_LOG(INFO, "xa start", K(ret), K(xid), K(flags), K(timeout_seconds), "tx_id", tx_desc->get_tx_id(), KPC(tx_desc));
|
||||
}
|
||||
|
||||
@ -1474,10 +1476,16 @@ int ObXAService::xa_commit(const ObXATransID &xid,
|
||||
if (ObXAFlag::is_tmnoflags(flags, ObXAReqType::XA_COMMIT)) {
|
||||
if (OB_FAIL(two_phase_xa_commit_(xid, timeout_us, request_id, has_tx_level_temp_table))) {
|
||||
TRANS_LOG(WARN, "two phase xa commit failed", K(ret), K(xid));
|
||||
xa_statistics_.inc_failure_xa_2pc_commit();
|
||||
} else {
|
||||
xa_statistics_.inc_success_xa_2pc_commit();
|
||||
}
|
||||
} else if (ObXAFlag::is_tmonephase(flags)) {
|
||||
if (OB_FAIL(one_phase_xa_commit_(xid, timeout_us, request_id, has_tx_level_temp_table))) {
|
||||
TRANS_LOG(WARN, "one phase xa commit failed", K(ret), K(xid));
|
||||
xa_statistics_.inc_failure_xa_1pc_commit();
|
||||
} else {
|
||||
xa_statistics_.inc_success_xa_1pc_commit();
|
||||
}
|
||||
} else {
|
||||
ret = OB_TRANS_XA_INVAL;
|
||||
@ -1632,6 +1640,7 @@ int ObXAService::xa_rollback(const ObXATransID &xid,
|
||||
}
|
||||
}
|
||||
TRANS_LOG(INFO, "xa rollback", K(ret), K(xid), K(xa_timeout_seconds));
|
||||
xa_statistics_.inc_xa_rollback();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -2154,6 +2163,11 @@ int ObXAService::xa_prepare(const ObXATransID &xid,
|
||||
ret = OB_TRANS_XA_RDONLY;
|
||||
}
|
||||
|
||||
if (OB_FAIL(ret)) {
|
||||
xa_statistics_.inc_failure_xa_prepare();
|
||||
} else {
|
||||
xa_statistics_.inc_success_xa_prepare();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -181,6 +181,7 @@ public:
|
||||
const ObTransID &trans_id,
|
||||
const share::ObLSID &coordinator,
|
||||
const ObAddr &sche_addr);
|
||||
ObXAStatistics &get_xa_statistics() { return xa_statistics_; }
|
||||
private:
|
||||
int local_one_phase_xa_commit_ (const ObXATransID &xid,
|
||||
const ObTransID &trans_id,
|
||||
@ -281,6 +282,7 @@ private:
|
||||
ObXAInnerTableGCWorker xa_inner_table_gc_worker_;
|
||||
bool is_running_;
|
||||
bool is_inited_;
|
||||
ObXAStatistics xa_statistics_;
|
||||
};
|
||||
|
||||
}//transaction
|
||||
|
@ -64,7 +64,7 @@ void ObXATransHeartbeatWorker::run1()
|
||||
while (!has_set_stop()) {
|
||||
int64_t start_time = ObTimeUtility::current_time();
|
||||
loop_count++;
|
||||
ObXAStatistics::get_instance().print_statistics(start_time);
|
||||
MTL(ObXAService *)->get_xa_statistics().print_statistics(start_time);
|
||||
|
||||
if (OB_UNLIKELY(!is_inited_)) {
|
||||
TRANS_LOG(WARN, "xa trans heartbeat not init");
|
||||
|
Reference in New Issue
Block a user