From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
Toon Claes <toon@iotcl.com>,
Kristoffer Haugsbakk <code@khaugsbakk.name>
Subject: Re: [PATCH v2 5/5] reftable: document reading and writing indices
Date: Tue, 6 Feb 2024 08:04:00 +0100 [thread overview]
Message-ID: <ZcHZ4HM8f1eGr710@tanuki> (raw)
In-Reply-To: <oslbbspnu4spohamhenhxyqv23fct7ltuqkdl67liw774opxwj@jjprhh7zy34o>
[-- Attachment #1: Type: text/plain, Size: 2275 bytes --]
On Mon, Feb 05, 2024 at 07:43:07PM -0600, jltobler wrote:
> On 24/02/01 08:52AM, Patrick Steinhardt wrote:
> > The way the index gets written and read is not trivial at all and
> > requires the reader to piece together a bunch of parts to figure out how
> > it works. Add some documentation to hopefully make this easier to
> > understand for the next reader.
> >
> > Signed-off-by: Patrick Steinhardt <ps@pks.im>
> > ---
> > reftable/reader.c | 27 +++++++++++++++++++++++++++
> > reftable/writer.c | 23 +++++++++++++++++++++++
> > 2 files changed, 50 insertions(+)
> >
> > diff --git a/reftable/reader.c b/reftable/reader.c
> > index 278f727a3d..6011d0aa04 100644
> > --- a/reftable/reader.c
> > +++ b/reftable/reader.c
> > @@ -508,11 +508,38 @@ static int reader_seek_indexed(struct reftable_reader *r,
> > if (err < 0)
> > goto done;
> >
> > + /*
> > + * The index may consist of multiple levels, where each level may have
> > + * multiple index blocks. We start by doing a linear search in the
> > + * highest layer that identifies the relevant index block as well as
> > + * the record inside that block that corresponds to our wanted key.
> > + */
> > err = reader_seek_linear(&index_iter, &want_index);
> > if (err < 0)
> > goto done;
> >
> > + /*
> > + * Traverse down the levels until we find a non-index entry.
> > + */
> > while (1) {
> > + /*
> > + * In case we seek a record that does not exist the index iter
> > + * will tell us that the iterator is over. This works because
> > + * the last index entry of the current level will contain the
> > + * last key it knows about. So in case our seeked key is larger
> > + * than the last indexed key we know that it won't exist.
>
> The last block in the highest-level index section should end with the
> record key of greatest value. Doesn't that mean the initial linear seek
> should be sufficient to stop the iterator from continuing if the wanted
> record key is of a greater value?
Yes. But we only notice it here when calling `table_iter_next()`. The
call to `reader_seek_linear()` will not return an end-of-iterator
indication.
Is there any way you think this comment can be improved to clarify this?
Patrick
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
prev parent reply other threads:[~2024-02-06 7:04 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-26 10:31 [PATCH 0/5] reftable: fix writing multi-level indices Patrick Steinhardt
2024-01-26 10:31 ` [PATCH 1/5] reftable/reader: be more careful about errors in indexed seeks Patrick Steinhardt
2024-01-26 10:31 ` [PATCH 2/5] reftable/writer: use correct type to iterate through index entries Patrick Steinhardt
2024-01-26 10:31 ` [PATCH 3/5] reftable/writer: simplify writing index records Patrick Steinhardt
2024-01-31 13:44 ` Toon Claes
2024-02-01 8:39 ` Patrick Steinhardt
2024-01-31 15:55 ` Kristoffer Haugsbakk
2024-02-01 8:39 ` Patrick Steinhardt
2024-01-26 10:31 ` [PATCH 4/5] reftable/writer: fix writing multi-level indices Patrick Steinhardt
2024-01-26 10:31 ` [PATCH 5/5] reftable: document reading and writing indices Patrick Steinhardt
2024-01-26 16:26 ` [PATCH 0/5] reftable: fix writing multi-level indices Junio C Hamano
2024-02-01 7:51 ` [PATCH v2 " Patrick Steinhardt
2024-02-01 7:51 ` [PATCH v2 1/5] reftable/reader: be more careful about errors in indexed seeks Patrick Steinhardt
2024-02-01 7:52 ` [PATCH v2 2/5] reftable/writer: use correct type to iterate through index entries Patrick Steinhardt
2024-02-01 7:52 ` [PATCH v2 3/5] reftable/writer: simplify writing index records Patrick Steinhardt
2024-02-01 7:52 ` [PATCH v2 4/5] reftable/writer: fix writing multi-level indices Patrick Steinhardt
2024-02-05 23:56 ` jltobler
2024-02-06 7:01 ` Patrick Steinhardt
2024-02-01 7:52 ` [PATCH v2 5/5] reftable: document reading and writing indices Patrick Steinhardt
2024-02-06 1:43 ` jltobler
2024-02-06 7:04 ` Patrick Steinhardt [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZcHZ4HM8f1eGr710@tanuki \
--to=ps@pks.im \
--cc=code@khaugsbakk.name \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=toon@iotcl.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.