Inconsistent state for Repository#branch_count and Repository#branch_names
@northrup moved a project from gitlab-cog/gitlab
to gitlab-cog/gitlab-admin
and found that the repository appeared empty on the Web UI.
When we looked at the state of the project cache, we saw this:
irb(main):057:0> proj.repository.branch_count
=> 0
irb(main):058:0> proj.repository.branch_names
=> ["master", "pc-try-without-tty", "refactor-runners", "refactor-runners-info", "templates-for-gitlab", "test"]
This is clearly an inconsistent state. Because branch_count
is 0, Repository#has_visible_content?
returned false
and showed an empty repo. Pushing to a new branch fixed the issue.
How did this happen? My guess is that when the project was moved, the cache was flushed. However, before the move was done, something checked Repository#has_visible_content?
, and since the repository was no longer there, the value got incorrectly set to 0.
It seems to me we may want to do something as the following:
- Don't cache the
branch_count
if it is 0; or if there is an error with Rugged, don't cache at all - Check if the
branch_count
andbranch_names.count
is consistent. If it is not, flag an error and expire something.
@DouweM @yorickpeterse Thoughts?