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
f90d7af4
Commit
f90d7af4
authored
Jan 01, 2018
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve implementation and testing of storage shard matching
parent
08cc49e0
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
47 additions
and
6 deletions
+47
-6
ee/app/models/geo_node_status.rb
ee/app/models/geo_node_status.rb
+15
-1
ee/app/serializers/geo_node_status_entity.rb
ee/app/serializers/geo_node_status_entity.rb
+1
-1
spec/ee/spec/models/geo_node_status_spec.rb
spec/ee/spec/models/geo_node_status_spec.rb
+28
-3
spec/ee/spec/serializers/geo_node_status_entity_spec.rb
spec/ee/spec/serializers/geo_node_status_entity_spec.rb
+1
-0
spec/factories/geo_node_statuses.rb
spec/factories/geo_node_statuses.rb
+1
-1
spec/fixtures/api/schemas/geo_node_status.json
spec/fixtures/api/schemas/geo_node_status.json
+1
-0
No files found.
ee/app/models/geo_node_status.rb
View file @
f90d7af4
...
@@ -154,10 +154,12 @@ class GeoNodeStatus < ActiveRecord::Base
...
@@ -154,10 +154,12 @@ class GeoNodeStatus < ActiveRecord::Base
calc_percentage
(
replication_slots_count
,
replication_slots_used_count
)
calc_percentage
(
replication_slots_count
,
replication_slots_used_count
)
end
end
# This method only is useful when the storage shard information is loaded
# from a remote node via JSON.
def
storage_shards_match?
def
storage_shards_match?
return
unless
Gitlab
::
Geo
.
primary?
return
unless
Gitlab
::
Geo
.
primary?
s
torage_shards
.
as_json
==
StorageShardSerializer
.
new
.
represent
(
StorageShard
.
all
).
as_json
s
hards_match?
(
storage_shards
.
as_json
,
current_shards
.
as_json
)
end
end
def
[]
(
key
)
def
[]
(
key
)
...
@@ -166,6 +168,18 @@ class GeoNodeStatus < ActiveRecord::Base
...
@@ -166,6 +168,18 @@ class GeoNodeStatus < ActiveRecord::Base
private
private
def
current_shards
StorageShardSerializer
.
new
.
represent
(
StorageShard
.
all
)
end
def
shards_match?
(
first
,
second
)
sort_by_name
(
first
)
==
sort_by_name
(
second
)
end
def
sort_by_name
(
shards
)
shards
.
sort_by
{
|
shard
|
shard
[
'name'
]
}
end
def
attachments_finder
def
attachments_finder
@attachments_finder
||=
Geo
::
AttachmentRegistryFinder
.
new
(
current_node:
geo_node
)
@attachments_finder
||=
Geo
::
AttachmentRegistryFinder
.
new
(
current_node:
geo_node
)
end
end
...
...
ee/app/serializers/geo_node_status_entity.rb
View file @
f90d7af4
...
@@ -70,7 +70,7 @@ class GeoNodeStatusEntity < Grape::Entity
...
@@ -70,7 +70,7 @@ class GeoNodeStatusEntity < Grape::Entity
end
end
expose
:storage_shards_match?
,
as: :storage_shards_match
,
if:
->
(
status
,
options
)
do
expose
:storage_shards_match?
,
as: :storage_shards_match
,
if:
->
(
status
,
options
)
do
status
.
storage_shards_match
.
present?
Gitlab
::
Geo
.
primary?
&&
status
.
storage_shards
.
present?
end
end
private
private
...
...
spec/ee/spec/models/geo_node_status_spec.rb
View file @
f90d7af4
...
@@ -406,16 +406,41 @@ describe GeoNodeStatus, :geo do
...
@@ -406,16 +406,41 @@ describe GeoNodeStatus, :geo do
it
'returns a new GeoNodeStatus excluding parameters'
do
it
'returns a new GeoNodeStatus excluding parameters'
do
status
=
create
(
:geo_node_status
)
status
=
create
(
:geo_node_status
)
data
=
status
.
as_json
data
=
GeoNodeStatusSerializer
.
new
.
represent
(
status
)
.
as_json
data
[
'id'
]
=
10000
data
[
'id'
]
=
10000
data
[
'storage_shards'
]
=
Settings
.
repositories
.
storages
result
=
GeoNodeStatus
.
from_json
(
data
)
result
=
GeoNodeStatus
.
from_json
(
data
)
expect
(
result
.
id
).
to
be_nil
expect
(
result
.
id
).
to
be_nil
expect
(
result
.
attachments_count
).
to
eq
(
status
.
attachments_count
)
expect
(
result
.
attachments_count
).
to
eq
(
status
.
attachments_count
)
expect
(
result
.
cursor_last_event_date
).
to
eq
(
status
.
cursor_last_event_date
)
expect
(
result
.
cursor_last_event_date
).
to
eq
(
Time
.
at
(
status
.
cursor_last_event_timestamp
)
)
expect
(
result
.
storage_shards
.
count
).
to
eq
(
Settings
.
repositories
.
storages
.
count
)
expect
(
result
.
storage_shards
.
count
).
to
eq
(
Settings
.
repositories
.
storages
.
count
)
end
end
end
end
describe
'#storage_shards_match?'
do
before
do
allow
(
Gitlab
::
Geo
).
to
receive
(
:primary?
).
and_return
(
true
)
end
it
'returns false if the storage shards do not match'
do
status
=
create
(
:geo_node_status
)
status
.
storage_shards
.
first
[
'name'
]
=
'broken-shard'
data
=
status
.
as_json
result
=
GeoNodeStatus
.
from_json
(
data
)
expect
(
status
.
storage_shards_match?
).
to
be
false
end
it
'returns true if the storage shards match in different order'
do
status
=
create
(
:geo_node_status
)
status
.
storage_shards
.
shuffle!
data
=
status
.
as_json
result
=
GeoNodeStatus
.
from_json
(
data
)
expect
(
status
.
storage_shards_match?
).
to
be
true
end
end
end
end
spec/ee/spec/serializers/geo_node_status_entity_spec.rb
View file @
f90d7af4
...
@@ -33,6 +33,7 @@ describe GeoNodeStatusEntity, :postgresql do
...
@@ -33,6 +33,7 @@ describe GeoNodeStatusEntity, :postgresql do
it
{
is_expected
.
to
have_key
(
:last_successful_status_check_timestamp
)
}
it
{
is_expected
.
to
have_key
(
:last_successful_status_check_timestamp
)
}
it
{
is_expected
.
to
have_key
(
:namespaces
)
}
it
{
is_expected
.
to
have_key
(
:namespaces
)
}
it
{
is_expected
.
to
have_key
(
:storage_shards
)
}
it
{
is_expected
.
to
have_key
(
:storage_shards
)
}
it
{
is_expected
.
to
have_key
(
:storage_shards_match
)
}
describe
'#healthy'
do
describe
'#healthy'
do
context
'when node is healthy'
do
context
'when node is healthy'
do
...
...
spec/factories/geo_node_statuses.rb
View file @
f90d7af4
...
@@ -2,7 +2,7 @@ FactoryBot.define do
...
@@ -2,7 +2,7 @@ FactoryBot.define do
factory
:geo_node_status
do
factory
:geo_node_status
do
sequence
(
:id
)
sequence
(
:id
)
geo_node
geo_node
storage_shards
{
StorageShard
.
all
}
storage_shards
{
StorageShard
Serializer
.
new
.
represent
(
StorageShard
.
all
)
}
trait
:healthy
do
trait
:healthy
do
health
nil
health
nil
...
...
spec/fixtures/api/schemas/geo_node_status.json
View file @
f90d7af4
...
@@ -63,6 +63,7 @@
...
@@ -63,6 +63,7 @@
"last_successful_status_check_timestamp"
:
{
"type"
:
[
"integer"
,
"null"
]
},
"last_successful_status_check_timestamp"
:
{
"type"
:
[
"integer"
,
"null"
]
},
"namespaces"
:
{
"type"
:
"array"
},
"namespaces"
:
{
"type"
:
"array"
},
"storage_shards"
:
{
"type"
:
"array"
},
"storage_shards"
:
{
"type"
:
"array"
},
"storage_shards_match"
:
{
"type"
:
"boolean"
},
"version"
:
{
"type"
:
[
"string"
]
},
"version"
:
{
"type"
:
[
"string"
]
},
"revision"
:
{
"type"
:
[
"string"
]
}
"revision"
:
{
"type"
:
[
"string"
]
}
},
},
...
...
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