fix sql_audit snapshot_source display bug
This commit is contained in:
@ -268,6 +268,7 @@ int ObSqlTransControl::end_trans(ObExecContext &exec_ctx,
|
|||||||
LOG_INFO("end_trans", K(session->is_in_transaction()),
|
LOG_INFO("end_trans", K(session->is_in_transaction()),
|
||||||
K(session->has_explicit_start_trans()),
|
K(session->has_explicit_start_trans()),
|
||||||
K(exec_ctx.get_execution_id()),
|
K(exec_ctx.get_execution_id()),
|
||||||
|
KPC(session->get_tx_desc()),
|
||||||
KP(callback));
|
KP(callback));
|
||||||
#endif
|
#endif
|
||||||
if (OB_ISNULL(session) || OB_ISNULL(plan_ctx)) {
|
if (OB_ISNULL(session) || OB_ISNULL(plan_ctx)) {
|
||||||
@ -1051,6 +1052,7 @@ int ObSqlTransControl::end_stmt(ObExecContext &exec_ctx, const bool rollback)
|
|||||||
bool is_plain_select = false;
|
bool is_plain_select = false;
|
||||||
transaction::ObTxSEQ savepoint = das_ctx.get_savepoint();
|
transaction::ObTxSEQ savepoint = das_ctx.get_savepoint();
|
||||||
int exec_errcode = exec_ctx.get_errcode();
|
int exec_errcode = exec_ctx.get_errcode();
|
||||||
|
int64_t tx_id = 0;
|
||||||
|
|
||||||
CK (OB_NOT_NULL(session), OB_NOT_NULL(plan_ctx));
|
CK (OB_NOT_NULL(session), OB_NOT_NULL(plan_ctx));
|
||||||
CK (OB_NOT_NULL(plan = plan_ctx->get_phy_plan()));
|
CK (OB_NOT_NULL(plan = plan_ctx->get_phy_plan()));
|
||||||
@ -1063,6 +1065,7 @@ int ObSqlTransControl::end_stmt(ObExecContext &exec_ctx, const bool rollback)
|
|||||||
CK (OB_NOT_NULL(tx_desc));
|
CK (OB_NOT_NULL(tx_desc));
|
||||||
ObTransID tx_id_before_rollback;
|
ObTransID tx_id_before_rollback;
|
||||||
OX (tx_id_before_rollback = tx_desc->get_tx_id());
|
OX (tx_id_before_rollback = tx_desc->get_tx_id());
|
||||||
|
tx_id = tx_id_before_rollback.get_id();
|
||||||
OX (ObTransDeadlockDetectorAdapter::maintain_deadlock_info_when_end_stmt(exec_ctx, rollback));
|
OX (ObTransDeadlockDetectorAdapter::maintain_deadlock_info_when_end_stmt(exec_ctx, rollback));
|
||||||
auto &tx_result = session->get_trans_result();
|
auto &tx_result = session->get_trans_result();
|
||||||
if (OB_FAIL(ret)) {
|
if (OB_FAIL(ret)) {
|
||||||
@ -1122,8 +1125,10 @@ int ObSqlTransControl::end_stmt(ObExecContext &exec_ctx, const bool rollback)
|
|||||||
#endif
|
#endif
|
||||||
if (print_log
|
if (print_log
|
||||||
&& OB_NOT_NULL(session)
|
&& OB_NOT_NULL(session)
|
||||||
&& OB_TRY_LOCK_ROW_CONFLICT != exec_ctx.get_errcode()) {
|
&& (OB_TRY_LOCK_ROW_CONFLICT != exec_ctx.get_errcode()
|
||||||
|
|| REACH_TIME_INTERVAL(1 * 1000 * 1000))) {
|
||||||
LOG_INFO("end stmt", K(ret),
|
LOG_INFO("end stmt", K(ret),
|
||||||
|
"tx_id", tx_id,
|
||||||
"plain_select", is_plain_select,
|
"plain_select", is_plain_select,
|
||||||
"stmt_type", stmt_type,
|
"stmt_type", stmt_type,
|
||||||
K(savepoint),
|
K(savepoint),
|
||||||
|
|||||||
@ -1267,11 +1267,13 @@ const char* ObTxReadSnapshot::get_source_name() const
|
|||||||
/*
|
/*
|
||||||
* format snapshot info for sql audit display
|
* format snapshot info for sql audit display
|
||||||
* contains: src, ls_id, ls_role, parts
|
* contains: src, ls_id, ls_role, parts
|
||||||
* when shorter than 128 char like:
|
* 1. local select:
|
||||||
* "src:GLOBAL;ls_id:1001;ls_role:LEADER;parts:[(id:1001,epoch:1111),(id:1002,epoch:12222)]"
|
* "src:LOCAL;ls_id:1001;ls_role:LEADER;parts:[1001,1002]"
|
||||||
* when longer than 128 char, with "..." in the end
|
* 2. glocal select, with no ls and ls_role: "src:GTS;parts[1001]"
|
||||||
* "src:GLOBAL;ls_id:1001;ls_role:LEADER;parts:[(lsid:1001,epoch:1111),(lsid:1002,epoch:122..."
|
* 3. insert: "NONE"
|
||||||
*/
|
* 4. longer than 128 chars, with "..." in the end
|
||||||
|
* "src:GLOBAL;ls_id:1001;ls_role:LEADER;parts:[1001,1002,102..."
|
||||||
|
*/
|
||||||
int ObTxReadSnapshot::format_source_for_display(char *buf, const int64_t buf_len) const
|
int ObTxReadSnapshot::format_source_for_display(char *buf, const int64_t buf_len) const
|
||||||
{
|
{
|
||||||
int ret = OB_SUCCESS;
|
int ret = OB_SUCCESS;
|
||||||
@ -1283,25 +1285,56 @@ int ObTxReadSnapshot::format_source_for_display(char *buf, const int64_t buf_len
|
|||||||
const char *snapshot_src = get_source_name();
|
const char *snapshot_src = get_source_name();
|
||||||
const char *ls_role = role_to_string(snapshot_ls_role_);
|
const char *ls_role = role_to_string(snapshot_ls_role_);
|
||||||
uint64_t ls_id = snapshot_lsid_.id();
|
uint64_t ls_id = snapshot_lsid_.id();
|
||||||
int n = snprintf(buf, buf_len, "src:%s;ls_id:%ld;ls_role:%s;parts:",
|
int n = 0;
|
||||||
snapshot_src, ls_id, ls_role);
|
bool need_fill = true;
|
||||||
|
if (SRC::NONE == source_) {
|
||||||
|
// insert has no stmt snapshot
|
||||||
|
need_fill = false;
|
||||||
|
n = snprintf(buf, buf_len, "NONE");
|
||||||
|
} else if (SRC::GLOBAL != source_) {
|
||||||
|
n = snprintf(buf, buf_len, "src:%s;ls_id:%ld;ls_role:%s;parts:[",
|
||||||
|
snapshot_src, ls_id, ls_role);
|
||||||
|
} else {
|
||||||
|
// GLOBAL snapshot not display ls_id and ls_role
|
||||||
|
n = snprintf(buf, buf_len, "src:%s;parts:[", snapshot_src);
|
||||||
|
}
|
||||||
if (n < 0){
|
if (n < 0){
|
||||||
ret = OB_UNEXPECT_INTERNAL_ERROR;
|
ret = OB_UNEXPECT_INTERNAL_ERROR;
|
||||||
TRANS_LOG(WARN, "fail to fill snapshot source", K(ret), KPC(this), K(n), K(pos), K(buf_len));
|
TRANS_LOG(WARN, "fail to fill snapshot source", K(ret), KPC(this), K(n), K(pos), K(buf_len));
|
||||||
} else {
|
} else if(need_fill) {
|
||||||
pos += n;
|
pos += n;
|
||||||
pos += parts_.to_string(buf + pos, buf_len - pos);
|
bool buf_not_enough = false;
|
||||||
if (pos >= buf_len - 1) {
|
for (int i = 0; i < parts_.count(); i++) {
|
||||||
// buf full, parts fill not complete
|
n = snprintf(buf + pos, buf_len - pos, "%ld,", parts_[i].left_.id());
|
||||||
// replace end 3 chars with ...
|
if (n < 0) {
|
||||||
buf[pos - 2] = '.';
|
ret = OB_UNEXPECT_INTERNAL_ERROR;
|
||||||
buf[pos - 3] = '.';
|
TRANS_LOG(WARN, "fail to fill snapshot source", K(ret), KPC(this), K(n), K(pos), K(buf_len));
|
||||||
buf[pos - 4] = '.';
|
} else if (n > buf_len - pos) {
|
||||||
|
buf_not_enough = true;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
pos += n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (buf_not_enough) {
|
||||||
|
// buf full, parts fill not complete
|
||||||
|
int remain_cnt = buf_len - pos;
|
||||||
|
pos = remain_cnt < 4 ? buf_len - 4 : pos;
|
||||||
|
buf[pos] = '.';
|
||||||
|
buf[pos + 1] = '.';
|
||||||
|
buf[pos + 2] = '.';
|
||||||
|
buf[pos + 3] = '\0';
|
||||||
|
} else if(parts_.count() > 0) {
|
||||||
|
buf[pos - 1] = ']';
|
||||||
|
} else {
|
||||||
|
buf[pos] = ']';
|
||||||
|
buf[pos + 1] = '\0';
|
||||||
}
|
}
|
||||||
buf[pos - 1] = '\0';
|
|
||||||
TRANS_LOG(DEBUG, "succeed to generate snapshot source", KPC(this), K(pos), K(buf_len), K(ObString(buf)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (OB_FAIL(ret)) {
|
||||||
|
TRANS_LOG(WARN, "fail to generate snapshot source", KPC(this), K(pos), K(buf_len), K(ObString(buf)));
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -722,6 +722,8 @@ int ObTransService::get_ls_read_snapshot(ObTxDesc &tx,
|
|||||||
snapshot.parts_.reset();
|
snapshot.parts_.reset();
|
||||||
if(acquire_from_follower) {
|
if(acquire_from_follower) {
|
||||||
snapshot.snapshot_ls_role_ = common::ObRole::FOLLOWER;
|
snapshot.snapshot_ls_role_ = common::ObRole::FOLLOWER;
|
||||||
|
} else {
|
||||||
|
snapshot.snapshot_ls_role_ = common::ObRole::LEADER;
|
||||||
}
|
}
|
||||||
// If tx id is valid , record tx_id and scn
|
// If tx id is valid , record tx_id and scn
|
||||||
if (tx.tx_id_.is_valid()) {
|
if (tx.tx_id_.is_valid()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user