Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions patches.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@
},
"Add Zookeeper and flock locks": {
"2.2.5 - 2.2.8": "MAGECLOUD-3054__add_zookeeper_and_flock_locks__2.2.5.patch",
"2.3.0 - 2.3.1": "MAGECLOUD-3054__add_zookeeper_and_flock_locks__2.3.0.patch"
"2.3.0": "MAGECLOUD-3054__add_zookeeper_and_flock_locks__2.3.0.patch",
"2.3.1": "MAGECLOUD-3054__add_zookeeper_and_flock_locks__2.3.1.patch",
">=2.3.2 <2.3.5": "MCLOUD_6139__improvement_flock_locks__2.3.2.patch"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is now 2.3.0 - 2.3.5 - This should be ">=2.3.2 <2.3.6" ?

Copy link
Contributor Author

@BaDos BaDos Jun 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch MCLOUD_6139__improvement_flock_locks__2.3.2.patch contains changes for Magento 2.3.2 - 2.3.4-px where x is some number. So, we cannot use a constraint like this 2.3.2 - 2.3.4 and we use this one >=2.3.2 <2.3.5

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay that's fine - just wanted to check that was the reason!

},
"Reduce memory usage when importing customers and addresses": {
"2.1.4 - 2.1.10": "SET-36__fix_oom_during_customer_import__2.1.4.patch",
Expand Down Expand Up @@ -245,13 +247,17 @@
"Fix load balancer issue": {
">=2.3.4 <2.3.6": "MCLOUD-5837__fix_filesystem_load_balancer_issue__2.3.4.patch"
},
"Cache Locking performance issue": {
"2.3.3": "MDVA-27538__fix_performance_issue_in_cache_locking_mechanism__2.3.3.patch",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is a "Create Patch" PR - why are these being removed? Are the Redis patches replacing these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The patches in this PR contain the same improvements and more.

">=2.3.3-p1 <2.3.4": "MDVA-27538__fix_performance_issue_in_cache_locking_mechanism__2.3.3-p1.patch",
">=2.3.4 <2.3.5": "MDVA-26795__fix_performance_issue_in_cache_locking_mechanism__2.3.4.patch"
},
"Large amount of Keys Block Cache": {
">=2.3.1 <2.3.5": "MDVA-22950__large_amount_of_keys_block_cache__2.3.1.patch"
},
"Redis improvements": {
"2.3.0": "MCLOUD-6139_MCLOUD-6211__redis_improvement_patches__2.3.0.patch",
"2.3.1": "MCLOUD-6139_MCLOUD-6211__redis_improvement_patches__2.3.1.patch",
">=2.3.2 <2.3.3": "MCLOUD-6139_MCLOUD-6211__redis_improvement_patches__2.3.2.patch",
"2.3.3": "MCLOUD-6139_MCLOUD-6211__redis_improvement_patches__2.3.3.patch",
">=2.3.3-p1 <2.3.4": "MCLOUD-6139_MCLOUD-6211__redis_improvement_patches__2.3.3-p1.patch",
">=2.3.4 <2.3.5": "MCLOUD-6139_MCLOUD-6211__redis_improvement_patches__2.3.4.patch",
">=2.3.5 <2.3.6": "MCLOUD-6211__redis_improvement_patches__2.3.5.patch"
}
},
"magento/module-paypal": {
Expand Down
147 changes: 145 additions & 2 deletions patches/MAGECLOUD-3054__add_zookeeper_and_flock_locks__2.3.0.patch
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ diff -Naur a/app/etc/di.xml b/app/etc/di.xml
<preference for="Magento\Framework\Api\AttributeTypeResolverInterface" type="Magento\Framework\Reflection\AttributeTypeResolver" />
<preference for="Magento\Framework\Api\Search\SearchResultInterface" type="Magento\Framework\Api\Search\SearchResult" />
<preference for="Magento\Framework\Api\Search\SearchCriteriaInterface" type="Magento\Framework\Api\Search\SearchCriteria"/>
diff -Naur a/vendor/magento/framework/Lock/Backend/FileLock.php b/vendor/magento/framework/Lock/Backend/FileLock.php
diff --git a/vendor/magento/framework/Lock/Backend/FileLock.php b/vendor/magento/framework/Lock/Backend/FileLock.php
new file mode 100644
--- /dev/null
+++ b/vendor/magento/framework/Lock/Backend/FileLock.php
@@ -0,0 +1,194 @@
@@ -0,0 +1,196 @@
+<?php
+/**
+ * Copyright © Magento, Inc. All rights reserved.
Expand Down Expand Up @@ -107,6 +108,7 @@ diff -Naur a/vendor/magento/framework/Lock/Backend/FileLock.php b/vendor/magento
+
+ while (!$this->tryToLock($fileResource)) {
+ if (!$skipDeadline && $deadline <= microtime(true)) {
+ $this->tryToUnlock($fileResource);
+ $this->fileDriver->fileClose($fileResource);
+ return false;
+ }
Expand Down Expand Up @@ -140,6 +142,7 @@ diff -Naur a/vendor/magento/framework/Lock/Backend/FileLock.php b/vendor/magento
+ } else {
+ $result = true;
+ }
+ $this->tryToUnlock($fileResource);
+ $this->fileDriver->fileClose($fileResource);
+ }
+ } catch (FileSystemException $exception) {
Expand Down Expand Up @@ -208,6 +211,7 @@ diff -Naur a/vendor/magento/framework/Lock/Backend/FileLock.php b/vendor/magento
+ }
+ }
+}

diff -Naur a/vendor/magento/framework/Lock/Backend/Zookeeper.php b/vendor/magento/framework/Lock/Backend/Zookeeper.php
--- /dev/null
+++ b/vendor/magento/framework/Lock/Backend/Zookeeper.php
Expand Down Expand Up @@ -1053,3 +1057,142 @@ diff -Naur a/setup/src/Magento/Setup/Model/ConfigOptionsList/Lock.php b/setup/sr
+ }
+ }
+}
diff -Nuar a/vendor/magento/framework/Lock/Backend/Cache.php b/vendor/magento/framework/Lock/Backend/Cache.php
new file mode 100644
--- /dev/null
+++ b/vendor/magento/framework/Lock/Backend/Cache.php
@@ -0,0 +1,134 @@
+<?php
+/**
+ * Copyright © Magento, Inc. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+declare(strict_types=1);
+
+namespace Magento\Framework\Lock\Backend;
+
+use Magento\Framework\Cache\FrontendInterface;
+
+/**
+ * Implementation of the lock manager on the basis of the caching system.
+ */
+class Cache implements \Magento\Framework\Lock\LockManagerInterface
+{
+ /**
+ * Prefix for marking that key is locked or not.
+ */
+ const LOCK_PREFIX = 'LOCKED_RECORD_INFO_';
+
+ /**
+ * @var FrontendInterface
+ */
+ private $cache;
+
+ /**
+ * Sign for locks, helps to avoid removing a lock that was created by another client
+ *
+ * @string
+ */
+ private $lockSign;
+
+ /**
+ * @param FrontendInterface $cache
+ */
+ public function __construct(FrontendInterface $cache)
+ {
+ $this->cache = $cache;
+ $this->lockSign = $this->generateLockSign();
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function lock(string $name, int $timeout = -1): bool
+ {
+ if (empty($this->lockSign)) {
+ $this->lockSign = $this->generateLockSign();
+ }
+
+ $data = $this->cache->load($this->getIdentifier($name));
+
+ if (false !== $data) {
+ return false;
+ }
+
+ $timeout = $timeout <= 0 ? null : $timeout;
+ $this->cache->save($this->lockSign, $this->getIdentifier($name), [], $timeout);
+
+ $data = $this->cache->load($this->getIdentifier($name));
+
+ if ($data === $this->lockSign) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function unlock(string $name): bool
+ {
+ if (empty($this->lockSign)) {
+ return false;
+ }
+
+ $data = $this->cache->load($this->getIdentifier($name));
+
+ if (false === $data) {
+ return false;
+ }
+
+ $removeResult = false;
+ if ($data === $this->lockSign) {
+ $removeResult = (bool)$this->cache->remove($this->getIdentifier($name));
+ }
+
+ return $removeResult;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function isLocked(string $name): bool
+ {
+ return (bool)$this->cache->test($this->getIdentifier($name));
+ }
+
+ /**
+ * Get cache locked identifier based on cache identifier.
+ *
+ * @param string $cacheIdentifier
+ * @return string
+ */
+ private function getIdentifier(string $cacheIdentifier): string
+ {
+ return self::LOCK_PREFIX . $cacheIdentifier;
+ }
+
+ /**
+ * Function that generates lock sign that helps to avoid removing a lock that was created by another client.
+ *
+ * @return string
+ */
+ private function generateLockSign()
+ {
+ $sign = implode(
+ '-',
+ [
+ \getmypid(), \crc32(\gethostname())
+ ]
+ );
+
+ try {
+ $sign .= '-' . \bin2hex(\random_bytes(4));
+ } catch (\Exception $e) {
+ $sign .= '-' . \uniqid('-uniqid-');
+ }
+
+ return $sign;
+ }
+}
Loading