Commit 5289b2d9 authored by Nick Thomas's avatar Nick Thomas

Prevent the Geo log cursor from running on primary nodes

parent a7046b5b
---
title: Prevent the Geo log cursor from running on primary nodes
merge_request: 3411
author:
type: fixed
...@@ -4,6 +4,7 @@ module Gitlab ...@@ -4,6 +4,7 @@ module Gitlab
class Daemon class Daemon
VERSION = '0.2.0'.freeze VERSION = '0.2.0'.freeze
BATCH_SIZE = 250 BATCH_SIZE = 250
SECONDARY_CHECK_INTERVAL = 1.minute
attr_reader :options attr_reader :options
...@@ -17,6 +18,12 @@ module Gitlab ...@@ -17,6 +18,12 @@ module Gitlab
trap_signals trap_signals
until exit? until exit?
# Prevent the node from processing events unless it's a secondary
unless Geo.secondary?
sleep(SECONDARY_CHECK_INTERVAL)
next
end
lease = Lease.try_obtain_with_ttl { run_once! } lease = Lease.try_obtain_with_ttl { run_once! }
return if exit? return if exit?
......
...@@ -2,7 +2,7 @@ module EE ...@@ -2,7 +2,7 @@ module EE
module GeoHelpers module GeoHelpers
def stub_current_geo_node(node) def stub_current_geo_node(node)
allow(::Gitlab::Geo).to receive(:current_node).and_return(node) allow(::Gitlab::Geo).to receive(:current_node).and_return(node)
allow(node).to receive(:current?).and_return(true) allow(node).to receive(:current?).and_return(true) unless node.nil?
end end
end end
end end
...@@ -42,6 +42,26 @@ describe Gitlab::Geo::LogCursor::Daemon, :postgresql, :clean_gitlab_redis_shared ...@@ -42,6 +42,26 @@ describe Gitlab::Geo::LogCursor::Daemon, :postgresql, :clean_gitlab_redis_shared
daemon.run! daemon.run!
end end
it 'skips execution if not a Geo node' do
stub_current_geo_node(nil)
is_expected.to receive(:exit?).and_return(false, true)
is_expected.to receive(:sleep).with(1.minute)
is_expected.not_to receive(:run_once!)
daemon.run!
end
it 'skips execution if the current node is a primary' do
stub_current_geo_node(primary)
is_expected.to receive(:exit?).and_return(false, true)
is_expected.to receive(:sleep).with(1.minute)
is_expected.not_to receive(:run_once!)
daemon.run!
end
end end
describe '#run_once!' do describe '#run_once!' do
......
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