From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Subject: [PATCH 03/13] reftable/reader: unify indexed and linear seeking
Date: Wed, 8 May 2024 13:03:47 +0200 [thread overview]
Message-ID: <716863a580f9e1ef8ea796c25c97e50c63585a7b.1715166175.git.ps@pks.im> (raw)
In-Reply-To: <cover.1715166175.git.ps@pks.im>
[-- Attachment #1: Type: text/plain, Size: 3957 bytes --]
In `reader_seek_internal()` we either end up doing an indexed seek when
there is one or a linear seek otherwise. These two code paths are
disjunct without a good reason, where the indexed seek will cause us to
exit early.
Refactor the two code paths such that it becomes possible to share a bit
more code between them.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
reftable/reader.c | 42 ++++++++++++++++--------------------------
1 file changed, 16 insertions(+), 26 deletions(-)
diff --git a/reftable/reader.c b/reftable/reader.c
index 6bfadcad71..cf7f126d8d 100644
--- a/reftable/reader.c
+++ b/reftable/reader.c
@@ -425,7 +425,7 @@ static int reader_seek_linear(struct table_iter *ti,
struct strbuf want_key = STRBUF_INIT;
struct strbuf got_key = STRBUF_INIT;
struct reftable_record rec;
- int err = -1;
+ int err;
reftable_record_init(&rec, reftable_record_type(want));
reftable_record_key(want, &want_key);
@@ -499,8 +499,8 @@ static int reader_seek_linear(struct table_iter *ti,
return err;
}
-static int reader_seek_indexed(struct reftable_reader *r,
- struct reftable_iterator *it,
+static int reader_seek_indexed(struct table_iter *ti,
+ struct reftable_reader *r,
struct reftable_record *rec)
{
struct reftable_record want_index = {
@@ -510,13 +510,9 @@ static int reader_seek_indexed(struct reftable_reader *r,
.type = BLOCK_TYPE_INDEX,
.u.idx = { .last_key = STRBUF_INIT },
};
- struct table_iter ti = TABLE_ITER_INIT, *malloced;
- int err = 0;
+ int err;
reftable_record_key(rec, &want_index.u.idx.last_key);
- err = reader_start(r, &ti, reftable_record_type(rec), 1);
- if (err < 0)
- goto done;
/*
* The index may consist of multiple levels, where each level may have
@@ -524,7 +520,7 @@ static int reader_seek_indexed(struct reftable_reader *r,
* 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(&ti, &want_index);
+ err = reader_seek_linear(ti, &want_index);
if (err < 0)
goto done;
@@ -550,36 +546,30 @@ static int reader_seek_indexed(struct reftable_reader *r,
* all levels of the index only to find out that the key does
* not exist.
*/
- err = table_iter_next(&ti, &index_result);
+ err = table_iter_next(ti, &index_result);
if (err != 0)
goto done;
- err = reader_table_iter_at(r, &ti, index_result.u.idx.offset, 0);
+ err = reader_table_iter_at(r, ti, index_result.u.idx.offset, 0);
if (err != 0)
goto done;
- err = block_iter_seek_key(&ti.bi, &ti.br, &want_index.u.idx.last_key);
+ err = block_iter_seek_key(&ti->bi, &ti->br, &want_index.u.idx.last_key);
if (err < 0)
goto done;
- if (ti.typ == reftable_record_type(rec)) {
+ if (ti->typ == reftable_record_type(rec)) {
err = 0;
break;
}
- if (ti.typ != BLOCK_TYPE_INDEX) {
+ if (ti->typ != BLOCK_TYPE_INDEX) {
err = REFTABLE_FORMAT_ERROR;
goto done;
}
}
- REFTABLE_ALLOC_ARRAY(malloced, 1);
- *malloced = ti;
- iterator_from_table_iter(it, malloced);
-
done:
- if (err)
- table_iter_close(&ti);
reftable_record_release(&want_index);
reftable_record_release(&index_result);
return err;
@@ -595,15 +585,15 @@ static int reader_seek_internal(struct reftable_reader *r,
struct table_iter ti = TABLE_ITER_INIT, *p;
int err;
- if (idx > 0)
- return reader_seek_indexed(r, it, rec);
-
- err = reader_start(r, &ti, reftable_record_type(rec), 0);
+ err = reader_start(r, &ti, reftable_record_type(rec), !!idx);
if (err < 0)
goto out;
- err = reader_seek_linear(&ti, rec);
- if (err < 0)
+ if (idx)
+ err = reader_seek_indexed(&ti, r, rec);
+ else
+ err = reader_seek_linear(&ti, rec);
+ if (err)
goto out;
REFTABLE_ALLOC_ARRAY(p, 1);
--
2.45.0
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2024-05-08 11:03 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-08 11:03 [PATCH 00/13] reftable: prepare for re-seekable iterators Patrick Steinhardt
2024-05-08 11:03 ` [PATCH 01/13] reftable/block: use `size_t` to track restart point index Patrick Steinhardt
2024-05-08 11:03 ` [PATCH 02/13] reftable/reader: avoid copying index iterator Patrick Steinhardt
2024-05-08 11:03 ` Patrick Steinhardt [this message]
2024-05-08 11:03 ` [PATCH 04/13] reftable/reader: separate concerns of table iter and reftable reader Patrick Steinhardt
2024-05-08 11:03 ` [PATCH 05/13] reftable/reader: inline `reader_seek_internal()` Patrick Steinhardt
2024-05-08 11:04 ` [PATCH 06/13] reftable/reader: set up the reader when initializing table iterator Patrick Steinhardt
2024-05-08 11:04 ` [PATCH 07/13] reftable/merged: split up initialization and seeking of records Patrick Steinhardt
2024-05-10 19:18 ` Justin Tobler
2024-05-13 8:36 ` Patrick Steinhardt
2024-05-08 11:04 ` [PATCH 08/13] reftable/merged: simplify indices for subiterators Patrick Steinhardt
2024-05-10 19:25 ` Justin Tobler
2024-05-13 8:36 ` Patrick Steinhardt
2024-05-08 11:04 ` [PATCH 09/13] reftable/generic: move seeking of records into the iterator Patrick Steinhardt
2024-05-10 21:44 ` Justin Tobler
2024-05-13 8:36 ` Patrick Steinhardt
2024-05-08 11:04 ` [PATCH 10/13] reftable/generic: adapt interface to allow reuse of iterators Patrick Steinhardt
2024-05-08 11:04 ` [PATCH 11/13] reftable/reader: " Patrick Steinhardt
2024-05-10 21:48 ` Justin Tobler
2024-05-13 8:36 ` Patrick Steinhardt
2024-05-08 11:04 ` [PATCH 12/13] reftable/stack: provide convenience functions to create iterators Patrick Steinhardt
2024-05-08 11:04 ` [PATCH 13/13] reftable/merged: adapt interface to allow reuse of iterators Patrick Steinhardt
2024-05-08 23:42 ` [PATCH 00/13] reftable: prepare for re-seekable iterators Junio C Hamano
2024-05-09 0:16 ` Junio C Hamano
2024-05-10 7:48 ` Patrick Steinhardt
2024-05-10 15:40 ` Junio C Hamano
2024-05-10 16:13 ` Patrick Steinhardt
2024-05-10 17:17 ` Junio C Hamano
2024-05-13 8:46 ` [PATCH v2 " Patrick Steinhardt
2024-05-13 8:47 ` [PATCH v2 01/13] reftable/block: use `size_t` to track restart point index Patrick Steinhardt
2024-05-21 13:34 ` Karthik Nayak
2024-05-22 7:23 ` Patrick Steinhardt
2024-05-13 8:47 ` [PATCH v2 02/13] reftable/reader: avoid copying index iterator Patrick Steinhardt
2024-05-13 8:47 ` [PATCH v2 03/13] reftable/reader: unify indexed and linear seeking Patrick Steinhardt
2024-05-21 14:41 ` Karthik Nayak
2024-05-22 7:23 ` Patrick Steinhardt
2024-05-22 7:56 ` Karthik Nayak
2024-05-13 8:47 ` [PATCH v2 04/13] reftable/reader: separate concerns of table iter and reftable reader Patrick Steinhardt
2024-05-13 8:47 ` [PATCH v2 05/13] reftable/reader: inline `reader_seek_internal()` Patrick Steinhardt
2024-05-13 8:47 ` [PATCH v2 06/13] reftable/reader: set up the reader when initializing table iterator Patrick Steinhardt
2024-05-13 8:47 ` [PATCH v2 07/13] reftable/merged: split up initialization and seeking of records Patrick Steinhardt
2024-05-13 8:47 ` [PATCH v2 08/13] reftable/merged: simplify indices for subiterators Patrick Steinhardt
2024-05-13 8:47 ` [PATCH v2 09/13] reftable/generic: move seeking of records into the iterator Patrick Steinhardt
2024-05-13 8:47 ` [PATCH v2 10/13] reftable/generic: adapt interface to allow reuse of iterators Patrick Steinhardt
2024-05-13 8:47 ` [PATCH v2 11/13] reftable/reader: " Patrick Steinhardt
2024-05-13 8:47 ` [PATCH v2 12/13] reftable/stack: provide convenience functions to create iterators Patrick Steinhardt
2024-05-13 8:48 ` [PATCH v2 13/13] reftable/merged: adapt interface to allow reuse of iterators Patrick Steinhardt
2024-05-15 20:15 ` [PATCH v2 00/13] reftable: prepare for re-seekable iterators Justin Tobler
2024-05-21 15:31 ` Karthik Nayak
2024-05-22 7:23 ` Patrick Steinhardt
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=716863a580f9e1ef8ea796c25c97e50c63585a7b.1715166175.git.ps@pks.im \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).