Commit b5e81899 authored by Michael Kozono's avatar Michael Kozono

Merge branch '223254-remove-rake-task-to-refresh-the-foreign-tables' into 'master'

Geo - Remove rake task to refresh the foreign tables

See merge request gitlab-org/gitlab!38632
parents 7d9a74db 3e3991b5
---
title: 'Geo: Remove rake task to refresh foreign tables definition in Geo Secondary
node'
merge_request: 38632
author:
type: removed
...@@ -7,12 +7,6 @@ module Gitlab ...@@ -7,12 +7,6 @@ module Gitlab
FOREIGN_SERVER = 'gitlab_secondary' FOREIGN_SERVER = 'gitlab_secondary'
FOREIGN_SCHEMA = 'gitlab_secondary' FOREIGN_SCHEMA = 'gitlab_secondary'
CACHE_KEYS = %i(
geo_FOREIGN_SCHEMA_exist
geo_foreign_schema_tables_match
geo_fdw_count_tables
).freeze
class << self class << self
# Return if FDW is enabled for this instance # Return if FDW is enabled for this instance
# #
...@@ -36,10 +30,6 @@ module Gitlab ...@@ -36,10 +30,6 @@ module Gitlab
FOREIGN_SCHEMA + ".#{table_name}" FOREIGN_SCHEMA + ".#{table_name}"
end end
def foreign_tables_up_to_date?
has_foreign_schema? && foreign_schema_tables_match?
end
# Number of existing tables # Number of existing tables
# #
# @return [Integer] number of tables # @return [Integer] number of tables
...@@ -56,10 +46,6 @@ module Gitlab ...@@ -56,10 +46,6 @@ module Gitlab
end end
end end
def expire_cache!
Gitlab::Geo.expire_cache_keys!(CACHE_KEYS)
end
private private
def fdw_capable? def fdw_capable?
......
...@@ -34,36 +34,6 @@ module Gitlab ...@@ -34,36 +34,6 @@ module Gitlab
exit 1 exit 1
end end
end end
def refresh_foreign_tables!
sql = <<~SQL
DROP SCHEMA IF EXISTS gitlab_secondary CASCADE;
CREATE SCHEMA gitlab_secondary;
IMPORT FOREIGN SCHEMA public
FROM SERVER gitlab_secondary
INTO gitlab_secondary;
SQL
Gitlab::Geo::DatabaseTasks.with_geo_db do
ActiveRecord::Base.transaction do
ActiveRecord::Base.connection.execute(sql)
end
end
Gitlab::Geo::Fdw.expire_cache!
end
def foreign_server_configured?
sql = <<~SQL
SELECT count(1)
FROM pg_foreign_server
WHERE srvname = '#{Gitlab::Geo::Fdw::FOREIGN_SERVER}';
SQL
Gitlab::Geo::DatabaseTasks.with_geo_db do
ActiveRecord::Base.connection.execute(sql).first.fetch('count').to_i == 1
end
end
end end
end end
end end
...@@ -50,18 +50,6 @@ namespace :geo do ...@@ -50,18 +50,6 @@ namespace :geo do
Gitlab::Geo::DatabaseTasks.load_seed Gitlab::Geo::DatabaseTasks.load_seed
end end
desc 'GitLab | Geo | DB | Refresh Foreign Tables definition in Geo Secondary node'
task refresh_foreign_tables: [:environment] do
if Gitlab::Geo::GeoTasks.foreign_server_configured?
print "\nRefreshing foreign tables for FDW: #{Gitlab::Geo::Fdw::FOREIGN_SCHEMA} ... "
Gitlab::Geo::GeoTasks.refresh_foreign_tables!
puts 'Done!'
else
puts "Error: Cannot refresh foreign tables, there is no foreign server configured."
exit 1
end
end
# IMPORTANT: This task won't dump the schema if ActiveRecord::Base.dump_schema_after_migration is set to false # IMPORTANT: This task won't dump the schema if ActiveRecord::Base.dump_schema_after_migration is set to false
task _dump: [:environment] do task _dump: [:environment] do
if Gitlab::Geo::DatabaseTasks.dump_schema_after_migration? if Gitlab::Geo::DatabaseTasks.dump_schema_after_migration?
......
...@@ -101,24 +101,6 @@ RSpec.describe Gitlab::Geo::Fdw, :geo do ...@@ -101,24 +101,6 @@ RSpec.describe Gitlab::Geo::Fdw, :geo do
end end
end end
describe '.foreign_tables_up_to_date?' do
it 'returns false when foreign schema does not exist' do
drop_foreign_schema
expect(described_class.foreign_tables_up_to_date?).to eq false
end
it 'returns false when foreign schema exists but tables in schema doesnt match' do
create_foreign_table(:gitlab_test)
expect(described_class.foreign_tables_up_to_date?).to eq false
end
it 'returns true when foreign schema exists and foreign schema has same tables as secondary database' do
expect(described_class.foreign_tables_up_to_date?).to eq true
end
end
describe '.foreign_schema_tables_count' do describe '.foreign_schema_tables_count' do
before do before do
drop_foreign_schema drop_foreign_schema
...@@ -138,14 +120,6 @@ RSpec.describe Gitlab::Geo::Fdw, :geo do ...@@ -138,14 +120,6 @@ RSpec.describe Gitlab::Geo::Fdw, :geo do
end end
end end
describe '.expire_cache!' do
it 'calls Gitlab::Geo.expire_cache_keys!' do
expect(Gitlab::Geo).to receive(:expire_cache_keys!).with(Gitlab::Geo::Fdw::CACHE_KEYS)
described_class.expire_cache!
end
end
def with_foreign_connection def with_foreign_connection
Geo::TrackingBase.connection Geo::TrackingBase.connection
end end
......
...@@ -29,8 +29,6 @@ RSpec.describe 'geo rake tasks', :geo do ...@@ -29,8 +29,6 @@ RSpec.describe 'geo rake tasks', :geo do
it 'Gitlab::Geo::GeoTasks responds to all methods used in Geo rake tasks' do it 'Gitlab::Geo::GeoTasks responds to all methods used in Geo rake tasks' do
%i[ %i[
foreign_server_configured?
refresh_foreign_tables!
set_primary_geo_node set_primary_geo_node
update_primary_geo_node_url update_primary_geo_node_url
].each do |method| ].each do |method|
...@@ -115,15 +113,6 @@ RSpec.describe 'geo rake tasks', :geo do ...@@ -115,15 +113,6 @@ RSpec.describe 'geo rake tasks', :geo do
end end
end end
describe 'geo:db:refresh_foreign_tables' do
it 'refreshes foreign tables definition on secondary node' do
allow(Gitlab::Geo::GeoTasks).to receive(:foreign_server_configured?).and_return(true)
expect(Gitlab::Geo::GeoTasks).to receive(:refresh_foreign_tables!)
run_rake_task('geo:db:refresh_foreign_tables')
end
end
describe 'geo:db:_dump' do describe 'geo:db:_dump' do
it 'dumps the schema' do it 'dumps the schema' do
allow(Gitlab::Geo::DatabaseTasks).to receive(:dump_schema_after_migration?).and_return(true) allow(Gitlab::Geo::DatabaseTasks).to receive(:dump_schema_after_migration?).and_return(true)
...@@ -231,15 +220,6 @@ RSpec.describe 'geo rake tasks', :geo do ...@@ -231,15 +220,6 @@ RSpec.describe 'geo rake tasks', :geo do
end end
end end
describe 'geo:db:test:refresh_foreign_tables' do
it 'refreshes foreign tables definitions in test environment' do
allow(ActiveRecord::Tasks::DatabaseTasks).to receive(:env)
expect(Rake::Task['geo:db:refresh_foreign_tables']).to receive(:invoke)
run_rake_task('geo:db:test:refresh_foreign_tables')
end
end
describe 'geo:set_primary_node' do describe 'geo:set_primary_node' do
before do before do
stub_config_setting(url: 'https://example.com:1234/relative_part') stub_config_setting(url: 'https://example.com:1234/relative_part')
......
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