Commit 7eec5485 authored by Douwe Maan's avatar Douwe Maan

Merge branch '3876-can-push-code-to-geo-secondaries' into 'master'

Geo: read-only safeguards was not working on Secondary node

Closes #3876

See merge request gitlab-org/gitlab-ee!3227
parents 5f8d74c4 05bed98a
---
title: 'Geo: read-only safeguards was not working on Secondary node'
merge_request: 3227
author:
type: fixed
module EE
module Gitlab
module Database
def self.read_only?
raise NotImplementedError unless defined?(super)
Gitlab::Geo.secondary? || super
end
end
end
end
module Gitlab
module Database
extend ::EE::Gitlab::Database
# The max value of INTEGER type is the same between MySQL and PostgreSQL:
# https://www.postgresql.org/docs/9.2/static/datatype-numeric.html
# http://dev.mysql.com/doc/refman/5.7/en/integer-types.html
......@@ -33,7 +31,7 @@ module Gitlab
# Overridden in EE
def self.read_only?
false
Gitlab::Geo.secondary?
end
def self.read_write?
......
require Rails.root.join('ee/lib/ee/gitlab/database')
require Rails.root.join('lib/gitlab/database')
require Rails.root.join('lib/gitlab/database/migration_helpers')
require Rails.root.join('db/migrate/20151007120511_namespaces_projects_path_lower_indexes')
......
......@@ -273,4 +273,35 @@ describe Gitlab::Database do
expect(config['prepared_statements']).to eq(false)
end
end
describe '.read_only?' do
context 'with Geo enabled' do
before do
allow(Gitlab::Geo).to receive(:enabled?) { true }
allow(Gitlab::Geo).to receive(:current_node) { geo_node }
end
context 'is Geo secondary node' do
let(:geo_node) { create(:geo_node) }
it 'returns true' do
expect(described_class.read_only?).to be_truthy
end
end
context 'is Geo primary node' do
let(:geo_node) { create(:geo_node, :primary) }
it 'returns false when is Geo primary node' do
expect(described_class.read_only?).to be_falsey
end
end
end
context 'with Geo disabled' do
it 'returns false' do
expect(described_class.read_only?).to be_falsey
end
end
end
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