Skip to content

feat(caching): implement negative stat cache to optimize polling of missing files#4729

Open
alleaditya wants to merge 87 commits into
GoogleCloudPlatform:masterfrom
alleaditya:add-negative-stat-cache
Open

feat(caching): implement negative stat cache to optimize polling of missing files#4729
alleaditya wants to merge 87 commits into
GoogleCloudPlatform:masterfrom
alleaditya:add-negative-stat-cache

Conversation

@alleaditya

@alleaditya alleaditya commented May 25, 2026

Copy link
Copy Markdown
Contributor

Description

This change implements negative entry caching (non-existent path caching) to optimize workloads that aggressively poll missing files (e.g., JupyterLab).

Activation: Controlled by metadata-cache: negative-ttl-secs config parameter (or --metadata-cache-negative-ttl-secs flag). It is enabled by default with a 5-second TTL. Setting it to 0 disables the feature.
Proactive Listing Cache: Empty directory listings (ListObjects returning 0 results) are proactively cached as negative directory entries to fully protect against implicit directory network probes.
VFS Routing: LookUpChild tracks definitive negative cache hits and short-circuits immediately in memory, avoiding network fallback.

Benchmark Results

A custom sustained benchmarking script (bench.sh) was executed against a locally mounted test bucket to measure performance over sustained 60-second polling windows.

The metrics demonstrate that negative caching successfully eliminates redundant network traffic across all lookup scenarios, including those requiring implicit directory checking.

1. Implicit Dirs vs Explicit Dirs (Throughput & Network Calls)

In --implicit-dirs scenarios, FUSE previously required both a StatObject and a fallback ListObjects call per lookup. With this change, both are aggressively short-circuited:

Scenario (60s Polling) Negative Caching TTL=0s Negative Caching TTL=5s Result
Explicit Dirs Ops: 771
StatObject calls: 1,544
ListObjects calls: 1
Ops: 845,720
StatObject calls: 24
ListObjects calls: 1
98.4% network drop.
Throughput: +109,591% (>1,000x)
Implicit Dirs Ops: 735
StatObject calls: 736
ListObjects calls: 737
Ops: 874,744
StatObject calls: 12
ListObjects calls: 15
98.2% network drop.
Throughput: +118,912% (>1,000x)

(Note: Network calls exactly match mathematically expected TTL expiration rates - approximately 1 network call per 5 seconds).

Link to the issue in case of a bug fix.

https://b.corp.google.com/issues/511786738

Testing details

  1. Manual - Verified sustained polling behavior against local mounts with and without --implicit-dirs, validating exact TTL expiration counts and throughput improvements.
  2. Unit tests - Added TestLookUpChild_NegativeCacheHit in dir_test.go and TestGCSMetrics_RequestCount_NegativeCachingShortCircuit in gcs_metrics_test.go. Verified negative caching upon empty listings in ListObjectsTest_InsertListing.EmptyListing.
  3. Integration tests - Ran existing E2E caching suites successfully

Any backward incompatible change? If so, please explain.

No.

…issing files

This change adds negative caching to StatCache, short-circuits LookUpChild on negative hits, and adds metrics/integration tests to verify.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces negative stat caching to optimize performance in scenarios where applications frequently poll for non-existent files. By caching negative results (404s) and short-circuiting lookups in the filesystem layer, the change significantly reduces redundant backend network traffic. The implementation includes configurable TTL settings and comprehensive integration tests to ensure correctness and efficiency.

Highlights

  • Negative Stat Caching: Implemented negative caching for non-existent paths to reduce redundant backend GCS requests for workloads that poll missing files.
  • Short-circuit Logic: Updated LookUpChild to short-circuit on confirmed negative hits for both files and directories, preventing unnecessary backend calls.
  • Metrics and Testing: Added integration tests to verify that negative cache hits correctly short-circuit and do not emit backend network requests.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@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 implements negative stat-cache functionality to optimize lookups for non-existent files and directories, reducing redundant backend GCS requests. Key changes include updates to LookUpChild in dir.go to short-circuit on confirmed negative hits, and logic in fast_stat_bucket.go to manage negative cache entries. Documentation and tests were also added to support this feature. Review feedback suggests removing speculative negative caching in insertListing to avoid correctness issues with paginated GCS listings and adding a warning in the documentation regarding the risks of using an infinite TTL for negative entries.

Comment thread internal/storage/caching/fast_stat_bucket.go Outdated
Comment thread docs/semantics.md
…s blocking CI

- Remove speculative negative caching from listing path to avoid pagination bugs (addressed review comment).
- Add warning about infinite negative TTL usage in semantics.md (addressed review comment).
- Fix deadlock in createFile's defer in fs.go when error occurs before child inode is minted.
- Fix data race in downloader Job by deep-copying MinObject, preventing race with reader thread.
- Fix missing lock in fake bucket's MoveObject, resolving race with StatObject.
…hing, add doc warning

