Skip to content

Commit 1d11456

Browse files
committed
MAGETWO-93669: [Forwardport] Implement parallelization for Category Product Indexer
1 parent 79a568f commit 1d11456

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

app/code/Magento/Indexer/Model/ProcessManager.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Indexer\Model;
79

810
/**
@@ -107,7 +109,7 @@ private function multiThreadsExecute($userFunctions)
107109
*
108110
* @return bool
109111
*/
110-
private function isCanBeParalleled()
112+
private function isCanBeParalleled(): bool
111113
{
112114
return function_exists('pcntl_fork');
113115
}
@@ -117,7 +119,7 @@ private function isCanBeParalleled()
117119
*
118120
* @return bool
119121
*/
120-
private function isSetupMode()
122+
private function isSetupMode(): bool
121123
{
122124
return $this->registry->registry('setup-mode-enabled') ?: false;
123125
}
@@ -128,7 +130,7 @@ private function isSetupMode()
128130
* @param callable $userFunction
129131
* @SuppressWarnings(PHPMD.ExitExpression)
130132
*/
131-
private function startChildProcess($userFunction)
133+
private function startChildProcess(callable $userFunction)
132134
{
133135
$status = call_user_func($userFunction);
134136
$status = is_integer($status) ? $status : 0;
@@ -140,7 +142,7 @@ private function startChildProcess($userFunction)
140142
*
141143
* @param int $threadNumber
142144
*/
143-
private function executeParentProcess(&$threadNumber)
145+
private function executeParentProcess(int &$threadNumber)
144146
{
145147
$threadNumber++;
146148
if ($threadNumber >= $this->threadsCount) {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@
4242
<plugin name="page-cache-indexer-reindex-clean-cache"
4343
type="Magento\Indexer\Model\Processor\CleanCache" sortOrder="10"/>
4444
</type>
45-
45+
<type name="\Magento\Indexer\Model\ProcessManager">
46+
<arguments>
47+
<argument name="threadsCount" xsi:type="init_parameter">Magento\Indexer\Model\ProcessManager::THREADS_COUNT</argument>
48+
</arguments>
49+
</type>
4650
<type name="Magento\Framework\Console\CommandListInterface">
4751
<arguments>
4852
<argument name="commands" xsi:type="array">

lib/internal/Magento/Framework/App/ResourceConnection.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,21 @@ public function getConnection($resourceName = self::DEFAULT_CONNECTION)
104104
*/
105105
public function closeConnection($resourceName = self::DEFAULT_CONNECTION)
106106
{
107-
$processConnectionName = $this->getProcessConnectionName($this->config->getConnectionName($resourceName));
108-
if (isset($this->connections[$processConnectionName])) {
109-
$this->connections[$processConnectionName] = null;
107+
if ($resourceName === null) {
108+
foreach ($this->connections as $processConnection) {
109+
if ($processConnection !== null) {
110+
$processConnection->closeConnection();
111+
}
112+
}
113+
$this->connections = [];
114+
} else {
115+
$processConnectionName = $this->getProcessConnectionName($this->config->getConnectionName($resourceName));
116+
if (isset($this->connections[$processConnectionName])) {
117+
if ($this->connections[$processConnectionName] !== null) {
118+
$this->connections[$processConnectionName]->closeConnection();
119+
}
120+
$this->connections[$processConnectionName] = null;
121+
}
110122
}
111123
}
112124

setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ public function testInstall()
316316
$appState->expects($this->once())
317317
->method('setAreaCode')
318318
->with(\Magento\Framework\App\Area::AREA_GLOBAL);
319+
$registry = $this->createMock(\Magento\Framework\Registry::class);
319320
$this->setupFactory->expects($this->atLeastOnce())->method('create')->with($resource)->willReturn($setup);
320321
$this->dataSetupFactory->expects($this->atLeastOnce())->method('create')->willReturn($dataSetup);
321322
$this->objectManager->expects($this->any())
@@ -346,7 +347,8 @@ public function testInstall()
346347
->will($this->returnValueMap([
347348
[\Magento\Framework\App\State::class, $appState],
348349
[\Magento\Framework\App\Cache\Manager::class, $cacheManager],
349-
[\Magento\Setup\Model\DeclarationInstaller::class, $this->declarationInstallerMock]
350+
[\Magento\Setup\Model\DeclarationInstaller::class, $this->declarationInstallerMock],
351+
[\Magento\Framework\Registry::class, $registry]
350352
]));
351353
$this->adminFactory->expects($this->once())->method('create')->willReturn(
352354
$this->createMock(\Magento\Setup\Model\AdminAccount::class)

0 commit comments

Comments
 (0)