Skip to content

Encrypted storage reads and caches whole leaves; encrypt column blocks separately so reads stay leaflet-sized #2113

Done

Description

@bplatz

On encrypted storage, the smallest unit the engine can read is a whole leaf. Leaflets were meant to make that a few column blocks.

Today

EncryptedStorage seals each object as one AES-GCM envelope. A range read fetches the whole object, decrypts it and slices (read_byte_range falls back to read + decrypt + slice; partial ranges of the ciphertext can't be authenticated). So reading one leaflet's columns from an encrypted leaf decrypts the whole leaf, about 721 KiB at the default geometry.

The cached plaintext leaf is heap memory, charged in full against the same budget as decoded leaflets. Moka's TinyLFU admission keeps a one-pass scan from flushing hot entries. A workload that keeps touching more distinct encrypted leaves than the budget holds will displace decoded leaflets. Not measured: no A/B so far has an encrypted variant.

A remote store with the disk cache turned off (budget 0), or a Permanent store that didn't opt in to the disk cache, does the same under the whole-leaf fetch policy (#2048). There is no file to map, so whole leaves are held on the heap.

Options

  1. Encrypt each zstd column block as its own AEAD chunk. A leaf's column blocks are already independent, separately compressed units, and the directory already records their offsets. Sealing each block separately lets a ranged read fetch and decrypt only the blocks a query projects. Only decoded leaflets would be cached, never a whole decrypted leaf, which brings back the leaflet's purpose on encrypted storage.
    • The leaf header and directory hold first and last keys, row counts and offsets, so they need encrypting too, as their own chunk read once per leaf.
    • Each chunk needs its own nonce (from the leaf identity and block offset, or stored with the block) and its own tag: 16 bytes per block.
    • It's a format change. It needs a version bump and a reindex of encrypted ledgers, and it interacts with Storage: return shared handles from get and move the disk cache into a store wrapper #2029's open stage 4 (encryption above the cache: content ids over ciphertext, key rotation rewriting envelopes).
    • A format-agnostic variant: fixed-size AEAD chunks at the storage layer. That's simpler, but chunk boundaries wouldn't line up with column blocks, so reads decrypt more than they use.
  2. Give heap whole leaves their own small pool (e.g. 1/8 of the leaflet budget, like the stats-view pool's 1/16), so they can never evict decoded leaflets. This is a cache-only change and covers the no-disk-cache remote case too, but encrypted reads stay whole-leaf.
  3. Don't cache decrypted leaves, going back to decrypting per open. That trades memory for repeated decrypts and fetches.

Measure first

Add an encrypted variant to the BSBM and DBLP A/B runs: hit rates, decoded-leaflet evictions and latency, with and without the whole-leaf entries. That shows how much option 2 buys before taking on option 1.

Split out of the review of #2035, which leaves its leaf caching as is.

Activity

  1. added
    P2
    area:storage
    performance
    on Oct 13, 2026
  2. bplatz commented on Nov 20, 2026

    @bplatz
    ContributorAuthor

    #2130 (merged into next 2026-10-20) did the storage-layer variant of option 1 for local stores: fixed-size AEAD segments, read by range. Remote encrypted reads, including a remote store with no disk cache, still decrypt whole objects; that waits on #2029 stage 4. Encrypting each column block separately (option 1 proper) is still open, and is a format change.

  3. added this to the 5.0.0 milestone on Nov 20, 2026
  4. bplatz commented on Nov 23, 2026

    @bplatz
    ContributorAuthor

    Closing: the local-store half is fixed on next, and what remains is tracked elsewhere.

    • Local encrypted stores read by range since perf: read encrypted storage by range within the cache budget #2130 (next). Objects are sealed in 64 KiB segments with a tag each, and leaves, forward dictionary packs and reverse dictionary leaves open as ranged sources. A whole decrypted leaf enters the leaflet cache only for a version-1 envelope, and v5's first index build, always a full rebuild, writes every leaf as version 2. main (4.x) still decrypts whole objects; the fix ships with 5.0.
    • Remote encrypted reads still fetch and decrypt whole objects and keep whole leaves in the leaflet cache. That's Storage: return shared handles from get and move the disk cache into a store wrapper #2029 stage 4 (encryption above the disk cache).
    • Option 1 proper (one AEAD chunk per column block) isn't needed. Its gain over perf: read encrypted storage by range within the cache budget #2130 is segment boundaries lining up with column blocks. The segment size is per object in the envelope header (4 KiB to 16 MiB), so leaves can be written with smaller segments, with no format change, if measurement shows reads decrypting much more than they use. Segments that know nothing of the leaf layout also suit stage 4, which moves encryption into a store wrapper.
    • Option 2 (a pool of its own for whole leaves) now applies only to remote whole-leaf reads. If measurement shows them evicting decoded leaflets, that's a cache change to file then.
    • The measurement this issue asked for is Benchmark encrypted storage, single-stream and under concurrent queries #2147.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2area:storageperformance

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions