git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
* Recovering from gc errors
@ 2017-11-13 21:13 Marc Branchaud
  2017-11-14  5:53 ` Jeff King
  0 siblings, 1 reply; 5+ messages in thread
From: Marc Branchaud @ 2017-11-13 21:13 UTC (permalink / raw)
  To: Git Mailing List

(I'm using git 2.15.0.)

So today "git gc" started complaining:

error: Could not read 2bc277bcb7e9cc6ef2ea677dd1c3dcd1f9af0c2b
fatal: Failed to traverse parents of commit 
9c355a7726e31b3033b8e714cf7edb4f0a41d8d4
error: failed to run repack

I suspect I'm a victim of the worktree+submodule bugs -- as a longtime 
user of contrib/workdir/git-new-workdir, I've been playing with the 
"worktree" command since it was first introduced.  The "git gc" error 
occurs when it's run in my main repo; I have not tried it in any of my 
worktrees/workdirs.

Various incantations of "git show ... 9c355a7726e31" only fail with the 
same error, so I can't determine much about the problematic commit. 
Luckily I'm not particularly concerned with losing objects, as I push 
any important progress to named refs in backup repos.

But I would like to clean this up in my local repo so that gc stops 
failing.  I tried simply removing this and other loose commits that trip 
up gc (i.e. the objects/9c/355a7726e31b3033b8e714cf7edb4f0a41d8d4 file 
-- there are 49 such files, all of which are several months old), but 
now gc complains of a bad tree object:

error: Could not read c1a99c3520f0b456b8025c50302a4cc9b0b2d777
fatal: bad tree object c1a99c3520f0b456b8025c50302a4cc9b0b2d777
error: failed to run repack

This object is not lying around loose.  "git fsck" lists several 
dangling blob/commit/tree objects, but none of them are c1a99c3520f0b4.

So I'm not sure what to do next.

Any suggestions?

Thanks,

		M.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Recovering from gc errors
  2017-11-13 21:13 Recovering from gc errors Marc Branchaud
@ 2017-11-14  5:53 ` Jeff King
  2017-11-14 15:39   ` Marc Branchaud
  0 siblings, 1 reply; 5+ messages in thread
From: Jeff King @ 2017-11-14  5:53 UTC (permalink / raw)
  To: Marc Branchaud; +Cc: Git Mailing List

On Mon, Nov 13, 2017 at 04:13:19PM -0500, Marc Branchaud wrote:

> Various incantations of "git show ... 9c355a7726e31" only fail with the same
> error, so I can't determine much about the problematic commit. Luckily I'm
> not particularly concerned with losing objects, as I push any important
> progress to named refs in backup repos.

Doing "git show" will require looking at the parent commit to produce
the diff. Probably "git show -s" would work. But in general for poking
at corruption, something bare-bones like "git cat-file commit 9c355a77"
is going to be your best bet.

> But I would like to clean this up in my local repo so that gc stops failing.
> I tried simply removing this and other loose commits that trip up gc (i.e.
> the objects/9c/355a7726e31b3033b8e714cf7edb4f0a41d8d4 file -- there are 49
> such files, all of which are several months old), but now gc complains of a
> bad tree object:

You can't generally fix corruption issues by deleting objects[1]. The
"source" that makes Git want to have these objects is the refs and
reflogs. So your best bet is to find which of those point to the
problematic objects and delete them.

I'd start by seeing if the breakage is reachable from any refs:

  git rev-list --objects --all >/dev/null

If that command succeeds, then all your refs are intact and the problem
is in the reflogs. You can try to figure out which, but I'd probably
just blow them all away:

  rm -rf .git/logs

If the rev-list fails, then one or more branch is corrupted.
Unfortunately the usual efficient tools for asking "which branch
contains this object" are likely to be broken by the corruption. But you
can brute-force it, like:

  git for-each-ref --format='%(refname)' |
  while read ref; do
    git rev-list --objects "$ref" >/dev/null 2>&1 ||
    echo "$ref is broken"
  done

Hopefully that turns up only branches with little value, and you can
delete them:

  git update-ref -d $broken_ref

-Peff

[1] A note on my "you can't fix corruption by deleting objects".

    Since abcb86553d (pack-objects: match prune logic for discarding
    objects, 2014-10-15) , git-gc also traverses the history graph of
    unreachable but "recent" objects. This is to keep whole chunks of
    the history graph intact during the gc grace period (which is 2
    weeks by default). So object themselves _can_ be a source of
    traversal for git-gc.

    We do that traversal with the ignore_missing_links flag, so
    breakages in the unreachable objects _shouldn't_ cause what you're
    seeing. IIRC we did turn up a bug or two with ignore_missing_links.
    The only one I could find was a3ba6bf10a (revision.c: ignore broken
    tags with ignore_missing_links, 2017-05-20), which I think wouldn't
    generate the output you're seeing.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Recovering from gc errors
  2017-11-14  5:53 ` Jeff King
