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
74d906ea
Commit
74d906ea
authored
Aug 16, 2018
by
Michael Kozono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Log repo update event on keep around
parent
575bfa8a
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
105 additions
and
18 deletions
+105
-18
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+1
-2
app/models/diff_note.rb
app/models/diff_note.rb
+10
-6
app/models/merge_request_diff.rb
app/models/merge_request_diff.rb
+1
-3
app/models/repository.rb
app/models/repository.rb
+14
-7
ee/app/models/ee/repository.rb
ee/app/models/ee/repository.rb
+15
-0
ee/changelogs/unreleased/mk-geo-replicate-keep-around-refs.yml
...angelogs/unreleased/mk-geo-replicate-keep-around-refs.yml
+5
-0
ee/spec/models/repository_spec.rb
ee/spec/models/repository_spec.rb
+41
-0
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+18
-0
No files found.
app/models/ci/pipeline.rb
View file @
74d906ea
...
...
@@ -666,8 +666,7 @@ module Ci
def
keep_around_commits
return
unless
project
project
.
repository
.
keep_around
(
self
.
sha
)
project
.
repository
.
keep_around
(
self
.
before_sha
)
project
.
repository
.
keep_around
(
self
.
sha
,
self
.
before_sha
)
end
def
valid_source
...
...
app/models/diff_note.rb
View file @
74d906ea
...
...
@@ -191,14 +191,18 @@ class DiffNote < Note
end
def
keep_around_commits
project
.
repository
.
keep_around
(
self
.
original_position
.
base_sha
)
project
.
repository
.
keep_around
(
self
.
original_position
.
start_sha
)
project
.
repository
.
keep_around
(
self
.
original_position
.
head_sha
)
shas
=
[
self
.
original_position
.
base_sha
,
self
.
original_position
.
start_sha
,
self
.
original_position
.
head_sha
]
if
self
.
position
!=
self
.
original_position
project
.
repository
.
keep_around
(
self
.
position
.
base_sha
)
project
.
repository
.
keep_around
(
self
.
position
.
start_sha
)
project
.
repository
.
keep_around
(
self
.
position
.
head_sha
)
shas
<<
self
.
position
.
base_sha
shas
<<
self
.
position
.
start_sha
shas
<<
self
.
position
.
head_sha
end
project
.
repository
.
keep_around
(
*
shas
)
end
end
app/models/merge_request_diff.rb
View file @
74d906ea
...
...
@@ -314,9 +314,7 @@ class MergeRequestDiff < ActiveRecord::Base
def
keep_around_commits
[
repository
,
merge_request
.
source_project
.
repository
].
uniq
.
each
do
|
repo
|
repo
.
keep_around
(
start_commit_sha
)
repo
.
keep_around
(
head_commit_sha
)
repo
.
keep_around
(
base_commit_sha
)
repo
.
keep_around
(
start_commit_sha
,
head_commit_sha
,
base_commit_sha
)
end
end
end
app/models/repository.rb
View file @
74d906ea
...
...
@@ -252,15 +252,22 @@ class Repository
# Git GC will delete commits from the repository that are no longer in any
# branches or tags, but we want to keep some of these commits around, for
# example if they have comments or CI builds.
def
keep_around
(
sha
)
return
unless
sha
.
present?
&&
commit_by
(
oid:
sha
)
#
# For Geo's sake, pass in multiple shas rather than calling it multiple times,
# to avoid unnecessary syncing.
def
keep_around
(
*
shas
)
shas
.
each
do
|
sha
|
begin
next
unless
sha
.
present?
&&
commit_by
(
oid:
sha
)
return
if
kept_around?
(
sha
)
next
if
kept_around?
(
sha
)
# This will still fail if the file is corrupted (e.g. 0 bytes)
raw_repository
.
write_ref
(
keep_around_ref_name
(
sha
),
sha
,
shell:
false
)
rescue
Gitlab
::
Git
::
CommandError
=>
ex
Rails
.
logger
.
error
"Unable to create keep-around reference for repository
#{
disk_path
}
:
#{
ex
}
"
# This will still fail if the file is corrupted (e.g. 0 bytes)
raw_repository
.
write_ref
(
keep_around_ref_name
(
sha
),
sha
,
shell:
false
)
rescue
Gitlab
::
Git
::
CommandError
=>
ex
Rails
.
logger
.
error
"Unable to create keep-around reference for repository
#{
disk_path
}
:
#{
ex
}
"
end
end
end
def
kept_around?
(
sha
)
...
...
ee/app/models/ee/repository.rb
View file @
74d906ea
...
...
@@ -5,6 +5,7 @@ module EE
# and be prepended in the `Repository` model
module
Repository
extend
ActiveSupport
::
Concern
extend
::
Gitlab
::
Utils
::
Override
MIRROR_REMOTE
=
"upstream"
.
freeze
...
...
@@ -69,5 +70,19 @@ module EE
false
end
end
override
:keep_around
def
keep_around
(
*
shas
)
super
ensure
log_geo_updated_event
end
def
log_geo_updated_event
return
unless
::
Gitlab
::
Geo
.
primary?
source
=
is_wiki
?
::
Geo
::
RepositoryUpdatedEvent
::
WIKI
:
::
Geo
::
RepositoryUpdatedEvent
::
REPOSITORY
::
Geo
::
RepositoryUpdatedService
.
new
(
self
.
project
,
source:
source
).
execute
end
end
end
ee/changelogs/unreleased/mk-geo-replicate-keep-around-refs.yml
0 → 100644
View file @
74d906ea
---
title
:
'
Geo:
Replicate
keep
around
refs'
merge_request
:
6922
author
:
type
:
fixed
ee/spec/models/repository_spec.rb
View file @
74d906ea
...
...
@@ -2,6 +2,7 @@ require 'spec_helper'
describe
Repository
do
include
RepoHelpers
include
::
EE
::
GeoHelpers
TestBlob
=
Struct
.
new
(
:path
)
let
(
:project
)
{
create
(
:project
,
:repository
)
}
...
...
@@ -113,4 +114,44 @@ describe Repository do
expect
(
repository
.
upstream_branches
.
first
.
name
).
to
eq
(
'upstream_branch'
)
end
end
describe
'#keep_around'
do
set
(
:primary_node
)
{
create
(
:geo_node
,
:primary
)
}
set
(
:secondary_node
)
{
create
(
:geo_node
)
}
let
(
:sha
)
{
sample_commit
.
id
}
context
'on a Geo primary'
do
before
do
stub_current_geo_node
(
primary_node
)
end
context
'when a single SHA is passed'
do
it
'creates a RepositoryUpdatedEvent'
do
expect
do
repository
.
keep_around
(
sha
)
end
.
to
change
{
::
Geo
::
RepositoryUpdatedEvent
.
count
}.
by
(
1
)
end
end
context
'when multiple SHAs are passed'
do
it
'creates exactly one RepositoryUpdatedEvent'
do
expect
do
repository
.
keep_around
(
sha
,
sample_big_commit
.
id
)
end
.
to
change
{
::
Geo
::
RepositoryUpdatedEvent
.
count
}.
by
(
1
)
end
end
end
context
'on a Geo secondary'
do
before
do
stub_current_geo_node
(
secondary_node
)
end
it
'does not create a RepositoryUpdatedEvent'
do
expect
do
repository
.
keep_around
(
sha
)
end
.
not_to
change
{
::
Geo
::
RepositoryUpdatedEvent
.
count
}
end
end
end
end
spec/models/repository_spec.rb
View file @
74d906ea
...
...
@@ -2005,6 +2005,24 @@ describe Repository do
File
.
delete
(
path
)
end
context
'for multiple SHAs'
do
it
'skips non-existent SHAs'
do
repository
.
keep_around
(
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
,
sample_commit
.
id
)
expect
(
repository
.
kept_around?
(
sample_commit
.
id
)).
to
be_truthy
end
it
'skips already-kept-around SHAs'
do
repository
.
keep_around
(
sample_commit
.
id
)
expect
(
repository
.
raw_repository
).
to
receive
(
:write_ref
).
exactly
(
1
).
and_call_original
repository
.
keep_around
(
sample_commit
.
id
,
another_sample_commit
.
id
)
expect
(
repository
.
kept_around?
(
another_sample_commit
.
id
)).
to
be_truthy
end
end
end
describe
'#update_ref'
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