Skip to content

cache: the predictive cache a mount builds has no reachable statistics #223

Closed

Description

@scttfrdmn

What

PredictiveCache computes PredictionAccuracy, PrefetchEfficiency, and CacheHitImprovement, and on a running mount there is no way to read any of them.

MultiLevelCache.initializeLevels (internal/cache/multilevel.go:358-381) wraps the L1 cache in a PredictiveCache whenever prefetch is enabled — internal/adapter/adapter.go:136 sets Prefetch: true unconditionally, so this is every mount — and stores it as a types.Cache in a CacheLevel. From there:

  • types.Cache is six methods about bytes. No statistics beyond Stats().
  • MultiLevelCache.GetLevelStats("L1") returns a types.CacheStats — hits, misses, size, hit ratio. None of the three predictive fields.
  • There is no exported accessor on MultiLevelCache that reaches a level's underlying cache. Close gets at it only through the unexported CacheCloser type assertion.

So the numbers are computed on every read, aggregated on a 30-second ticker, and discarded at unmount.

How it surfaced

docs/features/read-ahead.md documented the way to read them:

predictiveCache := cache.GetPredictiveCache()
stats := predictiveCache.GetPredictiveStats()

GetPredictiveCache does not exist under that or any other name — zero hits repo-wide. It was caught by TestDocumentedGoSymbolsExist (internal/config/docs_symbols_test.go), the #182 gate, on its first run. The documentation is now corrected to say the statistics are unreachable and to point here.

GetPredictiveStats itself is real (internal/cache/predictive.go:396). It is reachable only on a PredictiveCache the caller constructed, which observes that caller's accesses and nothing the filesystem does.

Options

  1. Export them through the metrics surface. The most useful outcome: these are exactly the numbers an operator wants when deciding whether prefetch is earning its bandwidth. internal/metrics already exports objectfs_cache_requests_total and objectfs_cache_size_bytes; three gauges alongside them would make prefetch effectiveness observable in Prometheus, which is where the rest of the cache telemetry already is.
  2. An accessor on MultiLevelCache. Cheaper — something like PredictiveStats() (PredictiveStats, bool), returning false when L1 is not wrapped. Makes them reachable in-process, but nothing currently in the tree would call it, so it risks being a second unexercised path.
  3. Delete the three fields. Consistent with the argument in metrics: percentile fields are never assigned and the latency histogram is a modulo, not a bucketing #222: a statistic nothing can read is not a feature. Weaker here than there, though — unlike metrics: percentile fields are never assigned and the latency histogram is a modulo, not a bucketing #222's percentiles these are computed correctly, so the defect is plumbing rather than arithmetic.

Option 1 is the recommendation. Note the ordering against the ML predictor: docs/index.md's not-yet-wired-up table records that internal/analytics's Predictor field is never set on the mount path, so PredictionAccuracy today measures the pattern detector rather than the model the documentation attributes it to. Exporting the metric without that context would publish a number under a misleading name — the same shape of defect as #222's zero percentiles.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: cacheeffort: smallpriority: mediumtype: technical-debt

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions