Commit 043f8273 authored by Stan Hu's avatar Stan Hu

Geo: Always update the default branch on the secondary

Previously, we would only update the default branch on a Geo secondary
if the default branch didn't match the primary default branch. However,
the Gitaly FindDefaultBranch RPC may return an arbitrary branch if HEAD
points to an invalid branch, so we can't trust that result to be
correct.

To ensure that the default branch is always correct, we now write it out
on the Geo secondary whenever we do a sync. This incurs an additional
filesystem write, but that should be relatively minor.

Closes https://gitlab.com/gitlab-org/gitlab-ee/issues/9084
parent fb8cb53e
......@@ -476,7 +476,7 @@ module EE
# Update the default branch querying the remote to determine its HEAD
def update_root_ref(remote_name)
root_ref = repository.find_remote_root_ref(remote_name)
change_head(root_ref) if root_ref.present? && root_ref != default_branch
change_head(root_ref) if root_ref.present?
end
def feature_flags_client_token
......
---
title: 'Geo: Always update the default branch on the secondary'
merge_request: 9064
author:
type: fixed
......@@ -1520,11 +1520,16 @@ describe Project do
.to('feature')
end
it 'does not update the default branch when HEAD does not change' do
it 'always updates the default branch even when HEAD does not change' do
stub_find_remote_root_ref(project, ref: 'master')
expect { project.update_root_ref('origin') }
.not_to change { project.default_branch }
expect(project).to receive(:change_head).with('master').and_call_original
project.update_root_ref('origin')
# For good measure, expunge the root ref cache and reload.
project.repository.expire_all_method_caches
expect(project.reload.default_branch).to eq('master')
end
it 'does not update the default branch when HEAD does not exist' do
......
......@@ -253,8 +253,8 @@ describe Geo::RepositorySyncService do
.and_return(project.default_branch)
end
it 'does not sync gitattributes to info/attributes' do
expect(repository).not_to receive(:copy_gitattributes)
it 'syncs gitattributes to info/attributes' do
expect(repository).to receive(:copy_gitattributes)
subject.execute
end
......@@ -265,7 +265,7 @@ describe Geo::RepositorySyncService do
.twice
.and_call_original
expect(project).not_to receive(:change_head)
expect(project).to receive(:change_head).with('master').once
subject.execute
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment