Repository navigation
Conversation
Registry._get_registry_proto() took _refresh_lock before checking the cache, and a refresh holds that lock for the whole registry download. While a refresh waited on slow or unresponsive object storage, every allow_cache=True read waited too, including the feature server's /health, even though the in-memory cache was still valid. Return the cached proto before taking the lock when the cache is within its TTL and, for a local registry file in sync mode, the file has not changed since it was last read. All other reads take the locked path as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Youngbeom Choi <helloybz@gmail.com>
There was a problem hiding this comment.
Devin Review found 1 potential issue.
1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
| if allow_cache and self.is_cache_valid() and not self._registry_file_changed(): | ||
| return self.cached_registry_proto |
There was a problem hiding this comment.
🔴 Offline writes use superseded destinations
While a changed local registry reloads in sync mode, _get_registry_proto can return the old snapshot. The reload publishes _file_mtime before replacing cached_registry_proto. Offline writes then persist rows to the previous batch source.
Learn more
In sync mode, a cached lookup must reload a local registry file when its modification time advances. The locked reload currently records that time before it loads the replacement proto. A second lookup during the load sees the new time and returns the old snapshot without waiting. Before the fast path, the second lookup waited for the reload. Offline writes resolve their destination once and send the batch to that source, so completing the registry reload does not repair a misdirected write.
Example: Apply a feature view update that moves its batch source from table A to table B, with the same schema. A cached lookup starts reloading the registry. An offline write resolves the view during that reload and writes to A instead of B.
Recommended fix: Do not advance _file_mtime until the replacement proto has been loaded and published. Keep readers of a changed local file on the locked path while that load is in progress. Add an event-driven test that pauses a change-triggered reload inside get_registry_proto and verifies that a second cached lookup waits for the new snapshot.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Fixed in ff1ce31. The locked reload path no longer stores the new file mtime before it reloads the file. It already stored the mtime after the reload, so only the early assignment is removed, and a cached read during the reload now sees the file as changed and waits on the lock.
Added test_cached_read_waits_for_reload_of_modified_local_file, which pauses a change-triggered reload inside get_registry_proto and checks that a second cached read waits and then returns the new snapshot. It fails on the previous commit and passes on master and with this fix.
The locked reload path stored the new file mtime as soon as it noticed the change, before it replaced the cached proto. With the lock-free cache check, a cached read in that window saw an unchanged file and returned the old snapshot. The mtime is already stored after the reload, so drop the early assignment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Youngbeom Choi <helloybz@gmail.com>
| assert [p.name for p in projects] == ["fresh_project"] | ||
|
|
||
|
|
||
| def test_cached_read_picks_up_modified_local_file(file_registry: Registry) -> None: |
There was a problem hiding this comment.
Non-blocking: could we simplify the test additions to three cases: valid cached reads don’t wait for a refresh, expired caches fetch fresh data, and concurrent reads of a changed local file wait for the updated snapshot? The concurrent-reload test already covers detecting local-file changes, so we could remove test_cached_read_picks_up_modified_local_file, inline _write_project_to_registry_file into its remaining caller, and shorten the docstrings while keeping the concurrency synchronization and cleanup.
There was a problem hiding this comment.
Thanks, done in 7915d25. I removed test_cached_read_picks_up_modified_local_file, moved the setup from _write_project_to_registry_file into test_cached_read_waits_for_reload_of_modified_local_file, and shortened the docstrings to one line each.
I also switched both concurrency tests from ThreadPoolExecutor to threading.Thread with join(timeout=...), which is how the other unit tests here wait on threads. The synchronization and cleanup are the same: the reload is paused on an event, and the lock and the paused reload are released in finally.
Drop test_cached_read_picks_up_modified_local_file, because test_cached_read_waits_for_reload_of_modified_local_file already fails when the early return skips the file modification check. Inline the setup helper into its only remaining caller, shorten the docstrings, and wait on threading.Thread like the other unit tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Youngbeom Choi <helloybz@gmail.com>
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7237 +/- ##
=======================================
Coverage 54.10% 54.11%
=======================================
Files 467 467
Lines 58940 58949 +9
Branches 8688 8690 +2
=======================================
+ Hits 31890 31899 +9
Misses 24892 24892
Partials 2158 2158
Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
What this PR does / why we need it:
The file-based registry keeps its state in a single file, either on local disk or in object storage such as S3 or GCS. Every read on it goes through
Registry._get_registry_proto(), which took_refresh_lockbefore looking at the cache, even when the caller passedallow_cache=Trueand the cache was still valid. A refresh holds the same lock for the whole download, becauserefresh()calls_get_registry_proto(allow_cache=False). So while a refresh is waiting on slow or unresponsive object storage, every cached read waits too, although it only needs the proto that is already in memory.In the feature server,
/healthand online feature retrieval both read the registry withallow_cache=True./healthcallsstore.registry.list_projects(allow_cache=True)inside anasync defhandler. Take a registry stored on S3 as an example. If a download stops responding, the periodic refresh holds the lock until botocore gives up, and botocore's default connect and read timeouts are 60 seconds each./healthblocks on the lock, and because it blocks the event loop, other requests on that worker stall as well. A container health check with a timeout of a few seconds then marks a worker that could still serve from its cache as unhealthy, and the orchestrator replaces it. The new worker has to download the registry at startup, so it may not come up while the store is still hanging.With this change,
_get_registry_proto()returns the cached proto before taking the lock when all of these hold:allow_cache=True,is_cache_valid()),In every other case the locked path runs, including its TTL and file modification checks. The new
_registry_file_changed()only reads the file's mtime and never updates_file_mtime, so it is safe to call without the lock.The locked path used to store the new file mtime as soon as it noticed a change, before it reloaded the file. With the check above running outside the lock, a cached read during that reload would see an unchanged file and return the old snapshot. The locked path now stores the mtime only after the reloaded proto is in the cache. It already stored the mtime after the reload, so this only removes the early assignment. As a side effect, a reload that fails is retried on the next read instead of after the TTL.
Reading
cached_registry_protowithout the lock matches the rest of the class._get_registry_proto()is the only place that uses_refresh_lock, andproto(),_prepare_registry_for_changes()andcommit()already read or replace the cached proto without it. The lock keeps concurrent refreshes from downloading at the same time, and it still does.Only
Registryinsdk/python/feast/infra/registry/registry.pychanges.CachingRegistry, which the SQL registry and others use, is not touched.Which issue(s) this PR fixes:
There is no existing issue for the file-based registry. The same problem was reported for the SQL registry in #4898 and fixed in
CachingRegistryby #5068, which skips the refresh instead of waiting when the lock is already held. This PR does the same for the file-basedRegistrywhen its cache is still valid. I searched open and closed issues and PRs for_refresh_lock,_get_registry_protoand the health endpoint and found no duplicate.This is on the same refresh path as #7219, but it changes a different file and does not depend on it.
Checks
git commit -s)Testing Strategy
New tests in
sdk/python/tests/unit/infra/registry/test_file_registry.py:test_cached_read_does_not_wait_for_in_progress_refresh: while_refresh_lockis held, as a stuck refresh would hold it,list_projects(allow_cache=True)must return within 2 seconds. Fails on master, where the read is still waiting on the lock after 2 seconds, and passes with this change.test_expired_cache_read_fetches_from_store: once the TTL has passed, a cached read must still download from the registry store. Passes on master too. It fails if the new early return skips the TTL check.test_cached_read_waits_for_reload_of_modified_local_file: while a reload of a changed local file is paused insideget_registry_proto, a second cached read must wait and then return the new snapshot. Passes on master too. It fails if the locked path stores the new mtime before replacing the cached proto, because the second read then returns the old snapshot right away. It also fails if the early return skips the file modification check, because the first read then returns the cached snapshot without reloading.make test-python-unitpasses locally (4462 passed, 37 skipped), andruff check,ruff formatandmypyare clean on the changed files.Misc
If the store hangs for longer than the cache TTL (600 seconds by default), the cache expires and reads take the locked path and wait again. Serving the expired cache when the lock is held, as #5068 does for
CachingRegistry, would cover that case. I left it out because it changes what callers get after the TTL has passed. I am happy to add it here or in a follow-up if you prefer.This change was written with help from an AI assistant (Claude Code). I reviewed it and ran the tests above.
🤖 Generated with Claude Code