Skip to content

fix(hns): cache root bucket properly in _get_dirs_and_update_cache - #990

Open
yuxin00j wants to merge 1 commit into
fsspec:mainfrom
yuxin00j:fix-hns-dircache
Open

fix(hns): cache root bucket properly in _get_dirs_and_update_cache#990
yuxin00j wants to merge 1 commit into
fsspec:mainfrom
yuxin00j:fix-hns-dircache

Conversation

@yuxin00j

@yuxin00j yuxin00j commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes a performance bottleneck where _get_dirs_and_update_cache skipped updating fsspec.dircache when listing the root bucket (dir_key == "") in Hierarchical Namespace (HNS) enabled buckets. This caused repeated metadata cache misses and redundant GCP network requests when loading multi-file datasets (e.g., Hugging Face datasets / Parquet).

Root Cause & Technical Fix

  • Before: In gcsfs/core.py (_get_dirs_and_update_cache), the parent directory traversal loop terminated early when encountering the root bucket (not dir_key). Because the root bucket listing was never written to self.dircache, subsequent fs.info("bucket/file") calls triggered cache misses and made synchronous HTTP network requests to GCS for every file.
  • Fix:
    • Updated _get_dirs_and_update_cache so that cache_entries is populated for root buckets ("bucket"), ensuring the directory contents are cached in self.dircache["bucket"].
    • Guarded dirs[parent] assignment with if dir_key: so that root buckets are not incorrectly synthesized as subdirectories inside themselves (which previously caused 409 Conflict: The bucket you tried to delete is not empty during test teardown).

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request simplifies a directory cache update condition in gcsfs/core.py and adds a new integration test to verify that find() populates the directory cache for the root bucket. However, the new test method was accidentally inserted in the middle of an existing test, which truncates the original test and incorrectly indents its remaining assertions under the new test. A code suggestion has been provided to properly separate the tests and clean up an unused variable.

Comment thread gcsfs/tests/integration/test_extended_hns.py
@yuxin00j
yuxin00j force-pushed the fix-hns-dircache branch 2 times, most recently from 8eea016 to 1184271 Compare July 29, 2026 05:57
@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.66%. Comparing base (8e98a12) to head (db5d3f1).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #990      +/-   ##
==========================================
- Coverage   89.68%   89.66%   -0.03%     
==========================================
  Files          16       16              
  Lines        3579     3581       +2     
==========================================
+ Hits         3210     3211       +1     
- Misses        369      370       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@yuxin00j

Copy link
Copy Markdown
Collaborator Author

/gcbrun

1 similar comment
@yuxin00j

Copy link
Copy Markdown
Collaborator Author

/gcbrun

@yuxin00j

Copy link
Copy Markdown
Collaborator Author

/gcbrun

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

Successfully merging this pull request may close these issues.

1 participant