Skip to content

Set default indexer mode to 'schedule' #36347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
5 changes: 2 additions & 3 deletions app/code/Magento/Indexer/Model/Mview/View/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function __construct(
\Magento\Framework\App\DeploymentConfig $configReader = null
) {
if (!isset($data['mode'])) {
$data['mode'] = self::MODE_DISABLED;
$data['mode'] = self::MODE_ENABLED;
}
if (!isset($data['status'])) {
$data['status'] = self::STATUS_IDLE;
Expand Down Expand Up @@ -150,8 +150,7 @@ public function getStatus()
{
$status = $this->getData('status');
if ($this->isUseApplicationLock()) {
if (
$status == \Magento\Framework\Mview\View\StateInterface::STATUS_WORKING &&
if ($status == \Magento\Framework\Mview\View\StateInterface::STATUS_WORKING &&
!$this->lockManager->isLocked($this->lockPrefix . $this->getViewId())
) {
return \Magento\Framework\Mview\View\StateInterface::STATUS_IDLE;
Expand Down
10 changes: 10 additions & 0 deletions app/code/Magento/Indexer/Test/Unit/Model/Mview/View/StateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\Model\Context;
use Magento\Framework\Mview\View\StateInterface;
use Magento\Framework\Registry;
use Magento\Indexer\Model\Mview\View\State;
use Magento\Indexer\Model\ResourceModel\Mview\View\State\Collection;
Expand Down Expand Up @@ -158,4 +159,13 @@ public function testSetterAndGetterWithApplicationLock($setStatus, $getStatus, $
$this->model->setStatus($setStatus);
$this->assertEquals($getStatus, $this->model->getStatus());
}

public function testDefaultValues(): void
{
$this->assertEquals(StateInterface::MODE_ENABLED, $this->model->getMode());
$this->assertEquals(StateInterface::STATUS_IDLE, $this->model->getStatus());
$this->assertNull($this->model->getUpdated());
$this->assertNull($this->model->getVersionId());
$this->assertNull($this->model->getViewId());
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/Indexer/etc/db_schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<column xsi:type="int" name="state_id" unsigned="true" nullable="false" identity="true"
comment="View State ID"/>
<column xsi:type="varchar" name="view_id" nullable="true" length="255" comment="View ID"/>
<column xsi:type="varchar" name="mode" nullable="true" length="16" default="disabled" comment="View Mode"/>
<column xsi:type="varchar" name="mode" nullable="true" length="16" default="enabled" comment="View Mode"/>
<column xsi:type="varchar" name="status" nullable="true" length="16" default="idle" comment="View Status"/>
<column xsi:type="datetime" name="updated" on_update="false" nullable="true" comment="View updated time"/>
<column xsi:type="int" name="version_id" unsigned="true" nullable="true" identity="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ return [
'--remote-storage-bucket' => 'myBucket',
'--remote-storage-region' => 'us-east-1',
]
]
],
*/
[
// Indexers start in 'schedule' mode, but many of our tests assume that
// indexers are up to date. Because we don't run cron in our testsuite,
// we need to ensure that the indexers are up to date before we run our
// tests.
'command' => 'indexer:reindex',
'config' => [],
],
];
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ public function install($cleanup)
}
$this->_shell->execute($installCmd, $installArgs);
}
/* Set Indexer mode as "Update on Save" & Reindex all the Indexers */
$this->_shell->execute(
'php -f ' . BP . '/bin/magento indexer:set-mode realtime -vvv'
);
$this->_shell->execute(
'php -f ' . BP . '/bin/magento indexer:reindex -vvv'
);

$this->runPostInstallCommands();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ return [
[
'command' => 'setup:upgrade',
'config' => []
]
],
*/
[
// Indexers start in 'schedule' mode, but many of our tests assume that
// indexers are up to date. Because we don't run cron in our testsuite,
// we need to ensure that the indexers are up to date before we run our
// tests.
'command' => 'indexer:reindex',
'config' => [],
],
];
36 changes: 0 additions & 36 deletions setup/src/Magento/Setup/Model/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\RuntimeException;
use Magento\Framework\Filesystem;
use Magento\Framework\Indexer\IndexerInterface;
use Magento\Framework\Indexer\IndexerRegistry;
use Magento\Framework\Model\ResourceModel\Db\Context;
use Magento\Framework\Module\ModuleList\Loader as ModuleLoader;
use Magento\Framework\Module\ModuleListInterface;
Expand All @@ -47,7 +45,6 @@
use Magento\Framework\Setup\UpgradeDataInterface;
use Magento\Framework\Setup\UpgradeSchemaInterface;
use Magento\Framework\Validation\ValidationException;
use Magento\Indexer\Model\Indexer\Collection;
use Magento\RemoteStorage\Driver\DriverException;
use Magento\Setup\Console\Command\InstallCommand;
use Magento\Setup\Controller\ResponseTypeInterface;
Expand Down Expand Up @@ -348,8 +345,6 @@ public function __construct(
* @throws FileSystemException
* @throws LocalizedException
* @throws RuntimeException
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function install($request)
{
Expand Down Expand Up @@ -387,9 +382,6 @@ public function install($request)
$script[] = ['Disabling Maintenance Mode:', 'setMaintenanceMode', [0]];
$script[] = ['Post installation file permissions check...', 'checkApplicationFilePermissions', []];
$script[] = ['Write installation date...', 'writeInstallationDate', []];
if (empty($request['magento-init-params'])) {
$script[] = ['Enabling Update by Schedule Indexer Mode...', 'setIndexerModeSchedule', []];
}
$estimatedModules = $this->createModulesConfig($request, true);
$total = count($script) + 4 * count(array_filter($estimatedModules));
$this->progress = new Installer\Progress($total, 0);
Expand Down Expand Up @@ -1799,32 +1791,4 @@ private function revertRemoteStorageConfiguration()
$configData = [$remoteStorageData->getFileKey() => $remoteStorageData->getData()];
$this->deploymentConfigWriter->saveConfig($configData, true);
}

/**
* Set Index mode as 'Update by Schedule'
*
* @return void
* @SuppressWarnings(PHPMD.UnusedPrivateMethod) Called by install() via callback.
* @throws LocalizedException
* @throws \Exception
*/
private function setIndexerModeSchedule(): void
{
/** @var Collection $indexCollection */
$indexCollection = $this->objectManagerProvider->get()->get(Collection::class);
$indexerIds = $indexCollection->getAllIds();
try {
foreach ($indexerIds as $indexerId) {
/** @var IndexerInterface $model */
$model = $this->objectManagerProvider->get()->get(IndexerRegistry::class)
->get($indexerId);
$model->setScheduled(true);
}
$this->log->log(__('%1 indexer(s) are in "Update by Schedule" mode.', count($indexerIds)));
} catch (LocalizedException $e) {
$this->log->log($e->getMessage());
} catch (\Exception $e) {
$this->log->log(__("We couldn't change indexer(s)' mode because of an error: ".$e->getMessage()));
}
}
}
60 changes: 0 additions & 60 deletions setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
use Magento\Framework\Filesystem;
use Magento\Framework\Filesystem\Directory\WriteInterface;
use Magento\Framework\Filesystem\DriverPool;
use Magento\Framework\Indexer\IndexerInterface;
use Magento\Framework\Indexer\IndexerRegistry;
use Magento\Framework\Model\ResourceModel\Db\Context;
use Magento\Framework\Module\ModuleList\Loader;
use Magento\Framework\Module\ModuleListInterface;
Expand All @@ -45,7 +43,6 @@
use Magento\Framework\Setup\SchemaListener;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Framework\Validation\ValidationException;
use Magento\Indexer\Model\Indexer\Collection;
use Magento\RemoteStorage\Driver\DriverException;
use Magento\RemoteStorage\Setup\ConfigOptionsList as RemoteStorageValidator;
use Magento\Setup\Console\Command\InstallCommand;
Expand Down Expand Up @@ -228,19 +225,6 @@ class InstallerTest extends TestCase
*/
private $patchApplierFactoryMock;

