-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Cache] Decrease the probability of invalidation loss on tag eviction #44015
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
Conversation
d40aa72
to
f8b5113
Compare
Hey! I think @fancyweb has recently worked with this code. Maybe they can help review this? Cheers! Carsonbot |
if (isset($invalidatedTags[$tag])) { | ||
$invalidatedTags[$tag] = $version->set(++$tagVersions[$tag]); | ||
if (!$version->isHit()) { | ||
$newTags[] = $version->set($newVersion ?? $newVersion = random_int(\PHP_INT_MIN, \PHP_INT_MAX)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mt_rand()
is faster than random_int()
and gives the same level of randomness
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer keeping random_int(): the speed difference is negligible compared to network round-trips, and it cannot be seeded, while mt_rand() can, with bad side effects for our use case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree.
f8b5113
to
4cfc727
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
Thank you @nicolas-grekas. |
From @sbelyshkin in the linked PR:
This PR goes one step further and borrows from #42997: instead of incrementing the version number on invalidation, we delete the value from the backend, and recreate it when needed with a random offset.
This PR also removes auto-commit on tag-invalidation: this behavior adds complexity, is not needed and is not consistent with Redis|FilesystemTagAwareAdapter.
/cc @sbelyshkin can you please give it a go in a review?