Skip to content

🐛 fix: raise LMDB mapsize cap 8GB→16GB + PersistentEmbeddingCache auto-resize on MDB_MAP_FULL (#189) - #190

Merged
flupkede merged 4 commits into
developfrom
fix/mdb-map-full-189
Aug 5, 2026
Merged

🐛 fix: raise LMDB mapsize cap 8GB→16GB + PersistentEmbeddingCache auto-resize on MDB_MAP_FULL (#189)#190
flupkede merged 4 commits into
developfrom
fix/mdb-map-full-189

Conversation

@flupkede

@flupkede flupkede commented Aug 5, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes the fatal MDB_MAP_FULL: Environment mapsize limit reached crash on large corpus indexing (#189).

Two complementary changes:

  1. Raise the LMDB mapsize cap from 8 GB → 16 GB default, with an env-var override escape hatch.
  2. Auto-resize PersistentEmbeddingCache on MDB_MAP_FULL — the cache LMDB was the remaining failure surface after VectorStore::build_index already had this fix; the cache's own put/put_batch paths still aborted on a full map.

Root cause

Two LMDB environments share the process, and only one of them could grow past its cap on MDB_MAP_FULL:

  • VectorStore::build_index already had a resize-retry loop.
  • PersistentEmbeddingCache::put / put_batch did not — a full cache map was a hard crash.

On top of that, the global MAX_LMDB_MAP_SIZE_MB cap (8 GB) was too small for the repro in #189, so even the resize-capable paths hit the ceiling.

Changes by stage

  • Stage 1 (7a58e78)src/constants.rs, src/vectordb/store.rs
    • Raise MAX_LMDB_MAP_SIZE_MB 8 GB → 16 GB.
    • New max_lmdb_map_size_mb() accessor with env override CODESEARCH_MAX_LMDB_MAP_SIZE_MB (clamped to ≥ 1024 MB; fail-fast on parse error).
    • Route all 5 vector-store cap comparisons through the accessor (no logic change, single source of truth).
  • Stage 2 (89244a1)src/embed/cache.rs
    • Add MDB_MAP_FULL auto-resize retry loops to PersistentEmbeddingCache::put / put_batch, mirroring the existing VectorStore::build_index pattern.
    • Persist the grown mapsize across restarts; &self receiver preserved (no API churn).
  • Stage 3 (e58e225)src/embed/cache.rs
    • 3 tests pinning resize-on-full, persist-after-grow, and reopen-with-persisted-mapsize. Defect-injection verified by reviewer.
  • Post-stage (116176c)src/constants.rs
    • Lower the cap 32 GB → 16 GB per user direction: 16 GB is ample for the mapsize fatal crash #189 repro, and the env override remains the escape hatch for any larger corpus.

Escape hatch

# Override the mapsize cap (MB), e.g. 32 GB for a very large corpus
export CODESEARCH_MAX_LMDB_MAP_SIZE_MB=32768

Clamped to a minimum of 1024 MB; a non-integer value fails fast at startup rather than silently falling back.

Validation

All green on push (QC gate):

  • cargo fmt --all -- --check
  • cargo check --all-targets
  • cargo clippy --all-targets -- -D warnings
  • cargo test --lib --bins558 passed / 0 failed

Reviews

All 4 stages reviewed individually (4× PASS, zero Critical / zero Important findings).

Files changed

File Delta What
src/constants.rs +50 / -3 mapsize cap, accessor + env override
src/vectordb/store.rs +6 / -13 route caps through accessor
src/embed/cache.rs +333 / -0 auto-resize + persist + 3 tests

Closes #189

Note: in this develop-based gitflow, Closes #189 resolves when the change reaches master (the release merge), not on the merge into develop. The trailer is included for traceability either way.

Test User added 4 commits August 4, 2026 23:25
)

The 8GB hard cap (MAX_LMDB_MAP_SIZE_MB=8192) was too low for very large
corpora — GitHub issue #189 shows a 1GB / 53k-file cargo-registry source
with >1.2M chunks legitimately exceeding it, crashing after auto-resize
exhausts ("already at max size 8192MB" → fatal MDB_MAP_FULL).

- constants.rs: raise MAX_LMDB_MAP_SIZE_MB 8192→32768 (32GB). On 64-bit
  Linux/macOS the mapsize is just a VA reservation (free until written);
  on Windows the file may be pre-allocated but only to the grown size,
  which only happens on demand when MDB_MAP_FULL bites.
- constants.rs: add max_lmdb_map_size_mb() reading the new
  CODESEARCH_MAX_LMDB_MAP_SIZE_MB env var (clamped to >= default), so
  operators with extreme corpora or Windows instances can tune the cap
  without rebuilding.
- store.rs: route the 5 runtime cap comparisons (pin_map_size,
  resize_environment check+message, build_index, delete_chunks,
  insert_chunks_with_ids) through max_lmdb_map_size_mb(). The cap test
  is now env-aware (asserts against the resolved fn, not the const).

Stage 1 of 3 for #189. Stage 2 adds the same auto-resize to
PersistentEmbeddingCache (currently hardcoded 512MB, no resize).
@flupkede
flupkede merged commit 4c9fc4b into develop Aug 5, 2026
1 check passed
@flupkede
flupkede deleted the fix/mdb-map-full-189 branch August 5, 2026 08:10
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