Skip to content

Prevent flushing same tags several times #29885

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

Merged
merged 4 commits into from
Oct 7, 2020

Conversation

siimm
Copy link
Contributor

@siimm siimm commented Sep 3, 2020

Description (*)

If a product is saved in admin - changed name, price, stock, weight, added category to product. Then after indexing, the same tags are flushed several times.
Here is an example of default Magento behaviour on cleaning cache tags during indexing (different arrays belong to different indexers cleaning the cache):

root@c119d6a06fcb:/var/www/m2clean$  bin/magento cron:run --group=index --bootstrap=standaloneProcessStarted=1

Array
(
)


Array
(
)


Array
(
    [0] => cat_p_1
    [1] => cat_c_2
    [2] => cat_c_1
    [3] => cat_c_2
    [4] => cat_c_3
    [5] => cat_c_1
)

Array
(
    [0] => cat_p_1
    [1] => cat_c_2
    [2] => cat_c_1
    [3] => cat_c_2
    [4] => cat_c_3
    [5] => cat_c_1
)


Array
(
    [0] => cat_p_1
    [1] => cat_c_2
    [2] => cat_c_1
    [3] => cat_c_2
    [4] => cat_c_3
    [5] => cat_c_1
)


Array
(
    [0] => cat_p_1
)

Array
(
    [0] => cat_p_1
    [1] => cat_p_1
    [2] => cat_p_1
    [3] => cat_p_1
    [4] => cat_c_2
    [5] => cat_c_1
    [6] => cat_c_2
    [7] => cat_c_3
    [8] => cat_c_1
)


Array
(
    [0] => cat_p_1
    [1] => cat_p_1
    [2] => cat_p_1
    [3] => cat_p_1
    [4] => cat_c_2
    [5] => cat_c_1
    [6] => cat_c_2
    [7] => cat_c_3
    [8] => cat_c_1
)

Array
(
    [0] => cat_p_1
    [1] => cat_p_1
    [2] => cat_p_1
    [3] => cat_p_1
    [4] => cat_p_1
    [5] => cat_c_2
    [6] => cat_c_1
    [7] => cat_c_2
    [8] => cat_c_3
    [9] => cat_c_1
)


Array
(
    [0] => cat_p_1
    [1] => cat_p_1
    [2] => cat_p_1
    [3] => cat_p_1
    [4] => cat_p_1
    [5] => cat_c_2
    [6] => cat_c_1
    [7] => cat_c_2
    [8] => cat_c_3
    [9] => cat_c_1
)

Array
(
    [0] => cat_p_1
    [1] => cat_p_1
    [2] => cat_p_1
    [3] => cat_p_1
    [4] => cat_p_1
    [5] => cat_p_1
    [6] => cat_c_2
    [7] => cat_c_1
    [8] => cat_c_2
    [9] => cat_c_3
    [10] => cat_c_1
)


Array
(
    [0] => cat_p_1
    [1] => cat_p_1
    [2] => cat_p_1
    [3] => cat_p_1
    [4] => cat_p_1
    [5] => cat_p_1
    [6] => cat_c_2
    [7] => cat_c_1
    [8] => cat_c_2
    [9] => cat_c_3
    [10] => cat_c_1
)


Array
(
    [0] => cat_p_1
    [1] => cat_p_1
    [2] => cat_p_1
    [3] => cat_p_1
    [4] => cat_p_1
    [5] => cat_p_1
    [6] => cat_c_2
    [7] => cat_c_1
    [8] => cat_c_2
    [9] => cat_c_3
    [10] => cat_c_1
)


Array
(
    [0] => cat_p_1
    [1] => cat_p_1
    [2] => cat_p_1
    [3] => cat_p_1
    [4] => cat_p_1
    [5] => cat_p_1
    [6] => cat_c_2
    [7] => cat_c_1
    [8] => cat_c_2
    [9] => cat_c_3
    [10] => cat_c_1
)


Array
(
    [0] => cat_p_1
    [1] => cat_p_1
    [2] => cat_p_1
    [3] => cat_p_1
    [4] => cat_p_1
    [5] => cat_p_1
    [6] => cat_c_2
    [7] => cat_c_1
    [8] => cat_c_2
    [9] => cat_c_3
    [10] => cat_c_1
)

Here is the same output with the changes applied:

root@c119d6a06fcb:/var/www/m2clean$  bin/magento cron:run --group=index --bootstrap=standaloneProcessStarted=1
Array
(
)


Array
(
)


Array
(
    [0] => cat_p_1
    [1] => cat_c_2
    [2] => cat_c_1
    [4] => cat_c_3
)

Array
(
    [0] => cat_p_1
    [1] => cat_c_2
    [2] => cat_c_1
    [4] => cat_c_3
)


Array
(
    [0] => cat_p_1
    [1] => cat_c_2
    [2] => cat_c_1
    [4] => cat_c_3
)


Array
(
    [0] => cat_p_1
)

Array
(
    [0] => cat_p_1
    [4] => cat_c_2
    [5] => cat_c_1
    [7] => cat_c_3
)


Array
(
    [0] => cat_p_1
    [4] => cat_c_2
    [5] => cat_c_1
    [7] => cat_c_3
)

Array
(
    [0] => cat_p_1
    [5] => cat_c_2
    [6] => cat_c_1
    [8] => cat_c_3
)


Array
(
    [0] => cat_p_1
    [5] => cat_c_2
    [6] => cat_c_1
    [8] => cat_c_3
)

Array
(
    [0] => cat_p_1
    [6] => cat_c_2
    [7] => cat_c_1
    [9] => cat_c_3
)

Array
(
    [0] => cat_p_1
    [6] => cat_c_2
    [7] => cat_c_1
    [9] => cat_c_3
)

Array
(
    [0] => cat_p_1
    [6] => cat_c_2
    [7] => cat_c_1
    [9] => cat_c_3
)

Array
(
    [0] => cat_p_1
    [6] => cat_c_2
    [7] => cat_c_1
    [9] => cat_c_3
)


Array
(
    [0] => cat_p_1
    [6] => cat_c_2
    [7] => cat_c_1
    [9] => cat_c_3
)

Related Pull Requests

Fixed Issues (if relevant)

  1. Fixes magento/magento2#<issue_number>

Manual testing scenarios (*)

  1. Observe the output of \Magento\Framework\Indexer\CacheContext::getIdentities during indexer run, same tags are flushed up to 10 times per one indexer instance
  2. ...

Questions or comments

Together with #29699 it will probably reduce the amount of cache flushing significatly

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 are green)

Resolved issues:

  1. resolves [Issue] Prevent flushing same tags several times #29890: Prevent flushing same tags several times

@m2-assistant
Copy link

m2-assistant bot commented Sep 3, 2020

Hi @siimm. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests

You can find more information about the builds here

ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review.

For more details, please, review the Magento Contributor Guide documentation.

⚠️ According to the Magento Contribution requirements, all Pull Requests must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@magento-engcom-team magento-engcom-team added Component: Indexer Release Line: 2.4 Partner: Vaimo Pull Request is created by partner Vaimo partners-contribution Pull Request is created by Magento Partner labels Sep 3, 2020
@sidolov sidolov added Priority: P3 May be fixed according to the position in the backlog. Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. labels Sep 3, 2020
@sidolov
Copy link
Contributor

sidolov commented Sep 3, 2020

@magento create issue

@rogyar
Copy link
Contributor

rogyar commented Sep 3, 2020

Hi @siimm. Thank you for your collaboration. Nice catch!
Could I ask you to cover your change with a simple unit test, please? The unit test will assert that the method returns only unique values.

Thank you!

@siimm
Copy link
Contributor Author

siimm commented Sep 4, 2020

Hi @rogyar, attached a minimalistic test case to this PR
f17148f

@lenaorobei
Copy link
Contributor

@magento run all tests

@gabrieldagama
Copy link
Contributor

The risk was set tomedium due to: the suggested changes may affect other areas/modules.

@lenaorobei
Copy link
Contributor

@magento run all tests

@ihor-sviziev
Copy link
Contributor

@magento run all tests

@engcom-Charlie engcom-Charlie self-assigned this Sep 21, 2020
Copy link
Contributor

@engcom-Bravo engcom-Bravo left a comment

Choose a reason for hiding this comment

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

❌ QA Failed

Hello @siimm
Looks like the changes provided in this PR do not solve the original issue. I'm getting the same Output before and after switching to the PR
cat1

Please, see the Manual testing scenario

  1. Go to System - Index Management
  2. Select All Indexers and change the Actions to Update by Schedule
  3. Go to Catalog - Categories, and change the Category Name for at least two Categories, for example
  4. Go to Catalog - Products and change the Price, Quantity, Weight for at least two Products
  5. Run bin/magento cron:run --group=index --bootstrap=standaloneProcessStarted=1
  6. Observe the output of \Magento\Framework\Indexer\CacheContext::getIdentities

@ghost ghost dismissed stale reviews from rogyar and BarnyShergold September 28, 2020 11:01

Pull Request state was updated. Re-review required.

@siimm
Copy link
Contributor Author

siimm commented Oct 5, 2020

@engcom-Bravo
Did you check the values what the getIdentities method returns? - from the screenshot I can assume the values were inspected inside of the method itself - the $ids variable is hinting that.

@engcom-Bravo
Copy link
Contributor

✔️ QA Passed

Further investigation discovered that the changes provided in this PR, fix the original issue

Manual Testing scenario

  1. Go to System - Index Management
  2. Select All Indexers and change the Actions to Update by Schedule
  3. Go to Catalog - Categories, and change the Category Name for at least two Categories, for example
  4. Go to Catalog - Products and change the Price, Quantity, Weight for at least two Products
  5. Run bin/magento cron:run --group=index --bootstrap=standaloneProcessStarted=1
  6. Observe the return of \Magento\Framework\Indexer\CacheContext::getIdentities

BEFORE applying changes
before

AFTER switching to the PR
after

@engcom-Bravo
Copy link
Contributor

engcom-Bravo commented Oct 6, 2020

@rogyar @BarnyShergold Can you please review the PR again?

Thank you

* @param array $expected
* @dataProvider getTagsDataProvider
*/
public function testUniqueTags($tagsData, $expected)
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a recommendation for the future to use type hinting whenever it's possible. It's a very useful habit in PHP 7.x

@magento-engcom-team
Copy link
Contributor

Hi @rogyar, thank you for the review.
ENGCOM-8237 has been created to process this Pull Request

@m2-assistant
Copy link

m2-assistant bot commented Oct 7, 2020

Hi @siimm, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Award: test coverage Component: Indexer Partner: Vaimo Pull Request is created by partner Vaimo partners-contribution Pull Request is created by Magento Partner Priority: P3 May be fixed according to the position in the backlog. Progress: accept QA: Added to Regression Scope Scenario was analysed and added to Regression Testing Scope Release Line: 2.4 Risk: medium Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[Issue] Prevent flushing same tags several times
10 participants