@ 2017-11-14 15:39   ` Marc Branchaud
  2017-11-14 16:48     ` Eric Sunshine
  2017-11-15  0:19     ` Jeff King
  0 siblings, 2 replies; 5+ messages in thread
From: Marc Branchaud @ 2017-11-14 15:39 UTC (permalink / raw)
  To: Jeff King
  Cc: Git Mailing List, Nguyễn Thái Ngọc Duy, Eric Sunshine

(It turned out that this problem is related to worktrees.  CCing some 
worktree folks.)

On 2017-11-14 12:53 AM, Jeff King wrote:
> On Mon, Nov 13, 2017 at 04:13:19PM -0500, Marc Branchaud wrote:
> 
>> Various incantations of "git show ... 9c355a7726e31" only fail with the same
>> error, so I can't determine much about the problematic commit. Luckily I'm
>> not particularly concerned with losing objects, as I push any important
>> progress to named refs in backup repos.
> 
> Doing "git show" will require looking at the parent commit to produce
> the diff. Probably "git show -s" would work. But in general for poking
> at corruption, something bare-bones like "git cat-file commit 9c355a77"
> is going to be your best bet.

Thanks, I'd forgotten about cat-file (show's -s did not work).

Only one or two of the bad commits could possibly belong in a submodule, 
so I don't think I'm seeing a worktree+submodule problem.

There are some definite "rebase -i" commits (e.g. "fixup!"), and a lot 
of what were probably cherry-picks.  I know I did these operations in a 
worktree (see below).

>> But I would like to clean this up in my local repo so that gc stops failing.
>> I tried simply removing this and other loose commits that trip up gc (i.e.
>> the objects/9c/355a7726e31b3033b8e714cf7edb4f0a41d8d4 file -- there are 49
>> such files, all of which are several months old), but now gc complains of a
>> bad tree object:
> 
> You can't generally fix corruption issues by deleting objects[1]. The
> "source" that makes Git want to have these objects is the refs and
> reflogs. So your best bet is to find which of those point to the
> problematic objects and delete them.
> 
> I'd start by seeing if the breakage is reachable from any refs:
> 
>    git rev-list --objects --all >/dev/null

That command does succeed.

> If that command succeeds, then all your refs are intact and the problem
> is in the reflogs. You can try to figure out which, but I'd probably
> just blow them all away:
> 
>    rm -rf .git/logs

Unfortunately, removing the logs directory does not fix "git gc".  So I 
restored it.

However I did find all of the bad SHAs in the HEAD logs of four of my 
worktrees.

All of those worktrees have directories in .git/worktrees/, but "git 
worktree list" does not show two of them.  "git worktree prune -v" 
displays and does nothing.  (I do not want to play with --expire, 
because I'd rather keep my other worktrees.)

I removed all of those worktrees' directories from .git/worktrees/, and 
now "git gc" succeeds.  I've also removed those worktrees' working 
directories, as I don't really need them anymore.

Thanks for your help!

I'm willing to chalk this up to bugs in the early worktree code, unless 
one of the CC'd worktree developers thinks otherwise.

An explicit "git worktree delete" command would be nice for manually 
cleaning things up.  It's easy to just delete the directory, but having 
a "delete" command gives the user assurance that they're not missing 
something.

		M.

> If the rev-list fails, then one or more branch is corrupted.
> Unfortunately the usual efficient tools for asking "which branch
> contains this object" are likely to be broken by the corruption. But you
> can brute-force it, like:
> 
>    git for-each-ref --format='%(refname)' |
>    while read ref; do
>      git rev-list --objects "$ref" >/dev/null 2>&1 ||
>      echo "$ref is broken"
>    done
> 
> Hopefully that turns up only branches with little value, and you can
> delete them:
> 
>    git update-ref -d $broken_ref
> 
> -Peff
> 
> [1] A note on my "you can't fix corruption by deleting objects".
> 
>      Since abcb86553d (pack-objects: match prune logic for discarding
>      objects, 2014-10-15) , git-gc also traverses the history graph of
>      unreachable but "recent" objects. This is to keep whole chunks of
>      the history graph intact during the gc grace period (which is 2
>      weeks by default). So object themselves _can_ be a source of
>      traversal for git-gc.
> 
>      We do that traversal with the ignore_missing_links flag, so
>      breakages in the unreachable objects _shouldn't_ cause what you're
>      seeing. IIRC we did turn up a bug or two with ignore_missing_links.
>      The only one I could find was a3ba6bf10a (revision.c: ignore broken
>      tags with ignore_missing_links, 2017-05-20), which I think wouldn't
>      generate the output you're seeing.
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Recovering from gc errors
  2017-11-14 15:39   ` Marc Branchaud
