sql_cacher: add support for reads of sql_cached_value while table is being reloaded #3731
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.
Summary
When calling
$sql_cached_value
during a reload initiated by MI it locks the whole table and that read tries to acquire a lock and can only acquire it once the write has finished, this can block SIP processing unnecessarily as the cachedb implementations typically lock on their own values, eg. cachedb_local locks on each hash which corresponds to a row, this PR adds support to read during a full reload and only lock the row being read, if a reload is in progress you can read the previous version value during the reload if it is returnedDetails and Solution
Uses stdatomic to set a boolean flag once the write lock is acquired, this can then be tested during reads and be more permissive with values returned as long as the version is only current version - 1 otherwise it returns null
Compatibility
Changes the default behaviour to now be more permissive but adds a new param to
cache_table
calledfull_caching_lock_scope
which can be set torow
ortable
, defaults torow
and setting it totable
provides support for the current way it works