Skip to content

Commit 742c8d8

Browse files
author
Abhinav Agarwal
committed
WL#15339 step 1: Remove transaction buffering when plugin is SUSPENDED
Foundation Commit ================= Description: ----------- - To recover transactions from Binlog, Rapid plugin needs to track GTIDs of the committed transactions so that tracked GTIDs can be used as exclude set to use Binlog Iterator API (WL#13901). - Tracked Gtid_set has its own `Sid_map` (and not `global_sid_map`). - In after commit hook, the GTID of the committing transaction is computed from the argument of type Trans_gtid_info. Trans_gtid_info has sidno which is relative to global_sid_map. - Since plugin uses its own Gtid_set to track transactions, `sidno` is insufficient to compute correct GTID. The type needs to have `sid` (rpl_sid type) which is global server identifier and must be used to compute GTID and keep in private `Sid_map`. Changes: ------- -> Added member `sid` (type rpl_sid) in Trans_gtid_info. -> Changes in `class Last_used_gtid_tracker_ctx`: - Added member `m_last_used_sid` (type rpl_sid) - Modifed `set_last_used_gtid()` to set the `sid` of the transaction along with GTID. - Added `get_last_used_sid()` to get the `sid` of the last transaction. -> In caller of after commit hook, populate `sid` from `last_used_gtid_tracker`. Change-Id: I4f669c5a84c24bce764c7462c245dceb93eaa912
1 parent df9d7ab commit 742c8d8

File tree

5 files changed

+23
-3
lines changed

5 files changed

+23
-3
lines changed

sql/replication.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ typedef struct Trans_context_info {
119119
This represents the GTID context of the transaction.
120120
*/
121121
typedef struct Trans_gtid_info {
122+
rpl_sid sid; // transaction sid
122123
ulong type; // enum values in enum_gtid_type
123124
int sidno; // transaction sidno
124125
long long int gno; // transaction gno

sql/rpl_context.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,21 @@ Last_used_gtid_tracker_ctx::Last_used_gtid_tracker_ctx() {
195195

196196
Last_used_gtid_tracker_ctx::~Last_used_gtid_tracker_ctx() = default;
197197

198-
void Last_used_gtid_tracker_ctx::set_last_used_gtid(const Gtid &gtid) {
198+
void Last_used_gtid_tracker_ctx::set_last_used_gtid(const Gtid &gtid,
199+
const rpl_sid &sid) {
199200
(*m_last_used_gtid).set(gtid.sidno, gtid.gno);
201+
m_last_used_sid.copy_from(sid);
200202
}
201203

202204
void Last_used_gtid_tracker_ctx::get_last_used_gtid(Gtid &gtid) {
203205
gtid.sidno = (*m_last_used_gtid).sidno;
204206
gtid.gno = (*m_last_used_gtid).gno;
205207
}
206208

209+
void Last_used_gtid_tracker_ctx::get_last_used_sid(rpl_sid &sid) {
210+
m_last_used_sid.copy_to(sid.bytes);
211+
}
212+
207213
Transaction_compression_ctx::Transaction_compression_ctx(PSI_memory_key key)
208214
: m_managed_buffer_memory_resource(psi_memory_resource(key)),
209215
m_managed_buffer_sequence(Grow_calculator_t(),

sql/rpl_context.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,9 @@ class Last_used_gtid_tracker_ctx {
255255
Set the last used GTID the session.
256256
257257
@param[in] gtid the used gtid.
258+
@param[in] sid the used sid.
258259
*/
259-
void set_last_used_gtid(const Gtid &gtid);
260+
void set_last_used_gtid(const Gtid &gtid, const rpl_sid &sid);
260261

261262
/**
262263
Get the last used GTID the session.
@@ -265,8 +266,16 @@ class Last_used_gtid_tracker_ctx {
265266
*/
266267
void get_last_used_gtid(Gtid &gtid);
267268

269+
/**
270+
Get the last used SID of the session.
271+
272+
@param[out] sid the used sid.
273+
*/
274+
void get_last_used_sid(rpl_sid &sid);
275+
268276
private:
269277
std::unique_ptr<Gtid> m_last_used_gtid;
278+
rpl_sid m_last_used_sid;
270279
};
271280

272281
class Transaction_compression_ctx {

sql/rpl_gtid_state.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ enum_return_status Gtid_state::acquire_ownership(THD *thd, const Gtid &gtid) {
9696
thd->owned_gtid = gtid;
9797
thd->owned_gtid.dbug_print(nullptr, "set owned_gtid in acquire_ownership");
9898
thd->owned_sid = sid_map->sidno_to_sid(gtid.sidno);
99-
thd->rpl_thd_ctx.last_used_gtid_tracker_ctx().set_last_used_gtid(gtid);
99+
thd->rpl_thd_ctx.last_used_gtid_tracker_ctx().set_last_used_gtid(
100+
gtid, thd->owned_sid);
100101
}
101102
RETURN_OK;
102103
err:

sql/rpl_handler.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,9 @@ int Trans_delegate::after_commit(THD *thd, bool all) {
816816
param.gtid_info.sidno = gtid.sidno;
817817
param.gtid_info.gno = gtid.gno;
818818

819+
thd->rpl_thd_ctx.last_used_gtid_tracker_ctx().get_last_used_sid(
820+
param.gtid_info.sid);
821+
819822
bool is_real_trans =
820823
(all || !thd->get_transaction()->is_active(Transaction_ctx::SESSION));
821824
if (is_real_trans) param.flags |= TRANS_IS_REAL_TRANS;

0 commit comments

Comments
 (0)