Subject: Re: Question: .idx without .pack causes performance issues?

From: Junio C Hamano <[email-masked]>
Date: Tue, 21 Jul 2015 11:57:48 -0700

Doug Kelly <[email-masked]> writes:

> I just wanted to relay an issue we've seen before at my day job (and
> it just recently cropped up again).  When moving users from Git for
> Windows 1.8.3 to 1.9.5, we found a few users started having operations
> take an excruciatingly long amount of time.  At some point, we traced
> the issue to a number of .pack files had been deleted (possibly
> garbage collected?) -- but their associated .idx files were still
> present.  Upon removing the "orphaned" idx files, we found performance
> returned to normal.  Otherwise, git fsck reported no issues with the
> repositories.
>
> Other users have noted that using git gc would sometimes correct the
> issue for them, but not always.
>
> Anyway, has anyone else experienced this performance degradation?

I wouldn't be surprised if such a configuration to have leftover
".idx" files that lack ".pack" affected performance, but I think you
really have to work on getting into such a situation (unless your
operating system is very cooperative and tries hard to corrupt your
repository, that is ;-), so I wouldn't be surprised if you were the
first one to report this.

We open the ".idx" file and try to keep as many of them in-core,
without opening corresponding ".pack" until the data is needed. 

When we need an object, we learn from an ".idx" file that a
particular pack ought to have a copy of it, and then attempt to open
the corresponding ".pack" file.  If this fails, we do protect
ourselves from strange repositories with only ".idx" files by not
using that ".idx" and try to see if the sought-after object exists
elsewhere (and if there isn't we say "no such object", which is also
a correct thing to do).

I however do not think that we mark the in-core structure that
corresponds to an open ".idx" file in any way when such a failure
happens.  If we really cared enough, we could do so, saying "we know
there is .idx file, but do not bother looking at it again, as we
know the corresponding .pack is missing", and that would speed things
up a bit, essentially bringing us back to a sane situation without
any ".idx" without corresponding ".pack".

I do not think it is worth the effort, though.  It would be more
fruitful to find out how you end up with ".idx exists but not
corresponding .pack" and if that is some systemic failure, see if
there is a way to prevent that from happening in the first place.

Also, I think it may not be a bad idea to teach "gc" to remove stale
".idx" files that do not have corresponding ".pack" as garbage.