colinmollenhour / Cm_Cache_Backend_Redis

A Zend_Cache backend for Redis with full support for tags (works great with Magento)
Other
390 stars 142 forks source link

Database connection settings are cached and shared across Redis instances and Magento cluster backend nodes #159

Open Guard1an opened 4 years ago

Guard1an commented 4 years ago

When running multiple synchronized Redis instances in master+slave or cluster configuration the Magento configuration cache is shared among different Magento backend nodes. When etc/local.xml file differs between nodes shared cache causes nodes miss-configuration issues. I.e. when Node1 is configured to use Mysql1 backend and Node2 to use Mysql2 backend due to shared config cache all nodes will share the same Mysql backend settings (one which was cached first).

I applied a dirty fix to Core/Model/Config.php to address this issue. See patch attached.

--- D:/Storage/www/avtoto/html/svn/branches/2.0_staging/app/code/core/Mage/Core/Model/Config.php    Tue Jan 30 09:57:29 2018
+++ D:/Storage/www/avtoto/html/svn/branches/2.0_staging/app/code/local/Mage/Core/Model/Config.php   Tue Aug 18 11:45:43 2020
@@ -462,0 +463 @@ class Mage_Core_Model_Config extends Mage_Core_Mod
+            unset($xml->global->resources->default_setup->connection);
@@ -1636,0 +1638,23 @@ class Mage_Core_Model_Config extends Mage_Core_Mod
+
+    /**
+     * Enter description here...
+     *
+     * @return boolean
+     */
+    public function loadCache()
+    {
+        if (!$this->validateCacheChecksum()) {
+            return false;
+        }
+
+        $xmlString = $this->_loadCache($this->getCacheId());
+        $xml = simplexml_load_string($xmlString, $this->_elementClass);
+        if ($xml) {
+            //$this->_xml = $xml;
+            $this->getNode()->extend($xml, true);
+            $this->setCacheSaved(true);
+            return true;
+        }
+
+        return false;
+    }

Please share your experience on Magento cluster setup, how do you deal with shared configuration among nodes?

colinmollenhour commented 4 years ago

I can see the merits of what you're trying to do but I've always approached it more at the system level. E.g. using a load balancer or a DNS address that resolves to multiple IPs (managed by something like Kubernetes or Docker Swarm). So having the same local.xml across all nodes is a less flexible approach but I also think it has some merits.

If you aren't using Docker I'd strongly recommend looking into it.