Re: [PATCH v3] fetch: commit references fetched before backfilling tags
- From
Karthik Nayak <karthik.188@gmail.com>
- Date
- Oct 21, 2026, 10:05 UTC
- Message-ID
- <CAOLa=ZR-mg6ah4VwStR3SJvT1uWdW5uv7q9x486FN7UawkJYeg@mail.gmail.com>
- In-Reply-To
- <atftdOihoUHTdvfu@denethor>
Justin Tobler <jltobler@gmail.com> writes:
Show 24 quoted lines
> 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. >
Yup, there's nothing we can do for atomic fetches with the current approach.
Show 17 quoted lines
>> 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. >
I've replied to this with Patrick's email, let's continue there.
[snip]
Show 35 quoted lines
>> 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?
>Since we use batched updates, some refs could fail, but we continue as we may have still applied some updates and we can continue doing the rest of the work.
Show 36 quoted lines
>> +
>> + 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,
> -JustinNot really, since we use batched updates, the backfilling tags transaction could fail to initialize but we still want to set upstreams and set HEAD.