Subject: Re: [PATCH 00/13] reftable: prepare for re-seekable iterators

From: Junio C Hamano <[email-masked]>
Date: Wed, 08 May 2024 16:42:11 -0700

Patrick Steinhardt <[email-masked]> writes:

> To address this inefficiency, the patch series at hand refactors the
> reftable library such that creation of iterators and seeking on an
> iterator are separate steps. This refactoring prepares us for reusing
> iterators to perform multiple seeks, which in turn will allow us to
> reuse internal data structures for subsequent seeks.

;-)

> Note: this series does not yet go all the way to re-seekable iterators,
> and there are no users yet. The patch series is complex enough as-is
> already, so I decided to defer that to the next iteration. Thus, the
> whole refactoring here should essentially be a large no-op that prepares
> the infrastructure for re-seekable iterators.
>
> The series depends on pks/reftable-write-optim at fa74f32291
> (reftable/block: reuse compressed array, 2024-04-08).

There is another topic on reftable to make write options tweakable,
whose addition of reftable/dump and reader_print_blocks interface
needs to be adjusted to this change, I think.

 reftable/reader.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git c/reftable/reader.c w/reftable/reader.c
index 2ea830bdb6..fd516e01db 100644
--- c/reftable/reader.c
+++ w/reftable/reader.c
@@ -841,7 +841,7 @@ int reftable_reader_print_blocks(const char *tablename)
 		},
 	};
 	struct reftable_block_source src = { 0 };
-	struct table_iter ti = TABLE_ITER_INIT;
+	struct table_iter *ti;
 	struct reftable_reader *r = NULL;
 	size_t i;
 	int err;
@@ -854,11 +854,14 @@ int reftable_reader_print_blocks(const char *tablename)
 	if (err < 0)
 		goto done;
 
+	REFTABLE_ALLOC_ARRAY(ti, 1);
+	table_iter_init(ti, r);
+
 	printf("header:\n");
 	printf("  block_size: %d\n", r->block_size);
 
 	for (i = 0; i < ARRAY_SIZE(sections); i++) {
-		err = reader_start(r, &ti, sections[i].type, 0);
+		err = table_iter_seek_start(ti, sections[i].type, 0);
 		if (err < 0)
 			goto done;
 		if (err > 0)
@@ -867,10 +870,10 @@ int reftable_reader_print_blocks(const char *tablename)
 		printf("%s:\n", sections[i].name);
 
 		while (1) {
-			printf("  - length: %u\n", ti.br.block_len);
-			printf("    restarts: %u\n", ti.br.restart_count);
+			printf("  - length: %u\n", ti->br.block_len);
+			printf("    restarts: %u\n", ti->br.restart_count);
 
-			err = table_iter_next_block(&ti);
+			err = table_iter_next_block(ti);
 			if (err < 0)
 				goto done;
 			if (err > 0)
@@ -880,6 +883,6 @@ int reftable_reader_print_blocks(const char *tablename)
 
 done:
 	reftable_reader_free(r);
-	table_iter_close(&ti);
+	table_iter_close(ti);
 	return err;
 }