Skip to content

fix(storage): open metadata DB without engine-level TTL - #218

Merged
ovaistariq merged 1 commit into
mainfrom
fix/metadata-db-no-engine-ttl
Aug 18, 2026
Merged

ovaistariq merged 1 commit into
mainfrom
fix/metadata-db-no-engine-ttl

Conversation

@ovaistariq

@ovaistariq ovaistariq commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The metadata DB is opened with grocksdb.OpenDbWithTTL(opts, dbPath, ttl) where ttl is the cache-wide entry TTL (TAG passes 24 h). RocksDB's TTL DB applies a compaction filter to every key in the DB, silently dropping any key not rewritten within the window — including internal bookkeeping that must outlive entry TTLs:

  • per-segment delete-index records (!delete:segment/…) — the recompactor's only fragmentation signal
  • the FIFO eviction index
  • bucketed access keys

A segment's delete index receives its last merge roughly when the segment's last entry expires (~T+24 h for 24 h-TTL data), so RocksDB erases the record around T+48 h and the segment looks clean forever. Its dead bytes become permanently unreclaimable.

Production impact (ORD, 3 nodes, TAG v1.17.5 / ocache v1.10.1): live accounting ~258 GB/pod (under the 400 GB eviction cap) while segments/ held 814 GiB in 3,267 files — ~68% dead bytes, growing ~200 GB/pod/day. ocache_recompaction_segments_total stayed 0 over 30 h (54 runs). PVCs reached 82% and low-disk alerts fired.

Reproduced locally: two MakeDeleteIndexOperand merges into a TTL-opened MetaDB read back correctly within TTL (entries=2, bytes=250), then after TTL + one CompactRange the key is silently absent.

Fix

Open the metadata DB with engine TTL 0 ("never expire"). Entry expiry is owned by the application cleaner, which scans metadata and stages reclamation correctly (it deleted ~232 GB / ~240k keys per pod in those same 30 h) — the engine TTL was redundant for its intended purpose and destructive to bookkeeping.

OpenDbWithTTL(…, 0) keeps the on-disk value format (timestamp suffixes), so existing production DBs remain readable — no migration needed.

Testing

  • New regression test TestDeleteIndexSurvivesEntryTTL: delete-index records outlive an entry-TTL-sized wait plus a full compaction (fails against the old behavior with engine TTL = entry TTL)
  • Full ./storage/... suite passes (11 packages)

Related: perfloop could not trace this one (anchor_failed — startup-config + engine-internal actors aren't workload-reachable), hence the direct fix. Sibling leak (Put overwrite skipping stageFileDeletion) is being worked by perfloop as case_ch2hff4wv9.

Note: this fix prevents future orphaning; bytes already orphaned have no surviving records and need a one-time cache wipe to reclaim.

🤖 Generated with Claude Code

https://claude.ai/code/session_01L5DLvDTo9dhD38YQXhHpU9


Note

Cursor Bugbot is generating a summary for commit aa35544. Configure here.

RocksDB's TTL compaction filter drops every key not rewritten within the
window — including per-segment delete-index records, the FIFO eviction
index, and bucketed access keys. With the DB TTL set to the cache entry
TTL (24h in prod), a segment's delete-index record is silently erased
~24h after its last merge, so the recompactor loses its only
fragmentation signal and dead segment bytes become permanently
unreclaimable. Observed on ORD: 68% of 814 GiB of segments dead with
zero recompactions over 30h; PVCs hit 82%.

Entry expiry is owned by the application cleaner (which scans metadata
and stages reclamation); the engine TTL was redundant for that. Opening
with OpenDbWithTTL(..., 0) disables the filter while preserving the
on-disk value format, so existing DBs stay readable.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01L5DLvDTo9dhD38YQXhHpU9
Signed-off-by: Ovais Tariq <[email protected]>
@greptile-apps

greptile-apps Bot commented Aug 18, 2026

Copy link
Copy Markdown

Greptile Summary

This PR disables RocksDB engine-level TTL for the metadata database so application-owned cleanup can expire entries without deleting long-lived lifecycle indexes.

  • Opens metadata with TTL zero while retaining the TTL-compatible on-disk format.
  • Adds a regression test proving delete-index records survive an entry-TTL-sized delay and forced compaction.

Confidence Score: 4/5

The PR appears safe to merge, with non-blocking follow-up recommended for migration coverage and the now-inert TTL configuration surface.

The application Cleaner continues to own entry expiration and all production metadata initialization uses zero engine TTL; the remaining concerns are test coverage for upgrading existing databases and misleading dead configuration.

Files Needing Attention: storage/metadata_engine_ttl_test.go, storage/storage.go

Important Files Changed

Filename Overview
storage/storage.go Correctly disables destructive engine-level expiry, but leaves StorageConfig.TTL as an ignored and potentially misleading configuration field.
storage/metadata_engine_ttl_test.go Covers delete-index survival in a fresh zero-TTL database but not the claimed nonzero-to-zero production reopen path.

Reviews (1): Last reviewed commit: "fix(storage): open metadata DB without e..." | Re-trigger Greptile

// multiplex merge operator installed. The entry TTL the cache would use is
// deliberately tiny so the wait below exceeds it.
const entryTTLSeconds = 1
db, err := metadata.NewMetaDB(dir, 0, merge.NewMultiplexOperator(), nil)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Cover the production TTL transition

This test creates a fresh database with engine TTL disabled, so it does not exercise the promised production transition where a database written with a nonzero engine TTL is reopened with TTL zero. Add coverage for that reopen sequence so an on-disk compatibility regression cannot pass this test while making existing metadata unreadable.

Knowledge Base Used: Storage Engine

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment thread storage/storage.go
// cleaner, which scans metadata and stages reclamation; the engine TTL was redundant for that.
// OpenDbWithTTL(…, 0) keeps the on-disk value format (timestamp suffixes) so existing DBs
// remain readable; 0 means "never expire".
meta, err := metadata.NewMetaDB(config.DiskPath, 0, mergeOp, rocksConfig)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Remove the inert TTL configuration

This literal makes StorageConfig.TTL ineffective while production and test callers continue to populate it. Remove or deprecate the field and update its callers, or document its new semantics, so configuration and tests do not imply that changing it still affects the metadata engine.

Knowledge Base Used: Storage Engine

@ovaistariq
ovaistariq merged commit dde0375 into main Aug 18, 2026
12 checks passed
@ovaistariq
ovaistariq deleted the fix/metadata-db-no-engine-ttl branch August 18, 2026 02:32
ovaistariq added a commit that referenced this pull request Aug 18, 2026
…#223)

Removing the metadata DB's engine-level TTL (#218) left
StorageConfig.TTL with no consumer: a Put with no key-level TTL never
received an expiry, so configured default expiry silently stopped
working (flagged by Cursor Bugbot on the release PR). Apply the default
app-side in Put, where expiry is enforced by the cleaner — which stages
file and segment reclamation — instead of the engine filter that
dropped bookkeeping keys and orphaned backing bytes.

Signed-off-by: Ovais Tariq <[email protected]>
@tigrisdata-argocd-bot

Copy link
Copy Markdown

🎉 This PR is included in version 1.10.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants