Component Deep Dive: src/entry.rs

The entry module defines the smallest logical unit handled by the storage engine: a single columnar value augmented with optional metadata fields. Entries are aggregated into Pages and constitute the payload manipulated by higher-level operations.

Source Snapshot

src/entry.rs
 5  pub fn current_epoch_millis() -> u64 { … }
12  #[derive(Serialize, Deserialize, Clone)]
13  pub struct Entry { prefix_meta, data, suffix_meta }
19  impl Entry { pub fn new(data: &str) -> Self { … } }

Responsibilities

┌────────────────────────────────────────────┐
│ Entry                                      │
│  - Immutable columnar value wrapper        │
│  - Serializable via Serde                  │
│  - Used inside Page::entries               │
└────────────────────────────────────────────┘
  1. Logical Value Carrier
    Entry encapsulates the raw string data associated with a single row/column intersection. The surrounding metadata fields (prefix_meta, suffix_meta) are placeholders for future bookkeeping (compression hints, digests, etc.).

  2. Serialization Compatibility
    The derive macros (Serialize, Deserialize, Clone) guarantee that Entry can be persisted and resurrected via bincode, which underpins the compressor, WAL, and eventual page durability.

  3. Timestamp Utility
    current_epoch_millis() exposes a monotonic timestamp used elsewhere for LRU eviction (PageCache) and MVCC bookkeeping (TableMetaStore). Centralizing this helper in the entry module avoids circular dependencies.

Memory Layout

Entry
├─ prefix_meta : String   (reserved for future use)
├─ data        : String   (user payload)
└─ suffix_meta : String   (reserved for trailing metadata)

In memory, each Entry owns three String allocations. Compression and serialization shrink and merge these allocations when persisted inside a Page.

Lifecycle

create Entry::new(data)
        │
        ▼
Page::add_entry pushes Entry into Vec<Entry>
        │
        ▼
Page serialized via bincode
        │
        ▼
Compressor applies LZ4
        │
        ▼
Stored in CPC / disk as part of a Page blob

Interactions

  • Page (src/page.rs) owns a Vec<Entry> and uses direct push semantics for appends and updates.
  • ops_handler uses Entry::new to materialize both new rows and updated values when mutating pages.
  • Future WAL/compaction layers will treat Entry as the leaf node of the storage structure.

Extensibility Notes

  • The placeholder metadata fields allow seamless evolution toward richer value envelopes (e.g., checksum, encoding hints) without changing external APIs.
  • Consider making Entry fields public or providing accessors once per-entry inspection becomes necessary for predicate pushdown or indexing.