fix(2meet-data-optimizer): take the index lock on the primary under read/write splitting
- when $wpdb has send_reads_to_masters() (HyperDB, LudicrousDB), it is called before SELECT GET_LOCK, which a replica would take without locking out the ALTER on the primary - Verify: GroupCompositeIndexTest (call order through a wpdb proxy), integration 583, unit 701, phpcs, stan - PR: PR-108
This commit is contained in:
@@ -231,6 +231,11 @@ final class TMDO_Schema_Manager {
|
||||
// processes both "acquire" an option lock; GET_LOCK is atomic and is
|
||||
// released by MySQL if this process dies.
|
||||
$lock = self::index_lock_name();
|
||||
if ( method_exists( $wpdb, 'send_reads_to_masters' ) ) {
|
||||
// HyperDB / LudicrousDB would send the SELECT GET_LOCK to a replica,
|
||||
// where it locks nothing against the ALTER on the primary.
|
||||
$wpdb->send_reads_to_masters();
|
||||
}
|
||||
if ( '1' !== (string) $wpdb->get_var( $wpdb->prepare( 'SELECT GET_LOCK(MD5(CONCAT(DATABASE(), %s)), 0)', $lock ) ) ) {
|
||||
return; // Another process is adding indexes.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user