* Re: [PATCH 2/2] packfile: recover when a multi-pack-index names a removed pack
2026-08-18 22:34 ` [PATCH 2/2] packfile: recover when a multi-pack-index names a removed pack Elijah Newren via GitGitGadget
@ 2026-08-19 18:21 ` Junio C Hamano
2026-08-20 7:54 ` Patrick Steinhardt
` (3 subsequent siblings)
4 siblings, 0 replies; 19+ messages in thread
From: Junio C Hamano @ 2026-08-19 18:21 UTC (permalink / raw)
To: Elijah Newren via GitGitGadget; +Cc: git, Elijah Newren, Patrick Steinhardt
"Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:
> @@ -31,6 +31,35 @@ static int find_pack_entry(struct odb_source_packed *store,
> }
> }
>
> + /*
> + * Recovery for a concurrent-repack race: a MIDX can name an owning
> + * pack for an object that a simultaneous repack has since deleted,
> + * even though the object still exists in another pack the same MIDX
> + * covers (e.g. a kept base pack that geometric repack did not rewrite).
> + * If the object is present in a MIDX yet none of the paths above could
> + * serve it, its recorded owning pack has become unavailable. The
> + * regular fallback above deliberately skips MIDX-covered packs, so
> + * scan this MIDX's packs directly to find the surviving copy. The
> + * bsearch gate keeps genuine misses (objects absent from the MIDX) on
> + * the fast path.
> + */
> + if (store->midx) {
> + struct multi_pack_index *m = store->midx;
> + uint32_t midx_pos, i;
> +
> + if (bsearch_midx(oid, m, &midx_pos)) {
> + for (i = 0; i < m->num_packs + m->num_packs_in_base; i++) {
> + struct packed_git *p;
> +
> + if (prepare_midx_pack(m, i))
> + continue;
> + p = nth_midxed_pack(m, i);
> + if (p && packfile_fill_entry(p, oid, e))
> + return 1;
> + }
> + }
> + }
> +
> return 0;
> }
I'll prepare an evil-merge to rewrite this line to
if (p && packfile_fill_entry(p, oid, e, bad_pack))
to adjust to the API change another topic in-flight brings in when
merging these patches to 'seen'.
This is strictly FYI. You do not need to rebase on top of the other
topic, until I and/or the author of the other topic ask you.
Thanks.
^ permalink raw reply [flat|nested] 19+ messages in thread* Re: [PATCH 2/2] packfile: recover when a multi-pack-index names a removed pack
2026-08-18 22:34 ` [PATCH 2/2] packfile: recover when a multi-pack-index names a removed pack Elijah Newren via GitGitGadget
2026-08-19 18:21 ` Junio C Hamano
@ 2026-08-20 7:54 ` Patrick Steinhardt
2026-08-21 1:36 ` Elijah Newren
2026-08-24 4:55 ` Jeff King
` (2 subsequent siblings)
4 siblings, 1 reply; 19+ messages in thread
From: Patrick Steinhardt @ 2026-08-20 7:54 UTC (permalink / raw)
To: Elijah Newren via GitGitGadget; +Cc: git, Elijah Newren
On Tue, Aug 18, 2026 at 10:34:06PM +0000, Elijah Newren via GitGitGadget wrote:
> From: Elijah Newren <newren@gmail.com>
>
> When a geometric repack runs concurrently with other git processes, it
> can write a new pack and multi-pack-index and then delete older packs
> that the new one subsumes. One or more of those older packs may have
> been indexed by the previous multi-pack-index. A process that already
> had the previous multi-pack-index open keeps using it, and that stale
> index still records the removed pack(s) as owning some objects.
>
> Because a multi-pack-index attributes each object to exactly one pack,
> an object that exists in multiple covered packs is served only through
> its recorded owner. If that owner is the pack a concurrent repack just
> removed, find_pack_entry() cannot serve the object: fill_midx_entry()
> routes the lookup to the missing pack (prepare_midx_pack() fails), and
> the regular pack fallback deliberately skips every multi-pack-index
> covered pack. The object is reported missing even though a perfectly
> good copy survives in another covered pack -- for example a large "base"
> pack that geometric repacking intentionally kept.
Okay. Rephrasing in my own words: the object in question exists in two
packs covered by the MIDX. We rewrite one of those two packs, and the
MIDX used to reference the object via the pack we're about to rewrite.
Consequently, the MIDX is stale now and it cannot be used to find the
object anymore because its pack has disappeared. And as we know to skip
searching packfiles for the object that are already covered by the MIDX
we won't be able to find it via the second packfile, either.
> The false negative is not limited to one caller. Any reader
> (cat-file, rev-list, pack-objects, ...) can spuriously fail with
> "unable to read object", and callers that only ask whether an object
> exists get a wrong answer too, since the OBJECT_INFO_QUICK path never
> retries. Writers that merge in-core, such as "git replay", are hit
> hardest: merge-ort treats the unreadable tree as a premature abort, sets
> result.clean < 0, and returns without a result tree.
Hm. Isn't there a slight variant of the race though for any caller that
does not use OBJECT_INFO_QUICK?
Namely, the packfile containing our object disappears and is being
written to a new packfile, and that file is the only one containing it.
Without OBJECT_INFO_QUICK we would be fine: we notice the object could
not be found, and then we perform a second read that makes the "packed"
backend reload its packfiles. It would find the new packfile, and
because it's not covered by its MIDX it would use it to surface the
object. But without OBJECT_INFO_QUICK that's not the case, as we would
skip reloading packfiles altogether, and hence we would not be able to
find that object at all.
As far as I can see though, we don't seem to pass OBJECT_INFO_QUICK in
any of the mentioned readers. I could very well be missing something
here, but I would have thought that those readers are fine in this
scenario?
> diff --git a/odb/source-packed.c b/odb/source-packed.c
> index 0890704e76..de96215069 100644
> --- a/odb/source-packed.c
> +++ b/odb/source-packed.c
> @@ -31,6 +31,35 @@ static int find_pack_entry(struct odb_source_packed *store,
> }
> }
>
> + /*
> + * Recovery for a concurrent-repack race: a MIDX can name an owning
> + * pack for an object that a simultaneous repack has since deleted,
> + * even though the object still exists in another pack the same MIDX
> + * covers (e.g. a kept base pack that geometric repack did not rewrite).
> + * If the object is present in a MIDX yet none of the paths above could
> + * serve it, its recorded owning pack has become unavailable. The
> + * regular fallback above deliberately skips MIDX-covered packs, so
> + * scan this MIDX's packs directly to find the surviving copy. The
> + * bsearch gate keeps genuine misses (objects absent from the MIDX) on
> + * the fast path.
> + */
> + if (store->midx) {
> + struct multi_pack_index *m = store->midx;
> + uint32_t midx_pos, i;
> +
> + if (bsearch_midx(oid, m, &midx_pos)) {
Okay. I was initially worried that we now unconditionally search through
all packfiles a second time, as that could have an impact on
performance. But we really only do this in case we have a MIDX and we
know that the MIDX _should_ have contained the object, but didn't yield
it.
> + for (i = 0; i < m->num_packs + m->num_packs_in_base; i++) {
> + struct packed_git *p;
> +
> + if (prepare_midx_pack(m, i))
> + continue;
> + p = nth_midxed_pack(m, i);
> + if (p && packfile_fill_entry(p, oid, e))
> + return 1;
> + }
And here we now loop through all packs covered by the MIDX and manually
try to look up the object in those. Makes sense.
> + }
> + }
I was wondering whether a preferable fix would be to eagerly load
any packfile referenced by the MIDX when loading the MIDX itself. And if
that fails, we'd ignore the MIDX altogether. This would guarantee that
the MIDX remains valid, and we wouldn't have to worry about any
disappearing packfiles.
The downside is of course that we now eagerly open packfiles, and we
didn't have to do that before. So I think your fix is preferable, as we
can rather easily detect the case where the MIDX should've yielded the
object but didn't, and consequently the additional search only triggers
in very specific edge cases.
Overall I think this patch looks good to me. The one thing that I'm a
bit puzzled about is the above discussion around OBJECT_INFO_QUICK. I
feel like I'm missing something there.
Thanks!
Patrick
^ permalink raw reply [flat|nested] 19+ messages in thread* Re: [PATCH 2/2] packfile: recover when a multi-pack-index names a removed pack
2026-08-20 7:54 ` Patrick Steinhardt
@ 2026-08-21 1:36 ` Elijah Newren
2026-08-24 4:48 ` Jeff King
0 siblings, 1 reply; 19+ messages in thread
From: Elijah Newren @ 2026-08-21 1:36 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: Elijah Newren via GitGitGadget, git
On Thu, Aug 20, 2026 at 12:54 AM Patrick Steinhardt <ps@pks.im> wrote:
>
> On Tue, Aug 18, 2026 at 10:34:06PM +0000, Elijah Newren via GitGitGadget wrote:
> > From: Elijah Newren <newren@gmail.com>
> >
> > When a geometric repack runs concurrently with other git processes, it
> > can write a new pack and multi-pack-index and then delete older packs
> > that the new one subsumes. One or more of those older packs may have
> > been indexed by the previous multi-pack-index. A process that already
> > had the previous multi-pack-index open keeps using it, and that stale
> > index still records the removed pack(s) as owning some objects.
> >
> > Because a multi-pack-index attributes each object to exactly one pack,
> > an object that exists in multiple covered packs is served only through
> > its recorded owner. If that owner is the pack a concurrent repack just
> > removed, find_pack_entry() cannot serve the object: fill_midx_entry()
> > routes the lookup to the missing pack (prepare_midx_pack() fails), and
> > the regular pack fallback deliberately skips every multi-pack-index
> > covered pack. The object is reported missing even though a perfectly
> > good copy survives in another covered pack -- for example a large "base"
> > pack that geometric repacking intentionally kept.
>
> Okay. Rephrasing in my own words: the object in question exists in two
> packs covered by the MIDX. We rewrite one of those two packs, and the
> MIDX used to reference the object via the pack we're about to rewrite.
> Consequently, the MIDX is stale now and it cannot be used to find the
> object anymore because its pack has disappeared. And as we know to skip
> searching packfiles for the object that are already covered by the MIDX
> we won't be able to find it via the second packfile, either.
Yep.
> > The false negative is not limited to one caller. Any reader
> > (cat-file, rev-list, pack-objects, ...) can spuriously fail with
> > "unable to read object", and callers that only ask whether an object
> > exists get a wrong answer too, since the OBJECT_INFO_QUICK path never
> > retries. Writers that merge in-core, such as "git replay", are hit
> > hardest: merge-ort treats the unreadable tree as a premature abort, sets
> > result.clean < 0, and returns without a result tree.
>
> Hm. Isn't there a slight variant of the race though for any caller that
> does not use OBJECT_INFO_QUICK?
>
> Namely, the packfile containing our object disappears and is being
> written to a new packfile, and that file is the only one containing it.
> Without OBJECT_INFO_QUICK we would be fine: we notice the object could
> not be found, and then we perform a second read that makes the "packed"
> backend reload its packfiles. It would find the new packfile, and
> because it's not covered by its MIDX it would use it to surface the
> object. But without OBJECT_INFO_QUICK that's not the case, as we would
> skip reloading packfiles altogether, and hence we would not be able to
> find that object at all.
>
> As far as I can see though, we don't seem to pass OBJECT_INFO_QUICK in
> any of the mentioned readers. I could very well be missing something
> here, but I would have thought that those readers are fine in this
> scenario?
Nicely caught -- and you're right that the readers named above are
fine: they're all non-QUICK, so the second read reloads the packfiles
and finds the object in its new, non-MIDX-covered home, exactly as you
describe.
But the variant you describe is a real bug for QUICK callers that
don't get that second read -- e.g. upload-pack's object-existence
checks and mktree --batch. I have three more race-condition patches
to clean up and submit, and this is one of them: it forces the reload
even under OBJECT_INFO_QUICK once we notice a pack has vanished out
from under us.
Your wording also makes me realize that my fix in this unsubmitted
patch still has a hole: it triggers when opening the pack .idx fails,
but if the timing is such that the .idx is already mmapped and only
the .pack has gone missing, it won't fire. I'll look into that before
submitting...and then clean up/submit my two other race fixes as well.
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH 2/2] packfile: recover when a multi-pack-index names a removed pack
2026-08-21 1:36 ` Elijah Newren
@ 2026-08-24 4:48 ` Jeff King
2026-08-24 5:13 ` Patrick Steinhardt
0 siblings, 1 reply; 19+ messages in thread
From: Jeff King @ 2026-08-24 4:48 UTC (permalink / raw)
To: Elijah Newren; +Cc: Patrick Steinhardt, Elijah Newren via GitGitGadget, git
On Thu, Aug 20, 2026 at 06:36:09PM -0700, Elijah Newren wrote:
> > > The false negative is not limited to one caller. Any reader
> > > (cat-file, rev-list, pack-objects, ...) can spuriously fail with
> > > "unable to read object", and callers that only ask whether an object
> > > exists get a wrong answer too, since the OBJECT_INFO_QUICK path never
> > > retries. Writers that merge in-core, such as "git replay", are hit
> > > hardest: merge-ort treats the unreadable tree as a premature abort, sets
> > > result.clean < 0, and returns without a result tree.
> >
> > Hm. Isn't there a slight variant of the race though for any caller that
> > does not use OBJECT_INFO_QUICK?
> >
> > Namely, the packfile containing our object disappears and is being
> > written to a new packfile, and that file is the only one containing it.
> > Without OBJECT_INFO_QUICK we would be fine: we notice the object could
> > not be found, and then we perform a second read that makes the "packed"
> > backend reload its packfiles. It would find the new packfile, and
> > because it's not covered by its MIDX it would use it to surface the
> > object. But without OBJECT_INFO_QUICK that's not the case, as we would
> > skip reloading packfiles altogether, and hence we would not be able to
> > find that object at all.
> >
> > As far as I can see though, we don't seem to pass OBJECT_INFO_QUICK in
> > any of the mentioned readers. I could very well be missing something
> > here, but I would have thought that those readers are fine in this
> > scenario?
>
> Nicely caught -- and you're right that the readers named above are
> fine: they're all non-QUICK, so the second read reloads the packfiles
> and finds the object in its new, non-MIDX-covered home, exactly as you
> describe.
OK, so do I understand correctly that you _can't_ get the "unable to
read object" result that the commit message claims? I.e., the reprepare
/ packfile reload is helps us (just like it does for the non-midx case
when an idx has been mapped but the pack disappears before we open it).
So there is no bug there for non-QUICK callers. But then...
> But the variant you describe is a real bug for QUICK callers that
> don't get that second read -- e.g. upload-pack's object-existence
> checks and mktree --batch. I have three more race-condition patches
> to clean up and submit, and this is one of them: it forces the reload
> even under OBJECT_INFO_QUICK once we notice a pack has vanished out
> from under us.
This seems wrong. The whole point of the QUICK flag is that the caller
is OK producing a false negative for an object lookup, and it would
prefer that outcome to spending the time to reload. If there are callers
passing QUICK that aren't OK with false negatives, they are broken and
the fix should be there. But repreparing the packs for a QUICK miss is
going to reintroduce the performance problems that QUICK was introduced
to help.
So between the two cases, it sounds like things (or at least the
low-level lookups) are working as designed, and there is no bug. Or am I
misunderstanding something?
> Your wording also makes me realize that my fix in this unsubmitted
> patch still has a hole: it triggers when opening the pack .idx fails,
> but if the timing is such that the .idx is already mmapped and only
> the .pack has gone missing, it won't fire. I'll look into that before
> submitting...and then clean up/submit my two other race fixes as well.
I think it would be fine, for the same reason that regular idx lookups
are fine. In packfile_fill_entry() we call is_pack_valid(), checking
that the pack is still there (and relying on its side effect of leaving
the fd/mmap open so that it remains accessible even if the file is
deleted).
-Peff
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH 2/2] packfile: recover when a multi-pack-index names a removed pack
2026-08-24 4:48 ` Jeff King
@ 2026-08-24 5:13 ` Patrick Steinhardt
2026-08-24 6:55 ` Jeff King
0 siblings, 1 reply; 19+ messages in thread
From: Patrick Steinhardt @ 2026-08-24 5:13 UTC (permalink / raw)
To: Jeff King; +Cc: Elijah Newren, Elijah Newren via GitGitGadget, git
On Mon, Aug 24, 2026 at 12:48:22AM -0400, Jeff King wrote:
> So between the two cases, it sounds like things (or at least the
> low-level lookups) are working as designed, and there is no bug. Or am I
> misunderstanding something?
I agree that QUICK is working as designed, and that callers that pass it
without being able to accommodate for false negatives are buggy. But the
patch sent by Elijah still fixes an actual bug where we may not find an
object that is contained in two MIDXd packs where the preferred pack for
a respective object vanishes concurrently. Filling the packfile entry
via the MIDX will fail because the pack vanished, and the lookup via the
non-preferred pack will fail, too, because we skip over any packs that
are covered by the MIDX when doing the non-MIDX lookup. Consequently, we
won't find the object at all.
That case is broken no matter whether we pass QUICK or not.
Patrick
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH 2/2] packfile: recover when a multi-pack-index names a removed pack
2026-08-24 5:13 ` Patrick Steinhardt
@ 2026-08-24 6:55 ` Jeff King
2026-08-24 7:06 ` Jeff King
0 siblings, 1 reply; 19+ messages in thread
From: Jeff King @ 2026-08-24 6:55 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: Elijah Newren, Elijah Newren via GitGitGadget, git
On Mon, Aug 24, 2026 at 07:13:39AM +0200, Patrick Steinhardt wrote:
> On Mon, Aug 24, 2026 at 12:48:22AM -0400, Jeff King wrote:
> > So between the two cases, it sounds like things (or at least the
> > low-level lookups) are working as designed, and there is no bug. Or am I
> > misunderstanding something?
>
> I agree that QUICK is working as designed, and that callers that pass it
> without being able to accommodate for false negatives are buggy. But the
> patch sent by Elijah still fixes an actual bug where we may not find an
> object that is contained in two MIDXd packs where the preferred pack for
> a respective object vanishes concurrently. Filling the packfile entry
> via the MIDX will fail because the pack vanished, and the lookup via the
> non-preferred pack will fail, too, because we skip over any packs that
> are covered by the MIDX when doing the non-MIDX lookup. Consequently, we
> won't find the object at all.
Ah, OK. I get it now. Thanks for explaining.
It feels like the midx is foiling the usual reprepare strategy
(well, SECOND_READ these days) because we don't actually flush it for
the second read. Assuming the writing side always generates a new midx
(that no longer references the to-be-deleted pack) before deleting the
pack itself, then we'd be able to find the object by refreshing the
midx. Just like we find new objects by refreshing the pack list and
finding the new .idx files.
And I guess that's what the original commit message was saying here:
This recovers the object without touching the multi-pack-index itself.
Reloading the stale index would be a more complete fix but would be much
more involved: other code (pack bitmaps, object name disambiguation)
borrows and caches the "struct multi_pack_index *" across object reads,
so freeing it underneath them would be a use-after-free. Refreshing the
index with proper invalidation of those borrowers is left for future
work.
That's not a problem for packs because we _don't_ free the packfile
structs. We keep them around forever. So presumably we'd have to do the
same for stale midxs. But I agree that it might end up more complicated
than we'd like (especially because there's so much "there is only one
midx" assumption baked into various parts of the code). So working
around it in a more immediate way makes some sense.
> That case is broken no matter whether we pass QUICK or not.
Right. It would be OK to skip Elijah's fallback workaround when
SECOND_READ is not set; the QUICK callers are prepared to accept the
false negative. But since it is cheap-ish to do the fallback check, it
is perhaps OK to just do it on the first pass?
I wonder how true that is. Imagine you had a midx covering a million
packs, and you notice an object is missing, but you're in QUICK mode. Do
you really want to individually check each of those million pack idx
files (that were otherwise not even opened or mmap'd because they're
covered by the midx!).
I think it's mostly academic. You'd have to do the million-pack search
if we are not in QUICK mode. And the point of QUICK mode is mostly
avoiding tons of fruitless searches for objects we don't actually have.
The bsearch() conditional means that we _know_ this is a racy negative
and not just some object we never even had. So it would trigger
generally only when the search is useful.
-Peff
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH 2/2] packfile: recover when a multi-pack-index names a removed pack
2026-08-24 6:55 ` Jeff King
@ 2026-08-24 7:06 ` Jeff King
2026-08-24 7:23 ` Jeff King
0 siblings, 1 reply; 19+ messages in thread
From: Jeff King @ 2026-08-24 7:06 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: Elijah Newren, Elijah Newren via GitGitGadget, git
On Mon, Aug 24, 2026 at 02:55:39AM -0400, Jeff King wrote:
> Right. It would be OK to skip Elijah's fallback workaround when
> SECOND_READ is not set; the QUICK callers are prepared to accept the
> false negative. But since it is cheap-ish to do the fallback check, it
> is perhaps OK to just do it on the first pass?
>
> I wonder how true that is. Imagine you had a midx covering a million
> packs, and you notice an object is missing, but you're in QUICK mode. Do
> you really want to individually check each of those million pack idx
> files (that were otherwise not even opened or mmap'd because they're
> covered by the midx!).
>
> I think it's mostly academic. You'd have to do the million-pack search
> if we are not in QUICK mode. And the point of QUICK mode is mostly
> avoiding tons of fruitless searches for objects we don't actually have.
> The bsearch() conditional means that we _know_ this is a racy negative
> and not just some object we never even had. So it would trigger
> generally only when the search is useful.
Actually, thinking on this more: we _don't_ usually scan the million
packs for an object we actually have. If the object is available in a
new pack, the SECOND_READ scan should find that pack and put it at the
front of the packfile list (because they sort by reverse mtime), and
we'd find the object immediately, without having to open the new packs.
It's only the case that this patch is helping (when the object is not
moved at all, but an existing duplicate is hidden in the midx) where we
have to re-scan all of those packs. But we don't know which case is
which until we get to the SECOND_READ stage. So I think this probably
should only kick in for SECOND_READ.
-Peff
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH 2/2] packfile: recover when a multi-pack-index names a removed pack
2026-08-24 7:06 ` Jeff King
@ 2026-08-24 7:23 ` Jeff King
0 siblings, 0 replies; 19+ messages in thread
From: Jeff King @ 2026-08-24 7:23 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: Elijah Newren, Elijah Newren via GitGitGadget, git
On Mon, Aug 24, 2026 at 03:06:01AM -0400, Jeff King wrote:
> On Mon, Aug 24, 2026 at 02:55:39AM -0400, Jeff King wrote:
>
> > Right. It would be OK to skip Elijah's fallback workaround when
> > SECOND_READ is not set; the QUICK callers are prepared to accept the
> > false negative. But since it is cheap-ish to do the fallback check, it
> > is perhaps OK to just do it on the first pass?
> >
> > I wonder how true that is. Imagine you had a midx covering a million
> > packs, and you notice an object is missing, but you're in QUICK mode. Do
> > you really want to individually check each of those million pack idx
> > files (that were otherwise not even opened or mmap'd because they're
> > covered by the midx!).
> >
> > I think it's mostly academic. You'd have to do the million-pack search
> > if we are not in QUICK mode. And the point of QUICK mode is mostly
> > avoiding tons of fruitless searches for objects we don't actually have.
> > The bsearch() conditional means that we _know_ this is a racy negative
> > and not just some object we never even had. So it would trigger
> > generally only when the search is useful.
>
> Actually, thinking on this more: we _don't_ usually scan the million
> packs for an object we actually have. If the object is available in a
> new pack, the SECOND_READ scan should find that pack and put it at the
> front of the packfile list (because they sort by reverse mtime), and
> we'd find the object immediately, without having to open the new packs.
Er, this final sentence should be "without having to open the (million)
old packs".
-Peff
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH 2/2] packfile: recover when a multi-pack-index names a removed pack
2026-08-18 22:34 ` [PATCH 2/2] packfile: recover when a multi-pack-index names a removed pack Elijah Newren via GitGitGadget
2026-08-19 18:21 ` Junio C Hamano
2026-08-20 7:54 ` Patrick Steinhardt
@ 2026-08-24 4:55 ` Jeff King
2026-08-24 5:40 ` Patrick Steinhardt
2026-08-24 14:45 ` Derrick Stolee
2026-08-24 14:46 ` Derrick Stolee
4 siblings, 1 reply; 19+ messages in thread
From: Jeff King @ 2026-08-24 4:55 UTC (permalink / raw)
To: Elijah Newren via GitGitGadget; +Cc: git, Elijah Newren
On Tue, Aug 18, 2026 at 10:34:06PM +0000, Elijah Newren via GitGitGadget wrote:
> Teach find_pack_entry() to recover. After the normal multi-pack-index
> lookup and the regular pack fallback both miss, check whether the object
> is nonetheless present in a covered multi-pack-index (bsearch_midx()).
> If it is, its recorded owner must have become unavailable, so scan that
> index's packs directly for a surviving copy. The bsearch gate keeps
> genuine misses (i.e. objects absent from the index) on the fast path, and
> because the recovery lives in find_pack_entry() itself it also fixes the
> OBJECT_INFO_QUICK callers that never reprepare.
You don't even have to pay the bsearch() again. We'd already have looked
in the midx earlier in the function. We just need to distinguish three
cases:
1. it was not in the midx (or there is no midx)
2. it was in the midx but we could not load it (pack invalid, or
object in the bad_objects list)
3. it was in the midx and is available
In fill_midx_entry() we return a boolean that lumps cases 1+2 together,
versus case 3. It could return a tri-state that would let us distinguish
all three. And then your fallback would kick in only for case 2 (case 3
already returned with success, and case 1 means the midx does not even
mention the object).
This is all assuming the fallback is worth pursuing. I'm still puzzled
why this specific case would matter when we have the same (already
solved) problem of reading a regular .idx whose .pack has gone away.
-Peff
^ permalink raw reply [flat|nested] 19+ messages in thread* Re: [PATCH 2/2] packfile: recover when a multi-pack-index names a removed pack
2026-08-24 4:55 ` Jeff King
@ 2026-08-24 5:40 ` Patrick Steinhardt
2026-08-24 7:03 ` Jeff King
0 siblings, 1 reply; 19+ messages in thread
From: Patrick Steinhardt @ 2026-08-24 5:40 UTC (permalink / raw)
To: Jeff King; +Cc: Elijah Newren via GitGitGadget, git, Elijah Newren
On Mon, Aug 24, 2026 at 12:55:29AM -0400, Jeff King wrote:
> On Tue, Aug 18, 2026 at 10:34:06PM +0000, Elijah Newren via GitGitGadget wrote:
>
> > Teach find_pack_entry() to recover. After the normal multi-pack-index
> > lookup and the regular pack fallback both miss, check whether the object
> > is nonetheless present in a covered multi-pack-index (bsearch_midx()).
> > If it is, its recorded owner must have become unavailable, so scan that
> > index's packs directly for a surviving copy. The bsearch gate keeps
> > genuine misses (i.e. objects absent from the index) on the fast path, and
> > because the recovery lives in find_pack_entry() itself it also fixes the
> > OBJECT_INFO_QUICK callers that never reprepare.
>
> You don't even have to pay the bsearch() again. We'd already have looked
> in the midx earlier in the function. We just need to distinguish three
> cases:
>
> 1. it was not in the midx (or there is no midx)
>
> 2. it was in the midx but we could not load it (pack invalid, or
> object in the bad_objects list)
>
> 3. it was in the midx and is available
>
> In fill_midx_entry() we return a boolean that lumps cases 1+2 together,
> versus case 3. It could return a tri-state that would let us distinguish
> all three. And then your fallback would kick in only for case 2 (case 3
> already returned with success, and case 1 means the midx does not even
> mention the object).
>
> This is all assuming the fallback is worth pursuing. I'm still puzzled
> why this specific case would matter when we have the same (already
> solved) problem of reading a regular .idx whose .pack has gone away.
I've tried to clarify in a parallel message already, but the issue is
that we skip over any packfiles that covered by a MIDX when doing the
lookup. So any secondary packfiles that contain the object would be
completely ignored, and that's why we don't find the object there.
But this mail here suggests an alternative fix: instead of re-scanning
all packfiles like the patch proposes, wouldn't the proper fix be to not
ignore _all_ MIDX'd packs, but only the pack that _should_ have
contained the object?
Ultimately though, this would be equivalent to turning the function's
return value into a tri-state as suggested by Peff here. The only case
where the issue can occur is in case (2), and in that case we should not
skip MIDX'd packs at all as the MIDX'd pack that should've contained the
pack does not exist anyway.
Patrick
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH 2/2] packfile: recover when a multi-pack-index names a removed pack
2026-08-24 5:40 ` Patrick Steinhardt
@ 2026-08-24 7:03 ` Jeff King
0 siblings, 0 replies; 19+ messages in thread
From: Jeff King @ 2026-08-24 7:03 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: Elijah Newren via GitGitGadget, git, Elijah Newren
On Mon, Aug 24, 2026 at 07:40:22AM +0200, Patrick Steinhardt wrote:
> > This is all assuming the fallback is worth pursuing. I'm still puzzled
> > why this specific case would matter when we have the same (already
> > solved) problem of reading a regular .idx whose .pack has gone away.
>
> I've tried to clarify in a parallel message already, but the issue is
> that we skip over any packfiles that covered by a MIDX when doing the
> lookup. So any secondary packfiles that contain the object would be
> completely ignored, and that's why we don't find the object there.
Yes, thanks. Your other message cleared it up for me.
> But this mail here suggests an alternative fix: instead of re-scanning
> all packfiles like the patch proposes, wouldn't the proper fix be to not
> ignore _all_ MIDX'd packs, but only the pack that _should_ have
> contained the object?
Do you mean in the main code path, or in the fallback?
In the main code path we definitely don't want to do this. Imagine we
have a midx that covers a million packs, and says object X is in pack P.
A simultaneous writer deletes P and rewrites the midx, and the object is
now in a new pack Q (which might be covered by the new midx, but we
don't know because we're working with the stale one).
We definitely want to look in Q for the object after the midx can't find
it. But we probably don't want to immediately search in the other
million midx packs. Most objects won't have such a duplicate and the
search is fruitless.
-Peff
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH 2/2] packfile: recover when a multi-pack-index names a removed pack
2026-08-18 22:34 ` [PATCH 2/2] packfile: recover when a multi-pack-index names a removed pack Elijah Newren via GitGitGadget
` (2 preceding siblings ...)
2026-08-24 4:55 ` Jeff King
@ 2026-08-24 14:45 ` Derrick Stolee
2026-08-24 14:46 ` Derrick Stolee
4 siblings, 0 replies; 19+ messages in thread
From: Derrick Stolee @ 2026-08-24 14:45 UTC (permalink / raw)
To: Elijah Newren via GitGitGadget, git; +Cc: Elijah Newren
On 8/18/2026 6:34 PM, Elijah Newren via GitGitGadget wrote:
> From: Elijah Newren <newren@gmail.com>
>
> When a geometric repack runs concurrently with other git processes, it
> can write a new pack and multi-pack-index and then delete older packs
> that the new one subsumes. One or more of those older packs may have
> been indexed by the previous multi-pack-index. A process that already
> had the previous multi-pack-index open keeps using it, and that stale
> index still records the removed pack(s) as owning some objects.
This kind of race is why 'git multi-pack-index expire' exists, to
delete packfiles whose objects are all referenced within other
packfiles. The inclusion of these "stale" packs in the multi-pack-index
helps halt reads of those packfiles by new processes while allowing
them to be read by existing processes.
This is currently used in the incremental repacks done by 'git
multi-pack-index repack' and maybe could be used again in this kind
of geometric repack.
(This dance is more important on Windows platforms where read handles
prevent deletions, so it's common to have a foreground operation
prevent a packfile deletion in background maintenance.)
I do think your attempts to be more robust to missing packs is good,
but the comment thread does show that it's a complicated situation
that we may want to avoid whenever possible. Leaving some redundant
data around for some time interval can reduce the number of times
that the fallback logic is triggered.
Thanks,
-Stolee
^ permalink raw reply [flat|nested] 19+ messages in thread* Re: [PATCH 2/2] packfile: recover when a multi-pack-index names a removed pack
2026-08-18 22:34 ` [PATCH 2/2] packfile: recover when a multi-pack-index names a removed pack Elijah Newren via GitGitGadget
` (3 preceding siblings ...)
2026-08-24 14:45 ` Derrick Stolee
@ 2026-08-24 14:46 ` Derrick Stolee
4 siblings, 0 replies; 19+ messages in thread
From: Derrick Stolee @ 2026-08-24 14:46 UTC (permalink / raw)
To: Elijah Newren via GitGitGadget, git; +Cc: Elijah Newren
On 8/18/2026 6:34 PM, Elijah Newren via GitGitGadget wrote:
> From: Elijah Newren <newren@gmail.com>
>
> When a geometric repack runs concurrently with other git processes, it
> can write a new pack and multi-pack-index and then delete older packs
> that the new one subsumes. One or more of those older packs may have
> been indexed by the previous multi-pack-index. A process that already
> had the previous multi-pack-index open keeps using it, and that stale
> index still records the removed pack(s) as owning some objects.
This kind of race is why 'git multi-pack-index expire' exists, to
delete packfiles whose objects are all referenced within other
packfiles. The inclusion of these "stale" packs in the multi-pack-index
helps halt reads of those packfiles by new processes while allowing
them to be read by existing processes.
This is currently used in the incremental repacks done by 'git
multi-pack-index repack' and maybe could be used again in this kind
of geometric repack.
(This dance is more important on Windows platforms where read handles
prevent deletions, so it's common to have a foreground operation
prevent a packfile deletion in background maintenance.)
I do think your attempts to be more robust to missing packs is good,
but the comment thread does show that it's a complicated situation
that we may want to avoid whenever possible. Leaving some redundant
data around for some time interval can reduce the number of times
that the fallback logic is triggered.
Thanks,
-Stolee
^ permalink raw reply [flat|nested] 19+ messages in thread