- Revert data race fixes in downloader Job (moved to separate PR).
- Revert name length checks and deadlock fix in fs.go (moved to separate PR).
- Revert name length checks in dir.go (moved to separate PR), keeping only LookUpChild short-circuiting.
- Revert MoveObject lock fix in fake bucket (moved to separate PR), keeping FetchOnlyFromCache checks.
- Remove speculative negative caching on empty directory listing to avoid pagination bugs (addressed review comment).
- Add warning about infinite TTL usage for negative caching in semantics.md (addressed review comment).
@alleaditya alleaditya requested review from vadlakondaswetha and removed request for geertj May 25, 2026 13:36
@alleaditya alleaditya self-assigned this May 25, 2026
@alleaditya alleaditya added execute-perf-test Execute performance test in PR execute-integration-tests Run only integration tests execute-integration-tests-on-zb To run E2E tests on zonal bucket. and removed execute-perf-test Execute performance test in PR execute-integration-tests Run only integration tests labels May 25, 2026
@alleaditya alleaditya requested a review from raj-prince June 1, 2026 08:31
@alleaditya alleaditya enabled auto-merge (squash) June 1, 2026 08:31
@alleaditya alleaditya disabled auto-merge June 1, 2026 08:31
Comment thread internal/fs/inode/dir.go Outdated
@alleaditya alleaditya requested a review from raj-prince June 4, 2026 08:31
…_bucket

Address PR comments by avoiding changes to inode/dir.go and limiting
negative caching to fast_stat_bucket. Skip negative caching for HNS
buckets.
Comment thread internal/storage/caching/fast_stat_bucket.go Outdated
Comment thread internal/storage/caching/fast_stat_bucket.go Outdated
Comment thread internal/storage/caching/fast_stat_bucket_test.go Outdated
Comment thread internal/fs/inode/dir.go
Comment thread internal/fs/inode/dir.go Outdated
Comment thread internal/storage/caching/fast_stat_bucket.go Outdated
Comment thread internal/storage/caching/fast_stat_bucket.go
Comment thread internal/storage/caching/fast_stat_bucket_test.go Outdated
setup.SaveGCSFuseLogFileInCaseOfFailure(s.T())
// Wait for the metadata cache TTL to expire so that negatively cached entries
// don't pollute subsequent tests.
time.Sleep(2500 * time.Millisecond)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why do we need this change? Also, kind of brittle if someone change the value of metadata-cache-ttl.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Prince, removing this is causing denrty flat bucket test failures

"Running tests with flags: [--implicit-dirs --experimental-enable-dentry-cache --metadata-cache-ttl-secs=2 --client-protocol=grpc --metadata-cache-negative-ttl-secs=2]"

Why time.Sleep(2100 * time.Millisecond) is required in TestStatWithDentryCacheEnabled:

  1. Stale Cache Prevention: The test suite configures a 2-second stat cache TTL (--metadata-cache-ttl-secs=2). Because the test updates the file out-of-band directly on GCS (client.WriteToObject), GCSFuse is unaware of the modification. Sleeping >2s ensures the cached metadata expires so the subsequent stat call fetches the updated object size from GCS rather than returning a stale cache hit.
  2. Preventing Cascading Rate Limits & Cache Pollution: Removing the sleep causes the test to fail immediately and disrupt timing intervals between test iterations (#01). This leads to GCS backend throttling (HTTP 429 Too Many Requests) during directory setup and causes negative dentry cache lookups (ENOENT) from preceding cleanup phases to bleed into subsequent test runs.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why we were not seeing the failure before? Is it because of negative implicit-directory caching? And if the test is not implemented with negative implicit-directory caching then we can explicitly disable it.

@raj-prince raj-prince left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Changes looks good, few minor comments.

@alleaditya alleaditya requested a review from raj-prince July 3, 2026 17:27
@alleaditya alleaditya added execute-perf-test Execute performance test in PR execute-integration-tests-on-zb To run E2E tests on zonal bucket. labels Jul 3, 2026
@alleaditya alleaditya force-pushed the add-negative-stat-cache branch from 962835f to f36031a Compare July 4, 2026 12:30
@alleaditya alleaditya removed execute-integration-tests-on-zb To run E2E tests on zonal bucket. execute-perf-test Execute performance test in PR labels Jul 4, 2026
@alleaditya alleaditya enabled auto-merge (squash) July 5, 2026 03:13
@alleaditya alleaditya added execute-integration-tests-on-zb To run E2E tests on zonal bucket. execute-perf-test Execute performance test in PR execute-integration-tests Run only integration tests and removed execute-integration-tests Run only integration tests execute-integration-tests-on-zb To run E2E tests on zonal bucket. labels Jul 5, 2026
@alleaditya alleaditya force-pushed the add-negative-stat-cache branch from 5d74924 to 4d4fc09 Compare July 9, 2026 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

execute-integration-tests Run only integration tests execute-perf-test Execute performance test in PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants