Re: [PATCH 14/16] reftable/table: introduce iterator for table blocks
- From
Justin Tobler <jltobler@gmail.com>
- Date
- Apr 2, 2025, 21:46 UTC
- Message-ID
- <q6shqgjoe5vlt3fduj6cq6473plz7mmlmnmyuwft7huuod5hhn@je7sijo3v54z>
- In-Reply-To
- <20250331-pks-reftable-polishing-v1-14-ebed5247434c@pks.im>
On 25/03/31 10:41AM, Patrick Steinhardt wrote:
Show 42 quoted lines
> Introduce a new iterator that allows the caller to iterate through all
> blocks contained in a table. This gives users more fine-grained control
> over how exactly those blocks are being read and exposes information to
> callers that was previously inaccessible.
>
> This iterator will be required by a future patch series that adds
> consistency checks for the reftable backend. In addition to that though
> we will also reimplement `reftable_table_print_blocks()` on top of this
> new iterator in a subsequent commit.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
> reftable/reftable-table.h | 16 ++++++
> reftable/table.c | 47 +++++++++++++++++
> t/unit-tests/t-reftable-table.c | 109 ++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 172 insertions(+)
>
> diff --git a/reftable/reftable-table.h b/reftable/reftable-table.h
> index a78db9eea7e..f0f1784c664 100644
> --- a/reftable/reftable-table.h
> +++ b/reftable/reftable-table.h
> @@ -10,6 +10,7 @@
> #define REFTABLE_TABLE_H
>
> #include "reftable-iterator.h"
> +#include "reftable-block.h"
> #include "reftable-blocksource.h"
>
> /*
> @@ -99,4 +100,19 @@ uint64_t reftable_table_min_update_index(struct reftable_table *t);
> /* print blocks onto stdout for debugging. */
> int reftable_table_print_blocks(const char *tablename);
>
> +/*
> + * An iterator that iterates through the blocks contained in a given table.
> + */
> +struct reftable_table_iterator {
> + void *iter_arg;
> +};
> +
> +int reftable_table_init_table_iterator(struct reftable_table *t,
> + struct reftable_table_iterator *it);Any reason we don't call this `reftable_table_iterator_init`? Seems like it would more closely match the other functions.
Show 7 quoted lines
> + > +void reftable_table_iterator_release(struct reftable_table_iterator *it); > + > +int reftable_table_iterator_next(struct reftable_table_iterator *it, > + const struct reftable_block **out); > + > #endif