Skip to content

Getting too many surrogate keys #104

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
daniel-ifrim opened this issue Sep 18, 2017 · 6 comments
Closed

Getting too many surrogate keys #104

daniel-ifrim opened this issue Sep 18, 2017 · 6 comments

Comments

@daniel-ifrim
Copy link

I'm getting this in the logs:

[2017-09-17 18:05:25] report.CRITICAL: Return status 400 {"method":"GET","url":"http:/","invalidateInfo":"https://api.fastly.com/service/ [service_id] /purge"} []

I added a debug message on $responseBody in _purge() function and I see this:

[2017-09-17 18:05:25] report.CRITICAL: HTTP/1.1 400 Bad Request {"status": "fail", "reason": "Batch surrogate key request only supports up to 256 surrogate keys"} {"method":"GET","url":"http:/","invalidateInfo":"https://api.fastly.com/service/ [service_id] /purge"} []

Maybe split the cache tag keys and send consecutive purges with keys sets, each having 250-256 keys ? Or something better ?

@udovicic
Copy link
Contributor

@daniel-ifrim On which Magento version is this issue observed?

@daniel-ifrim
Copy link
Author

@udovicic On Magento EE 2.1.4.
The store has products with many options.
One way to reproduce is to use Target Rule (Related Products Rules in admin) and have a rule active that covers many products. It will try to send many cache tags to purge.
But I'm not in this case. The 256 surrogate keys limit could be handled by the extension.

Is there already a check in the code on 256 max surrogate keys ? I just don't know if I'm missing it.

@udovicic
Copy link
Contributor

@daniel-ifrim Currently, there are no restrictions on length of the keys. There is a piece of code that shortens the keys so more can fit, but that is it. I will see what can be done about this and will keep you updated

@daniel-ifrim
Copy link
Author

@udovicic I don't know if I made myself clear.
It's about validation of the number of surrogate keys that Fastly accepts.
It's not about the length of a single surrogate key.
What I saw in logs was Fastly saying that the purge request sent too many surrogate keys. And Fastly returns HTTP 400 Bad Request.

In another case, there are configurable products with many options that can have over 256 simple products attached. Splitting 400 surrogate keys into 2 purge requests (vendor/fastly/magento2/Model/Api.php/Api.php::cleanBySurrogateKey()) with the first one having 256 keys and the second one 134 keys looks ok.

The issue with Target Rule is extreme.
In the case of Target Rule where indexer wants to clean cache by tags for a lot of products, there can be a hard limit in the extension like 3-10 purge requests (10 x 256 = 2560 surrogate keys to clean). So Magento 2 won't spam Fastly.

@udovicic
Copy link
Contributor

@daniel-ifrim Yes, I understand the issue, no worries.

Current state is that all cache tags are bundled into single purge request. So in case you have a 1000 tags to clear, it would be required to send them in smaller batches as they do not fit in the single request. And yes, there needs to be a limit on how many batches as well or someone will spam the service.

I will keep you updated.

@vvuksan
Copy link
Contributor

vvuksan commented Jan 17, 2018

Fixed in #133 and part of 1.2.39 release.

@vvuksan vvuksan closed this as completed Jan 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants