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
1271fdf1
Commit
1271fdf1
authored
Dec 15, 2020
by
Mike Kozono
Committed by
Gabriel Mazetto
Jan 23, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Verify only synced registries
And add tests for Geo::VerifiableRegistry.
parent
3c40b659
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
121 additions
and
3 deletions
+121
-3
ee/app/models/concerns/geo/verifiable_registry.rb
ee/app/models/concerns/geo/verifiable_registry.rb
+15
-0
ee/lib/gitlab/geo/verification_state.rb
ee/lib/gitlab/geo/verification_state.rb
+18
-3
ee/spec/support/shared_examples/models/geo_verifiable_registry_shared_examples.rb
...xamples/models/geo_verifiable_registry_shared_examples.rb
+88
-0
No files found.
ee/app/models/concerns/geo/verifiable_registry.rb
View file @
1271fdf1
...
...
@@ -15,6 +15,21 @@ module Geo::VerifiableRegistry
def
verification_state_model_key
self
::
MODEL_FOREIGN_KEY
end
override
:verification_pending_batch_relation
def
verification_pending_batch_relation
(
batch_size
:)
super
.
synced
end
override
:verification_failed_batch_relation
def
verification_failed_batch_relation
(
batch_size
:)
super
.
synced
end
override
:needs_verification_relation
def
needs_verification_relation
super
.
synced
end
end
included
do
...
...
ee/lib/gitlab/geo/verification_state.rb
View file @
1271fdf1
...
...
@@ -101,25 +101,40 @@ module Gitlab
# query.
#
def
verification_pending_batch
(
batch_size
:)
relation
=
verification_pending
.
order
(
Gitlab
::
Database
.
nulls_first_order
(
:verified_at
)).
limit
(
batch_size
)
# rubocop:disable CodeReuse/ActiveRecord
relation
=
verification_pending
_batch_relation
(
batch_size:
batch_size
)
start_verification_batch
(
relation
)
end
# Overridden by Geo::VerifiableRegistry
def
verification_pending_batch_relation
(
batch_size
:)
verification_pending
.
order
(
Gitlab
::
Database
.
nulls_first_order
(
:verified_at
)).
limit
(
batch_size
)
# rubocop:disable CodeReuse/ActiveRecord
end
# Returns IDs of records that failed to verify (calculate and save checksum).
#
# Atomically marks those records "verification_started" in the same DB
# query.
#
def
verification_failed_batch
(
batch_size
:)
relation
=
verification_failed
.
order
(
Gitlab
::
Database
.
nulls_first_order
(
:verification_retry_at
)).
limit
(
batch_size
)
# rubocop:disable CodeReuse/ActiveRecord
relation
=
verification_failed
_batch_relation
(
batch_size:
batch_size
)
start_verification_batch
(
relation
)
end
# Overridden by Geo::VerifiableRegistry
def
verification_failed_batch_relation
(
batch_size
:)
verification_failed
.
order
(
Gitlab
::
Database
.
nulls_first_order
(
:verification_retry_at
)).
limit
(
batch_size
)
# rubocop:disable CodeReuse/ActiveRecord
end
# @return [Integer] number of records that need verification
def
needs_verification_count
(
limit
:)
needs_verification
.
limit
(
limit
).
count
# rubocop:disable CodeReuse/ActiveRecord
needs_verification_relation
.
limit
(
limit
).
count
# rubocop:disable CodeReuse/ActiveRecord
end
# Overridden by Geo::VerifiableRegistry
def
needs_verification_relation
needs_verification
end
# Atomically marks the records as verification_started, with a
...
...
ee/spec/support/shared_examples/models/geo_verifiable_registry_shared_examples.rb
View file @
1271fdf1
...
...
@@ -7,6 +7,90 @@ RSpec.shared_examples 'a Geo verifiable registry' do
subject
(
:registry_record
)
{
create
(
registry_class_factory
,
:synced
)
}
describe
'.verification_pending_batch'
do
before
do
subject
.
save!
end
it
'returns IDs of rows which are synced and pending verification'
do
expect
(
described_class
.
verification_pending_batch
(
batch_size:
4
)).
to
match_array
([
subject
.
model_record_id
])
end
it
'excludes rows which are not synced or are not pending verification'
do
# rubocop:disable Rails/SaveBang
create
(
registry_class_factory
,
verification_state:
verification_state_value
(
:verification_pending
))
create
(
registry_class_factory
,
:started
,
verification_state:
verification_state_value
(
:verification_pending
))
create
(
registry_class_factory
,
:failed
,
verification_state:
verification_state_value
(
:verification_pending
))
create
(
registry_class_factory
,
:synced
,
verification_state:
verification_state_value
(
:verification_failed
),
verification_failure:
'foo'
)
create
(
registry_class_factory
,
:synced
,
verification_state:
verification_state_value
(
:verification_started
))
create
(
registry_class_factory
,
:synced
,
verification_state:
verification_state_value
(
:verification_succeeded
),
verification_checksum:
'abc123'
)
# rubocop:enable Rails/SaveBang
expect
(
described_class
.
verification_pending_batch
(
batch_size:
4
)).
to
match_array
([
subject
.
model_record_id
])
end
it
'marks verification as started'
do
described_class
.
verification_pending_batch
(
batch_size:
4
)
expect
(
subject
.
reload
.
verification_started?
).
to
be_truthy
expect
(
subject
.
verification_started_at
).
to
be_present
end
end
describe
'.verification_failed_batch'
do
before
do
subject
.
verification_failed_with_message!
(
'foo'
)
end
it
'returns IDs of rows which are synced and failed verification'
do
expect
(
described_class
.
verification_failed_batch
(
batch_size:
4
)).
to
match_array
([
subject
.
model_record_id
])
end
it
'excludes rows which are not synced or have not failed verification'
do
# rubocop:disable Rails/SaveBang
create
(
registry_class_factory
,
verification_state:
verification_state_value
(
:verification_failed
),
verification_failure:
'foo'
)
create
(
registry_class_factory
,
:started
,
verification_state:
verification_state_value
(
:verification_failed
),
verification_failure:
'foo'
)
create
(
registry_class_factory
,
:failed
,
verification_state:
verification_state_value
(
:verification_failed
),
verification_failure:
'foo'
)
create
(
registry_class_factory
,
:synced
,
verification_state:
verification_state_value
(
:verification_pending
))
create
(
registry_class_factory
,
:synced
,
verification_state:
verification_state_value
(
:verification_started
))
create
(
registry_class_factory
,
:synced
,
verification_state:
verification_state_value
(
:verification_succeeded
),
verification_checksum:
'abc123'
)
# rubocop:enable Rails/SaveBang
expect
(
described_class
.
verification_failed_batch
(
batch_size:
4
)).
to
match_array
([
subject
.
model_record_id
])
end
it
'marks verification as started'
do
described_class
.
verification_failed_batch
(
batch_size:
4
)
expect
(
subject
.
reload
.
verification_started?
).
to
be_truthy
expect
(
subject
.
verification_started_at
).
to
be_present
end
end
describe
'.needs_verification_count'
do
before
do
subject
.
save!
end
it
'returns the number of rows which are synced and (pending or failed) verification'
do
create
(
registry_class_factory
,
:synced
,
verification_state:
verification_state_value
(
:verification_failed
),
verification_failure:
'foo'
)
# rubocop:disable Rails/SaveBang
expect
(
described_class
.
needs_verification_count
(
limit:
3
)).
to
eq
(
2
)
end
it
'excludes rows which are not synced or are not (pending or failed) verification'
do
# rubocop:disable Rails/SaveBang
create
(
registry_class_factory
,
verification_state:
verification_state_value
(
:verification_pending
))
create
(
registry_class_factory
,
:started
,
verification_state:
verification_state_value
(
:verification_pending
))
create
(
registry_class_factory
,
:failed
,
verification_state:
verification_state_value
(
:verification_pending
))
create
(
registry_class_factory
,
:synced
,
verification_state:
verification_state_value
(
:verification_started
))
create
(
registry_class_factory
,
:synced
,
verification_state:
verification_state_value
(
:verification_succeeded
),
verification_checksum:
'abc123'
)
# rubocop:enable Rails/SaveBang
expect
(
described_class
.
needs_verification_count
(
limit:
3
)).
to
eq
(
1
)
end
end
describe
'#verification_succeeded!'
,
:aggregate_failures
do
before
do
subject
.
verification_started!
...
...
@@ -108,4 +192,8 @@ RSpec.shared_examples 'a Geo verifiable registry' do
end
end
end
def
verification_state_value
(
key
)
described_class
.
verification_state_value
(
key
)
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