Skip to content

Commit d2b9d7a

Browse files
committed
Merge remote-tracking branch 'origin/2.3-develop' into MC-15406
2 parents 8e75d54 + 19e9ada commit d2b9d7a

File tree

26 files changed

+2104
-207
lines changed

26 files changed

+2104
-207
lines changed

app/code/Magento/Config/App/Config/Type/System.php

Lines changed: 50 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Config\App\Config\Type;
78

89
use Magento\Framework\App\Config\ConfigSourceInterface;
@@ -13,18 +14,20 @@
1314
use Magento\Config\App\Config\Type\System\Reader;
1415
use Magento\Framework\App\ScopeInterface;
1516
use Magento\Framework\Cache\FrontendInterface;
17+
use Magento\Framework\Cache\LockGuardedCacheLoader;
1618
use Magento\Framework\Lock\LockManagerInterface;
1719
use Magento\Framework\Serialize\SerializerInterface;
1820
use Magento\Store\Model\Config\Processor\Fallback;
19-
use Magento\Store\Model\ScopeInterface as StoreScope;
2021
use Magento\Framework\Encryption\Encryptor;
22+
use Magento\Store\Model\ScopeInterface as StoreScope;
2123

2224
/**
2325
* System configuration type
2426
*
2527
* @api
2628
* @since 100.1.2
2729
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
30+
* @SuppressWarnings(PHPMD.UnusedPrivateMethod)
2831
*/
2932
class System implements ConfigTypeInterface
3033
{
@@ -42,22 +45,6 @@ class System implements ConfigTypeInterface
4245
* @var string
4346
*/
4447
private static $lockName = 'SYSTEM_CONFIG';
45-
/**
46-
* Timeout between retrieves to load the configuration from the cache.
47-
*
48-
* Value of the variable in microseconds.
49-
*
50-
* @var int
51-
*/
52-
private static $delayTimeout = 100000;
53-
/**
54-
* Lifetime of the lock for write in cache.
55-
*
56-
* Value of the variable in seconds.
57-
*
58-
* @var int
59-
*/
60-
private static $lockTimeout = 42;
6148

6249
/**
6350
* @var array
@@ -106,9 +93,9 @@ class System implements ConfigTypeInterface
10693
private $encryptor;
10794

10895
/**
109-
* @var LockManagerInterface
96+
* @var LockGuardedCacheLoader
11097
*/
111-
private $locker;
98+
private $lockQuery;
11299

113100
/**
114101
* @param ConfigSourceInterface $source
@@ -122,6 +109,7 @@ class System implements ConfigTypeInterface
122109
* @param Reader|null $reader
123110
* @param Encryptor|null $encryptor
124111
* @param LockManagerInterface|null $locker
112+
* @param LockGuardedCacheLoader|null $lockQuery
125113
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
126114
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
127115
*/
@@ -136,7 +124,8 @@ public function __construct(
136124
$configType = self::CONFIG_TYPE,
137125
Reader $reader = null,
138126
Encryptor $encryptor = null,
139-
LockManagerInterface $locker = null
127+
LockManagerInterface $locker = null,
128+
LockGuardedCacheLoader $lockQuery = null
140129
) {
141130
$this->postProcessor = $postProcessor;
142131
$this->cache = $cache;
@@ -145,8 +134,8 @@ public function __construct(
145134
$this->reader = $reader ?: ObjectManager::getInstance()->get(Reader::class);
146135
$this->encryptor = $encryptor
147136
?: ObjectManager::getInstance()->get(Encryptor::class);
148-
$this->locker = $locker
149-
?: ObjectManager::getInstance()->get(LockManagerInterface::class);
137+
$this->lockQuery = $lockQuery
138+
?: ObjectManager::getInstance()->get(LockGuardedCacheLoader::class);
150139
}
151140

152141
/**
@@ -225,91 +214,64 @@ private function getWithParts($path)
225214
}
226215

227216
/**
228-
* Make lock on data load.
229-
*
230-
* @param callable $dataLoader
231-
* @param bool $flush
232-
* @return array
233-
*/
234-
private function lockedLoadData(callable $dataLoader, bool $flush = false): array
235-
{
236-
$cachedData = $dataLoader(); //optimistic read
237-
238-
while ($cachedData === false && $this->locker->isLocked(self::$lockName)) {
239-
usleep(self::$delayTimeout);
240-
$cachedData = $dataLoader();
241-
}
242-
243-
while ($cachedData === false) {
244-
try {
245-
if ($this->locker->lock(self::$lockName, self::$lockTimeout)) {
246-
if (!$flush) {
247-
$data = $this->readData();
248-
$this->cacheData($data);
249-
$cachedData = $data;
250-
} else {
251-
$this->cache->clean(\Zend_Cache::CLEANING_MODE_MATCHING_TAG, [self::CACHE_TAG]);
252-
$cachedData = [];
253-
}
254-
}
255-
} finally {
256-
$this->locker->unlock(self::$lockName);
257-
}
258-
259-
if ($cachedData === false) {
260-
usleep(self::$delayTimeout);
261-
$cachedData = $dataLoader();
262-
}
263-
}
264-
265-
return $cachedData;
266-
}
267-
268-
/**
269-
* Load configuration data for all scopes
217+
* Load configuration data for all scopes.
270218
*
271219
* @return array
272220
*/
273221
private function loadAllData()
274222
{
275-
return $this->lockedLoadData(function () {
223+
$loadAction = function () {
276224
$cachedData = $this->cache->load($this->configType);
277225
$data = false;
278226
if ($cachedData !== false) {
279227
$data = $this->serializer->unserialize($this->encryptor->decrypt($cachedData));
280228
}
281229
return $data;
282-
});
230+
};
231+
232+
return $this->lockQuery->lockedLoadData(
233+
self::$lockName,
234+
$loadAction,
235+
\Closure::fromCallable([$this, 'readData']),
236+
\Closure::fromCallable([$this, 'cacheData'])
237+
);
283238
}
284239

285240
/**
286-
* Load configuration data for default scope
241+
* Load configuration data for default scope.
287242
*
288243
* @param string $scopeType
289244
* @return array
290245
*/
291246
private function loadDefaultScopeData($scopeType)
292247
{
293-
return $this->lockedLoadData(function () use ($scopeType) {
248+
$loadAction = function () use ($scopeType) {
294249
$cachedData = $this->cache->load($this->configType . '_' . $scopeType);
295250
$scopeData = false;
296251
if ($cachedData !== false) {
297252
$scopeData = [$scopeType => $this->serializer->unserialize($this->encryptor->decrypt($cachedData))];
298253
}
299254
return $scopeData;
300-
});
255+
};
256+
257+
return $this->lockQuery->lockedLoadData(
258+
self::$lockName,
259+
$loadAction,
260+
\Closure::fromCallable([$this, 'readData']),
261+
\Closure::fromCallable([$this, 'cacheData'])
262+
);
301263
}
302264

303265
/**
304-
* Load configuration data for a specified scope
266+
* Load configuration data for a specified scope.
305267
*
306268
* @param string $scopeType
307269
* @param string $scopeId
308270
* @return array
309271
*/
310272
private function loadScopeData($scopeType, $scopeId)
311273
{
312-
return $this->lockedLoadData(function () use ($scopeType, $scopeId) {
274+
$loadAction = function () use ($scopeType, $scopeId) {
313275
$cachedData = $this->cache->load($this->configType . '_' . $scopeType . '_' . $scopeId);
314276
$scopeData = false;
315277
if ($cachedData === false) {
@@ -329,7 +291,14 @@ private function loadScopeData($scopeType, $scopeId)
329291
}
330292

331293
return $scopeData;
332-
});
294+
};
295+
296+
return $this->lockQuery->lockedLoadData(
297+
self::$lockName,
298+
$loadAction,
299+
\Closure::fromCallable([$this, 'readData']),
300+
\Closure::fromCallable([$this, 'cacheData'])
301+
);
333302
}
334303

335304
/**
@@ -371,7 +340,7 @@ private function cacheData(array $data)
371340
}
372341

373342
/**
374-
* Walk nested hash map by keys from $pathParts
343+
* Walk nested hash map by keys from $pathParts.
375344
*
376345
* @param array $data to walk in
377346
* @param array $pathParts keys path
@@ -408,7 +377,7 @@ private function readData(): array
408377
}
409378

410379
/**
411-
* Clean cache and global variables cache
380+
* Clean cache and global variables cache.
412381
*
413382
* Next items cleared:
414383
* - Internal property intended to store already loaded configuration data
@@ -420,11 +389,13 @@ private function readData(): array
420389
public function clean()
421390
{
422391
$this->data = [];
423-
$this->lockedLoadData(
424-
function () {
425-
return false;
426-
},
427-
true
392+
$cleanAction = function () {
393+
$this->cache->clean(\Zend_Cache::CLEANING_MODE_MATCHING_TAG, [self::CACHE_TAG]);
394+
};
395+
396+
$this->lockQuery->lockedCleanData(
397+
self::$lockName,
398+
$cleanAction
428399
);
429400
}
430401
}

app/code/Magento/Config/etc/di.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,18 @@
9090
<argument name="preProcessor" xsi:type="object">Magento\Framework\App\Config\PreProcessorComposite</argument>
9191
<argument name="serializer" xsi:type="object">Magento\Framework\Serialize\Serializer\Serialize</argument>
9292
<argument name="reader" xsi:type="object">Magento\Config\App\Config\Type\System\Reader\Proxy</argument>
93-
<argument name="locker" xsi:type="object">Magento\Framework\Lock\Backend\Cache</argument>
93+
<argument name="lockQuery" xsi:type="object">systemConfigQueryLocker</argument>
9494
</arguments>
9595
</type>
96+
97+
<virtualType name="systemConfigQueryLocker" type="Magento\Framework\Cache\LockGuardedCacheLoader">
98+
<arguments>
99+
<argument name="locker" xsi:type="object">Magento\Framework\Lock\Backend\Cache</argument>
100+
<argument name="lockTimeout" xsi:type="number">42000</argument>
101+
<argument name="delayTimeout" xsi:type="number">100</argument>
102+
</arguments>
103+
</virtualType>
104+
96105
<type name="Magento\Config\App\Config\Type\System\Reader">
97106
<arguments>
98107
<argument name="source" xsi:type="object">systemConfigSourceAggregated</argument>

app/code/Magento/Deploy/Console/DeployStaticOptions.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Magento\Deploy\Console;
88

9+
use Magento\Deploy\Process\Queue;
910
use Symfony\Component\Console\Input\InputOption;
1011
use Symfony\Component\Console\Input\InputArgument;
1112

@@ -57,6 +58,11 @@ class DeployStaticOptions
5758
*/
5859
const JOBS_AMOUNT = 'jobs';
5960

61+
/**
62+
* Key for max execution time option
63+
*/
64+
const MAX_EXECUTION_TIME = 'max-execution-time';
65+
6066
/**
6167
* Force run of static deploy
6268
*/
@@ -150,6 +156,7 @@ public function getOptionsList()
150156
* Basic options
151157
*
152158
* @return array
159+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
153160
*/
154161
private function getBasicOptions()
155162
{
@@ -216,6 +223,13 @@ private function getBasicOptions()
216223
'Enable parallel processing using the specified number of jobs.',
217224
self::DEFAULT_JOBS_AMOUNT
218225
),
226+
new InputOption(
227+
self::MAX_EXECUTION_TIME,
228+
null,
229+
InputOption::VALUE_OPTIONAL,
230+
'The maximum expected execution time of deployment static process (in seconds).',
231+
Queue::DEFAULT_MAX_EXEC_TIME
232+
),
219233
new InputOption(
220234
self::SYMLINK_LOCALE,
221235
null,

app/code/Magento/Deploy/Service/DeployStaticContent.php

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,24 +85,26 @@ public function deploy(array $options)
8585
return;
8686
}
8787

88-
$queue = $this->queueFactory->create(
89-
[
90-
'logger' => $this->logger,
91-
'options' => $options,
92-
'maxProcesses' => $this->getProcessesAmount($options),
93-
'deployPackageService' => $this->objectManager->create(
94-
\Magento\Deploy\Service\DeployPackage::class,
95-
[
96-
'logger' => $this->logger
97-
]
98-
)
99-
]
100-
);
88+
$queueOptions = [
89+
'logger' => $this->logger,
90+
'options' => $options,
91+
'maxProcesses' => $this->getProcessesAmount($options),
92+
'deployPackageService' => $this->objectManager->create(
93+
\Magento\Deploy\Service\DeployPackage::class,
94+
[
95+
'logger' => $this->logger
96+
]
97+
)
98+
];
99+
100+
if (isset($options[Options::MAX_EXECUTION_TIME])) {
101+
$queueOptions['maxExecTime'] = (int)$options[Options::MAX_EXECUTION_TIME];
102+
}
101103

102104
$deployStrategy = $this->deployStrategyFactory->create(
103105
$options[Options::STRATEGY],
104106
[
105-
'queue' => $queue
107+
'queue' => $this->queueFactory->create($queueOptions)
106108
]
107109
);
108110

@@ -133,6 +135,8 @@ public function deploy(array $options)
133135
}
134136

135137
/**
138+
* Returns amount of parallel processes, returns zero if option wasn't set.
139+
*
136140
* @param array $options
137141
* @return int
138142
*/
@@ -142,6 +146,8 @@ private function getProcessesAmount(array $options)
142146
}
143147

144148
/**
149+
* Checks if need to refresh only version.
150+
*
145151
* @param array $options
146152
* @return bool
147153
*/

0 commit comments

Comments
 (0)