1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//! Overlay: in-memory view of dirty files for incremental updates.
//!
//! The overlay provides read-your-writes freshness with atomic batch commits
//! and snapshot isolation. Pending edits are invisible until `commit_batch()`.
//!
//! Design: single merged query view (research.md section 7). Each
//! `commit_batch()` incrementally rebuilds the overlay, reusing docs from
//! the previous generation for unchanged files and reading only the delta
//! from disk.
use HashMap;
use ;
use Arc;
/// Kind of file change buffered by `notify_change` / `notify_delete`.
/// A buffered file edit not yet committed to the index snapshot.
/// A dirty file tracked by the overlay with its current content and grams.
///
/// # Memory: content is pinned for the overlay's lifetime
///
/// `content` holds the full file bytes and is carried forward across snapshot
/// generations via `Arc::clone` (refcount bump, no copy). This keeps verify-time
/// reads O(1) and avoids re-reading changed files on every commit. The cost is
/// that every dirty file's content stays resident for as long as it remains in
/// the overlay. With the 50%-of-base overlay cap (`OVERLAY_ENFORCE_THRESHOLD`)
/// and default 10 MB `max_file_size`, a long-lived process (watcher, library
/// consumer) can legitimately hold gigabytes of overlay content.
///
/// v2 mitigation (not yet implemented): store `content_hash` + `grams` only and
/// re-read content from disk at verify time via the same hardened path
/// (`resolve_doc`) used for base docs, or spill docs above a byte threshold.
/// The carry-forward cost note in `build_incremental_delta` applies equally to
/// any spill design.
/// Single merged in-memory gram index for all dirty files.
///
/// A fresh `OverlayView` is produced on each `commit_batch()`, but unchanged
/// file content is `Arc`-reused across generations (`OverlayDoc::content`);
/// posting lists are likewise `Arc`-shared so the delta commit path
/// (`build_incremental_delta`) clones the map as refcount bumps and only
/// deep-copies the lists it actually mutates. Query execution always does two
/// lookups: base segments + this single overlay.
// Re-export pending types so callers using `crate::index::overlay::*` continue to compile.
pub use crate;