From 7f294eb39bd071c9f9b22e72da8b247289f4d9cf Mon Sep 17 00:00:00 2001 From: "Andrew N. Shalaev" Date: Mon, 5 Jul 2021 11:13:46 +0500 Subject: [PATCH] feature: remove disable/enable host before rotation https://jira.railsc.ru/browse/BPC-19000 --- .rspec | 1 + lib/sphinx/integration/helper.rb | 3 +++ .../integration/helper_adapters/remote.rb | 26 +++---------------- .../helper_adapters/remote_spec.rb | 13 ++++------ spec/sphinx/integration/helper_spec.rb | 3 +++ 5 files changed, 16 insertions(+), 30 deletions(-) diff --git a/.rspec b/.rspec index 3f1d129..012aeb2 100644 --- a/.rspec +++ b/.rspec @@ -2,3 +2,4 @@ --tty --format progress --order random +--fail-fast diff --git a/lib/sphinx/integration/helper.rb b/lib/sphinx/integration/helper.rb index 0b77975..d10f7f3 100644 --- a/lib/sphinx/integration/helper.rb +++ b/lib/sphinx/integration/helper.rb @@ -20,6 +20,8 @@ class Helper end end + DEFAULT_ROTATION_TIME = 10.seconds + def initialize(options = {}) ::ThinkingSphinx.context.define_indexes @@ -63,6 +65,7 @@ def index index.switch_rt if rotate_index @sphinx.index(index) + sleep(Integer(index.local_options[:rotation_time] || DEFAULT_ROTATION_TIME)) if rotate_index index.last_indexing_time.write end diff --git a/lib/sphinx/integration/helper_adapters/remote.rb b/lib/sphinx/integration/helper_adapters/remote.rb index 6d48c4d..fbed28f 100644 --- a/lib/sphinx/integration/helper_adapters/remote.rb +++ b/lib/sphinx/integration/helper_adapters/remote.rb @@ -72,9 +72,8 @@ def logger end class Remote < Base - AVG_ROTATION_TIME = 10 - AVG_CLOSE_CONNECTIONS_TIME = 10 - private_constant :AVG_ROTATION_TIME, :AVG_CLOSE_CONNECTIONS_TIME + AVG_CLOSE_CONNECTIONS_TIME = 10.seconds + private_constant :AVG_CLOSE_CONNECTIONS_TIME def initialize(*) super @@ -143,32 +142,15 @@ def index(idx) # Returns nil def reload(idx) logger.info "Rotation #{idx.core_name}" - local_rotatition_time = idx.local_options[:rotation_time] - # behaviour by default - return sighup if local_rotatition_time.blank? || hosts.size == 1 - - hosts.each do |host| - begin - disable_host(host) - - @ssh.within(host) { sighup } - - sleep(local_rotatition_time) - ensure - enable_host(host) - end - end + hosts.each { |host| @ssh.within(host) { sighup } } end private def sighup - logger.info 'Sending SIGHUP to process. Waiting rotation...' - @ssh.execute('kill', "-SIGHUP `cat #{config.configuration.searchd.pid_file}`") - - sleep(AVG_ROTATION_TIME) + logger.info 'SIGHUP sent' end def indexer_args diff --git a/spec/sphinx/integration/helper_adapters/remote_spec.rb b/spec/sphinx/integration/helper_adapters/remote_spec.rb index 896c8b0..63963ec 100644 --- a/spec/sphinx/integration/helper_adapters/remote_spec.rb +++ b/spec/sphinx/integration/helper_adapters/remote_spec.rb @@ -6,7 +6,7 @@ let(:adapter) { described_class.new } before do - allow_any_instance_of(Sphinx::Integration::HelperAdapters::Remote).to receive(:sleep) + allow_any_instance_of(described_class).to receive(:sleep) class_double("Sphinx::Integration::HelperAdapters::SshProxy", new: ssh).as_stubbed_const end @@ -39,6 +39,7 @@ describe "#suspend" do it do + expect(adapter).to receive(:sleep) adapter.suspend server_status = Sphinx::Integration::ServerStatus.new(ThinkingSphinx::Configuration.instance.address) expect(server_status.available?).to be false @@ -92,12 +93,8 @@ expect(ssh).to receive(:execute).with("kill", /SIGHUP/).twice - expect(adapter).to receive(:disable_host) do |args| - expect(args).to match(/s\d\.dev/) - end.at_least(:twice) - expect(adapter).to receive(:enable_host) do |args| - expect(args).to match(/s\d\.dev/) - end.at_least(:twice) + expect(adapter).not_to receive(:disable_host) + expect(adapter).not_to receive(:enable_host) adapter.index(double('Index', core_name: 'index_name', local_options: {rotation_time: 5 * 60})) end @@ -111,7 +108,7 @@ end it do - expect(ssh).to receive(:within).with('s1.dev').and_yield + expect(ssh).to receive(:within).with('s1.dev').twice.and_yield expect(ssh).to receive(:execute). with("indexer", "--config /path/sphinx.conf", "--rotate", "--nohup", 'index_name', exit_status: [0, 2]) expect(ssh).to receive(:execute). diff --git a/spec/sphinx/integration/helper_spec.rb b/spec/sphinx/integration/helper_spec.rb index 0d6ccac..b8d803f 100644 --- a/spec/sphinx/integration/helper_spec.rb +++ b/spec/sphinx/integration/helper_spec.rb @@ -4,6 +4,8 @@ let(:adapter) { instance_double("Sphinx::Integration::HelperAdapters::Local") } let(:default_options) { {sphinx_adapter: adapter} } + before { allow_any_instance_of(described_class).to receive(:sleep) } + describe "#configure" do it do expect(ThinkingSphinx::Configuration.instance).to receive(:build).with(/test\.sphinx\.conf/) @@ -17,6 +19,7 @@ helper = described_class.new(default_options.merge(rotate: true, indexes: 'model_with_rt')) expect_any_instance_of(Sphinx::Integration::Mysql::Replayer).to receive(:reset) expect_any_instance_of(RedisMutex).to receive(:with_lock).and_yield + expect(helper).to receive(:sleep).with(60) expect(adapter).to receive(:index) do |args| expect(args.core_name).to eq('model_with_rt_core') end