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
FOREIGN_SERVER = '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
# Return if FDW is enabled for this instance
#
......@@ -36,10 +30,6 @@ module Gitlab
FOREIGN_SCHEMA + ".#{table_name}"
end
def foreign_tables_up_to_date?
has_foreign_schema? && foreign_schema_tables_match?
end
# Number of existing tables
#
# @return [Integer] number of tables
......@@ -56,10 +46,6 @@ module Gitlab
end
end
def expire_cache!
Gitlab::Geo.expire_cache_keys!(CACHE_KEYS)
end
private
def fdw_capable?
......
......@@ -34,36 +34,6 @@ module Gitlab
exit 1
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
......@@ -50,18 +50,6 @@ namespace :geo do
Gitlab::Geo::DatabaseTasks.load_seed
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
task _dump: [:environment] do
if Gitlab::Geo::DatabaseTasks.dump_schema_after_migration?
......
......@@ -101,24 +101,6 @@ RSpec.describe Gitlab::Geo::Fdw, :geo do
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
before do
drop_foreign_schema
......@@ -138,14 +120,6 @@ RSpec.describe Gitlab::Geo::Fdw, :geo do
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
Geo::TrackingBase.connection
end
......
......@@ -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
%i[
foreign_server_configured?
refresh_foreign_tables!
set_primary_geo_node
update_primary_geo_node_url
].each do |method|
......@@ -115,15 +113,6 @@ RSpec.describe 'geo rake tasks', :geo do
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
it 'dumps the schema' do
allow(Gitlab::Geo::DatabaseTasks).to receive(:dump_schema_after_migration?).and_return(true)
......@@ -231,15 +220,6 @@ RSpec.describe 'geo rake tasks', :geo do
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
before do
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