add seq num to sql audit to sequence stmt in transaction
This commit is contained in:
@ -1061,6 +1061,10 @@ int ObGvSqlAudit::fill_cells(obmysql::ObMySQLRequestRecord &record)
|
||||
cells[cell_idx].set_null();
|
||||
cells[cell_idx].set_default_collation_type();
|
||||
} break;
|
||||
case SEQ_NUM: {
|
||||
int64_t set_v = record.data_.seq_num_;
|
||||
cells[cell_idx].set_int(set_v);
|
||||
} break;
|
||||
default: {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
SERVER_LOG(WARN, "invalid column id", K(ret), K(cell_idx), K(col_id));
|
||||
|
||||
@ -172,6 +172,7 @@ private:
|
||||
PLSQL_EXEC_TIME,
|
||||
NETWORK_WAIT_TIME,
|
||||
STMT_TYPE,
|
||||
SEQ_NUM,
|
||||
};
|
||||
|
||||
const static int64_t PRI_KEY_IP_IDX = 0;
|
||||
|
||||
@ -11134,6 +11134,21 @@ int ObInnerTableSchema::all_virtual_sql_audit_schema(ObTableSchema &table_schema
|
||||
true, //is_nullable
|
||||
false); //is_autoincrement
|
||||
}
|
||||
|
||||
if (OB_SUCC(ret)) {
|
||||
ADD_COLUMN_SCHEMA("seq_num", //column_name
|
||||
++column_id, //column_id
|
||||
0, //rowkey_id
|
||||
0, //index_id
|
||||
0, //part_key_pos
|
||||
ObIntType, //column_type
|
||||
CS_TYPE_INVALID, //column_collation_type
|
||||
sizeof(int64_t), //column_length
|
||||
-1, //column_precision
|
||||
-1, //column_scale
|
||||
false, //is_nullable
|
||||
false); //is_autoincrement
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
table_schema.get_part_option().set_part_num(1);
|
||||
table_schema.set_part_level(PARTITION_LEVEL_ONE);
|
||||
@ -12934,7 +12949,24 @@ int ObInnerTableSchema::all_virtual_sql_audit_all_virtual_sql_audit_i1_schema(Ob
|
||||
true);//is_storing_column
|
||||
}
|
||||
|
||||
table_schema.set_max_used_column_id(column_id + 102);
|
||||
if (OB_SUCC(ret)) {
|
||||
ADD_COLUMN_SCHEMA_WITH_COLUMN_FLAGS("seq_num", //column_name
|
||||
column_id + 103, //column_id
|
||||
0, //rowkey_id
|
||||
0, //index_id
|
||||
0, //part_key_pos
|
||||
ObIntType, //column_type
|
||||
CS_TYPE_INVALID, //column_collation_type
|
||||
sizeof(int64_t), //column_length
|
||||
-1, //column_precision
|
||||
-1, //column_scale
|
||||
false,//is_nullable
|
||||
false,//is_autoincrement
|
||||
false,//is_hidden
|
||||
true);//is_storing_column
|
||||
}
|
||||
|
||||
table_schema.set_max_used_column_id(column_id + 103);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@ -1588,6 +1588,21 @@ int ObInnerTableSchema::all_virtual_sql_audit_ora_schema(ObTableSchema &table_sc
|
||||
true, //is_nullable
|
||||
false); //is_autoincrement
|
||||
}
|
||||
|
||||
if (OB_SUCC(ret)) {
|
||||
ADD_COLUMN_SCHEMA("SEQ_NUM", //column_name
|
||||
++column_id, //column_id
|
||||
0, //rowkey_id
|
||||
0, //index_id
|
||||
0, //part_key_pos
|
||||
ObNumberType, //column_type
|
||||
CS_TYPE_INVALID, //column_collation_type
|
||||
38, //column_length
|
||||
38, //column_precision
|
||||
0, //column_scale
|
||||
false, //is_nullable
|
||||
false); //is_autoincrement
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
table_schema.get_part_option().set_part_num(1);
|
||||
table_schema.set_part_level(PARTITION_LEVEL_ONE);
|
||||
@ -3388,7 +3403,24 @@ int ObInnerTableSchema::all_virtual_sql_audit_ora_all_virtual_sql_audit_i1_schem
|
||||
true);//is_storing_column
|
||||
}
|
||||
|
||||
table_schema.set_max_used_column_id(column_id + 102);
|
||||
if (OB_SUCC(ret)) {
|
||||
ADD_COLUMN_SCHEMA_WITH_COLUMN_FLAGS("SEQ_NUM", //column_name
|
||||
column_id + 103, //column_id
|
||||
0, //rowkey_id
|
||||
0, //index_id
|
||||
0, //part_key_pos
|
||||
ObNumberType, //column_type
|
||||
CS_TYPE_INVALID, //column_collation_type
|
||||
38, //column_length
|
||||
38, //column_precision
|
||||
0, //column_scale
|
||||
false,//is_nullable
|
||||
false,//is_autoincrement
|
||||
false,//is_hidden
|
||||
true);//is_storing_column
|
||||
}
|
||||
|
||||
table_schema.set_max_used_column_id(column_id + 103);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@ -8162,7 +8162,8 @@ def_table_schema(
|
||||
('pl_trace_id', 'varchar:OB_MAX_HOST_NAME_LENGTH', 'true'),
|
||||
('plsql_exec_time', 'int'),
|
||||
('network_wait_time', 'uint', 'true'),
|
||||
('stmt_type', 'varchar:MAX_STMT_TYPE_NAME_LENGTH', 'true')
|
||||
('stmt_type', 'varchar:MAX_STMT_TYPE_NAME_LENGTH', 'true'),
|
||||
('seq_num', 'int')
|
||||
],
|
||||
partition_columns = ['svr_ip', 'svr_port'],
|
||||
vtable_route_policy = 'distributed',
|
||||
|
||||
@ -399,6 +399,7 @@ struct ObAuditRecordData {
|
||||
int64_t scn_; // snapshot's position in the txn
|
||||
char const* source_; // snapshot's acquire source
|
||||
} snapshot_; // stmt's tx snapshot
|
||||
int64_t seq_num_; // sequence num, for sequencing stmts in transaction
|
||||
uint64_t txn_free_route_flag_; // flag contains txn free route meta
|
||||
uint64_t txn_free_route_version_; // the version of txn's state
|
||||
bool partition_hit_;// flag for need das partition route or not
|
||||
|
||||
@ -181,6 +181,7 @@ int ObSqlTransControl::explicit_start_trans(ObExecContext &ctx, const bool read_
|
||||
session->get_tx_desc() = NULL;
|
||||
}
|
||||
OX (session->get_raw_audit_record().trans_id_ = session->get_tx_id());
|
||||
OX (session->get_raw_audit_record().seq_num_ = ObSequence::get_max_seq_no());
|
||||
NG_TRACE_EXT(start_trans, OB_ID(ret), ret,
|
||||
OB_ID(trans_id), tx_id.get_id(),
|
||||
OB_ID(timeout), tx_param.timeout_us_,
|
||||
@ -235,6 +236,7 @@ int ObSqlTransControl::explicit_end_trans(ObExecContext &exec_ctx, const bool is
|
||||
CK (OB_NOT_NULL(callback = &session->get_end_trans_cb()));
|
||||
}
|
||||
OZ (end_trans(exec_ctx, is_rollback, true, callback));
|
||||
OX (session->get_raw_audit_record().seq_num_ = ObSequence::get_max_seq_no());
|
||||
FLT_SET_TAG(trans_id, txn_id.get_id());
|
||||
if (hint.length()) {
|
||||
LOG_INFO("explicit end trans with hint",
|
||||
@ -566,6 +568,7 @@ int ObSqlTransControl::start_stmt(ObExecContext &exec_ctx)
|
||||
ar_snapshot.scn_ = snapshot.core_.scn_.cast_to_int();
|
||||
(void)snapshot.format_source_for_display(audit_record.snapshot_source_, sizeof(audit_record.snapshot_source_));
|
||||
ar_snapshot.source_ = audit_record.snapshot_source_;
|
||||
audit_record.seq_num_ = ObSequence::get_max_seq_no();
|
||||
}
|
||||
if (OB_SUCC(ret) && !session->has_start_stmt()) {
|
||||
OZ (session->set_start_stmt());
|
||||
@ -828,6 +831,9 @@ int ObSqlTransControl::create_savepoint(ObExecContext &exec_ctx,
|
||||
ret = COVER_SUCC(tmp_ret);
|
||||
}
|
||||
}
|
||||
if (user_create) {
|
||||
OX(session->get_raw_audit_record().seq_num_ = ObSequence::get_max_seq_no());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -948,6 +954,9 @@ int ObSqlTransControl::rollback_savepoint(ObExecContext &exec_ctx,
|
||||
bool start_hook = false;
|
||||
OZ(start_hook_if_need_(*session, txs, start_hook));
|
||||
OZ (txs->rollback_to_explicit_savepoint(*session->get_tx_desc(), sp_name, stmt_expire_ts, get_real_session_id(*session)), sp_name);
|
||||
if (0 == session->get_raw_audit_record().seq_num_) {
|
||||
OX (session->get_raw_audit_record().seq_num_ = ObSequence::get_max_seq_no());
|
||||
}
|
||||
if (start_hook) {
|
||||
int tmp_ret = txs->sql_stmt_end_hook(session->get_xid(), *session->get_tx_desc());
|
||||
if (OB_SUCCESS != tmp_ret) {
|
||||
|
||||
@ -784,6 +784,7 @@ pl_trace_id varchar(128) YES NULL
|
||||
plsql_exec_time bigint(20) NO NULL
|
||||
network_wait_time bigint(20) unsigned YES NULL
|
||||
stmt_type varchar(128) YES NULL
|
||||
seq_num bigint(20) NO NULL
|
||||
select /*+QUERY_TIMEOUT(60000000)*/ IF(count(*) >= 0, 1, 0) from oceanbase.__all_virtual_sql_audit;
|
||||
IF(count(*) >= 0, 1, 0)
|
||||
1
|
||||
|
||||
@ -857,6 +857,7 @@ pl_trace_id varchar(128) YES NULL
|
||||
plsql_exec_time bigint(20) NO NULL
|
||||
network_wait_time bigint(20) unsigned YES NULL
|
||||
stmt_type varchar(128) YES NULL
|
||||
seq_num bigint(20) NO NULL
|
||||
select /*+QUERY_TIMEOUT(60000000)*/ IF(count(*) >= 0, 1, 0) from oceanbase.__all_virtual_sql_audit;
|
||||
IF(count(*) >= 0, 1, 0)
|
||||
1
|
||||
|
||||
Reference in New Issue
Block a user