mirror of
https://github.com/MariaDB/server.git
synced 2025-08-05 13:16:09 +03:00
MDEV-33668: More precise dependency tracking of XA XID in parallel replication
Keep track of each recently active XID, recording which worker it was queued on. If an XID might still be active, choose the same worker to queue event groups that refer to the same XID to avoid conflicts. Otherwise, schedule the XID freely in the next round-robin slot. This way, XA PREPARE can normally be scheduled without restrictions (unless duplicate XID transactions come close together). This improves scheduling and parallelism over the old method, where the worker thread to schedule XA PREPARE on was fixed based on a hash value of the XID. XA COMMIT will normally be scheduled on the same worker as XA PREPARE, but can be a different one if the XA PREPARE is far back in the event history. Testcase and code for trimming dynamic array due to Andrei. Reviewed-by: Andrei Elkin <andrei.elkin@mariadb.com> Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
This commit is contained in:
@@ -326,10 +326,26 @@ struct rpl_parallel_thread_pool {
|
||||
|
||||
|
||||
struct rpl_parallel_entry {
|
||||
/*
|
||||
A small struct to put worker threads references into a FIFO (using an
|
||||
I_List) for round-robin scheduling.
|
||||
*/
|
||||
struct sched_bucket : public ilink {
|
||||
sched_bucket() : thr(nullptr) { }
|
||||
rpl_parallel_thread *thr;
|
||||
};
|
||||
/*
|
||||
A struct to keep track of into which "generation" an XA XID was last
|
||||
scheduled. A "generation" means that we know that every worker thread
|
||||
slot in the rpl_parallel_entry was scheduled at least once. When more
|
||||
that two generations have passed, we can safely reuse the XID in a
|
||||
different worker.
|
||||
*/
|
||||
struct xid_active_generation {
|
||||
uint64 generation;
|
||||
sched_bucket *thr;
|
||||
xid_t xid;
|
||||
};
|
||||
|
||||
mysql_mutex_t LOCK_parallel_entry;
|
||||
mysql_cond_t COND_parallel_entry;
|
||||
@@ -373,6 +389,23 @@ struct rpl_parallel_entry {
|
||||
sched_bucket *rpl_threads;
|
||||
I_List<sched_bucket> *thread_sched_fifo;
|
||||
uint32 rpl_thread_max;
|
||||
/*
|
||||
Keep track of all XA XIDs that may still be active in a worker thread.
|
||||
The elements are of type xid_active_generation.
|
||||
*/
|
||||
DYNAMIC_ARRAY maybe_active_xid;
|
||||
/*
|
||||
Keeping track of the current scheduling generation.
|
||||
|
||||
A new generation means that every worker thread in the rpl_threads array
|
||||
have been scheduled at least one event group.
|
||||
|
||||
When we have scheduled to slot current_generation_idx= 0, 1, ..., N-1 in this
|
||||
order, we know that (at least) one generation has passed.
|
||||
*/
|
||||
uint64 current_generation;
|
||||
uint32 current_generation_idx;
|
||||
|
||||
/*
|
||||
The sub_id of the last transaction to commit within this domain_id.
|
||||
Must be accessed under LOCK_parallel_entry protection.
|
||||
@@ -426,11 +459,19 @@ struct rpl_parallel_entry {
|
||||
/* The group_commit_orderer object for the events currently being queued. */
|
||||
group_commit_orderer *current_gco;
|
||||
|
||||
void check_scheduling_generation(sched_bucket *cur);
|
||||
sched_bucket *check_xa_xid_dependency(xid_t *xid);
|
||||
rpl_parallel_thread * choose_thread(rpl_group_info *rgi, bool *did_enter_cond,
|
||||
PSI_stage_info *old_stage,
|
||||
Gtid_log_event *gtid_ev);
|
||||
int queue_master_restart(rpl_group_info *rgi,
|
||||
Format_description_log_event *fdev);
|
||||
/*
|
||||
the initial size of maybe_ array corresponds to the case of
|
||||
each worker receives perhaps unlikely XA-PREPARE and XA-COMMIT within
|
||||
the same generation.
|
||||
*/
|
||||
inline uint active_xid_init_alloc() { return 3 * 2 * rpl_thread_max; }
|
||||
};
|
||||
struct rpl_parallel {
|
||||
HASH domain_hash;
|
||||
|
Reference in New Issue
Block a user