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
35de9283
Commit
35de9283
authored
Oct 17, 2017
by
Valery Sizov
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'ce-to-ee-2017-10-13' of gitlab.com:gitlab-org/gitlab-ee into ce_upstream
parents
34d89620
3a2aa432
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
215 additions
and
181 deletions
+215
-181
app/models/geo/project_registry.rb
app/models/geo/project_registry.rb
+18
-8
app/services/geo/repository_created_event_store.rb
app/services/geo/repository_created_event_store.rb
+1
-1
app/workers/geo/project_sync_worker.rb
app/workers/geo/project_sync_worker.rb
+7
-21
changelogs/unreleased-ee/3569-geo-backfill-unconditional-wiki.yml
...gs/unreleased-ee/3569-geo-backfill-unconditional-wiki.yml
+5
-0
lib/gitlab/geo/log_cursor/daemon.rb
lib/gitlab/geo/log_cursor/daemon.rb
+5
-3
spec/factories/geo/event_log.rb
spec/factories/geo/event_log.rb
+1
-1
spec/lib/gitlab/geo/log_cursor/daemon_spec.rb
spec/lib/gitlab/geo/log_cursor/daemon_spec.rb
+80
-74
spec/models/geo/project_registry_spec.rb
spec/models/geo/project_registry_spec.rb
+66
-67
spec/services/geo/repository_created_event_store_spec.rb
spec/services/geo/repository_created_event_store_spec.rb
+15
-6
spec/workers/geo/project_sync_worker_spec.rb
spec/workers/geo/project_sync_worker_spec.rb
+17
-0
No files found.
app/models/geo/project_registry.rb
View file @
35de9283
...
@@ -20,19 +20,29 @@ class Geo::ProjectRegistry < Geo::BaseRegistry
...
@@ -20,19 +20,29 @@ class Geo::ProjectRegistry < Geo::BaseRegistry
.
where
(
resync_repository:
false
,
resync_wiki:
false
)
.
where
(
resync_repository:
false
,
resync_wiki:
false
)
end
end
def
re
sync_repository?
def
re
pository_sync_due?
(
scheduled_time
)
resync_repository
||
last_repository_successful_sync_at
.
nil?
never_synced_repository?
||
repository_sync_needed?
(
scheduled_time
)
end
end
def
resync_wiki?
def
wiki_sync_due?
(
scheduled_time
)
resync_wiki
||
last_wiki_successful_sync_at
.
nil?
project
.
wiki_enabled?
&&
(
never_synced_wiki?
||
wiki_sync_needed?
(
scheduled_time
))
end
end
def
repository_synced_since?
(
timestamp
)
private
last_repository_synced_at
&&
last_repository_synced_at
>
timestamp
def
never_synced_repository?
last_repository_successful_sync_at
.
nil?
end
def
never_synced_wiki?
last_wiki_successful_sync_at
.
nil?
end
def
repository_sync_needed?
(
timestamp
)
resync_repository?
&&
(
last_repository_synced_at
.
nil?
||
timestamp
>
last_repository_synced_at
)
end
end
def
wiki_sync
ed_since
?
(
timestamp
)
def
wiki_sync
_needed
?
(
timestamp
)
last_wiki_synced_at
&&
last_wiki_synced_at
>
timestamp
resync_wiki?
&&
(
last_wiki_synced_at
.
nil?
||
timestamp
>
last_wiki_synced_at
)
end
end
end
end
app/services/geo/repository_created_event_store.rb
View file @
35de9283
...
@@ -10,7 +10,7 @@ module Geo
...
@@ -10,7 +10,7 @@ module Geo
repository_storage_name:
project
.
repository
.
storage
,
repository_storage_name:
project
.
repository
.
storage
,
repository_storage_path:
project
.
repository_storage_path
,
repository_storage_path:
project
.
repository_storage_path
,
repo_path:
project
.
disk_path
,
repo_path:
project
.
disk_path
,
wiki_path:
"
#{
project
.
disk_path
}
.wiki"
,
wiki_path:
(
"
#{
project
.
disk_path
}
.wiki"
if
project
.
wiki_enabled?
)
,
project_name:
project
.
name
project_name:
project
.
name
)
)
end
end
...
...
app/workers/geo/project_sync_worker.rb
View file @
35de9283
...
@@ -11,30 +11,16 @@ module Geo
...
@@ -11,30 +11,16 @@ module Geo
end
end
def
perform
(
project_id
,
scheduled_time
)
def
perform
(
project_id
,
scheduled_time
)
project
=
Project
.
find
(
project_id
)
registry
=
Geo
::
ProjectRegistry
.
find_or_initialize_by
(
project_id:
project_id
)
registry
=
Geo
::
ProjectRegistry
.
find_or_initialize_by
(
project_id:
project_id
)
project
=
registry
.
project
Geo
::
RepositorySyncService
.
new
(
project
).
execute
if
sync_repository?
(
registry
,
scheduled_time
)
if
project
.
nil?
Geo
::
WikiSyncService
.
new
(
project
).
execute
if
sync_wiki?
(
registry
,
scheduled_time
)
Gitlab
::
Geo
::
Logger
.
error
(
class:
self
.
class
.
name
,
message:
"Couldn't find project, skipping syncing"
,
project_id:
project_id
)
rescue
ActiveRecord
::
RecordNotFound
=>
e
return
Gitlab
::
Geo
::
Logger
.
error
(
end
class:
self
.
class
.
name
,
message:
"Couldn't find project, skipping syncing"
,
project_id:
project_id
,
error:
e
)
end
private
def
sync_repository?
(
registry
,
scheduled_time
)
!
registry
.
repository_synced_since?
(
scheduled_time
)
&&
registry
.
resync_repository?
end
def
sync_wiki?
(
registry
,
scheduled_time
)
Geo
::
RepositorySyncService
.
new
(
project
).
execute
if
registry
.
repository_sync_due?
(
scheduled_time
)
!
registry
.
wiki_synced_since?
(
scheduled_time
)
&&
Geo
::
WikiSyncService
.
new
(
project
).
execute
if
registry
.
wiki_sync_due?
(
scheduled_time
)
registry
.
resync_wiki?
end
end
end
end
end
end
changelogs/unreleased-ee/3569-geo-backfill-unconditional-wiki.yml
0 → 100644
View file @
35de9283
---
title
:
'
Geo:
Don'
'
t
sync
disabled
project
wikis'
merge_request
:
3109
author
:
type
:
fixed
lib/gitlab/geo/log_cursor/daemon.rb
View file @
35de9283
...
@@ -19,9 +19,7 @@ module Gitlab
...
@@ -19,9 +19,7 @@ module Gitlab
full_scan!
if
options
[
:full_scan
]
full_scan!
if
options
[
:full_scan
]
until
exit
?
until
exit
?
Events
.
fetch_in_batches
do
|
batch
|
run_once!
handle_events
(
batch
)
end
return
if
exit
?
return
if
exit
?
...
@@ -30,6 +28,10 @@ module Gitlab
...
@@ -30,6 +28,10 @@ module Gitlab
end
end
end
end
def
run_once!
Events
.
fetch_in_batches
{
|
batch
|
handle_events
(
batch
)
}
end
# Execute routines to verify the required initial data is available
# Execute routines to verify the required initial data is available
# and mark non-replicated data as requiring replication.
# and mark non-replicated data as requiring replication.
def
full_scan!
def
full_scan!
...
...
spec/factories/geo/event_log.rb
View file @
35de9283
...
@@ -24,7 +24,7 @@ FactoryGirl.define do
...
@@ -24,7 +24,7 @@ FactoryGirl.define do
repository_storage_path
{
project
.
repository_storage_path
}
repository_storage_path
{
project
.
repository_storage_path
}
add_attribute
(
:repo_path
)
{
project
.
disk_path
}
add_attribute
(
:repo_path
)
{
project
.
disk_path
}
project_name
{
project
.
name
}
project_name
{
project
.
name
}
wiki_path
{
"{project.disk_path}.wiki"
}
wiki_path
{
"
#
{
project
.
disk_path
}
.wiki"
}
end
end
factory
:geo_repository_updated_event
,
class:
Geo
::
RepositoryUpdatedEvent
do
factory
:geo_repository_updated_event
,
class:
Geo
::
RepositoryUpdatedEvent
do
...
...
spec/lib/gitlab/geo/log_cursor/daemon_spec.rb
View file @
35de9283
This diff is collapsed.
Click to expand it.
spec/models/geo/project_registry_spec.rb
View file @
35de9283
require
'spec_helper'
require
'spec_helper'
describe
Geo
::
ProjectRegistry
do
describe
Geo
::
ProjectRegistry
do
subject
{
create
(
:geo_project_registry
)
}
using
RSpec
::
Parameterized
::
TableSyntax
set
(
:project
)
{
create
(
:project
)
}
set
(
:registry
)
{
create
(
:geo_project_registry
,
project_id:
project
.
id
)
}
subject
{
registry
}
describe
'relationships'
do
describe
'relationships'
do
it
{
is_expected
.
to
belong_to
(
:project
)
}
it
{
is_expected
.
to
belong_to
(
:project
)
}
...
@@ -33,85 +38,79 @@ describe Geo::ProjectRegistry do
...
@@ -33,85 +38,79 @@ describe Geo::ProjectRegistry do
end
end
end
end
describe
'#resync_repository?'
do
describe
'#repository_sync_due?'
do
it
'returns true when resync_repository is true'
do
where
(
:resync_repository
,
:last_successful_sync
,
:last_sync
,
:expected
)
do
subject
.
resync_repository
=
true
now
=
Time
.
now
past
=
now
-
1
.
year
expect
(
subject
.
resync_repository
).
to
be
true
future
=
now
+
1
.
year
end
true
|
nil
|
nil
|
true
it
'returns true when last_repository_successful_sync_at is nil'
do
true
|
now
|
nil
|
true
subject
.
last_repository_successful_sync_at
=
nil
false
|
nil
|
nil
|
true
false
|
now
|
nil
|
false
expect
(
subject
.
resync_repository
).
to
be
true
end
true
|
nil
|
past
|
true
true
|
now
|
past
|
true
it
'returns false when resync_repository is false and last_repository_successful_sync_at is present'
do
false
|
nil
|
past
|
true
subject
.
resync_repository
=
false
false
|
now
|
past
|
false
subject
.
last_repository_successful_sync_at
=
Time
.
now
true
|
nil
|
future
|
true
expect
(
subject
.
resync_repository
).
to
be
false
true
|
now
|
future
|
false
end
false
|
nil
|
future
|
true
end
false
|
now
|
future
|
false
describe
'#resync_wiki?'
do
it
'returns true when resync_wiki is true'
do
subject
.
resync_wiki
=
true
expect
(
subject
.
resync_wiki
).
to
be
true
end
end
it
'returns true when last_wiki_successful_sync_at is nil'
do
with_them
do
subject
.
last_wiki_successful_sync_at
=
nil
before
do
registry
.
update!
(
resync_repository:
resync_repository
,
last_repository_successful_sync_at:
last_successful_sync
,
last_repository_synced_at:
last_sync
)
end
expect
(
subject
.
resync_wiki
).
to
be
true
subject
{
registry
.
repository_sync_due?
(
Time
.
now
)
}
end
it
'returns false when resync_wiki is false and last_wiki_successful_sync_at is present'
do
subject
.
resync_wiki
=
false
subject
.
last_wiki_successful_sync_at
=
Time
.
now
expect
(
subject
.
resync_wiki
).
to
be
false
it
{
is_expected
.
to
eq
(
expected
)
}
end
end
end
end
describe
'#repository_synced_since?'
do
describe
'#wiki_sync_due?'
do
it
'returns false when last_repository_synced_at is nil'
do
where
(
:resync_wiki
,
:last_successful_sync
,
:last_sync
,
:expected
)
do
subject
.
last_repository_synced_at
=
nil
now
=
Time
.
now
past
=
now
-
1
.
year
expect
(
subject
.
repository_synced_since?
(
Time
.
now
)).
to
be_nil
future
=
now
+
1
.
year
true
|
nil
|
nil
|
true
true
|
now
|
nil
|
true
false
|
nil
|
nil
|
true
false
|
now
|
nil
|
false
true
|
nil
|
past
|
true
true
|
now
|
past
|
true
false
|
nil
|
past
|
true
false
|
now
|
past
|
false
true
|
nil
|
future
|
true
true
|
now
|
future
|
false
false
|
nil
|
future
|
true
false
|
now
|
future
|
false
end
end
it
'returns false when last_repository_synced_at before timestamp'
do
with_them
do
subject
.
last_repository_synced_at
=
Time
.
now
-
2
.
hours
before
do
registry
.
update!
(
resync_wiki:
resync_wiki
,
last_wiki_successful_sync_at:
last_successful_sync
,
last_wiki_synced_at:
last_sync
)
end
expect
(
subject
.
repository_synced_since?
(
Time
.
now
)).
to
be
false
subject
{
registry
.
wiki_sync_due?
(
Time
.
now
)
}
end
it
'returns true when last_repository_synced_at after timestamp'
do
context
'wiki enabled'
do
subject
.
last_repository_synced_at
=
Time
.
now
+
2
.
hours
it
{
is_expected
.
to
eq
(
expected
)
}
end
expect
(
subject
.
repository_synced_since?
(
Time
.
now
)).
to
be
true
end
end
describe
'#wiki_synced_since?'
do
it
'returns false when last_wiki_synced_at is nil'
do
subject
.
last_wiki_synced_at
=
nil
expect
(
subject
.
wiki_synced_since?
(
Time
.
now
)).
to
be_nil
end
it
'returns false when last_wiki_synced_at before timestamp'
do
subject
.
last_wiki_synced_at
=
Time
.
now
-
2
.
hours
expect
(
subject
.
wiki_synced_since?
(
Time
.
now
)).
to
be
false
end
it
'returns true when last_wiki_synced_at after timestamp'
do
context
'wiki disabled'
do
subject
.
last_wiki_synced_at
=
Time
.
now
+
2
.
hours
before
do
project
.
update!
(
wiki_enabled:
false
)
end
expect
(
subject
.
wiki_synced_since?
(
Time
.
now
)).
to
be
true
it
{
is_expected
.
to
be_falsy
}
end
end
end
end
end
end
end
spec/services/geo/repository_created_event_store_spec.rb
View file @
35de9283
require
'spec_helper'
require
'spec_helper'
describe
Geo
::
RepositoryCreatedEventStore
do
describe
Geo
::
RepositoryCreatedEventStore
do
l
et
(
:project
)
{
create
(
:project
)
}
s
et
(
:project
)
{
create
(
:project
)
}
subject
(
:
event
)
{
described_class
.
new
(
project
)
}
subject
(
:
create!
)
{
described_class
.
new
(
project
).
create
}
describe
'#create'
do
describe
'#create'
do
it
'does not create an event when not running on a primary node'
do
it
'does not create an event when not running on a primary node'
do
allow
(
Gitlab
::
Geo
).
to
receive
(
:primary?
)
{
false
}
allow
(
Gitlab
::
Geo
).
to
receive
(
:primary?
)
{
false
}
expect
{
event
.
create
}.
not_to
change
(
Geo
::
RepositoryCreatedEvent
,
:count
)
expect
{
create!
}.
not_to
change
(
Geo
::
RepositoryCreatedEvent
,
:count
)
end
end
context
'
when
running on a primary node'
do
context
'running on a primary node'
do
before
do
before
do
allow
(
Gitlab
::
Geo
).
to
receive
(
:primary?
)
{
true
}
allow
(
Gitlab
::
Geo
).
to
receive
(
:primary?
)
{
true
}
end
end
it
'creates a created event'
do
it
'creates a created event'
do
expect
{
event
.
create
}.
to
change
(
Geo
::
RepositoryCreatedEvent
,
:count
).
by
(
1
)
expect
{
create!
}.
to
change
(
Geo
::
RepositoryCreatedEvent
,
:count
).
by
(
1
)
end
end
it
'tracks information for the created project'
do
it
'tracks information for the created project'
do
event
.
create
create!
event
=
Geo
::
RepositoryCreatedEvent
.
last
event
=
Geo
::
RepositoryCreatedEvent
.
last
...
@@ -35,6 +35,15 @@ describe Geo::RepositoryCreatedEventStore do
...
@@ -35,6 +35,15 @@ describe Geo::RepositoryCreatedEventStore do
repository_storage_path:
project
.
repository_storage_path
repository_storage_path:
project
.
repository_storage_path
)
)
end
end
it
'does not set a wiki path if the wiki is disabled'
do
project
.
update!
(
wiki_enabled:
false
)
create!
event
=
Geo
::
RepositoryCreatedEvent
.
last
expect
(
event
.
wiki_path
).
to
be_nil
end
end
end
end
end
end
end
spec/workers/geo/project_sync_worker_spec.rb
View file @
35de9283
...
@@ -102,6 +102,23 @@ RSpec.describe Geo::ProjectSyncWorker do
...
@@ -102,6 +102,23 @@ RSpec.describe Geo::ProjectSyncWorker do
end
end
end
end
context
'wiki is not enabled for project'
do
let!
(
:registry
)
{
create
(
:geo_project_registry
,
resync_repository:
true
,
resync_wiki:
true
,
project:
project
)
}
before
do
project
.
update!
(
wiki_enabled:
false
)
subject
.
perform
(
project
.
id
,
Time
.
now
)
end
it
'syncs the project repository'
do
expect
(
repository_sync_service
).
to
have_received
(
:execute
)
end
it
'does not sync the project wiki'
do
expect
(
wiki_sync_service
).
not_to
have_received
(
:execute
)
end
end
context
'when project repository was synced after the time the job was scheduled in'
do
context
'when project repository was synced after the time the job was scheduled in'
do
it
'does not perform Geo::RepositorySyncService for the given project'
do
it
'does not perform Geo::RepositorySyncService for the given project'
do
create
(
:geo_project_registry
,
:synced
,
:repository_dirty
,
project:
project
,
last_repository_synced_at:
Time
.
now
)
create
(
:geo_project_registry
,
:synced
,
:repository_dirty
,
project:
project
,
last_repository_synced_at:
Time
.
now
)
...
...
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