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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
f35ff1ea
Commit
f35ff1ea
authored
Nov 27, 2018
by
Toon Claes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure all Routables have a parent
Or otherwise do not try to write repo config.
parent
de0cc8e4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
10 deletions
+23
-10
lib/gitlab/background_migration/backfill_project_fullpath_in_repo_config.rb
...und_migration/backfill_project_fullpath_in_repo_config.rb
+17
-10
spec/lib/gitlab/background_migration/backfill_project_fullpath_in_repo_config_spec.rb
...igration/backfill_project_fullpath_in_repo_config_spec.rb
+6
-0
No files found.
lib/gitlab/background_migration/backfill_project_fullpath_in_repo_config.rb
View file @
f35ff1ea
...
@@ -7,6 +7,8 @@ module Gitlab
...
@@ -7,6 +7,8 @@ module Gitlab
# Storing the full project path in the git config allows admins to
# Storing the full project path in the git config allows admins to
# easily identify a project when it is using hashed storage.
# easily identify a project when it is using hashed storage.
module
BackfillProjectFullpathInRepoConfig
module
BackfillProjectFullpathInRepoConfig
OrphanedNamespaceError
=
Class
.
new
(
StandardError
)
module
Storage
module
Storage
# Class that returns the disk path for a project using hashed storage
# Class that returns the disk path for a project using hashed storage
class
HashedProject
class
HashedProject
...
@@ -51,11 +53,15 @@ module Gitlab
...
@@ -51,11 +53,15 @@ module Gitlab
end
end
def
build_full_path
def
build_full_path
if
parent
&&
path
return
path
unless
has_parent?
raise
OrphanedNamespaceError
if
parent
.
nil?
parent
.
full_path
+
'/'
+
path
parent
.
full_path
+
'/'
+
path
else
path
end
end
def
has_parent?
read_attribute
(
association
(
:parent
).
reflection
.
foreign_key
)
end
end
end
end
...
@@ -81,7 +87,9 @@ module Gitlab
...
@@ -81,7 +87,9 @@ module Gitlab
include
Routable
include
Routable
belongs_to
:parent
,
class_name:
"Namespace"
belongs_to
:parent
,
class_name:
'Namespace'
,
inverse_of:
'namespaces'
has_many
:projects
,
inverse_of: :parent
has_many
:namespaces
,
inverse_of: :parent
end
end
# Project is where the repository (etc.) is stored
# Project is where the repository (etc.) is stored
...
@@ -93,9 +101,8 @@ module Gitlab
...
@@ -93,9 +101,8 @@ module Gitlab
FULLPATH_CONFIG_KEY
=
'gitlab.fullpath'
FULLPATH_CONFIG_KEY
=
'gitlab.fullpath'
belongs_to
:
namespace
belongs_to
:
parent
,
class_name:
'Namespace'
,
foreign_key: :namespace_id
,
inverse_of:
'projects'
delegate
:disk_path
,
to: :storage
delegate
:disk_path
,
to: :storage
alias_method
:parent
,
:namespace
def
add_fullpath_config
def
add_fullpath_config
entries
=
{
FULLPATH_CONFIG_KEY
=>
full_path
}
entries
=
{
FULLPATH_CONFIG_KEY
=>
full_path
}
...
@@ -150,14 +157,14 @@ module Gitlab
...
@@ -150,14 +157,14 @@ module Gitlab
end
end
def
perform
(
start_id
,
end_id
)
def
perform
(
start_id
,
end_id
)
Project
.
where
(
id:
start_id
..
end_id
).
each
do
|
project
|
Project
.
includes
(
:parent
).
where
(
id:
start_id
..
end_id
).
each
do
|
project
|
safe_perform_one
(
project
)
safe_perform_one
(
project
)
end
end
end
end
def
safe_perform_one
(
project
,
retry_count
=
0
)
def
safe_perform_one
(
project
,
retry_count
=
0
)
perform_one
(
project
)
perform_one
(
project
)
rescue
GRPC
::
NotFound
,
GRPC
::
InvalidArgument
rescue
GRPC
::
NotFound
,
GRPC
::
InvalidArgument
,
OrphanedNamespaceError
nil
nil
rescue
GRPC
::
BadStatus
rescue
GRPC
::
BadStatus
schedule_retry
(
project
,
retry_count
+
1
)
if
retry_count
<
MAX_RETRIES
schedule_retry
(
project
,
retry_count
+
1
)
if
retry_count
<
MAX_RETRIES
...
...
spec/lib/gitlab/background_migration/backfill_project_fullpath_in_repo_config_spec.rb
View file @
f35ff1ea
...
@@ -34,6 +34,12 @@ describe Gitlab::BackgroundMigration::BackfillProjectFullpathInRepoConfig, :migr
...
@@ -34,6 +34,12 @@ describe Gitlab::BackgroundMigration::BackfillProjectFullpathInRepoConfig, :migr
it
'returns path containing all parent namespaces'
do
it
'returns path containing all parent namespaces'
do
expect
(
project
.
full_path
).
to
eq
(
'foo/bar/baz'
)
expect
(
project
.
full_path
).
to
eq
(
'foo/bar/baz'
)
end
end
it
'raises OrphanedNamespaceError when any parent namespace does not exist'
do
subgroup
.
update_attribute
(
:parent_id
,
namespaces
.
maximum
(
:id
).
succ
)
expect
{
project
.
full_path
}.
to
raise_error
(
Gitlab
::
BackgroundMigration
::
BackfillProjectFullpathInRepoConfig
::
OrphanedNamespaceError
)
end
end
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