/**
* @var Collection|MockObject
*/
private $indexerMock;
/**
* @var IndexerRegistry|MockObject
*/
private $indexerRegistryMock;
/**
* @var IndexerInterface|MockObject
*/
private $indexerInterfaceMock;

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -288,10 +272,6 @@ protected function setUp(): void
$this->patchApplierFactoryMock->expects($this->any())->method('create')->willReturn(
$this->patchApplierMock
);
$this->indexerMock = $this->createMock(Collection::class);
$this->indexerRegistryMock = $this->createMock(IndexerRegistry::class);
$this->indexerInterfaceMock = $this->getMockForAbstractClass(IndexerInterface::class);

$this->object = $this->createObject();
}

Expand Down Expand Up @@ -460,8 +440,6 @@ public function testInstall(array $request, array $logMessages, array $logMetaMe
[Registry::class, $registry],
[SearchConfig::class, $searchConfigMock],
[RemoteStorageValidator::class, $remoteStorageValidatorMock],
[Collection::class, $this->indexerMock],
[IndexerRegistry::class, $this->indexerRegistryMock]
]
);
$this->adminFactory->expects($this->any())->method('create')->willReturn(
Expand All @@ -477,15 +455,6 @@ public function testInstall(array $request, array $logMessages, array $logMetaMe
$this->filePermissions->expects($this->once())
->method('getMissingWritableDirectoriesForDbUpgrade')
->willReturn([]);
$this->indexerMock->expects($this->once())->method('getAllIds')->willReturn(
[
'catalog_category_product',
'catalog_product_category',
]
);
$this->indexerRegistryMock->expects($this->exactly(2))->method('get')->willReturn(
$this->indexerInterfaceMock
);
$this->logger->expects($this->exactly(count($logMessages)))->method('log')
->willReturnCallback(function ($arg) use ($logMessages) {
if ($arg == $logMessages) {
Expand Down Expand Up @@ -546,8 +515,6 @@ public static function installDataProvider()
['Disabling Maintenance Mode:'],
['Post installation file permissions check...'],
['Write installation date...'],
['Enabling Update by Schedule Indexer Mode...'],
['2 indexer(s) are in "Update by Schedule" mode.'],
['Sample Data is installed with errors. See log file for details']
],
'logMetaMessages' => [
Expand Down Expand Up @@ -621,8 +588,6 @@ public static function installDataProvider()
['Disabling Maintenance Mode:'],
['Post installation file permissions check...'],
['Write installation date...'],
['Enabling Update by Schedule Indexer Mode...'],
['2 indexer(s) are in "Update by Schedule" mode.'],
['Sample Data is installed with errors. See log file for details']
],
'logMetaMessages' => [
Expand Down Expand Up @@ -794,19 +759,8 @@ public function testInstallWithOrderIncrementPrefix(array $request, array $logMe
[Registry::class, $registry],
[SearchConfig::class, $searchConfigMock],
[RemoteStorageValidator::class, $remoteStorageValidatorMock],
[Collection::class, $this->indexerMock],
[IndexerRegistry::class, $this->indexerRegistryMock]
]
);
$this->indexerMock->expects($this->once())->method('getAllIds')->willReturn(
[
'catalog_category_product',
'catalog_product_category',
]
);
$this->indexerRegistryMock->expects($this->exactly(2))->method('get')->willReturn(
$this->indexerInterfaceMock
);
$this->adminFactory->expects($this->any())->method('create')->willReturn(
$this->createMock(AdminAccount::class)
);
Expand Down Expand Up @@ -888,8 +842,6 @@ public static function installWithOrderIncrementPrefixDataProvider(): array
['Disabling Maintenance Mode:'],
['Post installation file permissions check...'],
['Write installation date...'],
['Enabling Update by Schedule Indexer Mode...'],
['2 indexer(s) are in "Update by Schedule" mode.'],
['Sample Data is installed with errors. See log file for details']
],
'logMetaMessages' => [
Expand Down Expand Up @@ -1272,9 +1224,6 @@ public function testInstallWithUnresolvableRemoteStorageValidator()
4 => [\Magento\Framework\App\State::class, $appState],
5 => [Registry::class, $registry],
6 => [Manager::class, $cacheManager],
7 => [Collection::class, $this->indexerMock],
8 => [IndexerRegistry::class, $this->indexerRegistryMock],
9 => [IndexerRegistry::class, $this->indexerRegistryMock]
];
$withArgs = $willReturnArgs = [];

Expand Down Expand Up @@ -1306,15 +1255,6 @@ public function testInstallWithUnresolvableRemoteStorageValidator()
}
});

$this->indexerMock->expects($this->once())->method('getAllIds')->willReturn(
[
'catalog_category_product',
'catalog_product_category',
]
);
$this->indexerRegistryMock->expects($this->exactly(2))->method('get')->willReturn(
$this->indexerInterfaceMock
);
$this->adminFactory->expects(static::any())->method('create')->willReturn(
$this->createMock(AdminAccount::class)
);
Expand Down