All of lore.kernel.org
 help / color / mirror / Atom feed
From: Justin Tobler <jltobler@gmail.com>
To: Karthik Nayak <karthik.188@gmail.com>
Cc: git@vger.kernel.org, gitster@pobox.com,
	"Mitja Bezenšek" <mitja.bezensek@login5.org>,
	"Patrick Steinhardt" <ps@pks.im>
Subject: Re: [PATCH v3] fetch: commit references fetched before backfilling tags
Date: Tue, 20 Oct 2026 18:05:22 -0500	[thread overview]
Message-ID: <atftdOihoUHTdvfu@denethor> (raw)
In-Reply-To: <20261015-799-shallow-fetch-with-tags-v3-1-90b6e38b98d2@gmail.com>

On 26/10/15 11:24PM, Karthik Nayak wrote:
> In 0e358de64a (fetch: use batched reference updates, 2025-05-19), the
> fetch code was modified to use batched updates to provide a good
> performance improvement. Batched updates are used both for the fetched
> references and to backfill tags.
> 
> When using batched updates, the references aren't yet committed to disk
> when we start backfilling tags. This means in situations such as shallow
> fetching the negotiation during backfilling tags, the newly fetched refs
> are not available for advertisement in the 'haves' section. This can
> cause the server to send all objects the client already has.

Ok, without the earlier fetched references committed, the backfill fetch
may ultimately ask for objects it already got. Make sense.

> The issue always existed when the '--atomic' flag was used, as both the
> regular ref updates and the tags need to be part of the same
> transaction.

So IIUC, you are saying that this problem already existed prior to
0e358de64a, but only for atomic fetches. Furthermore, this patch doesn't
fix anything for atomic fetches as they can only use a single
transaction.

> Fix this by committing the previous batched update and initiating a new
> one for backfilling tags. Use a separate error variable for tracking the
> reference updates: One, it ensures that errors from the regular ref
> updates don't cause a total failure. Two, if starting the transaction
> for backfilling tags fails, only those updates are not made to disk. The
> initial error is now printed straight away to clear the buffer for
> further errors.

Naively, I think it would be nice if it were possible supplement the
backfill fetch "haves" with the non-committed references in the pending
transaction directly. That would avoid having to commit the references
in the middle and probably also fix it for atomic fetches too, but I'm
uncertain if that would be a simple or reasonable thing to do.

Committing the intermediate state here does in part fix the issue, so it
may be a good first step regardless.

> Add two tests, one which validates that the 'haves' are filled when
> backfilling tags. The other, to test that upstream is still set and tags
> are backfilled even if the main ref update is rejected.
> 
> While this does make it a little slower than master, due to two
> transactions:
> 
> Benchmark 1: fetch: many refs (refformat = reftable, refcount = 10000, revision = master)
>   Time (mean ± σ):      82.1 ms ±   3.3 ms    [User: 60.2 ms, System: 24.4 ms]
>   Range (min … max):    77.4 ms …  89.4 ms    33 runs
> 
> Benchmark 2: fetch: many refs (refformat = reftable, refcount = 10000, revision = HEAD)
>   Time (mean ± σ):      82.6 ms ±   2.4 ms    [User: 59.3 ms, System: 25.2 ms]
>   Range (min … max):    78.1 ms …  88.7 ms    31 runs
> 
> Summary
>   fetch: many refs (refformat = reftable, refcount = 10000, revision = master) ran
>    1.01 ± 0.05 times faster than fetch: many refs (refformat = reftable, refcount = 10000, revision = HEAD)
> 
> It is still faster than not using batched updates:
> 
> Benchmark 1: fetch: many refs (refformat = reftable, refcount = 10000, revision = 0e358de64a9e014575d11ef884bfc9beb931e37f~1)
>   Time (mean ± σ):      1.468 s ±  0.041 s    [User: 0.839 s, System: 0.587 s]
>   Range (min … max):    1.427 s …  1.558 s    10 runs
> 
> Benchmark 2: fetch: many refs (refformat = reftable, refcount = 10000, revision = HEAD)
>   Time (mean ± σ):      84.4 ms ±   1.7 ms    [User: 60.9 ms, System: 25.8 ms]
>   Range (min … max):    81.4 ms …  88.6 ms    29 runs
> 
> Summary
>   fetch: many refs (refformat = reftable, refcount = 10000, revision = HEAD) ran
>    17.38 ± 0.61 times faster than fetch: many refs (refformat = reftable, refcount = 10000, revision = 0e358de64a9e014575d11ef884bfc9beb931e37f~1)
> 
> Reported-by: Mitja Bezenšek <mitja.bezensek@login5.org>
> Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
> ---
> The issue was reported by Mitja Bezenšek on GitLab's Git repo [1].
> 
> [1]: https://gitlab.com/gitlab-org/git/-/work_items/799
> ---
>  builtin/fetch.c  | 38 +++++++++++++++++++++++++++++++++++---
>  t/t5510-fetch.sh | 42 ++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 77 insertions(+), 3 deletions(-)
> 
> diff --git a/builtin/fetch.c b/builtin/fetch.c
> index b2decc6cfd..34fc37b58a 100644
> --- a/builtin/fetch.c
> +++ b/builtin/fetch.c
> @@ -1923,6 +1923,7 @@ static int do_fetch(struct transport *transport,
>  	struct strmap rejected_refs = STRMAP_INIT;
>  	int summary_width = 0;
>  	int follow_remote_head;
> +	int commit_ref_ret = 0;
>  
>  	if (tags == TAGS_DEFAULT) {
>  		if (transport->remote->fetch_tags == 2)
> @@ -2076,6 +2077,30 @@ static int do_fetch(struct transport *transport,
>  		struct ref *tags_ref_map = NULL, **tail = &tags_ref_map;
>  
>  		find_non_local_tags(remote_refs, transaction, &tags_ref_map, &tail);
> +
> +		/*
> +		 * As negotiation only reads references from disk, commit the references
> +		 * fetched so far, so that the backfill negotiation can advertise them as
> +		 * 'have's. Otherwise the server may re-send objects.
> +		 */
> +		if (tags_ref_map && !atomic_fetch) {
> +			commit_ref_ret = commit_ref_transaction(&transaction, false,
> +								transport->remote->name,
> +								&rejected_refs, &err);
> +			if (err.len) {
> +				error("%s", err.buf);
> +				strbuf_reset(&err);
> +			}

It looks like we log the error and continue even if committing the
transaction failed. Is there a reason we would want to still try to
start the next transaction?

> +
> +			transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
> +								  REF_TRANSACTION_ALLOW_FAILURE, &err);
> +			if (!transaction) {
> +				free_refs(tags_ref_map);
> +				tags_ref_map = NULL;
> +				commit_ref_ret = -1;
> +			}
> +		}
> +
>  		if (tags_ref_map) {
>  			/*
>  			 * If backfilling of tags fails then we want to tell
> @@ -2099,9 +2124,16 @@ static int do_fetch(struct transport *transport,
>  	if (verbosity >= 0)
>  		summary_width = transport_summary_width(ref_map);
>  
> -	retcode = commit_ref_transaction(&transaction, atomic_fetch,
> -					 transport->remote->name,
> -					 &rejected_refs, &err);
> +	/*
> +	 * The transaction may have failed to initialize, meaning there is nothing
> +	 * to commit. Carry forward with other operations in such cases.
> +	 */
> +	if (transaction)
> +		retcode = commit_ref_transaction(&transaction, atomic_fetch,
> +						 transport->remote->name,
> +						 &rejected_refs, &err);
> +	retcode |= commit_ref_ret;

hmmm, the error paths here are confusing me a bit. If the transaction
failed to be created in the first place, wouldn't we want to stop
earlier on?

Thanks,
-Justin

  reply	other threads:[~2026-10-20 23:05 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-08 22:10 [PATCH] fetch: commit references fetched before backfilling tags Karthik Nayak
2026-10-09 11:26 ` Patrick Steinhardt
2026-10-09 16:51   ` Justin Tobler
2026-10-09 22:16     ` Karthik Nayak
2026-10-09 22:31   ` Karthik Nayak
2026-10-12 15:29 ` [PATCH v2] " Karthik Nayak
2026-10-12 19:55   ` Junio C Hamano
2026-10-15 10:31     ` Karthik Nayak
2026-10-15 21:24 ` [PATCH v3] " Karthik Nayak
2026-10-20 23:05   ` Justin Tobler [this message]
2026-10-21  6:39     ` Patrick Steinhardt
2026-10-21 10:01       ` Karthik Nayak
2026-10-21 13:59         ` Justin Tobler
2026-10-22  9:13           ` Karthik Nayak
2026-10-21 10:05     ` Karthik Nayak
2026-10-22 21:00 ` [PATCH v4] fetch: advertise fetched refs when " Karthik Nayak
2026-10-23  6:40   ` Patrick Steinhardt
2026-10-23 10:58     ` Karthik Nayak
2026-10-23 12:00       ` Patrick Steinhardt
2026-10-23 22:01         ` Karthik Nayak
2026-10-23 22:12           ` Karthik Nayak
2026-10-28  9:47 ` [PATCH v5 0/3] " Karthik Nayak
2026-10-28  9:47   ` [PATCH v5 1/3] transport: add `transport_options_release()` Karthik Nayak
2026-10-28 11:42     ` Patrick Steinhardt
2026-10-28 20:18       ` Karthik Nayak
2026-10-29  8:07         ` Patrick Steinhardt
2026-10-29 10:02           ` Karthik Nayak
2026-10-28  9:48   ` [PATCH v5 2/3] fetch: advertise fetched refs when backfilling tags Karthik Nayak
2026-10-28  9:48   ` [PATCH v5 3/3] t5510: cover upstream info update on fetch failure Karthik Nayak
2026-10-28 11:42     ` Patrick Steinhardt
2026-10-28 20:19       ` Karthik Nayak
2026-10-29 12:45 ` [PATCH v6 0/3] fetch: advertise fetched refs when backfilling tags Karthik Nayak
2026-10-29 12:45   ` [PATCH v6 1/3] t5510: cover upstream info update on fetch failure Karthik Nayak
2026-10-29 12:45   ` [PATCH v6 2/3] transport: add `transport_options_release()` Karthik Nayak
2026-10-29 12:45   ` [PATCH v6 3/3] fetch: advertise fetched refs when backfilling tags Karthik Nayak
2026-10-29 14:00   ` [PATCH v6 0/3] " 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=atftdOihoUHTdvfu@denethor \
    --to=jltobler@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=karthik.188@gmail.com \
    --cc=mitja.bezensek@login5.org \
    --cc=ps@pks.im \
    /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.