BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
b1907694
Commit
b1907694
authored
Oct 27, 2017
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved renaming operations to storage layer abstraction
When project storage_version is `2` means attachments are using hashed storage.
parent
dfd6c3f8
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
76 additions
and
13 deletions
+76
-13
project.rb
app/models/project.rb
+5
-9
hashed_project.rb
app/models/storage/hashed_project.rb
+13
-0
legacy_project.rb
app/models/storage/legacy_project.rb
+7
-0
project_spec.rb
spec/models/project_spec.rb
+51
-4
No files found.
app/models/project.rb
View file @
b1907694
...
@@ -26,7 +26,10 @@ class Project < ActiveRecord::Base
...
@@ -26,7 +26,10 @@ class Project < ActiveRecord::Base
NUMBER_OF_PERMITTED_BOARDS
=
1
NUMBER_OF_PERMITTED_BOARDS
=
1
UNKNOWN_IMPORT_URL
=
'http://unknown.git'
.
freeze
UNKNOWN_IMPORT_URL
=
'http://unknown.git'
.
freeze
LATEST_STORAGE_VERSION
=
1
# Hashed Storage versions handle rolling out new storage to project and dependents models
# 1: repository
# 2: attachments
LATEST_STORAGE_VERSION
=
2
cache_markdown_field
:description
,
pipeline: :description
cache_markdown_field
:description
,
pipeline: :description
...
@@ -1384,7 +1387,7 @@ class Project < ActiveRecord::Base
...
@@ -1384,7 +1387,7 @@ class Project < ActiveRecord::Base
if
storage
.
rename_repo
if
storage
.
rename_repo
Gitlab
::
AppLogger
.
info
"Project was renamed:
#{
full_path_was
}
->
#{
new_full_path
}
"
Gitlab
::
AppLogger
.
info
"Project was renamed:
#{
full_path_was
}
->
#{
new_full_path
}
"
rename_repo_notify!
rename_repo_notify!
after_rename_repo
storage
.
after_rename_repo
else
else
Rails
.
logger
.
error
"Repository could not be renamed:
#{
full_path_was
}
->
#{
new_full_path
}
"
Rails
.
logger
.
error
"Repository could not be renamed:
#{
full_path_was
}
->
#{
new_full_path
}
"
...
@@ -1404,13 +1407,6 @@ class Project < ActiveRecord::Base
...
@@ -1404,13 +1407,6 @@ class Project < ActiveRecord::Base
reload_repository!
reload_repository!
end
end
def
after_rename_repo
path_before_change
=
previous_changes
[
'path'
].
first
Gitlab
::
UploadsTransfer
.
new
.
rename_project
(
path_before_change
,
self
.
path
,
namespace
.
full_path
)
Gitlab
::
PagesTransfer
.
new
.
rename_project
(
path_before_change
,
self
.
path
,
namespace
.
full_path
)
end
def
running_or_pending_build_count
(
force:
false
)
def
running_or_pending_build_count
(
force:
false
)
Rails
.
cache
.
fetch
([
'projects'
,
id
,
'running_or_pending_build_count'
],
force:
force
)
do
Rails
.
cache
.
fetch
([
'projects'
,
id
,
'running_or_pending_build_count'
],
force:
force
)
do
builds
.
running_or_pending
.
count
(
:all
)
builds
.
running_or_pending
.
count
(
:all
)
...
...
app/models/storage/hashed_project.rb
View file @
b1907694
...
@@ -32,6 +32,19 @@ module Storage
...
@@ -32,6 +32,19 @@ module Storage
true
true
end
end
def
after_rename_repo
path_before_change
=
project
.
previous_changes
[
'path'
].
first
# We need to check if project had been rolled out to move resource to hashed storage or not and decide
# if we need execute any take action or no-op.
unless
project
.
storage_version
>=
2
Gitlab
::
UploadsTransfer
.
new
.
rename_project
(
path_before_change
,
project
.
path
,
project
.
namespace
.
full_path
)
end
Gitlab
::
PagesTransfer
.
new
.
rename_project
(
path_before_change
,
project
.
path
,
project
.
namespace
.
full_path
)
end
private
private
# Generates the hash for the project path and name on disk
# Generates the hash for the project path and name on disk
...
...
app/models/storage/legacy_project.rb
View file @
b1907694
...
@@ -47,5 +47,12 @@ module Storage
...
@@ -47,5 +47,12 @@ module Storage
false
false
end
end
def
after_rename_repo
path_before_change
=
project
.
previous_changes
[
'path'
].
first
Gitlab
::
UploadsTransfer
.
new
.
rename_project
(
path_before_change
,
project
.
path
,
project
.
namespace
.
full_path
)
Gitlab
::
PagesTransfer
.
new
.
rename_project
(
path_before_change
,
project
.
path
,
project
.
namespace
.
full_path
)
end
end
end
end
end
spec/models/project_spec.rb
View file @
b1907694
...
@@ -2452,6 +2452,7 @@ describe Project do
...
@@ -2452,6 +2452,7 @@ describe Project do
context
'legacy storage'
do
context
'legacy storage'
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:gitlab_shell
)
{
Gitlab
::
Shell
.
new
}
let
(
:gitlab_shell
)
{
Gitlab
::
Shell
.
new
}
let
(
:project_storage
)
{
project
.
send
(
:storage
)
}
before
do
before
do
allow
(
project
).
to
receive
(
:gitlab_shell
).
and_return
(
gitlab_shell
)
allow
(
project
).
to
receive
(
:gitlab_shell
).
and_return
(
gitlab_shell
)
...
@@ -2546,6 +2547,30 @@ describe Project do
...
@@ -2546,6 +2547,30 @@ describe Project do
it
{
expect
{
subject
}.
to
raise_error
(
StandardError
)
}
it
{
expect
{
subject
}.
to
raise_error
(
StandardError
)
}
end
end
context
'gitlab pages'
do
before
do
expect
(
project_storage
).
to
receive
(
:rename_repo
)
{
true
}
end
it
'moves pages folder to new location'
do
expect_any_instance_of
(
Gitlab
::
PagesTransfer
).
to
receive
(
:rename_project
)
project
.
rename_repo
end
end
context
'attachments'
do
before
do
expect
(
project_storage
).
to
receive
(
:rename_repo
)
{
true
}
end
it
'moves uploads folder to new location'
do
expect_any_instance_of
(
Gitlab
::
UploadsTransfer
).
to
receive
(
:rename_project
)
project
.
rename_repo
end
end
end
end
describe
'#pages_path'
do
describe
'#pages_path'
do
...
@@ -2649,10 +2674,6 @@ describe Project do
...
@@ -2649,10 +2674,6 @@ describe Project do
.
to
receive
(
:execute_hooks_for
)
.
to
receive
(
:execute_hooks_for
)
.
with
(
project
,
:rename
)
.
with
(
project
,
:rename
)
expect_any_instance_of
(
Gitlab
::
UploadsTransfer
)
.
to
receive
(
:rename_project
)
.
with
(
'foo'
,
project
.
path
,
project
.
namespace
.
full_path
)
expect
(
project
).
to
receive
(
:expire_caches_before_rename
)
expect
(
project
).
to
receive
(
:expire_caches_before_rename
)
expect
(
project
).
to
receive
(
:expires_full_path_cache
)
expect
(
project
).
to
receive
(
:expires_full_path_cache
)
...
@@ -2673,6 +2694,32 @@ describe Project do
...
@@ -2673,6 +2694,32 @@ describe Project do
it
{
expect
{
subject
}.
to
raise_error
(
StandardError
)
}
it
{
expect
{
subject
}.
to
raise_error
(
StandardError
)
}
end
end
context
'gitlab pages'
do
it
'moves pages folder to new location'
do
expect_any_instance_of
(
Gitlab
::
PagesTransfer
).
to
receive
(
:rename_project
)
project
.
rename_repo
end
end
context
'attachments'
do
it
'keeps uploads folder location unchanged'
do
expect_any_instance_of
(
Gitlab
::
UploadsTransfer
).
not_to
receive
(
:rename_project
)
project
.
rename_repo
end
context
'when not rolled out'
do
let
(
:project
)
{
create
(
:project
,
:repository
,
storage_version:
1
)
}
it
'moves pages folder to new location'
do
expect_any_instance_of
(
Gitlab
::
UploadsTransfer
).
to
receive
(
:rename_project
)
project
.
rename_repo
end
end
end
end
end
describe
'#pages_path'
do
describe
'#pages_path'
do
...
...
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