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

L2 cache save operation stop working when the hash key exists on remo… #36418

Open
wants to merge 1 commit into
base: 2.4-develop
Choose a base branch
from

Conversation

georgebabarus
Copy link
Contributor

@georgebabarus georgebabarus commented Nov 3, 2022

Save operation stop working on L2 cache and remote cache when the hash key exists on remote server, but the data key was evicted meanwhile from remote cache.

Later edit: The original issue has been fixed int magento:2.4-develop branch, but this is a performance improvement implementation that should be beneficial by following argument: The concept of cache involves try loading the data from storage, generate if data doesn't exist in cache, and save it to cache. There is no need to check if data exist in cache in the save method.

Description (*)

When save method is called on L2 cache adapter there are 3 things do be done:

  • update the data on remote server (this will make sure the data exists on the remote server and the TTL is renewed)
  • update the version (hash) on the remote server (this will make sure the version id (hash) exists on the remote server and the TTL is renewed)
  • update the data in the local cache (this will make sure the data exists on the local server)

The original checks of the remote version of data are preventing the save of the cache to remote and local servers in the scenario where the version id exists and is correct but the data is missing from remote server. (eg: because it was evicted by Redis)

    $remHash = $this->loadRemoteDataVersion($id);

    if ($remHash !== false && $this->getDataVersion($data) === $remHash) {
        $dataToSave = $this->remote->load($id);
    } else {
        $this->remote->save($data, $id, $tags, $specificLifetime);
        $this->saveRemoteDataVersion($data, $id, $tags, $specificLifetime);
    }

In order to avoid unnecessary writes on the remote server for both entries from point 1 and 2, it needs to read both keys content and TTL in order to create a condition that will cover all the cases. I find this solution overkill and I think it make more sense to force write both keys on remote server. The cache lock is a different component that could perform the above purpose of reducing the writes.

Important note: the remote cache consistency check should be performed in the load method

Follow the red arrows to see the failing scenario:
L2-cache-save-diagram

Manual testing scenarios (*)

  1. Enable the L2 cache
  2. Manually remove the data key for one of the cache entries from remote server, but keep the version cache key
  3. Clear all the L2 cache entries
  4. Check if the data cache key is saved to the remote server next time the code is executed

Questions or comments

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)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Nov 3, 2022

Hi @georgebabarus. Thank you for your contribution
Here are 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
  13. Semantic Version Checker

You can find more information about the builds here

ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.

For more details, 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, join the Community Contributions Triage session to discuss the appropriate ticket.

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

@georgebabarus
Copy link
Contributor Author

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

1 similar comment
@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@georgebabarus
Copy link
Contributor Author

@magento run WebAPI Tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@georgebabarus
Copy link
Contributor Author

@magento run Integration Tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@georgebabarus
Copy link
Contributor Author

@magento run Functional Tests CE

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@georgebabarus
Copy link
Contributor Author

@magento run Functional Tests EE

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@georgebabarus
Copy link
Contributor Author

@magento run Functional Tests EE

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@georgebabarus
Copy link
Contributor Author

@magento run Functional Tests EE

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@georgebabarus
Copy link
Contributor Author

@magento run Functional Tests EE

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@leonhelmus
Copy link

leonhelmus commented Nov 14, 2022

@georgebabarus could this also cause the user (customer) that was on the checkout or somewhere else could be logged out by force because of this?

@georgebabarus
Copy link
Contributor Author

@leonhelmus This proposal is strictly related to cache storage. Not related to customer session issues.

…te server but the data key was evicted meanwhile

Later edit: this is a refactor solution after the solution was already provided for the original issue
@georgebabarus
Copy link
Contributor Author

@magento run tests

@magento-automated-testing
Copy link

Failed to run the builds. Please try to re-run them later.

@georgebabarus
Copy link
Contributor Author

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@georgebabarus
Copy link
Contributor Author

@magento run Functional Tests B2B

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@georgebabarus
Copy link
Contributor Author

@magento run Sample Data Tests B2B

@magento-automated-testing
Copy link

Failed to run the builds. Please try to re-run them later.

@georgebabarus
Copy link
Contributor Author

@magento run Sample Data Tests CE

@magento-automated-testing
Copy link

Failed to run the builds. Please try to re-run them later.

@georgebabarus
Copy link
Contributor Author

@magento run Sample Data Tests EE

@magento-automated-testing
Copy link

Failed to run the builds. Please try to re-run them later.

Copy link
Contributor

@engcom-Hotel engcom-Hotel left a comment

Choose a reason for hiding this comment

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

Hello @georgebabarus,

Thanks for the contribution!

Please have a look at my review comment.

Thanks

if (!$isRemoteUpToDate) {
$this->remote->save($data, $id, $tags, $specificLifetime);
$this->saveRemoteDataVersion($data, $id, $tags, $specificLifetime);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Hello @georgebabarus,

Can you please let us know the reason behind removing this code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@engcom-Hotel

The code is not useful: if the version is correct and the data is correct -> the save method is not called, because this is a cache hit by definition.

The purpose of the cache is to avoid generating the data, all the consistency check should be done in the load method which is preventing the data to be generated.

Once the data is generated I think is better to save it since the heavy processing was already done before the save action:

  1. consistency check with Remote storage, done in the load method -> this should say what a cache hit means
  2. data generated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: needs update Additional information is require, waiting for response Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: review
Projects
Pull Requests Dashboard
  
Review in Progress
Development

Successfully merging this pull request may close these issues.

None yet

4 participants