Skip to content

feat(#21): SstableIterator — lazy block loading + cobertura >90%#71

Merged
ElioNeto merged 2 commits into
developfrom
feature/issue-21-sst-iterator
Mar 6, 2026
Merged

feat(#21): SstableIterator — lazy block loading + cobertura >90%#71
ElioNeto merged 2 commits into
developfrom
feature/issue-21-sst-iterator

Conversation

@ElioNeto
Copy link
Copy Markdown
Owner

@ElioNeto ElioNeto commented Mar 6, 2026

Contexto

Implementa a Task 2.2 — SSTable Iterator (closes #21).


O que foi feito

src/storage/sst_iterator.rs — arquivo novo

SstableIterator implementa StorageIterator sobre um Arc<SstableReader>:

Método Comportamento
new(reader) Posiciona no primeiro entry do SSTable
new_seek(reader, key) Posiciona no primeiro key >= key
next() Avança um entry; carrega próximo bloco transparentemente
seek(key) Busca binária no índice esparso + scan linear no bloco
is_valid() true enquanto aponta para um entry válido

Blocos são carregados de forma lazy (da cache ou do disco via read_block) sem duplicar a lógica de decompressão.

src/storage/reader.rs

read_block promovido de fnpub(crate) fn para que SstableIterator possa reutilizá-lo.

src/storage/mod.rs

Adicionado pub mod sst_iterator.


Testes (27 novos)

Categoria Testes
Construção new posiciona no primeiro entry; new_seek posiciona corretamente
Scan completo Single-block e multi-block (com block_size pequeno)
Valores Decodificação correta de LogRecord
seek() Exact-match 1ª/última/meio, entre chaves, antes/depois de tudo, cross-boundary
Scan após seek Iteração do ponto de seek até o fim
Edge cases next() além do fim é no-op, is_valid() permanece false
SSTables grandes 200 entradas em 512-byte blocks — full scan e seek para último quarto
Tombstones Entradas deletadas são visíveis e marcadas corretamente
Helpers read_entry e read_key — happy path e dados truncados
Índice find_block_for_key nunca retorna índice fora-de-bounds

Cobertura estimada >90% (storage module + sst_iterator).

ElioNeto added 2 commits March 6, 2026 16:26
- Add SstableIterator in src/storage/sst_iterator.rs
  - Implements StorageIterator trait (key/value/is_valid/next/seek)
  - Loads blocks lazily from disk/cache via Arc<SstableReader>
  - next() transparently crosses block boundaries
  - seek() uses sparse-index binary search + in-block linear scan
  - SstableIterator::new() and new_seek() constructors
  - read_entry / read_key private helpers with bounds checking
  - 25 unit + integration tests (single block, multi-block,
    seek edge-cases, tombstones, large SSTables)

- src/storage/reader.rs: expose read_block as pub(crate)
  so SstableIterator can load blocks via the reader

- src/storage/mod.rs: register pub mod sst_iterator

Closes #21
@ElioNeto ElioNeto merged commit 37bef8f into develop Mar 6, 2026
14 checks passed
@github-actions github-actions Bot mentioned this pull request Mar 6, 2026
4 tasks
@ElioNeto ElioNeto deleted the feature/issue-21-sst-iterator branch April 9, 2026 21:27
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