Skip to content
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

[2.2] - Add command to view mview state and queue #12122

Merged
merged 18 commits into from
Dec 7, 2017

Conversation

convenient
Copy link
Contributor

@convenient convenient commented Nov 8, 2017

Description

Update indexer:status to output information about the schedule mview backlog

screen shot 2017-12-04 at 16 55 50

Manual testing scenarios

  1. Enable an indexer php bin/magento indexer:set-mode schedule catalog_product_price
  2. Trigger an action on the product price that will update the _cl table
  3. Run php bin/magento indexer:status to see the backlog increase
  4. magerun2 sys:cron:run indexer_update_all_views will trigger the mview processes
  5. See the backlog decrease

Original Description

This is similar to the magerun1 command here: netz98/n98-magerun#891

I like the ability to view the mview queue in realtime as its being processed, it can be quite helpful when debugging indexing issues.

This command will actually show how many items are in the list pending processing, as well information from the mview_state table.

php bin/magento indexer:status:mview

screen shot 2017-11-05 at 20 47 47

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

This is similar to the magerun1 command here: netz98/n98-magerun#891

I like the ability to view the mview queue in realtime as its being processed, it can be quite helpful when debugging indexing issues.

This command will actually show how many items are in the list pending processing, as well information from the `mview_state` table.

```
php bin/magento indexer:status:mview
+---------------------------+----------+--------+---------------------+------------+---------+
| ID                        | Mode     | Status | Updated             | Version ID | Backlog |
+---------------------------+----------+--------+---------------------+------------+---------+
| catalog_category_product  | enabled  | idle   | 2017-11-02 10:00:00 | 1          | 0       |
| catalog_product_attribute | enabled  | idle   | 2017-11-02 10:00:00 | 1          | 1       |
| catalog_product_category  | disabled | idle   | 2017-11-02 10:00:00 | 1          | 0       |
| catalog_product_price     | enabled  | idle   | 2017-11-02 10:00:00 | 1          | 0       |
+---------------------------+----------+--------+---------------------+------------+---------+
```

I'll point this PR into 2.1.x and raise a separate PR to pop it into 2.2.x.
@convenient convenient changed the title Add command to view mview state and queue [2.2] - Add command to view mview state and queue Nov 8, 2017
@okorshenko okorshenko self-assigned this Nov 8, 2017
@okorshenko okorshenko added this to the November 2017 milestone Nov 8, 2017
Copy link
Contributor

@ihor-sviziev ihor-sviziev left a comment

Choose a reason for hiding this comment

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

Unit tests are failed. Could you adjust them according to new phpunit version?

@kandy
Copy link
Contributor

kandy commented Nov 9, 2017

I personally more like the idea to update indexer:status command instead of introducing of new.

continue;
}

$pendingCount = count($changelog->getList($state->getVersionId(), $currentVersionId));
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe that this code will have memory usage issue in case of huge number of item in log

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, it's defined as

    public function getList($fromVersionId, $toVersionId)
    {
        $changelogTableName = $this->resource->getTableName($this->getName());
        if (!$this->connection->isTableExists($changelogTableName)) {
            throw new ChangelogTableNotExistsException(new Phrase("Table %1 does not exist", [$changelogTableName]));
        }

        $select = $this->connection->select()->distinct(
            true
        )->from(
            $changelogTableName,
            [$this->getColumnName()]
        )->where(
            'version_id > ?',
            (int)$fromVersionId
        )->where(
            'version_id <= ?',
            (int)$toVersionId
        );

        return $this->connection->fetchCol($select);
    }

I'll address.

@ishakhsuvarov
Copy link
Contributor

@convenient Please let us know when it's updated.
Thanks!

@convenient
Copy link
Contributor Author

@ishakhsuvarov can i have some clarification please.

Is this comment a requirement or a suggestion?

I personally more like the idea to update indexer:status command instead of introducing of new.

I'd prefer to keep them separate tbh, but let me know please.

@ihor-sviziev
Copy link
Contributor

ihor-sviziev commented Nov 13, 2017

@convenient from my perspective would be great to improve existing indexer:status command because mview status it's like part of indexer status (see as highly recommended), but if you can't do it right now - probably we could accept your implementation as MVP.
Could you share your idea why do you prefer to separate these two commans?

@convenient
Copy link
Contributor Author

I've given this a quick hack locally and I can't find a pretty way of outputting all the data I'd need to vary between the scheduled indexers, and the non scheduled indexers.

bin/magento indexer:status
+----------------------+------------------+-----------+-----------------+---------------------+------------+---------+
| Title                | Status           | Update On | Schedule Status | Updated             | Version ID | Backlog |
+----------------------+------------------+-----------+-----------------+---------------------+------------+---------+
| Design Config Grid   | Ready            | Save      |                 |                     |            |         |
| Catalog Product Rule | Reindex required | Schedule  | idle            | 2017-11-08 20:33:05 | 1          | 0       |
| Catalog Rule Product | Reindex required | Schedule  | idle            | 2017-11-08 20:33:04 | 1          | 0       |
| Catalog Search       | Ready            | Schedule  | idle            | 2017-11-08 20:33:07 | 1          | 4       |
| Category Products    | Reindex required | Schedule  | idle            | 2017-11-08 20:33:02 | 1          | 0       |
| Customer Grid        | Ready            | Schedule  | idle            | 2017-11-08 20:33:02 | 1          | 0       |
| Product Categories   | Reindex required | Schedule  | idle            | 2017-11-08 20:33:02 | 1          | 0       |
| Product EAV          | Reindex required | Schedule  | idle            | 2017-11-08 20:33:04 | 1          | 0       |
| Product Price        | Reindex required | Schedule  | idle            | 2017-11-08 20:33:03 | 1          | 0       |
| Stock                | Reindex required | Schedule  | idle            | 2017-11-08 20:33:04 | 1          | 0       |
+----------------------+------------------+-----------+-----------------+---------------------+------------+---------+

Having the $indexer->getStatus() as well as the $view->getStatus() in the same table just seems messy to me, especially for "Update on Save" indexers.

Either way I'm happy to do whatever is required, I just want to know how it should look at the end.

Bundling both the scheduled and the non-scheduled indexers into the same table as above really makes the indexer:show-mode command a bit superfluous as well.

What does everyone think?

@ihor-sviziev
Copy link
Contributor

@convenient probably show all information that we have isn't really good idea. I would like to remove "version id" column, and data from "backlog" column show as part of "schedule status", like "Idle (4 in backlog)", I think it will be better in this way.

@convenient
Copy link
Contributor Author

@ihor-sviziev

+----------------------+------------------+-----------+---------------------+---------------------+
| Title                | Status           | Update On | Schedule Status     | Schedule Updated    |
+----------------------+------------------+-----------+---------------------+---------------------+
| Design Config Grid   | Ready            | Save      |                     |                     |
| Catalog Product Rule | Reindex required | Schedule  | idle (0 in backlog) | 2017-11-08 20:33:05 |
| Catalog Rule Product | Reindex required | Schedule  | idle (0 in backlog) | 2017-11-08 20:33:04 |
| Catalog Search       | Ready            | Schedule  | idle (4 in backlog) | 2017-11-08 20:33:07 |
| Category Products    | Reindex required | Schedule  | idle (0 in backlog) | 2017-11-08 20:33:02 |
| Customer Grid        | Ready            | Schedule  | idle (0 in backlog) | 2017-11-08 20:33:02 |
| Product Categories   | Reindex required | Schedule  | idle (0 in backlog) | 2017-11-08 20:33:02 |
| Product EAV          | Reindex required | Schedule  | idle (0 in backlog) | 2017-11-08 20:33:04 |
| Product Price        | Reindex required | Schedule  | idle (0 in backlog) | 2017-11-08 20:33:03 |
| Stock                | Reindex required | Schedule  | idle (0 in backlog) | 2017-11-08 20:33:04 |
+----------------------+------------------+-----------+---------------------+---------------------+

It looks a little neater, but i'm usually a opposed to bundling semantic data into a string like this which would be a bit harder to awk out etc. But that might just be my preference :)

This data would still make indexer:show-mode a bit redundant. What do you think?

@ihor-sviziev
Copy link
Contributor

@convenient from my perspective - looks good.

@ishakhsuvarov could you review latest comment. Would it be ok to improve this command in this way?

@convenient
Copy link
Contributor Author

Once we've decided on how the output looks i'll update the test suite and push up my commits, just delaying doing any further work until the output is agreed.

@vkublytskyi
Copy link

@convenient I had a conversation with @kandy and he is ok with the proposed output.

This data would still make indexer:show-mode a bit redundant. What do you think?

