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
068a53dd
Commit
068a53dd
authored
Dec 05, 2017
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add FDW schema refresh to Geo rake task and refactor some code
parent
477dc9fb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
9 deletions
+58
-9
lib/gitlab/geo/geo_tasks.rb
lib/gitlab/geo/geo_tasks.rb
+43
-0
lib/tasks/geo.rake
lib/tasks/geo.rake
+15
-9
No files found.
lib/gitlab/geo/geo_tasks.rb
0 → 100644
View file @
068a53dd
module
Gitlab
module
Geo
module
GeoTasks
extend
self
def
set_primary_geo_node
node
=
GeoNode
.
new
(
primary:
true
,
url:
GeoNode
.
current_node_url
)
$stdout
.
puts
"Saving primary GeoNode with URL
#{
node
.
url
}
"
.
color
(
:green
)
node
.
save
$stdout
.
puts
"Error saving GeoNode:
\n
#{
node
.
errors
.
full_messages
.
join
(
"
\n
"
)
}
"
.
color
(
:red
)
unless
node
.
persisted?
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
end
def
foreign_server_configured?
sql
=
<<~
SQL
SELECT count(1)
FROM pg_foreign_server
WHERE srvname = '
#{
Gitlab
::
Geo
::
FDW_SCHEMA
}
';
SQL
Gitlab
::
Geo
::
DatabaseTasks
.
with_geo_db
do
ActiveRecord
::
Base
.
connection
.
execute
(
sql
).
first
.
fetch
(
'count'
).
to_i
==
1
end
end
end
end
end
lib/tasks/geo.rake
View file @
068a53dd
require
'gitlab/geo'
require
'gitlab/geo/database_tasks'
require
'gitlab/geo/geo_tasks'
task
spec:
[
'geo:db:test:prepare'
]
namespace
:geo
do
GEO_LICENSE_ERROR_TEXT
=
'GitLab Geo is not supported with this license. Please contact sales@gitlab.com.'
.
freeze
namespace
:db
do
|
ns
|
desc
'Drops the Geo tracking database from config/database_geo.yml for the current RAILS_ENV.'
task
:drop
do
...
...
@@ -145,15 +148,15 @@ namespace :geo do
desc
'Make this node the Geo primary'
task
set_primary_node: :environment
do
abort
'GitLab Geo is not supported with this license. Please contact sales@gitlab.com.'
unless
Gitlab
::
Geo
.
license_allows?
abort
GEO_LICENSE_ERROR_TEXT
unless
Gitlab
::
Geo
.
license_allows?
abort
'GitLab Geo primary node already present'
if
Gitlab
::
Geo
.
primary_node
.
present?
set_primary_geo_node
Gitlab
::
Geo
::
GeoTasks
.
set_primary_geo_node
end
desc
'Make this secondary node the primary'
task
set_secondary_as_primary: :environment
do
abort
'GitLab Geo is not supported with this license. Please contact sales@gitlab.com.'
unless
Gitlab
::
Geo
.
license_allows?
abort
GEO_LICENSE_ERROR_TEXT
unless
Gitlab
::
Geo
.
license_allows?
ActiveRecord
::
Base
.
transaction
do
primary_node
=
Gitlab
::
Geo
.
primary_node
...
...
@@ -174,11 +177,14 @@ namespace :geo do
end
end
def
set_primary_geo_node
node
=
GeoNode
.
new
(
primary:
true
,
url:
GeoNode
.
current_node_url
)
puts
"Saving primary GeoNode with URL
#{
node
.
url
}
"
.
color
(
:green
)
node
.
save
puts
"Error saving GeoNode:
\n
#{
node
.
errors
.
full_messages
.
join
(
"
\n
"
)
}
"
.
color
(
:red
)
unless
node
.
persisted?
desc
'Refresh Foreign Tables definition in Geo Secondary node'
task
:refresh_foreign_tables
do
if
Gitlab
::
Geo
::
GeoTasks
.
foreign_server_configured?
print
"
\n
Refreshing foreign tables for FDW:
#{
Gitlab
::
Geo
::
FDW_SCHEMA
}
... "
Gitlab
::
Geo
::
GeoTasks
.
refresh_foreign_tables!
puts
'Done!'
else
puts
"Warning: Cannot refresh foreign tables, there is no foreign server configured."
end
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