Page MenuHomePhabricator

`./bin/repository parents` fails with `AphrontQueryDuplicateKeyException`
Closed, ResolvedPublic

Description

I'm getting the following errors when using ./bin/repository parents on a large repository:

Rebuilding "rGAF"...                                                          
Rebuilding branch "master"...
Found 83,751 total commit(s); updating...
[2014-05-30 13:35:32] EXCEPTION: (AphrontQueryDuplicateKeyException) #1062: Duplicate entry '1406057-1406055' for key 'key_child' at [/usr/src/libphutil/src/aphront/storage/connection/mysql/AphrontMySQLDatabaseConnectionBase.php:299]
  #0 AphrontMySQLDatabaseConnectionBase::throwQueryCodeException(1062, Duplicate entry '1406057-1406055' for key 'key_child') called at [/usr/src/libphutil/src/aphront/storage/connection/mysql/AphrontMySQLDatabaseConnectionBase.php:278]
  #1 AphrontMySQLDatabaseConnectionBase::throwQueryException(Object mysqli) called at [/usr/src/libphutil/src/aphront/storage/connection/mysql/AphrontMySQLDatabaseConnectionBase.php:184]
  #2 AphrontMySQLDatabaseConnectionBase::executeRawQuery(INSERT INTO `repository_parents` (childCommitID, parentCommitID) VALUES (1406057, 1406055), (1406057, 1406055), (1406057, 1406056)) called at [/usr/src/libphutil/src/xsprintf/queryfx.php:9]
  #3 queryfx(Object AphrontMySQLiDatabaseConnection, INSERT INTO %T (childCommitID, parentCommitID) VALUES %Q, repository_parents, (1406057, 1406055), (1406057, 1406055), (1406057, 1406056)) called at [/usr/src/phabricator/src/applications/repository/management/PhabricatorRepositoryManagementParentsWorkflow.php:151]
  #4 PhabricatorRepositoryManagementParentsWorkflow::rebuildRepository(Object PhabricatorRepository) called at [/usr/src/phabricator/src/applications/repository/management/PhabricatorRepositoryManagementParentsWorkflow.php:43]
  #5 PhabricatorRepositoryManagementParentsWorkflow::execute(Object PhutilArgumentParser) called at [/usr/src/libphutil/src/parser/argument/PhutilArgumentParser.php:396]
  #6 PhutilArgumentParser::parseWorkflowsFull(Array of size 14 starting with: { PhabricatorRepositoryManagementCacheWorkflow => Object PhabricatorRepositoryManagementCacheWorkflow }) called at [/usr/src/libphutil/src/parser/argument/PhutilArgumentParser.php:292]
  #7 PhutilArgumentParser::parseWorkflows(Array of size 14 starting with: { PhabricatorRepositoryManagementCacheWorkflow => Object PhabricatorRepositoryManagementCacheWorkflow }) called at [/usr/src/phabricator/scripts/repository/manage_repositories.php:22]
PHP Fatal error:  Uncaught exception 'Exception' with message 'Process exited with an open transaction! The transaction will be implicitly rolled back. Calls to openTransaction() must always be paired with a call to saveTransaction() or killTransaction().' in /usr/src/libphutil/src/aphront/storage/connection/AphrontDatabaseTransactionState.php:71
Stack trace:
#0 [internal function]: AphrontDatabaseTransactionState->__destruct()
#1 {main}
  thrown in /usr/src/libphutil/src/aphront/storage/connection/AphrontDatabaseTransactionState.php on line 71

Fatal error: Uncaught exception 'Exception' with message 'Process exited with an open transaction! The transaction will be implicitly rolled back. Calls to openTransaction() must always be paired with a call to saveTransaction() or killTransaction().' in /usr/src/libphutil/src/aphront/storage/connection/AphrontDatabaseTransactionState.php:71
Stack trace:
#0 [internal function]: AphrontDatabaseTransactionState->__destruct()
#1 {main}
  thrown in /usr/src/libphutil/src/aphront/storage/connection/AphrontDatabaseTransactionState.php on line 71

Any thoughts?

Event Timeline

joshuaspence assigned this task to epriestley.
joshuaspence raised the priority of this task from to Needs Triage.
joshuaspence updated the task description. (Show Details)
joshuaspence added a project: Repositories.
joshuaspence added a subscriber: joshuaspence.

This is very weird:

VALUES (1406057, 1406055), (1406057, 1406055), (1406057, 1406056)

It suggests the commit has the same parent twice.

Try this:

  • Find the commit in question: SELECT * FROM phabricator_repository.repository_commit WHERE id = 1406057
  • Grab the commit identifier.
  • If you're in Git, run git log -n1 <hash> --format=%P
  • Does that list a single parent twice?
  • If so, does examining the commit provide an explanation of why?
In T5226#5, @epriestley wrote:
  • If you're in Git, run git log -n1 <hash> --format=%P
  • Does that list a single parent twice?
  • If so, does examining the commit provide an explanation of why?

It does:

> git log -n1 24706f21633a248e5ad60549da951a48a06153bc --format=%P
b58f1f88a35c92590787a33f01b602ca7fa14b28 b58f1f88a35c92590787a33f01b602ca7fa14b28 99c9882d8733c3be7d9fcdd15c168ee1f805e04a

The commit appears to be some kind of three-way merge commit:

commit 24706f21633a248e5ad60549da951a48a06153bc
Merge: b58f1f8 b58f1f8 99c9882
Author: Redacted
Date:   Mon Apr 23 17:58:27 2012 +1000

    Merge branch 'production', remote-tracking branch 'origin/hotfix-gc' into production

I can't figure out how to generate such a commit without using low-level commands like git commit-tree, but found at least one other case on the web where someone managed to create such a commit using a non-git Git frontend.

It looks like we aren't discarding any information by ignoring the duplicate. See, e.g., Linus in 2005:

http://code.google.com/p/git-core/source/detail?r=b389237ae8cd04c2f53db52e37c02e30c63bcc89

joshuaspence renamed this task from `./bin/repository parents` fails with `AphrontQueryDuplicateKeyException`. to `./bin/repository parents` fails with `AphrontQueryDuplicateKeyException`.Jul 10 2014, 7:44 PM