Commit 05bed98a authored by Gabriel Mazetto's avatar Gabriel Mazetto

Gitlab::Database.read_only? works correctly for EE version (specs included)

parent 917e7187
---
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 Gitlab
module Database module Database
extend ::EE::Gitlab::Database
# The max value of INTEGER type is the same between MySQL and PostgreSQL: # The max value of INTEGER type is the same between MySQL and PostgreSQL:
# https://www.postgresql.org/docs/9.2/static/datatype-numeric.html # https://www.postgresql.org/docs/9.2/static/datatype-numeric.html
# http://dev.mysql.com/doc/refman/5.7/en/integer-types.html # http://dev.mysql.com/doc/refman/5.7/en/integer-types.html
...@@ -33,7 +31,7 @@ module Gitlab ...@@ -33,7 +31,7 @@ module Gitlab
# Overridden in EE # Overridden in EE
def self.read_only? def self.read_only?
false Gitlab::Geo.secondary?
end end
def self.read_write? 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')
require Rails.root.join('lib/gitlab/database/migration_helpers') require Rails.root.join('lib/gitlab/database/migration_helpers')
require Rails.root.join('db/migrate/20151007120511_namespaces_projects_path_lower_indexes') require Rails.root.join('db/migrate/20151007120511_namespaces_projects_path_lower_indexes')
......
...@@ -273,4 +273,35 @@ describe Gitlab::Database do ...@@ -273,4 +273,35 @@ describe Gitlab::Database do
expect(config['prepared_statements']).to eq(false) expect(config['prepared_statements']).to eq(false)
end end
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 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