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
672545b3
Commit
672545b3
authored
Nov 09, 2020
by
Mike Kozono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move update_verification_state! method
...into the Geo::VerificationState concern.
parent
5dbbc40c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
83 additions
and
39 deletions
+83
-39
ee/app/models/concerns/geo/verifiable_replicator.rb
ee/app/models/concerns/geo/verifiable_replicator.rb
+2
-25
ee/lib/gitlab/geo/verification_state.rb
ee/lib/gitlab/geo/verification_state.rb
+21
-0
ee/spec/lib/gitlab/geo/verification_state_spec.rb
ee/spec/lib/gitlab/geo/verification_state_spec.rb
+45
-0
ee/spec/support/shared_examples/models/concerns/verifiable_replicator_shared_examples.rb
.../models/concerns/verifiable_replicator_shared_examples.rb
+15
-14
No files found.
ee/app/models/concerns/geo/verifiable_replicator.rb
View file @
672545b3
...
...
@@ -52,10 +52,10 @@ module Geo
def
verify
checksum
=
model_record
.
calculate_checksum
update_verification_state!
(
checksum:
checksum
)
model_record
.
update_verification_state!
(
checksum:
checksum
)
rescue
=>
e
log_error
(
'Error calculating the checksum'
,
e
)
update_verification_state!
(
failure:
e
.
message
)
model_record
.
update_verification_state!
(
failure:
e
.
message
)
end
# Check if given checksum matches known one
...
...
@@ -83,28 +83,5 @@ module Geo
def
secondary_checksum
registry
.
verification_checksum
end
private
# Update checksum on Geo primary database
#
# @param [String] checksum value generated by the checksum routine
# @param [String] failure (optional) stacktrace from failed execution
def
update_verification_state!
(
checksum:
nil
,
failure:
nil
)
retry_at
,
retry_count
=
calculate_next_retry_attempt
if
failure
.
present?
model_record
.
update!
(
verification_checksum:
checksum
,
verified_at:
Time
.
current
,
verification_failure:
failure
,
verification_retry_at:
retry_at
,
verification_retry_count:
retry_count
)
end
def
calculate_next_retry_attempt
retry_count
=
model_record
.
verification_retry_count
.
to_i
+
1
[
next_retry_time
(
retry_count
),
retry_count
]
end
end
end
ee/lib/gitlab/geo/verification_state.rb
View file @
672545b3
...
...
@@ -92,6 +92,27 @@ module Gitlab
end
end
# Update checksum on Geo primary database
#
# @param [String] checksum value generated by the checksum routine
# @param [String] failure (optional) stacktrace from failed execution
def
update_verification_state!
(
checksum:
nil
,
failure:
nil
)
retry_at
,
retry_count
=
calculate_next_retry_attempt
if
failure
.
present?
update!
(
verification_checksum:
checksum
,
verified_at:
Time
.
current
,
verification_failure:
failure
,
verification_retry_at:
retry_at
,
verification_retry_count:
retry_count
)
end
def
calculate_next_retry_attempt
retry_count
=
model_record
.
verification_retry_count
.
to_i
+
1
[
next_retry_time
(
retry_count
),
retry_count
]
end
# @param [String] message error information
# @param [StandardError] error exception
def
set_verification_failure
(
message
,
error
=
nil
)
...
...
ee/spec/lib/gitlab/geo/verification_state_spec.rb
0 → 100644
View file @
672545b3
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Gitlab
::
Geo
::
VerificationState
do
include
::
EE
::
GeoHelpers
let_it_be
(
:primary_node
)
{
create
(
:geo_node
,
:primary
)
}
let_it_be
(
:secondary_node
)
{
create
(
:geo_node
)
}
before
(
:all
)
do
create_dummy_model_table
end
after
(
:all
)
do
drop_dummy_model_table
end
before
do
stub_dummy_replicator_class
stub_dummy_model_class
end
subject
{
DummyModel
.
new
}
describe
'#update_verification_state!'
do
before
do
subject
.
save!
end
it
'saves the checksum'
do
subject
.
update_verification_state!
(
checksum:
'abc123'
)
expect
(
subject
.
reload
.
verification_checksum
).
to
eq
(
'abc123'
)
expect
(
subject
.
verified_at
).
not_to
be_nil
end
it
'saves the error message and increments retry counter'
do
subject
.
update_verification_state!
(
failure:
'Failure to calculate checksum'
)
expect
(
subject
.
reload
.
verification_failure
).
to
eq
'Failure to calculate checksum'
expect
(
subject
.
verification_retry_count
).
to
be
1
end
end
end
ee/spec/support/shared_examples/models/concerns/verifiable_replicator_shared_examples.rb
View file @
672545b3
...
...
@@ -127,24 +127,25 @@ RSpec.shared_examples 'a verifiable replicator' do
model_record
.
save!
end
it
'calculates the checksum'
do
expect
(
model_record
).
to
receive
(
:calculate_checksum
).
and_return
(
'abc123'
)
context
'when a Geo primary'
do
context
'when an error is raised during calculate_checksum!'
do
it
'delegates checksum calculation and the state change to model_record'
do
expect
(
model_record
).
to
receive
(
:calculate_checksum
).
and_return
(
'abc123'
)
expect
(
model_record
).
to
receive
(
:update_verification_state!
).
with
(
checksum:
'abc123'
)
replicator
.
verify
expect
(
model_record
.
reload
.
verification_checksum
).
to
eq
(
'abc123'
)
expect
(
model_record
.
verified_at
).
not_to
be_nil
end
replicator
.
verify
end
it
'saves the error message and increments retry counter
'
do
allow
(
model_record
).
to
receive
(
:calculate_checksum
)
do
raise
StandardError
.
new
(
'Failure to calculate checksum'
)
end
it
'passes the error message
'
do
allow
(
model_record
).
to
receive
(
:calculate_checksum
)
do
raise
StandardError
.
new
(
'Failure to calculate checksum'
)
end
replicator
.
verify
expect
(
model_record
).
to
receive
(
:update_verification_state!
).
with
(
failure:
'Failure to calculate checksum'
)
expect
(
model_record
.
reload
.
verification_failure
).
to
eq
'Failure to calculate checksum'
expect
(
model_record
.
verification_retry_count
).
to
be
1
replicator
.
verify
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