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

Re: [PATCH 2/4] odb/source-files: reload alternates on retry

From
Christian Couder <christian.couder@gmail.com>
Date
Oct 21, 2026, 14:32 UTC
Message-ID
<CAP8UFD0woTHVqy0cXtWJCL9Pt_jqWXT3m0bN=LufOQ_zJaKeAA@mail.gmail.com>
In-Reply-To
<20261020-pks-odb-files-reload-alternates-v1-2-d9e156323836@pks.im>
On Tue, Oct 20, 2026 at 11:01 AM Patrick Steinhardt <ps@pks.im> wrote:
Show 34 quoted lines
> diff --git a/odb/source-files.c b/odb/source-files.c
> index d31da6e5d9..86f3fd1136 100644
> --- a/odb/source-files.c
> +++ b/odb/source-files.c
> @@ -425,6 +425,7 @@ static enum odb_read_status odb_source_files_read_object_info(struct odb_source
>                                                               struct strbuf *errmsg)
>  {
>         struct odb_source_files *files = odb_source_files_downcast(source);
> +       struct odb_files_dir **tail = NULL;
>         enum odb_read_status status = ODB_READ_NOT_FOUND;
>         enum odb_read_status ret;
>         bool retry = false;
> @@ -448,10 +449,11 @@ static enum odb_read_status odb_source_files_read_object_info(struct odb_source
>                         status = ret;
>         }
>
> -       for (struct odb_files_dir *dir = files->dirs; dir; dir = dir->next) {
> -               if (retry)
> -                       break;
> -
> +       /*
> +        * When we have reprepared alternates then we only re-scan directories
> +        * that were newly added.
> +        */
> +       for (struct odb_files_dir *dir = tail ? *tail : files->dirs; dir; dir = dir->next) {
>                 ret = odb_source_read_object_info(&dir->loose->base, oid, oi, flags,
>                                                   status == ODB_READ_NOT_FOUND ? errmsg : NULL);
>                 if (!ret)
> @@ -461,6 +463,8 @@ static enum odb_read_status odb_source_files_read_object_info(struct odb_source
>         }
>
>         if (!retry && !(flags & OBJECT_INFO_QUICK)) {
> +               tail = files->dirs_tail;
> +               prepare_alternates(files, NULL);

This calls `read_alternates(files->dirs->abspath, ...)`, but when we use a temporary primary directory, `files->dirs` is that temporary primary directory. The prepare_alternates() call will then quietly find nothing new because temporary primary directories have no alternates.

Before 5946a564cd (odb/source: make `read_object_info()` function pluggable, 2026-03-05), when there was a temporary primary directory, reloading the alternates also found nothing new for the same reason (no alternates).

So we could think that there is no behavior change, but in the meantime there was bdee7b3013 (builtin/receive-pack: stage incoming objects via ODB transactions, 2026-07-10) which made the quarantine the temporary primary directory in receive-pack. Before that commit, receive-pack only passed its quarantine to child processes through environment variables, so its own lookups reloaded the repository's real alternates.

I wonder if it would be better to always reload the repository's real alternates, instead of `files->dirs`'s alternates. This way, objects that moved to an alternate would still be found, not only during a receive-pack like before 5946a564cd, but whenever a temporary primary directory is used.

It looks like with your 4/4 patch this improvement would add no extra cost.

Then `files->dirs` should also likely be replaced by the repository's own object directory in the following places inside odb_files_dir_is_usable():

- in the hashmap_entry_init() call that seeds the duplicate map, and
- in strbuf_realpath() when we are supposed to compare against the
resolved path of the primary.

These are not reachable today when a temporary primary directory is installed, as no alternates are read then. But they would become reachable if we reload the repository's real alternates, instead of `files->dirs`'s alternates.

>                 retry = true;
>                 goto retry;
>         }
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 4 of 38 in “odb/files: reload alternates on retry again”
  1. 0/4 odb/files: reload alternates on retry againPatrick Steinhardt, Oct 20, 2026
  2. 1/4 odb/source-files: rename alternates-related functionsPatrick Steinhardt, Oct 20, 2026
  3. 2/4 odb/source-files: reload alternates on retryPatrick Steinhardt, Oct 20, 2026
  4. Christian CouderOct 21, 2026
  5. Patrick SteinhardtOct 23, 2026
  6. 3/4 odb/source-files: avoid rechecking already-known alternatesPatrick Steinhardt, Oct 20, 2026
  7. 4/4 odb/source-files: only reload alternates when the file has changedPatrick Steinhardt, Oct 20, 2026
  8. Junio C HamanoOct 20, 2026
  9. Patrick SteinhardtOct 21, 2026
  10. 0/6 odb/files: reload alternates on retry againPatrick Steinhardt, Oct 23, 2026
  11. 1/6 odb/source-files: rename alternates-related functionsPatrick Steinhardt, Oct 23, 2026
  12. 2/6 odb/source-files: always load alternates via primary object directoryPatrick Steinhardt, Oct 23, 2026
  13. Christian CouderOct 27, 2026
  14. 3/6 odb/source-files: reload alternates on retryPatrick Steinhardt, Oct 23, 2026
  15. 4/6 odb/source-files: simplify directory duplication detectionPatrick Steinhardt, Oct 23, 2026
  16. Christian CouderOct 27, 2026
  17. Patrick SteinhardtOct 27, 2026
  18. 5/6 odb/source-files: avoid stat'ing already-known alternatesPatrick Steinhardt, Oct 23, 2026
  19. Christian CouderOct 27, 2026
  20. Patrick SteinhardtOct 27, 2026
  21. Christian CouderOct 27, 2026
  22. Patrick SteinhardtOct 28, 2026
  23. 6/6 odb/source-files: only reload alternates when the file has changedPatrick Steinhardt, Oct 23, 2026
  24. Christian CouderOct 27, 2026
  25. Patrick SteinhardtOct 27, 2026
  26. Christian CouderOct 27, 2026
  27. 0/6 odb/files: reload alternates on retry againPatrick Steinhardt, Oct 28, 2026
  28. 1/6 odb/source-files: rename alternates-related functionsPatrick Steinhardt, Oct 28, 2026
  29. 2/6 odb/source-files: always load alternates via primary object directoryPatrick Steinhardt, Oct 28, 2026
  30. 3/6 odb/source-files: reload alternates on retryPatrick Steinhardt, Oct 28, 2026
  31. 4/6 odb/source-files: simplify directory duplication detectionPatrick Steinhardt, Oct 28, 2026
  32. Christian CouderOct 28, 2026
  33. Patrick SteinhardtOct 28, 2026
  34. Junio C HamanoOct 28, 2026
  35. 5/6 odb/source-files: avoid stat'ing already-known alternatesPatrick Steinhardt, Oct 28, 2026
  36. 6/6 odb/source-files: only reload alternates when the file has changedPatrick Steinhardt, Oct 28, 2026
  37. Junio C HamanoOct 28, 2026
  38. Patrick SteinhardtOct 29, 2026

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.