|
| 1 | +diff --git a/vendor/magento/module-catalog-permissions/etc/di.xml b/vendor/magento/module-catalog-permissions/etc/di.xml |
| 2 | +index 01640cc..f1a96cd 100644 |
| 3 | +--- a/vendor/magento/module-catalog-permissions/etc/di.xml |
| 4 | ++++ b/vendor/magento/module-catalog-permissions/etc/di.xml |
| 5 | +@@ -81,7 +81,7 @@ |
| 6 | + <type name="Magento\Indexer\Console\Command\IndexerSetDimensionsModeCommand"> |
| 7 | + <arguments> |
| 8 | + <argument name="dimensionSwitchers" xsi:type="array"> |
| 9 | +- <item name="catalogpermissions_category" xsi:type="object">Magento\CatalogPermissions\Model\Indexer\Category\ModeSwitcher</item> |
| 10 | ++ <item name="catalogpermissions_category" xsi:type="object">Magento\CatalogPermissions\Model\Indexer\Category\ModeSwitcher\Proxy</item> |
| 11 | + </argument> |
| 12 | + </arguments> |
| 13 | + </type> |
| 14 | +diff --git a/vendor/magento/module-resource-connections/DB/Adapter/Pdo/MysqlProxy.php b/vendor/magento/module-resource-connections/DB/Adapter/Pdo/MysqlProxy.php |
| 15 | +index ce9c9d5..a30e608 100644 |
| 16 | +--- a/vendor/magento/module-resource-connections/DB/Adapter/Pdo/MysqlProxy.php |
| 17 | ++++ b/vendor/magento/module-resource-connections/DB/Adapter/Pdo/MysqlProxy.php |
| 18 | +@@ -36,12 +36,12 @@ class MysqlProxy extends Mysql |
| 19 | + protected $masterConnectionOnly = false; |
| 20 | + |
| 21 | + /** |
| 22 | +- * @var \Magento\Framework\DB\Adapter\Pdo\Mysql |
| 23 | ++ * @var Mysql|null |
| 24 | + */ |
| 25 | + protected $masterConnection; |
| 26 | + |
| 27 | + /** |
| 28 | +- * @var \Magento\Framework\DB\Adapter\Pdo\Mysql |
| 29 | ++ * @var Mysql|null |
| 30 | + */ |
| 31 | + protected $slaveConnection; |
| 32 | + |
| 33 | +@@ -75,6 +75,11 @@ class MysqlProxy extends Mysql |
| 34 | + private bool $synchronousReplication = false; |
| 35 | + |
| 36 | + /** |
| 37 | ++ * @var bool |
| 38 | ++ */ |
| 39 | ++ private bool $isCausalityCheckOnReadForSlaveEnabled = false; |
| 40 | ++ |
| 41 | ++ /** |
| 42 | + * Constructor |
| 43 | + * |
| 44 | + * @param LoggerInterface $logger |
| 45 | +@@ -91,11 +96,10 @@ class MysqlProxy extends Mysql |
| 46 | + $this->logger = $logger; |
| 47 | + $this->selectFactory = $selectFactory; |
| 48 | + $this->mysqlFactory = $mysqlFactory ?: ObjectManager::getInstance()->get(MysqlFactory::class); |
| 49 | ++ $this->masterConfig = $config; |
| 50 | + if (!isset($config['slave'])) { |
| 51 | +- $this->masterConfig = $config; |
| 52 | + $this->setUseMasterConnection(); |
| 53 | + } else { |
| 54 | +- $this->masterConfig = $config; |
| 55 | + unset($this->masterConfig['slave']); |
| 56 | + $this->slaveConfig = array_merge($this->masterConfig, $config['slave']); |
| 57 | + $this->synchronousReplication = $this->slaveConfig['synchronous_replication'] ?? false; |
| 58 | +@@ -103,6 +107,23 @@ class MysqlProxy extends Mysql |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | ++ * @inheritdoc |
| 63 | ++ */ |
| 64 | ++ public function _resetState() : void |
| 65 | ++ { |
| 66 | ++ if ($this->masterConnection) { |
| 67 | ++ $this->masterConnection->_resetState(); |
| 68 | ++ } |
| 69 | ++ if ($this->slaveConnection) { |
| 70 | ++ $this->slaveConnection->_resetState(); |
| 71 | ++ } |
| 72 | ++ $this->masterConnection = null; |
| 73 | ++ $this->slaveConnection = null; |
| 74 | ++ $this->isCausalityCheckOnReadForSlaveEnabled = false; |
| 75 | ++ parent::_resetState(); |
| 76 | ++ } |
| 77 | ++ |
| 78 | ++ /** |
| 79 | + * Set master connection |
| 80 | + * |
| 81 | + * @return $this |
| 82 | +@@ -192,9 +213,7 @@ class MysqlProxy extends Mysql |
| 83 | + return $this->getSlaveConnection(); |
| 84 | + } |
| 85 | + |
| 86 | +- if ($this->synchronousReplication === false) { |
| 87 | +- $this->setUseMasterConnection(); |
| 88 | +- } |
| 89 | ++ $this->prepareReadOnlyConnection(); |
| 90 | + |
| 91 | + return $this->getMasterConnection(); |
| 92 | + } |
| 93 | +@@ -219,6 +238,7 @@ class MysqlProxy extends Mysql |
| 94 | + if ($this->synchronousReplication |
| 95 | + && $this->getMasterConnection()->getTransactionLevel() === 0) { |
| 96 | + $this->masterConnectionOnly = false; |
| 97 | ++ $this->setCausalityCheckOnReadForSlave(); |
| 98 | + } |
| 99 | + return $this; |
| 100 | + } |
| 101 | +@@ -570,9 +590,7 @@ class MysqlProxy extends Mysql |
| 102 | + */ |
| 103 | + public function insertForce($table, array $bind) |
| 104 | + { |
| 105 | +- if ($this->synchronousReplication !== true) { |
| 106 | +- $this->setUseMasterConnection(); |
| 107 | +- } |
| 108 | ++ $this->prepareReadOnlyConnection(); |
| 109 | + return $this->getMasterConnection()->insertForce($table, $bind); |
| 110 | + } |
| 111 | + |
| 112 | +@@ -581,9 +599,7 @@ class MysqlProxy extends Mysql |
| 113 | + */ |
| 114 | + public function insertOnDuplicate($table, array $data, array $fields = []) |
| 115 | + { |
| 116 | +- if ($this->synchronousReplication !== true) { |
| 117 | +- $this->setUseMasterConnection(); |
| 118 | +- } |
| 119 | ++ $this->prepareReadOnlyConnection(); |
| 120 | + return $this->getMasterConnection()->insertOnDuplicate($table, $data, $fields); |
| 121 | + } |
| 122 | + |
| 123 | +@@ -592,9 +608,7 @@ class MysqlProxy extends Mysql |
| 124 | + */ |
| 125 | + public function insertMultiple($table, array $data) |
| 126 | + { |
| 127 | +- if ($this->synchronousReplication !== true) { |
| 128 | +- $this->setUseMasterConnection(); |
| 129 | +- } |
| 130 | ++ $this->prepareReadOnlyConnection(); |
| 131 | + return $this->getMasterConnection()->insertMultiple($table, $data); |
| 132 | + } |
| 133 | + |
| 134 | +@@ -603,9 +617,7 @@ class MysqlProxy extends Mysql |
| 135 | + */ |
| 136 | + public function insertArray($table, array $columns, array $data, $strategy = 0) |
| 137 | + { |
| 138 | +- if ($this->synchronousReplication !== true) { |
| 139 | +- $this->setUseMasterConnection(); |
| 140 | +- } |
| 141 | ++ $this->prepareReadOnlyConnection(); |
| 142 | + return $this->getMasterConnection()->insertArray($table, $columns, $data, $strategy); |
| 143 | + } |
| 144 | + |
| 145 | +@@ -988,9 +1000,7 @@ class MysqlProxy extends Mysql |
| 146 | + */ |
| 147 | + public function insertFromSelect(Select $select, $table, array $fields = [], $mode = false) |
| 148 | + { |
| 149 | +- if ($this->synchronousReplication !== true) { |
| 150 | +- $this->setUseMasterConnection(); |
| 151 | +- } |
| 152 | ++ $this->prepareReadOnlyConnection(); |
| 153 | + return $this->getMasterConnection()->insertFromSelect($select, $table, $fields, $mode); |
| 154 | + } |
| 155 | + |
| 156 | +@@ -1007,9 +1017,7 @@ class MysqlProxy extends Mysql |
| 157 | + */ |
| 158 | + public function updateFromSelect(Select $select, $table) |
| 159 | + { |
| 160 | +- if ($this->synchronousReplication !== true) { |
| 161 | +- $this->setUseMasterConnection(); |
| 162 | +- } |
| 163 | ++ $this->prepareReadOnlyConnection(); |
| 164 | + return $this->getMasterConnection()->updateFromSelect($select, $table); |
| 165 | + } |
| 166 | + |
| 167 | +@@ -1018,9 +1026,7 @@ class MysqlProxy extends Mysql |
| 168 | + */ |
| 169 | + public function deleteFromSelect(Select $select, $table) |
| 170 | + { |
| 171 | +- if ($this->synchronousReplication !== true) { |
| 172 | +- $this->setUseMasterConnection(); |
| 173 | +- } |
| 174 | ++ $this->prepareReadOnlyConnection(); |
| 175 | + return $this->getMasterConnection()->deleteFromSelect($select, $table); |
| 176 | + } |
| 177 | + |
| 178 | +@@ -1054,9 +1060,7 @@ class MysqlProxy extends Mysql |
| 179 | + */ |
| 180 | + public function forUpdate($sql) |
| 181 | + { |
| 182 | +- if ($this->synchronousReplication !== true) { |
| 183 | +- $this->setUseMasterConnection(); |
| 184 | +- } |
| 185 | ++ $this->prepareReadOnlyConnection(); |
| 186 | + return $this->getMasterConnection()->forUpdate($sql); |
| 187 | + } |
| 188 | + |
| 189 | +@@ -1257,9 +1261,7 @@ class MysqlProxy extends Mysql |
| 190 | + */ |
| 191 | + public function insert($table, array $bind) |
| 192 | + { |
| 193 | +- if ($this->synchronousReplication !== true) { |
| 194 | +- $this->setUseMasterConnection(); |
| 195 | +- } |
| 196 | ++ $this->prepareReadOnlyConnection(); |
| 197 | + return $this->getMasterConnection()->insert($table, $bind); |
| 198 | + } |
| 199 | + |
| 200 | +@@ -1268,20 +1270,48 @@ class MysqlProxy extends Mysql |
| 201 | + */ |
| 202 | + public function update($table, array $bind, $where = '') |
| 203 | + { |
| 204 | +- if ($this->synchronousReplication !== true) { |
| 205 | +- $this->setUseMasterConnection(); |
| 206 | +- } |
| 207 | ++ $this->prepareReadOnlyConnection(); |
| 208 | + return $this->getMasterConnection()->update($table, $bind, $where); |
| 209 | + } |
| 210 | + |
| 211 | + /** |
| 212 | ++ * Prepare connection for read-only operations. |
| 213 | ++ * |
| 214 | ++ * @return void |
| 215 | ++ */ |
| 216 | ++ private function prepareReadOnlyConnection(): void |
| 217 | ++ { |
| 218 | ++ $this->synchronousReplication ? $this->setCausalityCheckOnReadForSlave() : $this->setUseMasterConnection(); |
| 219 | ++ } |
| 220 | ++ |
| 221 | ++ /** |
| 222 | ++ * Enforces strict causality check on READ statements for slave node. |
| 223 | ++ * |
| 224 | ++ * This is required to prevent slave from reading stale data after write operation on master. |
| 225 | ++ * |
| 226 | ++ * @see https://galeracluster.com/library/documentation/mysql-wsrep-options.html#wsrep-sync-wait |
| 227 | ++ * @return void |
| 228 | ++ */ |
| 229 | ++ private function setCausalityCheckOnReadForSlave(): void |
| 230 | ++ { |
| 231 | ++ if ($this->isCausalityCheckOnReadForSlaveEnabled) { |
| 232 | ++ return; |
| 233 | ++ } |
| 234 | ++ try { |
| 235 | ++ $this->getSlaveConnection()->query('SET SESSION wsrep_sync_wait=1'); |
| 236 | ++ //phpcs:ignore Magento2.CodeAnalysis.EmptyBlock |
| 237 | ++ } catch (\Throwable $e) { |
| 238 | ++ // ignore exception, we cannot do anything here |
| 239 | ++ } |
| 240 | ++ $this->isCausalityCheckOnReadForSlaveEnabled = true; |
| 241 | ++ } |
| 242 | ++ |
| 243 | ++ /** |
| 244 | + * @inheritDoc |
| 245 | + */ |
| 246 | + public function delete($table, $where = '') |
| 247 | + { |
| 248 | +- if ($this->synchronousReplication !== true) { |
| 249 | +- $this->setUseMasterConnection(); |
| 250 | +- } |
| 251 | ++ $this->prepareReadOnlyConnection(); |
| 252 | + return $this->getMasterConnection()->delete($table, $where); |
| 253 | + } |
| 254 | + |
0 commit comments