MDEV-22370 safe_mutex: Trying to lock uninitialized mutex at /data/src/10.4-bug/sql/rpl_parallel.cc, line 470 upon shutdown during FTWRL
Problem:- When we issue FTWRL with shutdown in parallel, there is race between
FTWRL and shutdown. Shutdown might destroy the mutex (pool->LOCK_rpl_thread_pool)
before FTWRL can lock it. So we can get crash on FTWRL thread
Solution:- mysql_mutex_destroy(pool->LOCK_rpl_thread_pool) should wait for
FTWRL thread to complete its work , and then destroy.
So slave_prepare_for_shutdown will just deactivate the pool, and mutex is destroyed
later in end_slave()
Parallel slave server shutdown found to be hanging in
close_connections() triggered by shutdown due to a slave worker thread
would not be notified to exit in case the worker was sitting idle.
Fixed with destroying the worker pool earlier that is in
slave_prepare_for_shutdown() when all their driver threads have already left.
A test file is added to simulate the bug condition as well as check
multi-sourced and not-idle worker cases.
MDEV-19157 Optimistic Parallel Replication fails when gtid_slave_pos table is non transactional and binlog events are transactional
Problem:- In Optimistic/Aggressive mode of parallel replication when we have
conflict, we retry the transaction, But if gtid_slave_pos is non transactional
In that case retry may result into duplicate key error for table because
the conflicted transaction can not rollback the changes in gtid_slave_pos table
So when we try the same trans again, We get the Duplicate Key error
Solution:- Users are advised to use transactional storage engine for gtid_slave_pos.
In this patch we are throwing warning when we see that gtid_slave_pos in non
transactional.
Working:- is_gtid_slave_pos_transactional variable is added into rpl_slave_state
which will take care of caching result of gtid_slave_pos transactionality
We are updating this variable in find_gtid_pos_tables_cb, this function will
be called for each gtid_slave_pos_XYZ table at the time of start slave by
handle_slave_sql.
We are also checking for opt_gtid_pos_auto_plugins while giving warning
because it can be possible that respective gtid_slave_pos_XYZ table has
not been created yet but user has set the variable.
../sql/spatial.cc: In member function ‘double Gis_point::calculate_haversine(const Geometry*, double, int*)’:
../sql/spatial.cc:1093:45: error: ‘y1r’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
1093 | res= 2*sphere_radius*asin((sqrt(dlat + cos(y1r)*cos(y2r)*dlong)));
| ~~~^~~~~
../sql/spatial.cc:1092:20: error: ‘x1r’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
1092 | dlong= sin((x2r - x1r)/2)*sin((x2r - x1r)/2);
| ~~~~~^~~~~~
../sql/spatial.cc:1093:54: error: ‘y2r’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
1093 | res= 2*sphere_radius*asin((sqrt(dlat + cos(y1r)*cos(y2r)*dlong)));
| ~~~^~~~~
../sql/spatial.cc:1092:20: error: ‘x2r’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
1092 | dlong= sin((x2r - x1r)/2)*sin((x2r - x1r)/2);
| ~~~~~^~~~~~
c