[FW][FIX] registry: avoid re-signaling invalidated cache #41502
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In a multithreaded environment, when the cache is being cleared through
a call to
registry.clear_caches
, it's possible any number of otherthreads signal the database that the cache has been invalidated.
One of multiple scenarios where this can cause issues:
check_signaling
, sees it should beinvalidated and calls
registry.clear_caches
, settingregistry.cache_invalidated
to True while it clears the cache foreach model.
check_signaling
, seesregistry.clear_caches
is True and signals the database byincreasing the
base_cache_signaling
sequence.Should 2 multi-threaded servers run in parallel on the same database
(both handling many requests), it's possible this triggers alternatively
on each worker and loops indefinitely.
To fix this problem, we avoid setting
registry.cache_invalidated
toTrue when clearing the cache.
It's interesting to note that the cache invalidation is not thread-safe,
and can be in inconsistent states during its invalidation & clearing.
Fixing this fully requires a bigger design change that may come in the
future, but most likely not as a fix in a stable version.
Forward-Port-Of: #40983