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
9a64ac02
Commit
9a64ac02
authored
Oct 16, 2017
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use separate FDW classes to wrap ActiveRecord models
parent
1b0af3c3
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
37 additions
and
61 deletions
+37
-61
app/models/geo/base_fdw.rb
app/models/geo/base_fdw.rb
+13
-0
app/models/geo/fdw/lfs_object.rb
app/models/geo/fdw/lfs_object.rb
+8
-0
app/models/geo/fdw/upload.rb
app/models/geo/fdw/upload.rb
+7
-0
app/models/lfs_object.rb
app/models/lfs_object.rb
+0
-3
app/models/upload.rb
app/models/upload.rb
+0
-3
app/workers/geo/file_download_dispatch_worker.rb
app/workers/geo/file_download_dispatch_worker.rb
+4
-4
ee/app/models/concerns/ee/geo/foreign_data_wrapped.rb
ee/app/models/concerns/ee/geo/foreign_data_wrapped.rb
+0
-21
ee/app/models/ee/lfs_object.rb
ee/app/models/ee/lfs_object.rb
+0
-13
ee/app/models/ee/project.rb
ee/app/models/ee/project.rb
+0
-1
ee/app/models/ee/upload.rb
ee/app/models/ee/upload.rb
+0
-13
lib/gitlab/geo.rb
lib/gitlab/geo.rb
+5
-3
No files found.
app/models/geo/base_fdw.rb
0 → 100644
View file @
9a64ac02
class
Geo::BaseFdw
<
ActiveRecord
::
Base
self
.
abstract_class
=
true
if
Gitlab
::
Geo
.
geo_database_configured?
establish_connection
Rails
.
configuration
.
geo_database
end
def
self
.
connection
raise
'Geo secondary database is not configured'
unless
Gitlab
::
Geo
.
geo_database_configured?
super
end
end
app/models/geo/fdw/lfs_object.rb
0 → 100644
View file @
9a64ac02
module
Geo
module
Fdw
class
LfsObject
<
::
Geo
::
BaseFdw
self
.
table_name
=
Gitlab
::
Geo
.
fdw_table
(
'lfs_objects'
)
end
end
end
app/models/geo/fdw/upload.rb
0 → 100644
View file @
9a64ac02
module
Geo
module
Fdw
class
Upload
<
::
Geo
::
BaseFdw
self
.
table_name
=
Gitlab
::
Geo
.
fdw_table
(
'uploads'
)
end
end
end
app/models/lfs_object.rb
View file @
9a64ac02
class
LfsObject
<
ActiveRecord
::
Base
# EE specific modules
prepend
EE
::
LfsObject
has_many
:lfs_objects_projects
,
dependent: :destroy
# rubocop:disable Cop/ActiveRecordDependent
has_many
:projects
,
through: :lfs_objects_projects
...
...
app/models/upload.rb
View file @
9a64ac02
class
Upload
<
ActiveRecord
::
Base
# EE specific modules
prepend
EE
::
Upload
# Upper limit for foreground checksum processing
CHECKSUM_THRESHOLD
=
100
.
megabytes
...
...
app/workers/geo/file_download_dispatch_worker.rb
View file @
9a64ac02
...
...
@@ -54,10 +54,10 @@ module Geo
end
def
fdw_find_lfs_object_ids
fdw_table
=
"
#{
Gitlab
::
Geo
.
fdw_schema
}
.lfs_objects"
fdw_table
=
Geo
::
Fdw
::
LfsObject
.
table_name
# Filter out objects in object storage (this is done in GeoNode#lfs_objects)
LfsObject
.
fdw
.
joins
(
"LEFT OUTER JOIN file_registry ON file_registry.file_id =
#{
fdw_table
}
.id AND file_registry.file_type = 'lfs'"
)
Geo
::
Fdw
::
LfsObject
.
joins
(
"LEFT OUTER JOIN file_registry ON file_registry.file_id =
#{
fdw_table
}
.id AND file_registry.file_type = 'lfs'"
)
.
where
(
"
#{
fdw_table
}
.file_store IS NULL OR
#{
fdw_table
}
.file_store =
#{
LfsObjectUploader
::
LOCAL_STORE
}
"
)
.
where
(
'file_registry.file_id IS NULL'
)
.
order
(
created_at: :desc
)
...
...
@@ -67,10 +67,10 @@ module Geo
end
def
fdw_find_upload_object_ids
fdw_table
=
"
#{
Gitlab
::
Geo
.
fdw_schema
}
.uploads"
fdw_table
=
Geo
::
Fdw
::
Upload
.
table_name
obj_types
=
Geo
::
FileService
::
DEFAULT_OBJECT_TYPES
.
map
{
|
val
|
"'
#{
val
}
'"
}.
join
(
','
)
Upload
.
fdw
.
joins
(
"LEFT OUTER JOIN file_registry ON file_registry.file_id =
#{
fdw_table
}
.id AND file_registry.file_type IN (
#{
obj_types
}
)"
)
Geo
::
Fdw
::
Upload
.
joins
(
"LEFT OUTER JOIN file_registry ON file_registry.file_id =
#{
fdw_table
}
.id AND file_registry.file_type IN (
#{
obj_types
}
)"
)
.
where
(
'file_registry.file_id IS NULL'
)
.
order
(
created_at: :desc
)
.
limit
(
db_retrieve_batch_size
)
...
...
ee/app/models/concerns/ee/geo/foreign_data_wrapped.rb
deleted
100644 → 0
View file @
1b0af3c3
module
EE
module
Geo
module
ForeignDataWrapped
extend
ActiveSupport
::
Concern
class_methods
do
def
fdw
instance
=
self
.
clone
instance
.
table_name
=
"
#{
::
Gitlab
::
Geo
.
fdw_schema
}
.
#{
self
.
table_name
}
"
def
instance
.
name
table_name
end
instance
.
establish_connection
Rails
.
configuration
.
geo_database
instance
end
end
end
end
end
ee/app/models/ee/lfs_object.rb
deleted
100644 → 0
View file @
1b0af3c3
module
EE
# LfsObject EE mixin
#
# This module is intended to encapsulate EE-specific model logic
# and be prepended in the `LfsObject` model
module
LfsObject
extend
ActiveSupport
::
Concern
prepended
do
prepend
::
EE
::
Geo
::
ForeignDataWrapped
end
end
end
ee/app/models/ee/project.rb
View file @
9a64ac02
...
...
@@ -10,7 +10,6 @@ module EE
include
Elastic
::
ProjectsSearch
prepend
GeoAwareAvatar
prepend
ImportStatusStateMachine
prepend
::
EE
::
Geo
::
ForeignDataWrapped
before_validation
:mark_remote_mirrors_for_removal
...
...
ee/app/models/ee/upload.rb
deleted
100644 → 0
View file @
1b0af3c3
module
EE
# Upload EE mixin
#
# This module is intended to encapsulate EE-specific model logic
# and be prepended in the `Upload` model
module
Upload
extend
ActiveSupport
::
Concern
prepended
do
prepend
::
EE
::
Geo
::
ForeignDataWrapped
end
end
end
lib/gitlab/geo.rb
View file @
9a64ac02
...
...
@@ -14,6 +14,8 @@ module Gitlab
SECONDARY_JOBS
=
%i(repository_sync_job file_download_job)
.
freeze
FDW_SCHEMA
=
'gitlab_secondary'
.
freeze
def
self
.
current_node
self
.
cache_value
(
:geo_node_current
)
do
GeoNode
.
find_by
(
host:
Gitlab
.
config
.
gitlab
.
host
,
...
...
@@ -77,13 +79,13 @@ module Gitlab
def
self
.
fdw?
self
.
cache_value
(
:geo_fdw?
)
do
::
Geo
::
BaseRegistry
.
connection
.
execute
(
"SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = '
#{
self
.
fdw_schema
}
' AND table_type = 'FOREIGN TABLE'"
"SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = '
#{
FDW_SCHEMA
}
' AND table_type = 'FOREIGN TABLE'"
).
first
.
fetch
(
'count'
).
to_i
.
positive?
end
end
def
self
.
fdw_
schema
'gitlab_secondary'
.
freeze
def
self
.
fdw_
table
(
table_name
)
FDW_SCHEMA
+
".
#{
table_name
}
"
end
def
self
.
repository_sync_job
...
...
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