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

Re: [PATCH 07/13] reftable/merged: split up initialization and seeking of records

From
Justin Tobler <jltobler@gmail.com>
Date
May 10, 2024, 19:18 UTC
Message-ID
<dqnhhjdingkhhwwp5nwut2hsnkkze7m2ls4kscddqxm3txjzbf@5knvdk4vc6eg>
In-Reply-To
<21b3e3ab5f04e66fdd352187b1da699d1ab67cee.1715166175.git.ps@pks.im>
On 24/05/08 01:04PM, Patrick Steinhardt wrote:
> To initialize a `struct merged_iter`, we need to seek all subiterators
> to the wanted record and then add their results to the priority queue
> used to sort the records. This logic is split up across two functions,
> `merged_table_seek_record()` and `merged_table_iter()`. The scope of
Did we mean `merged_iter_init` instead of `merged_table_iter()` here?
Show 12 quoted lines
> these functions is somewhat weird though, where `merged_table_iter()` is
> only responsible for adding the records of the subiterators to the
> priority queue.
> 
> Clarify the scope of those functions such that `merged_table_iter()` is
> only responsible for initializing the iterator's structure. Performing
> the subiterator seeks are now part of `merged_table_seek_record()`.
> 
> This step is required to move seeking of records into the generic
> `struct reftable_iterator` infrastructure.
> 
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
...
Show 20 quoted lines
> @@ -246,32 +230,33 @@ static int merged_table_seek_record(struct reftable_merged_table *mt,
>  				    struct reftable_iterator *it,
>  				    struct reftable_record *rec)
>  {
> -	struct merged_iter merged = {
> -		.typ = reftable_record_type(rec),
> -		.hash_id = mt->hash_id,
> -		.suppress_deletions = mt->suppress_deletions,
> -		.advance_index = -1,
> -	};
> -	struct merged_iter *p;
> +	struct merged_iter merged, *p;
>  	int err;
>  
> -	REFTABLE_CALLOC_ARRAY(merged.subiters, mt->stack_len);
> +	merged_iter_init(&merged, mt);
> +
>  	for (size_t i = 0; i < mt->stack_len; i++) {
> +		reftable_record_init(&merged.subiters[merged.stack_len].rec,
> +				     reftable_record_type(rec));

I find it somewhat confusing how we increment the subiterator index here. I assume this is because when a record is not found we don't want to add it to the index. Might be nice to add a comment here explaining this.

Edit: Looks like you address this in the next commit so I guess we are
good :)
Show 32 quoted lines
> +
>  		err = reftable_table_seek_record(&mt->stack[i],
>  						 &merged.subiters[merged.stack_len].iter, rec);
>  		if (err < 0)
>  			goto out;
> -		if (!err)
> -			merged.stack_len++;
> -	}
> +		if (err > 0)
> +			continue;
>  
> -	err = merged_iter_init(&merged);
> -	if (err < 0)
> -		goto out;
> +		err = merged_iter_advance_subiter(&merged, merged.stack_len);
> +		if (err < 0)
> +			goto out;
> +
> +		merged.stack_len++;
> +	}
>  
> -	p = reftable_malloc(sizeof(struct merged_iter));
> +	p = reftable_malloc(sizeof(*p));
>  	*p = merged;
>  	iterator_from_merged_iter(it, p);
> +	err = 0;
>  
>  out:
>  	if (err < 0)
> -- 
> 2.45.0
> 
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 9 of 50 in “reftable: prepare for re-seekable iterators”
  1. 00/13 reftable: prepare for re-seekable iteratorsPatrick Steinhardt, May 8, 2024
  2. 01/13 reftable/block: use `size_t` to track restart point indexPatrick Steinhardt, May 8, 2024
  3. 02/13 reftable/reader: avoid copying index iteratorPatrick Steinhardt, May 8, 2024
  4. 03/13 reftable/reader: unify indexed and linear seekingPatrick Steinhardt, May 8, 2024
  5. 04/13 reftable/reader: separate concerns of table iter and reftable readerPatrick Steinhardt, May 8, 2024
  6. 05/13 reftable/reader: inline `reader_seek_internal()`Patrick Steinhardt, May 8, 2024
  7. 06/13 reftable/reader: set up the reader when initializing table iteratorPatrick Steinhardt, May 8, 2024
  8. 07/13 reftable/merged: split up initialization and seeking of recordsPatrick Steinhardt, May 8, 2024
  9. Justin ToblerMay 10, 2024
  10. Patrick SteinhardtMay 13, 2024
  11. 08/13 reftable/merged: simplify indices for subiteratorsPatrick Steinhardt, May 8, 2024
  12. Justin ToblerMay 10, 2024
  13. Patrick SteinhardtMay 13, 2024
  14. 09/13 reftable/generic: move seeking of records into the iteratorPatrick Steinhardt, May 8, 2024
  15. Justin ToblerMay 10, 2024
  16. Patrick SteinhardtMay 13, 2024
  17. 10/13 reftable/generic: adapt interface to allow reuse of iteratorsPatrick Steinhardt, May 8, 2024
  18. 11/13 reftable/reader: adapt interface to allow reuse of iteratorsPatrick Steinhardt, May 8, 2024
  19. Justin ToblerMay 10, 2024
  20. Patrick SteinhardtMay 13, 2024
  21. 12/13 reftable/stack: provide convenience functions to create iteratorsPatrick Steinhardt, May 8, 2024
  22. 13/13 reftable/merged: adapt interface to allow reuse of iteratorsPatrick Steinhardt, May 8, 2024
  23. Junio C HamanoMay 8, 2024
  24. Junio C HamanoMay 9, 2024
  25. Patrick SteinhardtMay 10, 2024
  26. Junio C HamanoMay 10, 2024
  27. Patrick SteinhardtMay 10, 2024
  28. Junio C HamanoMay 10, 2024
  29. 00/13 reftable: prepare for re-seekable iteratorsPatrick Steinhardt, May 13, 2024
  30. 01/13 reftable/block: use `size_t` to track restart point indexPatrick Steinhardt, May 13, 2024
  31. Karthik NayakMay 21, 2024
  32. Patrick SteinhardtMay 22, 2024
  33. 02/13 reftable/reader: avoid copying index iteratorPatrick Steinhardt, May 13, 2024
  34. 03/13 reftable/reader: unify indexed and linear seekingPatrick Steinhardt, May 13, 2024
  35. Karthik NayakMay 21, 2024
  36. Patrick SteinhardtMay 22, 2024
  37. Karthik NayakMay 22, 2024
  38. 04/13 reftable/reader: separate concerns of table iter and reftable readerPatrick Steinhardt, May 13, 2024
  39. 05/13 reftable/reader: inline `reader_seek_internal()`Patrick Steinhardt, May 13, 2024
  40. 06/13 reftable/reader: set up the reader when initializing table iteratorPatrick Steinhardt, May 13, 2024
  41. 07/13 reftable/merged: split up initialization and seeking of recordsPatrick Steinhardt, May 13, 2024
  42. 08/13 reftable/merged: simplify indices for subiteratorsPatrick Steinhardt, May 13, 2024
  43. 09/13 reftable/generic: move seeking of records into the iteratorPatrick Steinhardt, May 13, 2024
  44. 10/13 reftable/generic: adapt interface to allow reuse of iteratorsPatrick Steinhardt, May 13, 2024
  45. 11/13 reftable/reader: adapt interface to allow reuse of iteratorsPatrick Steinhardt, May 13, 2024
  46. 12/13 reftable/stack: provide convenience functions to create iteratorsPatrick Steinhardt, May 13, 2024
  47. 13/13 reftable/merged: adapt interface to allow reuse of iteratorsPatrick Steinhardt, May 13, 2024
  48. Justin ToblerMay 15, 2024
  49. Karthik NayakMay 21, 2024
  50. Patrick SteinhardtMay 22, 2024

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.