解决Gerrit的git unpack error问题

今天上午同事和我说neutron项目要换成全新的内部代码,原先仓库里的代码要全部废弃掉。于是我就简单地创建了一个空项目使用git push --force将其置空。

下午的时候,麻烦事情就来了,同事发现提交patch的时候,会发现如下报错:

remote: Resolving deltas: 100% (2/2)
error: unpack failed: error Missing unknown 613fd2557fba30aff2dbd51c3807cc57561bab08
fatal: Unpack error, check server log
To ssh://[email protected]:29418/neutron.git
 ! [remote rejected] HEAD -> refs/publish/datong (n/a (unpacker error))
error: failed to push some refs to 'ssh://[email protected]:29418/neutron.git'

通过google我找到了两篇文章:

《Gerrit Code Review - Unpack error Missing unknown》一文是说git的某object受损导致:

http://asheepapart.blogspot.jp/2011/10/gerrit-code-review-unpack-error-missing.html

我使用文提供的方法发现根本就不存在 613fd2557fba30aff2dbd51c3807cc57561bab08 object。

然后我又搜到了一个在stackoverflow上的相关提问:

http://stackoverflow.com/questions/16586642/git-unpack-error-on-push-to-gerrit

提问指出如果你使用了git 1.8 + gerrit 2.7版本的组合,就会出现这样的问题,可惜的是我所使用的git和gerrit版本均低于此。

 

鉴于网上没有靠谱的解决办法,只能自己去查问题所在了。先查看了gerrit的日志:

[2014-01-07 03:57:15,400] ERROR com.google.gerrit.sshd.BaseCommand : Internal server error (user newptone account 1) during git-receive-pack '/neutron.git'
com.google.gerrit.sshd.BaseCommand$Failure: fatal: Unpack error, check server log
        at com.google.gerrit.sshd.commands.Receive.runImpl(Receive.java:157)
        at com.google.gerrit.sshd.AbstractGitCommand.service(AbstractGitCommand.java:106)
        at com.google.gerrit.sshd.AbstractGitCommand.access$000(AbstractGitCommand.java:34)
        at com.google.gerrit.sshd.AbstractGitCommand$1.run(AbstractGitCommand.java:72)
        at com.google.gerrit.sshd.BaseCommand$TaskThunk.run(BaseCommand.java:430)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
        at java.util.concurrent.FutureTask.run(FutureTask.java:166)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:165)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:266)
        at com.google.gerrit.server.git.WorkQueue$Task.run(WorkQueue.java:337)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:701)
Caused by: java.io.IOException: Unpack error on project "neutron":
  AdvertiseRefsHook: org.eclipse.jgit.transport.AdvertiseRefsHookChain@77348c71class org.eclipse.jgit.transport.AdvertiseRefsHookChain

        at com.google.gerrit.sshd.commands.Receive.runImpl(Receive.java:156)
        ... 13 more
Caused by: org.eclipse.jgit.errors.UnpackException: Exception while parsing pack stream
        at org.eclipse.jgit.transport.ReceivePack.service(ReceivePack.java:202)
        at org.eclipse.jgit.transport.ReceivePack.receive(ReceivePack.java:142)
        at com.google.gerrit.sshd.commands.Receive.runImpl(Receive.java:98)
        ... 13 more
Caused by: org.eclipse.jgit.errors.MissingObjectException: Missing unknown 613fd2557fba30aff2dbd51c3807cc57561bab08
        at org.eclipse.jgit.storage.file.WindowCursor.open(WindowCursor.java:125)
        at org.eclipse.jgit.lib.ObjectReader.open(ObjectReader.java:228)
        at org.eclipse.jgit.revwalk.RevWalk.parseAny(RevWalk.java:812)
        at org.eclipse.jgit.transport.BaseReceivePack.checkConnectivity(BaseReceivePack.java:956)
        at org.eclipse.jgit.transport.BaseReceivePack.receivePackAndCheckConnectivity(BaseReceivePack.java:756)
        at org.eclipse.jgit.transport.ReceivePack.service(ReceivePack.java:167)
        ... 15 more

 

那么就定义到613fd2557fba30aff2dbd51c3807cc57561bab08这串哈希值,为什么会丢失这个object ?

我顺手敲了一个 git review -l,发现gerrit上居然有一个还没有关闭的patch:

1974  master  Add two interfaces for manipulate forwarding individually

我打开Gerrit web界面,点击这个patchset,跳出一段错误说明:613fd2557fba30aff2dbd51c3807cc57561bab08 cannot  found.

 

啊哈,到这里真相就大白了。原因就是上午我在删除原先的旧有neutron代码时,忘记把gerrit上相关的neutron提交做关闭处理,而输入git review命令时,gerrit会先做一个rebase操作,再做提交,然而neutron仓库发生变化后,存在数据库中的1974号patch_set找不到对应的object了,所以在执行:git push gerrit HEAD:refs/publish/datong 操作时发生了前面的问题。

事已至此,解决的办法就是到reviewdb数据库里,先从patch_sets表中找出change_id是1974的记录,确定无误后,我们从changes表中找出对应的记录:

mysql> select * from changes where change_id=1974\G;
*************************** 1. row ***************************
            change_key: I6596720099473969b19675f8fbb97a2db29b5532
            created_on: 2014-01-06 12:20:07
       last_updated_on: 2014-01-07 03:02:09
              sort_key: 002a4736000007b6
      owner_account_id: 25
     dest_project_name: neutron
      dest_branch_name: refs/heads/master
                  open: Y
                status: n
        nbr_patch_sets: 1
  current_patch_set_id: 1
               subject: Add two interfaces for manipulate forwarding individually
                 topic: portforwarding-api
last_sha1_merge_tested: NULL
             mergeable: N
           row_version: 2
             change_id: 1974
1 row in set (0.00 sec)

 

我们要做的是将其关闭,并把状态置为Abandon。(友情提醒,涉及重要业务,注意备份数据库)

mysql> update changes set open='N',status='A' where change_id=1974;
Query OK, 1 row affected (0.05 sec)
Rows matched: 1  Changed: 1  Warnings: 0

 

OK,现在neutron的提交已经恢复正常,我可以安心地去做其他事情了:)

你可能感兴趣的:(error)