Skip to content

wal: Batch.ReadPlaced returns each payload's page key and range - #14

Draft
Seif Lotfy (seiflotfy) wants to merge 1 commit into
mainfrom
read-placed
Draft

Seif Lotfy (seiflotfy) wants to merge 1 commit into
mainfrom
read-placed

Conversation

@seiflotfy

Copy link
Copy Markdown
Member

Batch.ReadPlaced is Batch.Read that also returns each payload's Place: the page's whole key in the log's store (the key Read GETs), and the payload's offset and length in that page. It runs after the same hash, CRC, header, record count and read budget checks; Read and ReadPlaced share one loop.

The contract is two guarantees:

  1. The object at a returned key is never rewritten or deleted.
  2. The payload lies verbatim at the returned offset.

The offset comes from the record's place in the page buffer, which Scan aliases (cap(page) - cap(record)), not from the header, whose length varies by page.

Test: TestLogReadPlaced commits one batch cut into two pages whose headers differ in length (151 and 21 records). Its records have length prefixes of 1, 2 and 3 bytes, and one is empty. Every payload ReadPlaced returns equals Read's, and GetRange at its place returns it. For the empty one, the byte before its offset is its length prefix, 0.

Each of these faults, planted alone, fails the test:

  • Off at the length prefix;
  • Off counted from the end of page 0's header on every page;
  • the page key off by one;
  • Off the record's position in the batch;
  • Len one byte short.

go vet ./... is clean and go test ./wal passes (go1.27.1).

Draft: not to be merged before review.

A caller that keeps a payload's place can read it again later with one
GetRange instead of reading its batch. ReadPlaced is Read that also
returns, for each payload in order, the page's whole key in the log's
store (the key Read GETs) and the payload's offset and length in that
page, after the same hash, CRC, header, record count and read budget
checks. Both share one loop. The offset comes from the record's place
in the page buffer, which Scan aliases, not from the header, whose
length varies by page.

The contract is two guarantees: the object at a returned key is never
rewritten or deleted, and the payload lies verbatim at the returned
offset.

TestLogReadPlaced commits one batch of two pages whose headers differ
in length, of records whose length prefixes take 1, 2 and 3 bytes, an
empty one among them. Every payload ReadPlaced returns equals Read's,
and GetRange at its place returns it.

Co-authored-by: Seif Lotfy <seif@axiom.co>
Amp-Thread-ID: https://ampcode.com/threads/T-01a1f19f-cfa5-7458-8386-467a892d7ae6
Co-authored-by: Amp <amp@ampcode.com>
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.

2 participants