Commit eb7df045 authored by Stan Hu's avatar Stan Hu

Gracefully handle case when no shard data is available

It's possible that if the GeoNodeStatus fails to fetch, we might end
up with a state where the primary loads the last known state without
any shard information. In this case, we should just report "UNKNOWN"
for the storage configuration match check.

Relates to #4586
parent bbf9174e
......@@ -175,6 +175,7 @@ class GeoNodeStatus < ActiveRecord::Base
# from a remote node via JSON.
def storage_shards_match?
return unless Gitlab::Geo.primary?
return unless current_shards && primary_shards
shards_match?(current_shards, primary_shards)
end
......
......@@ -476,22 +476,24 @@ describe GeoNodeStatus, :geo do
describe '#storage_shards_match?' do
before { stub_primary_node }
set(:status) { create(:geo_node_status) }
let(:data) { GeoNodeStatusSerializer.new.represent(status).as_json }
let(:result) { described_class.from_json(data) }
it 'returns nil if no shard data is available' do
data.delete('storage_shards')
expect(result.storage_shards_match?).to be nil
end
it 'returns false if the storage shards do not match' do
status = create(:geo_node_status)
data = GeoNodeStatusSerializer.new.represent(status).as_json
data['storage_shards'].first['name'] = 'broken-shard'
result = described_class.from_json(data)
expect(result.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 = GeoNodeStatusSerializer.new.represent(status).as_json
result = described_class.from_json(data)
expect(result.storage_shards_match?).to be true
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment