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

Re: [PATCH 2/2] builtin/pack-objects.c: ensure pack validity from MIDX bitmap objects

From
Taylor Blau <me@ttaylorr.com>
Date
May 14, 2022, 13:17 UTC
Message-ID
<Yn+r4lPi8vNK/qFG@nand.local>
In-Reply-To
<20220513230639.1099955-1-jonathantanmy@google.com>
On Fri, May 13, 2022 at 04:06:39PM -0700, Jonathan Tan wrote:
Show 19 quoted lines
> Taylor Blau <me@ttaylorr.com> writes:
> > An alternative approach to closing this race would have been to call
> > `is_pack_valid()` on _all_ packs in a multi-pack bitmap on load. This
> > has a couple of problems:
> >
> >   - it is unnecessarily expensive in the cases where we don't actually
> >     need to open any packs (e.g., in `git rev-list --use-bitmap-index
> >     --count`)
> >
> >   - more importantly, it means any time we would have hit this race,
> >     we'll avoid using bitmaps altogether, leading to significant
> >     slowdowns by forcing a full object traversal
>
> This answers a question I had about why we're only opening the preferred
> pack instead of all packs. (You mention in [1] that it's also answered
> in that patch message, but I didn't see it.) In any case, it might be
> clearer to move this part to the 1st commit.
>
> [1] https://lore.kernel.org/git/Yn63nDhSBIEa3%2F+%2F@nand.local/

Makes sense, will do. In [1] I was referring to why we wanted to call `is_pack_valid()` as early as we did, and not in `reuse_partial_packfile_from_bitmap()`.

But the quoted part here is useful context for the first patch, too, so I moved it up.

Show 20 quoted lines
> > Work around this by calling `is_pack_valid()` from within
> > `want_found_object()`, matching the behavior in
> > `want_object_in_pack_one()` (which has an analogous call). Most calls to
> > `is_pack_valid()` should be basically no-ops, since only the first call
> > requires us to open a file (subsequent calls realize the file is already
> > open, and return immediately).
> >
> > This does require us to make a small change in
> > `want_object_in_pack_one()`, since `want_found_object()` may return `-1`
> > (indicating "keep searching for other packs containing this object")
> > when `*found_pack` is non-NULL. Force `want_object_in_pack_one()` to
> > call `is_pack_valid()` when `p != *found_pack`, not just when
> > `*found_pack` is non-NULL.
>
> It took me a while to realize that the relevant want_found_object()
> invocation that may return -1 is not the one in
> want_object_in_pack_one(), but in the latter's caller
> want_object_in_pack(). But even in this case, couldn't
> want_found_object() return -1 (see the very end of the function) even
> before this patch?
Perhaps changing the parenthetical to be:
    (indicating that `want_object_in_pack()` should continue searching
    for other packs containing this object)

Yes, `want_found_object()` could have returned -1 before, but the only time when `*found_pack != NULL` and `want_found_object()` would have returned -1 is when given `--local` with at least one non-local pack.

I actually think it's possible we have a bug there, since AFAICT the pre-image of this patch would have left the non-NULL `*found_pack` alone but picked a copy of the given object from a _different_ pack. So I think this change inadvertently resolves that bug.

Show 30 quoted lines
> > @@ -1424,14 +1427,15 @@ static int want_object_in_pack_one(struct packed_git *p,
> >  				   off_t *found_offset)
> >  {
> >  	off_t offset;
> > +	int use_found = p == *found_pack;
> >
> > -	if (p == *found_pack)
> > +	if (use_found)
> >  		offset = *found_offset;
> >  	else
> >  		offset = find_pack_entry_one(oid->hash, p);
> >
> >  	if (offset) {
> > -		if (!*found_pack) {
> > +		if (!use_found) {
> >  			if (!is_pack_valid(p))
> >  				return -1;
> >  			*found_offset = offset;
>
> My understanding of the purpose of this code change is that if we reach
> here with a non-NULL *found_pack, it is likely that *found_pack contains
> an invalid pack, and this part overwrites *found_pack (and
> *found_offset) if it finds a valid pack. This seems like a good change,
> but I don't see how this is a result of something that "does require
> us" (as far as I can tell, *found_pack could have already been invalid
> before this patch, so the downstream code should already be able to
> handle it). Maybe it's just that we couldn't tell if the pack is invalid
> previously, but now we can; but if so, it would be better to say "use
> this added information to overwrite *found_pack when it makes sense" or
> something like that.

I think my reply above indicates why this change is necessary, but if we're talking about separate issues, let me know.

Thanks, Taylor

Previous: Jonathan TanNext: Jonathan Tan
Message 7 of 29 in “pack-objects: fix a pair of MIDX bitmap-related races”
  1. 0/2 pack-objects: fix a pair of MIDX bitmap-related racesTaylor Blau, May 13, 2022
  2. 1/2 pack-bitmap: check preferred pack validity when opening MIDX bitmapTaylor Blau, May 13, 2022
  3. Junio C HamanoMay 13, 2022
  4. Taylor BlauMay 13, 2022
  5. 2/2 builtin/pack-objects.c: ensure pack validity from MIDX bitmap objectsTaylor Blau, May 13, 2022
  6. Jonathan TanMay 13, 2022
  7. Taylor BlauMay 14, 2022
  8. Jonathan TanMay 16, 2022
  9. Taylor BlauMay 14, 2022
  10. Jonathan TanMay 16, 2022
  11. 0/4 pack-objects: fix a pair of MIDX bitmap-related racesTaylor Blau, May 24, 2022
  12. 1/4 pack-bitmap.c: check preferred pack validity when opening MIDX bitmapTaylor Blau, May 24, 2022
  13. Ævar Arnfjörð BjarmasonMay 24, 2022
  14. Taylor BlauMay 24, 2022
  15. Ævar Arnfjörð BjarmasonMay 24, 2022
  16. 2/4 builtin/pack-objects.c: avoid redundant NULL checkTaylor Blau, May 24, 2022
  17. Junio C HamanoMay 24, 2022
  18. Taylor BlauMay 25, 2022
  19. 3/4 builtin/pack-objects.c: ensure included `--stdin-packs` existTaylor Blau, May 24, 2022
  20. Ævar Arnfjörð BjarmasonMay 24, 2022
  21. Taylor BlauMay 24, 2022
  22. Ævar Arnfjörð BjarmasonMay 24, 2022
  23. Junio C HamanoMay 24, 2022
  24. Taylor BlauMay 25, 2022
  25. Victoria DyeMay 26, 2022
  26. Taylor BlauMay 26, 2022
  27. 4/4 builtin/pack-objects.c: ensure pack validity from MIDX bitmap objectsTaylor Blau, May 24, 2022
  28. Junio C HamanoMay 24, 2022
  29. Taylor BlauMay 25, 2022

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.