It still may be usable if someone need only to check when indexer will be triggered. Plus removing of CLI commands are not allowed due to backward compatibility policy.

@convenient
Copy link
Contributor Author

@vkublytskyi thanks, i'm working on this and will update soon.

* @param Indexer\IndexerInterface $indexer
* @return string
*/
protected function getStatus(Indexer\IndexerInterface $indexer)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you use private method visibility instead of protected?
Same for getPendingCount method


$this->assertCount(8, $linesOutput, 'There should be 8 lines output. 3 Spacers, 1 header, 4 content.');
$this->assertEquals($linesOutput[0], $linesOutput[2], "Lines 0, 2, 7 should be spacer lines");
$this->assertEquals($linesOutput[2], $linesOutput[7], "Lines 0, 2, 6 should be spacer lines");
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably there is mistake

* @throws ChangelogTableNotExistsException
*/
public function getList($fromVersionId, $toVersionId)
protected function getListSelect($fromVersionId, $toVersionId)
Copy link
Contributor

Choose a reason for hiding this comment

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

All new added methods should have private or public visibility

* @return int[]
* @throws ChangelogTableNotExistsException
*/
public function getListSize($fromVersionId, $toVersionId)
Copy link
Contributor

@ihor-sviziev ihor-sviziev Dec 3, 2017

Choose a reason for hiding this comment

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

This method was just added, this change is not backward compatible. Unfortunately we can't accept such change. Couldn't it be done without adding new methods?
If no - then we need to introduce new interface that will include new method.

Copy link
Contributor Author

@convenient convenient Dec 3, 2017

Choose a reason for hiding this comment

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

Thanks I was waiting for the suite to go green before raising questions about this function, this was my attempt to address this comment: #12122 (comment)

I don't believe this can be achieved without a similar query, I was trying to prevent the SELECT query from being generated in two places, but if the interface is not up for modification I can either do it in a new interface or directly within the Command class itself. How do you think this should be architected? If you'd suggest a new interface how do you think it should be named etc?

I'm very much appreciating all your feedback on this PR by the way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this 4af04b1 what you meant?


$state = $view->getState();

$pendingCount = $changelog->getListSize($state->getVersionId(), $currentVersionId);

Choose a reason for hiding this comment

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

\Magento\Framework\Mview\ViewInterface::getChangelog returns \Magento\Framework\Mview\View\ChangelogInterface so method getListSize cannot be used here as it is declared in ChangelogCounterInterface and is unkown in this code.

Seems there is no clean and backward compatible solution to implement counting without list load. I propose in the scope of this PR implement counting as was done in the initial version with count($changelog->getList()) and process this PR to deliver this feature to M2. Once PR will be merged new PR may be created with a refactoring of changelog and performance optimization.

@convenient, @ihor-sviziev, @kandy are you agree with this plan?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @vkublytskyi I was really struggling to balance out clean/backwards-compatability as you noted.

If @kandy agrees my plan of action will be

  1. Roll back to count($changelog->getList()) with associated tests
  2. Update description/title to properly highlight what is occurring in this PR
  3. Wait for approval from all parties (or potentially for merge?)
  4. Backport changes to [2.1] - Add command to view mview state and queue #12050

Sound good?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, looks good for me

@ihor-sviziev
Copy link
Contributor

ihor-sviziev commented Dec 4, 2017 via email

@magento-team magento-team merged commit 3d34bc8 into magento:2.2-develop Dec 7, 2017
magento-team pushed a commit that referenced this pull request Dec 7, 2017
[EngCom] Public Pull Requests - 2.2-develop
 - MAGETWO-84981: Trying to get data from non existent products #12539
 - MAGETWO-84979: [Backport 2.2-develop] Fix swagger-ui on instances of Magento running on a non-standard port #12541
 - MAGETWO-84903: Added namespace to product videos fotorama events #12469
 - MAGETWO-84862: [Backport 2.2-develop] #11409: Too many password reset requests even when disabled in settings #11435
 - MAGETWO-84856: Issue 12506: Fixup typo getDispretionPath -> getDispersionPath #12507
 - MAGETWO-84808: 12110: Missing cascade into attribute set deletion. #12167
 - MAGETWO-83503: [2.2] - Add command to view mview state and queue #12122
 - MAGETWO-80223: Fix syntax of expectException() calls #11099
@convenient convenient deleted the 2-2-0-mview-list branch December 18, 2017 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants