Repository navigation
wal: Batch.ReadPlaced returns each payload's page key and range - #14
Draft
Seif Lotfy (seiflotfy) wants to merge 1 commit into
Draft
Seif Lotfy (seiflotfy) wants to merge 1 commit into
Seif Lotfy (seiflotfy) wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Batch.ReadPlacedisBatch.Readthat also returns each payload'sPlace: the page's whole key in the log's store (the keyReadGETs), and the payload's offset and length in that page. It runs after the same hash, CRC, header, record count and read budget checks;ReadandReadPlacedshare one loop.The contract is two guarantees:
The offset comes from the record's place in the page buffer, which
Scanaliases (cap(page) - cap(record)), not from the header, whose length varies by page.Test:
TestLogReadPlacedcommits 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 payloadReadPlacedreturns equalsRead's, andGetRangeat 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:
Offat the length prefix;Offcounted from the end of page 0's header on every page;Offthe record's position in the batch;Lenone byte short.go vet ./...is clean andgo test ./walpasses (go1.27.1).Draft: not to be merged before review.