@ 2017-11-14 16:48     ` Eric Sunshine
  2017-11-15  0:19     ` Jeff King
  1 sibling, 0 replies; 5+ messages in thread
From: Eric Sunshine @ 2017-11-14 16:48 UTC (permalink / raw)
  To: Marc Branchaud
  Cc: Jeff King, Git Mailing List, Nguyễn Thái Ngọc Duy

On Tue, Nov 14, 2017 at 10:39 AM, Marc Branchaud <marcnarc@xiplink.com> wrote:
> I'm willing to chalk this up to bugs in the early worktree code, unless one
> of the CC'd worktree developers thinks otherwise.
>
> An explicit "git worktree delete" command would be nice for manually
> cleaning things up.  It's easy to just delete the directory, but having a
> "delete" command gives the user assurance that they're not missing
> something.

Duy does have a series in 'pu' which adds this functionality, but I
guess it's stalled for the moment. From "What's Cooking":

    * nd/worktree-move (2017-04-20) 6 commits
    - worktree remove: new command
    - worktree move: refuse to move worktrees with submodules
    - worktree move: accept destination as directory
    - worktree move: new command
    - worktree.c: add update_worktree_location()
    - worktree.c: add validate_worktree()

    "git worktree" learned move and remove subcommands.

    Expecting a reroll.
    cf. <20170420101024.7593-1-pclouds@gmail.com>
    cf. <20170421145916.mknekgqzhxffu7di@sigill.intra.peff.net>
    cf. <d0e81b1e-5869-299e-f462-4d43dc997bd1@ramsayjones.plus.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Recovering from gc errors
  2017-11-14 15:39   ` Marc Branchaud
  2017-11-14 16:48     ` Eric Sunshine
@ 2017-11-15  0:19     ` Jeff King
  1 sibling, 0 replies; 5+ messages in thread
From: Jeff King @ 2017-11-15  0:19 UTC (permalink / raw)
  To: Marc Branchaud
  Cc: Git Mailing List, Nguyễn Thái Ngọc Duy, Eric Sunshine

On Tue, Nov 14, 2017 at 10:39:31AM -0500, Marc Branchaud wrote:

> >    rm -rf .git/logs
> 
> Unfortunately, removing the logs directory does not fix "git gc".  So I
> restored it.
> 
> However I did find all of the bad SHAs in the HEAD logs of four of my
> worktrees.

Ah, right. There are more logs than .git/logs these days. That makes
sense.

> I'm willing to chalk this up to bugs in the early worktree code, unless one
> of the CC'd worktree developers thinks otherwise.

Perhaps fixed by acd9544a8f (revision.c: --reflog add HEAD reflog from
all worktrees, 2017-08-23). I think before then that prune/repack would
consider those objects unreachable.

-Peff

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-11-15  0:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-13 21:13 Recovering from gc errors Marc Branchaud
2017-11-14  5:53 ` Jeff King
2017-11-14 15:39   ` Marc Branchaud
2017-11-14 16:48     ` Eric Sunshine
2017-11-15  0:19     ` Jeff King

git@vger.kernel.org list mirror (unofficial, one of many)

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 git git/ https://public-inbox.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.io/gmane.comp.version-control.git
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git