Skip to content

Enable indexer application locking by default #36956

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

Open
wants to merge 7 commits into
base: 2.4-develop
Choose a base branch
from
Open
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
27 changes: 19 additions & 8 deletions app/code/Magento/Indexer/Model/Indexer/State.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Indexer\Model\Indexer;

use Magento\Framework\Indexer\StateInterface;
Expand Down Expand Up @@ -70,6 +72,7 @@ public function __construct(
if (!isset($data['status'])) {
$data['status'] = self::STATUS_INVALID;
}

$this->lockManager = $lockManager ?: \Magento\Framework\App\ObjectManager::getInstance()->get(
\Magento\Framework\Lock\LockManagerInterface::class
);
Expand All @@ -86,18 +89,21 @@ public function __construct(
*/
public function getIndexerId()
{
return parent::getIndexerId();
$id = parent::getIndexerId();
return $id;
}

/**
* Set indexer id
*
* @param string $value
*
* @return $this
*/
public function setIndexerId($value)
{
return parent::setIndexerId($value);
$self = parent::setIndexerId($value);
return $self;
}

/**
Expand All @@ -108,8 +114,7 @@ public function setIndexerId($value)
public function getStatus()
{
if ($this->isUseApplicationLock()) {
if (
parent::getStatus() == StateInterface::STATUS_WORKING &&
if (parent::getStatus() == StateInterface::STATUS_WORKING &&
!$this->lockManager->isLocked($this->lockPrefix . $this->getIndexerId())
) {
return StateInterface::STATUS_INVALID;
Expand All @@ -126,24 +131,28 @@ public function getStatus()
*/
public function getUpdated()
{
return parent::getUpdated();
$updated = parent::getUpdated();
return $updated;
}

/**
* Set updated
*
* @param string $value
*
* @return $this
*/
public function setUpdated($value)
{
return parent::setUpdated($value);
$self = parent::setUpdated($value);
return $self;
}

/**
* Fill object with state data by view ID
*
* @param string $indexerId
*
* @return $this
*/
public function loadByIndexer($indexerId)
Expand All @@ -159,6 +168,7 @@ public function loadByIndexer($indexerId)
* Status setter
*
* @param string $status
*
* @return $this
*/
public function setStatus($status)
Expand All @@ -170,6 +180,7 @@ public function setStatus($status)
$this->lockManager->unlock($this->lockPrefix . $this->getIndexerId());
}
}

return parent::setStatus($status);
}

Expand All @@ -189,8 +200,8 @@ public function beforeSave()
*
* @return bool
*/
private function isUseApplicationLock()
private function isUseApplicationLock(): bool
{
return $this->configReader->get($this->useApplicationLockConfig) ?: false;
return (bool) ($this->configReader->get($this->useApplicationLockConfig) ?? true);
}
}
7 changes: 3 additions & 4 deletions app/code/Magento/Indexer/Model/Mview/View/State.php
Original file line number Diff line number Diff line change
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 Expand Up @@ -229,8 +228,8 @@ public function setVersionId($versionId)
*
* @return bool
*/
private function isUseApplicationLock()
private function isUseApplicationLock(): bool
{
return $this->configReader->get($this->useApplicationLockConfig) ?: false;
return (bool) ($this->configReader->get($this->useApplicationLockConfig) ?? true);
}
}