git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: reftable [v6]: new ref storage format

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Aug 18, 2017, 09:24 UTC
Message-ID
<CAMy9T_EKLs7vDyRi=jNH47fuCaKcxSvcpK27mKB-7P2EtdBeoQ@mail.gmail.com>
In-Reply-To
<CAJo=hJum2boTfcXOaZVhxmbGB9Dygoc5=TM8RD2nqxo-Ahjv9g@mail.gmail.com>
On Wed, Aug 16, 2017 at 12:47 AM, Shawn Pearce <spearce@spearce.org> wrote:
Show 37 quoted lines
> On Mon, Aug 14, 2017 at 5:13 AM, Michael Haggerty <mhagger@alum.mit.edu> wrote:
>> On 08/07/2017 03:47 AM, Shawn Pearce wrote:
>>> 6th iteration of the reftable storage format.
> [...]
>>> #### index record
>>>
>>> An index record describes the last entry in another block.
>>> Index records are written as:
>>>
>>>     varint( prefix_length )
>>>     varint( (suffix_length << 3) | 0 )
>>>     suffix
>>>     varint( block_position )
>>>
>>> Index records use prefix compression exactly like `ref_record`.
>>>
>>> Index records store `block_position` after the suffix, specifying the
>>> absolute position in bytes (from the start of the file) of the block
>>> that ends with this reference.
>>
>> Is there a reason that the index lists the *last* refname that is
>> contained in a block rather than the *first* refname? I can't think of a
>> reason to choose one vs. the other, but your choice was initially
>> surprising. I don't think it matters either way; I was just curious.
>
> Yes, there is a reason. When a reader is searching the index block and
> discovers a key that is greater than their search needle, they are now
> sitting on a record with the block_position for that greater key. By
> using the *last* refname the current block_position is the one to seek
> to.
>
> If instead we used *first* refname, the reader would now have to
> backtrack to the prior index record to get the block_position out of
> that record. Or it has to keep a running "prior_position" local
> variable.
>
> Using last simplifies the reader's code.

Ah, OK. I was thinking of this as being a binary search, in which case you *must* see both bracketing records before you are done, and the chances are 50-50 which one you see first. But this search is a little bit different, because the index records within a restart block have to be scanned linearly. So it is much more likely that you see the "before" record followed by the "after" record.

Thanks for the explanation.
Michael
Previous: Shawn Pearce
Message 2 of 2 in “Re: reftable [v6]: new ref storage format”
  1. Shawn PearceAug 15, 2017
  2. Michael HaggertyAug 18, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.