Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
685cc4a6
Commit
685cc4a6
authored
Aug 05, 2020
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove Gitlab::Geo::Fdw class
Since Gitlab 13.2, Geo don't rely on FDW
parent
e9fae4ac
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
0 additions
and
270 deletions
+0
-270
.rubocop_todo.yml
.rubocop_todo.yml
+0
-1
ee/lib/gitlab/geo/fdw.rb
ee/lib/gitlab/geo/fdw.rb
+0
-113
ee/spec/lib/gitlab/geo/fdw_spec.rb
ee/spec/lib/gitlab/geo/fdw_spec.rb
+0
-156
No files found.
.rubocop_todo.yml
View file @
685cc4a6
...
...
@@ -257,7 +257,6 @@ Performance/Count:
Exclude
:
-
'
app/helpers/groups_helper.rb'
-
'
app/services/merge_requests/add_context_service.rb'
-
'
ee/lib/gitlab/geo/fdw.rb'
-
'
ee/lib/gitlab/graphql/aggregations/epics/epic_node.rb'
-
'
ee/spec/controllers/projects/feature_flags_controller_spec.rb'
-
'
ee/spec/requests/api/feature_flags_spec.rb'
...
...
ee/lib/gitlab/geo/fdw.rb
deleted
100644 → 0
View file @
e9fae4ac
# frozen_string_literal: true
module
Gitlab
module
Geo
class
Fdw
DEFAULT_SCHEMA
=
'public'
FOREIGN_SERVER
=
'gitlab_secondary'
FOREIGN_SCHEMA
=
'gitlab_secondary'
class
<<
self
# Return if FDW is enabled for this instance
#
# @return [Boolean] whether FDW is enabled
def
enabled?
return
false
unless
fdw_capable?
# FDW is enabled by default, disable it by setting `fdw: false` in config/database_geo.yml
value
=
Rails
.
configuration
.
geo_database
[
'fdw'
]
value
.
nil?
?
true
:
value
end
def
disabled?
!
enabled?
end
# Return full table name with foreign schema
#
# @param [String] table_name
def
foreign_table_name
(
table_name
)
FOREIGN_SCHEMA
+
".
#{
table_name
}
"
end
# Number of existing tables
#
# @return [Integer] number of tables
def
foreign_schema_tables_count
Gitlab
::
Geo
.
cache_value
(
:geo_fdw_count_tables
)
do
sql
=
<<~
SQL
SELECT COUNT(*)
FROM information_schema.foreign_tables
WHERE foreign_table_schema = '
#{
FOREIGN_SCHEMA
}
'
AND foreign_table_name NOT LIKE 'pg_%'
SQL
::
Geo
::
TrackingBase
.
connection
.
execute
(
sql
).
first
.
fetch
(
'count'
).
to_i
end
end
private
def
fdw_capable?
has_foreign_server?
&&
has_foreign_schema?
&&
foreign_schema_tables_count
>
0
rescue
::
Geo
::
TrackingBase
::
SecondaryNotConfigured
false
end
# Check if there is at least one foreign server configured
#
# @return [Boolean] whether any foreign server exists
def
has_foreign_server?
::
Geo
::
TrackingBase
.
connection
.
execute
(
"SELECT 1 FROM pg_foreign_server"
).
count
>
0
end
def
has_foreign_schema?
Gitlab
::
Geo
.
cache_value
(
:geo_FOREIGN_SCHEMA_exist
)
do
sql
=
<<~
SQL
SELECT 1
FROM information_schema.schemata
WHERE schema_name='
#{
FOREIGN_SCHEMA
}
'
SQL
::
Geo
::
TrackingBase
.
connection
.
execute
(
sql
).
count
>
0
end
end
# Check if foreign schema has exact the same tables and fields defined on secondary database
#
# @return [Boolean] whether schemas match and are not empty
def
foreign_schema_tables_match?
Gitlab
::
Geo
.
cache_value
(
:geo_foreign_schema_tables_match
)
do
gitlab_schema_tables
=
retrieve_gitlab_schema_tables
.
to_set
foreign_schema_tables
=
retrieve_foreign_schema_tables
.
to_set
gitlab_schema_tables
.
present?
&&
(
gitlab_schema_tables
==
foreign_schema_tables
)
end
end
def
retrieve_foreign_schema_tables
retrieve_schema_tables
(
::
Geo
::
TrackingBase
,
Rails
.
configuration
.
geo_database
[
'database'
],
FOREIGN_SCHEMA
).
to_a
end
def
retrieve_gitlab_schema_tables
retrieve_schema_tables
(
ActiveRecord
::
Base
,
ActiveRecord
::
Base
.
connection_config
[
:database
],
DEFAULT_SCHEMA
).
to_a
end
def
retrieve_schema_tables
(
adapter
,
database
,
schema
)
sql
=
<<~
SQL
SELECT table_name, column_name, data_type
FROM information_schema.columns
WHERE table_catalog = '
#{
database
}
'
AND table_schema = '
#{
schema
}
'
AND table_name NOT LIKE 'pg_%'
ORDER BY table_name, column_name, data_type
SQL
adapter
.
connection
.
select_all
(
sql
)
end
end
end
end
end
ee/spec/lib/gitlab/geo/fdw_spec.rb
deleted
100644 → 0
View file @
e9fae4ac
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Gitlab
::
Geo
::
Fdw
,
:geo
do
describe
'.enabled?'
do
it
'returns false when Geo secondary database is not configured'
do
allow
(
Gitlab
::
Geo
).
to
receive
(
:geo_database_configured?
).
and_return
(
false
)
expect
(
described_class
.
enabled?
).
to
eq
false
end
it
'returns false when foreign server does not exist'
do
drop_foreign_server
expect
(
described_class
.
enabled?
).
to
eq
false
end
it
'returns false when foreign server exists but foreign schema does not exist'
do
drop_foreign_schema
expect
(
described_class
.
enabled?
).
to
eq
false
end
it
'returns false when foreign server and schema exists but foreign tables are empty'
do
drop_foreign_schema
create_foreign_schema
expect
(
described_class
.
enabled?
).
to
eq
false
end
it
'returns false when fdw is disabled in `config/database_geo.yml`'
do
allow
(
Rails
.
configuration
).
to
receive
(
:geo_database
).
and_return
(
'fdw'
=>
false
)
expect
(
described_class
.
enabled?
).
to
be_falsey
end
it
'returns true when fdw is set in `config/database_geo.yml`'
do
allow
(
Rails
.
configuration
).
to
receive
(
:geo_database
).
and_return
(
'fdw'
=>
true
)
expect
(
described_class
.
enabled?
).
to
be_truthy
end
it
'returns true when fdw is nil in `config/database_geo.yml`'
do
allow
(
Rails
.
configuration
).
to
receive
(
:geo_database
).
and_return
(
'fdw'
=>
nil
)
expect
(
described_class
.
enabled?
).
to
be_truthy
end
it
'returns true with a functional fdw environment'
do
expect
(
described_class
.
enabled?
).
to
be_truthy
end
end
describe
'.disabled?'
do
it
'returns true when foreign server does not exist'
do
drop_foreign_server
expect
(
described_class
.
disabled?
).
to
eq
true
end
it
'returns true when foreign server exists but foreign schema does not exist'
do
drop_foreign_schema
expect
(
described_class
.
disabled?
).
to
eq
true
end
it
'returns true when foreign server and schema exists but foreign tables are empty'
do
drop_foreign_schema
create_foreign_schema
expect
(
described_class
.
disabled?
).
to
eq
true
end
it
'returns true when fdw is disabled in `config/database_geo.yml`'
do
allow
(
Rails
.
configuration
).
to
receive
(
:geo_database
).
and_return
(
'fdw'
=>
false
)
expect
(
described_class
.
disabled?
).
to
eq
true
end
it
'returns true when Geo secondary database is not configured'
do
allow
(
Gitlab
::
Geo
).
to
receive
(
:geo_database_configured?
).
and_return
(
false
)
expect
(
described_class
.
disabled?
).
to
eq
true
end
it
'returns false when fdw is set in `config/database_geo.yml`'
do
allow
(
Rails
.
configuration
).
to
receive
(
:geo_database
).
and_return
(
'fdw'
=>
true
)
expect
(
described_class
.
disabled?
).
to
eq
false
end
it
'returns false when fdw is nil in `config/database_geo.yml`'
do
allow
(
Rails
.
configuration
).
to
receive
(
:geo_database
).
and_return
(
'fdw'
=>
nil
)
expect
(
described_class
.
disabled?
).
to
eq
false
end
it
'returns false with a functional fdw environment'
do
expect
(
described_class
.
disabled?
).
to
eq
false
end
end
describe
'.foreign_schema_tables_count'
do
before
do
drop_foreign_schema
create_foreign_schema
end
it
'returns the number of tables in the foreign schema'
do
create_foreign_table
(
:gitlab_test
)
expect
(
described_class
.
foreign_schema_tables_count
).
to
eq
(
1
)
end
it
'excludes tables that start with `pg_`'
do
create_foreign_table
(
:pg_gitlab_test
)
expect
(
described_class
.
foreign_schema_tables_count
).
to
eq
(
0
)
end
end
def
with_foreign_connection
Geo
::
TrackingBase
.
connection
end
def
drop_foreign_server
with_foreign_connection
.
execute
<<-
SQL
DROP SERVER IF EXISTS
#{
described_class
::
FOREIGN_SERVER
}
CASCADE
SQL
end
def
drop_foreign_schema
with_foreign_connection
.
execute
<<-
SQL
DROP SCHEMA IF EXISTS
#{
described_class
::
FOREIGN_SCHEMA
}
CASCADE
SQL
end
def
create_foreign_schema
with_foreign_connection
.
execute
<<-
SQL
CREATE SCHEMA IF NOT EXISTS
#{
described_class
::
FOREIGN_SCHEMA
}
SQL
with_foreign_connection
.
execute
<<-
SQL
GRANT USAGE ON FOREIGN SERVER
#{
described_class
::
FOREIGN_SERVER
}
TO current_user
SQL
end
def
create_foreign_table
(
table_name
)
with_foreign_connection
.
execute
<<-
SQL
CREATE FOREIGN TABLE IF NOT EXISTS
#{
described_class
::
FOREIGN_SCHEMA
}
.
#{
table_name
}
(
id int
) SERVER
#{
described_class
::
FOREIGN_SERVER
}
SQL
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment