From 6eabce034d439a17644e571d267b0df780b78594 Mon Sep 17 00:00:00 2001 From: "Ryan T. Hosford" Date: Sat, 1 May 2021 00:09:17 -0500 Subject: [PATCH] Adopts blocklist/allowlist as suitable alternatives for the harmful terms blacklist/whitelist --- .../makara_abstract_adapter.rb | 2 +- lib/makara.rb | 6 +-- lib/makara/config_parser.rb | 4 +- lib/makara/connection_wrapper.rb | 30 ++++++------ lib/makara/error_handler.rb | 2 +- ...sted.rb => all_connections_blocklisted.rb} | 4 +- ..._connection.rb => blocklist_connection.rb} | 2 +- ...rb => blocklisted_while_in_transaction.rb} | 4 +- lib/makara/pool.rb | 44 ++++++++--------- lib/makara/proxy.rb | 16 +++---- lib/makara/strategies/priority_failover.rb | 4 +- lib/makara/strategies/round_robin.rb | 4 +- ...ra_abstract_adapter_error_handling_spec.rb | 8 ++-- .../makara_mysql2_adapter_spec.rb | 14 +++--- spec/config_parser_spec.rb | 20 ++++---- spec/connection_wrapper_spec.rb | 18 +++---- spec/pool_spec.rb | 48 +++++++++---------- spec/proxy_spec.rb | 32 ++++++------- spec/strategies/priority_failover_spec.rb | 4 +- spec/strategies/round_robin_spec.rb | 4 +- spec/strategies/shard_aware_spec.rb | 12 ++--- spec/support/helpers.rb | 8 ++-- 22 files changed, 145 insertions(+), 145 deletions(-) rename lib/makara/errors/{all_connections_blacklisted.rb => all_connections_blocklisted.rb} (67%) rename lib/makara/errors/{blacklist_connection.rb => blocklist_connection.rb} (84%) rename lib/makara/errors/{blacklisted_while_in_transaction.rb => blocklisted_while_in_transaction.rb} (55%) diff --git a/lib/active_record/connection_adapters/makara_abstract_adapter.rb b/lib/active_record/connection_adapters/makara_abstract_adapter.rb index 90b8c231..d02d0188 100644 --- a/lib/active_record/connection_adapters/makara_abstract_adapter.rb +++ b/lib/active_record/connection_adapters/makara_abstract_adapter.rb @@ -8,7 +8,7 @@ class ErrorHandler < ::Makara::ErrorHandler HARSH_ERRORS = [ 'ActiveRecord::RecordNotUnique', 'ActiveRecord::InvalidForeignKey', - 'Makara::Errors::BlacklistConnection' + 'Makara::Errors::BlocklistConnection' ].map(&:freeze).freeze CONNECTION_MATCHERS = [ diff --git a/lib/makara.rb b/lib/makara.rb index 5bad566d..7fe24e57 100644 --- a/lib/makara.rb +++ b/lib/makara.rb @@ -14,10 +14,10 @@ module Makara module Errors autoload :MakaraError, 'makara/errors/makara_error' - autoload :AllConnectionsBlacklisted, 'makara/errors/all_connections_blacklisted' - autoload :BlacklistConnection, 'makara/errors/blacklist_connection' + autoload :AllConnectionsBlocklisted, 'makara/errors/all_connections_blocklisted' + autoload :BlocklistConnection, 'makara/errors/blocklist_connection' autoload :NoConnectionsAvailable, 'makara/errors/no_connections_available' - autoload :BlacklistedWhileInTransaction, 'makara/errors/blacklisted_while_in_transaction' + autoload :BlocklistedWhileInTransaction, 'makara/errors/blocklisted_while_in_transaction' autoload :InvalidShard, 'makara/errors/invalid_shard' end diff --git a/lib/makara/config_parser.rb b/lib/makara/config_parser.rb index 8ed8457f..486b709f 100644 --- a/lib/makara/config_parser.rb +++ b/lib/makara/config_parser.rb @@ -11,7 +11,7 @@ # another: 'top level variable' # makara: # primary_ttl: 3 -# blacklist_duration: 20 +# blocklist_duration: 20 # connections: # - role: 'master' # Deprecated in favor of 'primary' # - role: 'primary' @@ -23,7 +23,7 @@ module Makara class ConfigParser DEFAULTS = { primary_ttl: 5, - blacklist_duration: 30, + blocklist_duration: 30, sticky: true } diff --git a/lib/makara/connection_wrapper.rb b/lib/makara/connection_wrapper.rb index 51ccf617..0e477690 100644 --- a/lib/makara/connection_wrapper.rb +++ b/lib/makara/connection_wrapper.rb @@ -1,7 +1,7 @@ require 'active_support/core_ext/hash/keys' # Makara::ConnectionWrapper wraps the instance of an underlying connection. -# The wrapper provides methods for tracking blacklisting and individual makara configurations. +# The wrapper provides methods for tracking blocklisting and individual makara configurations. # Upon creation, the wrapper defines methods in the underlying object giving it access to the # Makara::Proxy. @@ -18,7 +18,7 @@ def initialize(proxy, connection, config) @proxy = proxy if connection.nil? - _makara_blacklist! + _makara_blocklist! else _makara_decorate_connection(connection) end @@ -38,25 +38,25 @@ def _makara_shard_id @config[:shard_id] end - # has this node been blacklisted? - def _makara_blacklisted? - @blacklisted_until.present? && @blacklisted_until.to_i > Time.now.to_i + # has this node been blocklisted? + def _makara_blocklisted? + @blocklisted_until.present? && @blocklisted_until.to_i > Time.now.to_i end def _makara_in_transaction? @connection && @connection.open_transactions > 0 end - # blacklist this node for @config[:blacklist_duration] seconds - def _makara_blacklist! + # blocklist this node for @config[:blocklist_duration] seconds + def _makara_blocklist! @connection.disconnect! if @connection @connection = nil - @blacklisted_until = Time.now.to_i + @config[:blacklist_duration] unless @config[:disable_blacklist] + @blocklisted_until = Time.now.to_i + @config[:blocklist_duration] unless @config[:disable_blocklist] end - # release the blacklist - def _makara_whitelist! - @blacklisted_until = nil + # release the blocklist + def _makara_allowlist! + @blocklisted_until = nil end # custom error messages @@ -66,7 +66,7 @@ def _makara_custom_error_matchers def _makara_connected? _makara_connection.present? - rescue Makara::Errors::BlacklistConnection + rescue Makara::Errors::BlocklistConnection false end @@ -75,13 +75,13 @@ def _makara_connection if current current - else # blacklisted connection or initial error + else # blocklisted connection or initial error new_connection = @proxy.graceful_connection_for(@config) # Already wrapped because of initial failure if new_connection.is_a?(Makara::ConnectionWrapper) - _makara_blacklist! - raise Makara::Errors::BlacklistConnection.new(self, new_connection.initial_error) + _makara_blocklist! + raise Makara::Errors::BlocklistConnection.new(self, new_connection.initial_error) else @connection = new_connection _makara_decorate_connection(new_connection) diff --git a/lib/makara/error_handler.rb b/lib/makara/error_handler.rb index 6a1a4fdd..011bfbb7 100644 --- a/lib/makara/error_handler.rb +++ b/lib/makara/error_handler.rb @@ -17,7 +17,7 @@ def handle(connection) protected def gracefully(connection, e) - err = Makara::Errors::BlacklistConnection.new(connection, e) + err = Makara::Errors::BlocklistConnection.new(connection, e) ::Makara::Logging::Logger.log("Gracefully handling: #{err}") raise err end diff --git a/lib/makara/errors/all_connections_blacklisted.rb b/lib/makara/errors/all_connections_blocklisted.rb similarity index 67% rename from lib/makara/errors/all_connections_blacklisted.rb rename to lib/makara/errors/all_connections_blocklisted.rb index a6b04b9d..c7beeaed 100644 --- a/lib/makara/errors/all_connections_blacklisted.rb +++ b/lib/makara/errors/all_connections_blocklisted.rb @@ -1,10 +1,10 @@ module Makara module Errors - class AllConnectionsBlacklisted < MakaraError + class AllConnectionsBlocklisted < MakaraError def initialize(pool, errors) errors = [*errors] messages = errors.empty? ? 'No error details' : errors.map(&:message).join(' -> ') - super "[Makara/#{pool.role}] All connections are blacklisted -> " + messages + super "[Makara/#{pool.role}] All connections are blocklisted -> " + messages end end end diff --git a/lib/makara/errors/blacklist_connection.rb b/lib/makara/errors/blocklist_connection.rb similarity index 84% rename from lib/makara/errors/blacklist_connection.rb rename to lib/makara/errors/blocklist_connection.rb index 2756607d..735d090d 100644 --- a/lib/makara/errors/blacklist_connection.rb +++ b/lib/makara/errors/blocklist_connection.rb @@ -1,6 +1,6 @@ module Makara module Errors - class BlacklistConnection < MakaraError + class BlocklistConnection < MakaraError attr_reader :original_error def initialize(connection, error) diff --git a/lib/makara/errors/blacklisted_while_in_transaction.rb b/lib/makara/errors/blocklisted_while_in_transaction.rb similarity index 55% rename from lib/makara/errors/blacklisted_while_in_transaction.rb rename to lib/makara/errors/blocklisted_while_in_transaction.rb index 398bcc00..eda3b61f 100644 --- a/lib/makara/errors/blacklisted_while_in_transaction.rb +++ b/lib/makara/errors/blocklisted_while_in_transaction.rb @@ -1,11 +1,11 @@ module Makara module Errors - class BlacklistedWhileInTransaction < MakaraError + class BlocklistedWhileInTransaction < MakaraError attr_reader :role def initialize(role) @role = role - super "[Makara] Blacklisted while in transaction in the #{role} pool" + super "[Makara] Blocklisted while in transaction in the #{role} pool" end end end diff --git a/lib/makara/pool.rb b/lib/makara/pool.rb index b2ef5878..b23a8eb5 100644 --- a/lib/makara/pool.rb +++ b/lib/makara/pool.rb @@ -9,7 +9,7 @@ class Pool # there are cases when we understand the pool is busted and we essentially want to skip # all execution attr_accessor :disabled - attr_reader :blacklist_errors + attr_reader :blocklist_errors attr_reader :role attr_reader :connections attr_reader :strategy @@ -20,7 +20,7 @@ def initialize(role, proxy) @role = role == "master" ? "primary" : role @proxy = proxy @connections = [] - @blacklist_errors = [] + @blocklist_errors = [] @disabled = false if proxy.shard_aware_for(role) @strategy = Makara::Strategies::ShardAware.new(self) @@ -31,9 +31,9 @@ def initialize(role, proxy) end end - def completely_blacklisted? + def completely_blocklisted? @connections.each do |connection| - return false unless connection._makara_blacklisted? + return false unless connection._makara_blocklisted? end true end @@ -66,7 +66,7 @@ def send_to_all(method, *args, &block) errors = [] @connections.each do |con| - next if con._makara_blacklisted? + next if con._makara_blocklisted? begin ret = @proxy.error_handler.handle(con) do @@ -78,15 +78,15 @@ def send_to_all(method, *args, &block) end one_worked = true - rescue Makara::Errors::BlacklistConnection => e + rescue Makara::Errors::BlocklistConnection => e errors.insert(0, e) - con._makara_blacklist! + con._makara_blocklist! end end if !one_worked if connection_made? - raise Makara::Errors::AllConnectionsBlacklisted.new(self, errors) + raise Makara::Errors::AllConnectionsBlocklisted.new(self, errors) else raise Makara::Errors::NoConnectionsAvailable.new(@role) unless @disabled end @@ -95,46 +95,46 @@ def send_to_all(method, *args, &block) ret end - # Provide a connection that is not blacklisted and connected. Handle any errors + # Provide a connection that is not blocklisted and connected. Handle any errors # that may occur within the block. def provide attempt = 0 begin provided_connection = self.next - # nil implies that it's blacklisted + # nil implies that it's blocklisted if provided_connection value = @proxy.error_handler.handle(provided_connection) do yield provided_connection end - @blacklist_errors = [] + @blocklist_errors = [] value # if we've made any connections within this pool, we should report the blackout. elsif connection_made? - err = Makara::Errors::AllConnectionsBlacklisted.new(self, @blacklist_errors) - @blacklist_errors = [] + err = Makara::Errors::AllConnectionsBlocklisted.new(self, @blocklist_errors) + @blocklist_errors = [] raise err else raise Makara::Errors::NoConnectionsAvailable.new(@role) unless @disabled end - # when a connection causes a blacklist error within the provided block, we blacklist it then retry - rescue Makara::Errors::BlacklistConnection => e - @blacklist_errors.insert(0, e) + # when a connection causes a blocklist error within the provided block, we blocklist it then retry + rescue Makara::Errors::BlocklistConnection => e + @blocklist_errors.insert(0, e) in_transaction = self.role == "primary" && provided_connection._makara_in_transaction? - provided_connection._makara_blacklist! - raise Makara::Errors::BlacklistedWhileInTransaction.new(@role) if in_transaction + provided_connection._makara_blocklist! + raise Makara::Errors::BlocklistedWhileInTransaction.new(@role) if in_transaction attempt += 1 if attempt < @connections.length retry elsif connection_made? - err = Makara::Errors::AllConnectionsBlacklisted.new(self, @blacklist_errors) - @blacklist_errors = [] + err = Makara::Errors::AllConnectionsBlocklisted.new(self, @blocklist_errors) + @blocklist_errors = [] raise err else raise Makara::Errors::NoConnectionsAvailable.new(@role) unless @disabled @@ -149,9 +149,9 @@ def connection_made? @connections.any?(&:_makara_connected?) end - # Get the next non-blacklisted connection. If the proxy is setup + # Get the next non-blocklisted connection. If the proxy is setup # to be sticky, provide back the current connection assuming it is - # not blacklisted. + # not blocklisted. def next if @proxy.sticky && (curr = @strategy.current) curr diff --git a/lib/makara/proxy.rb b/lib/makara/proxy.rb index 866f242c..5a66a6f6 100644 --- a/lib/makara/proxy.rb +++ b/lib/makara/proxy.rb @@ -153,14 +153,14 @@ def graceful_connection_for(config) @error_handler.handle(fake_wrapper) do connection_for(config) end - rescue Makara::Errors::BlacklistConnection => e + rescue Makara::Errors::BlocklistConnection => e fake_wrapper.initial_error = e.original_error fake_wrapper end def disconnect! send_to_all(:disconnect!) - rescue ::Makara::Errors::AllConnectionsBlacklisted, ::Makara::Errors::NoConnectionsAvailable + rescue ::Makara::Errors::AllConnectionsBlocklisted, ::Makara::Errors::NoConnectionsAvailable # all connections are already down, nothing to do here end @@ -186,7 +186,7 @@ def any_connection yield con end end - rescue ::Makara::Errors::AllConnectionsBlacklisted, ::Makara::Errors::NoConnectionsAvailable + rescue ::Makara::Errors::AllConnectionsBlocklisted, ::Makara::Errors::NoConnectionsAvailable begin @primary_pool.disabled = true @replica_pool.provide do |con| @@ -215,13 +215,13 @@ def appropriate_pool(method_name, args) # for testing purposes pool = _appropriate_pool(method_name, args) yield pool - rescue ::Makara::Errors::AllConnectionsBlacklisted, ::Makara::Errors::NoConnectionsAvailable => e + rescue ::Makara::Errors::AllConnectionsBlocklisted, ::Makara::Errors::NoConnectionsAvailable => e if pool == @primary_pool - @primary_pool.connections.each(&:_makara_whitelist!) - @replica_pool.connections.each(&:_makara_whitelist!) + @primary_pool.connections.each(&:_makara_allowlist!) + @replica_pool.connections.each(&:_makara_allowlist!) Kernel.raise e else - @primary_pool.blacklist_errors << e + @primary_pool.blocklist_errors << e retry end end @@ -240,7 +240,7 @@ def _appropriate_pool(method_name, args) @primary_pool # all replicas are down (or empty) - elsif @replica_pool.completely_blacklisted? + elsif @replica_pool.completely_blocklisted? stick_to_primary(method_name, args) @primary_pool diff --git a/lib/makara/strategies/priority_failover.rb b/lib/makara/strategies/priority_failover.rb index d62e35e6..1fad51bd 100644 --- a/lib/makara/strategies/priority_failover.rb +++ b/lib/makara/strategies/priority_failover.rb @@ -35,13 +35,13 @@ def next nil end - # return the connection if it's not blacklisted + # return the connection if it's not blocklisted # otherwise return nil # optionally, store the position and context we're returning def safe_value(idx) con = @weighted_connections[idx] return nil unless con - return nil if con._makara_blacklisted? + return nil if con._makara_blocklisted? con end diff --git a/lib/makara/strategies/round_robin.rb b/lib/makara/strategies/round_robin.rb index 9e249f0e..a7eb1951 100644 --- a/lib/makara/strategies/round_robin.rb +++ b/lib/makara/strategies/round_robin.rb @@ -48,13 +48,13 @@ def next_index(idx) idx end - # return the connection if it's not blacklisted + # return the connection if it's not blocklisted # otherwise return nil # optionally, store the position and context we're returning def safe_value(idx, stick = false) con = @weighted_connections[idx] return nil unless con - return nil if con._makara_blacklisted? + return nil if con._makara_blocklisted? if stick @current_idx = idx diff --git a/spec/active_record/connection_adapters/makara_abstract_adapter_error_handling_spec.rb b/spec/active_record/connection_adapters/makara_abstract_adapter_error_handling_spec.rb index aa3489ca..e481c6a8 100644 --- a/spec/active_record/connection_adapters/makara_abstract_adapter_error_handling_spec.rb +++ b/spec/active_record/connection_adapters/makara_abstract_adapter_error_handling_spec.rb @@ -49,12 +49,12 @@ expect(handler).to be_connection_message(msg) end - it 'should blacklist the connection' do + it 'should blocklist the connection' do expect { handler.handle(connection) do raise msg end - }.to raise_error(Makara::Errors::BlacklistConnection) + }.to raise_error(Makara::Errors::BlocklistConnection) end end @@ -76,12 +76,12 @@ expect(handler).to be_custom_error_message(connection, msg4) end - it "blacklists the connection" do + it "blocklists the connection" do expect { handler.handle(connection) do raise msg1 end - }.to raise_error(Makara::Errors::BlacklistConnection) + }.to raise_error(Makara::Errors::BlocklistConnection) end end end diff --git a/spec/active_record/connection_adapters/makara_mysql2_adapter_spec.rb b/spec/active_record/connection_adapters/makara_mysql2_adapter_spec.rb index 74afbdfd..603f74cc 100644 --- a/spec/active_record/connection_adapters/makara_mysql2_adapter_spec.rb +++ b/spec/active_record/connection_adapters/makara_mysql2_adapter_spec.rb @@ -26,7 +26,7 @@ connection = ActiveRecord::Base.connection connection.replica_pool.connections.each do |c| - allow(c).to receive(:_makara_blacklisted?){ true } + allow(c).to receive(:_makara_blocklisted?){ true } allow(c).to receive(:_makara_connected?){ false } expect(c).to receive(:execute).with('SET @t1 = 1').never end @@ -45,7 +45,7 @@ connection = ActiveRecord::Base.connection (connection.replica_pool.connections | connection.primary_pool.connections).each do |c| - allow(c).to receive(:_makara_blacklisted?){ true } + allow(c).to receive(:_makara_blocklisted?){ true } allow(c).to receive(:_makara_connected?){ false } expect(c).to receive(:execute).with('SET @t1 = 1').never end @@ -84,7 +84,7 @@ original_method.call(config) end - ActiveRecord::Base.connection.replica_pool.connections.each(&:_makara_whitelist!) + ActiveRecord::Base.connection.replica_pool.connections.each(&:_makara_allowlist!) ActiveRecord::Base.connection.replica_pool.provide do |con| res = con.execute('SELECT count(*) FROM users') if defined?(JRUBY_VERSION) @@ -173,18 +173,18 @@ connection.reconnect! end - it 'should allow reconnecting when one of the nodes is blacklisted' do + it 'should allow reconnecting when one of the nodes is blocklisted' do con = connection.replica_pool.connections.first - allow(con).to receive(:_makara_blacklisted?){ true } + allow(con).to receive(:_makara_blocklisted?){ true } connection.reconnect! end if !defined?(JRUBY_VERSION) # yml settings only for mysql2 - it 'should blacklist on timeout' do + it 'should blocklist on timeout' do expect { connection.execute('SELECT SLEEP(2)') # read timeout set to 1 - }.to raise_error(Makara::Errors::AllConnectionsBlacklisted) + }.to raise_error(Makara::Errors::AllConnectionsBlocklisted) end end end diff --git a/spec/config_parser_spec.rb b/spec/config_parser_spec.rb index 109cef87..b35d73e6 100644 --- a/spec/config_parser_spec.rb +++ b/spec/config_parser_spec.rb @@ -25,7 +25,7 @@ let(:config_without_url) do { primary_ttl: 5, - blacklist_duration: 30, + blocklist_duration: 30, sticky: true, adapter: 'mysql2_makara', encoding: 'utf8', @@ -40,7 +40,7 @@ let(:config_with_url) do { primary_ttl: 5, - blacklist_duration: 30, + blocklist_duration: 30, sticky: true, adapter: 'mysql2_makara', encoding: 'utf8', @@ -114,7 +114,7 @@ name: 'theprimary', top_level: 'value', sticky: true, - blacklist_duration: 30, + blocklist_duration: 30, primary_ttl: 5 } ]) @@ -123,22 +123,22 @@ name: 'replica1', top_level: 'value', sticky: true, - blacklist_duration: 30, + blocklist_duration: 30, primary_ttl: 5 }, { name: 'replica2', top_level: 'value', sticky: true, - blacklist_duration: 30, + blocklist_duration: 30, primary_ttl: 5 } ]) end it 'connection configuration should override makara config' do - config[:makara][:blacklist_duration] = 123 - config[:makara][:connections][0][:blacklist_duration] = 456 + config[:makara][:blocklist_duration] = 123 + config[:makara][:connections][0][:blocklist_duration] = 456 config[:makara][:connections][1][:top_level] = 'replica value' parser = described_class.new(config) @@ -147,7 +147,7 @@ name: 'theprimary', top_level: 'value', sticky: true, - blacklist_duration: 456, + blocklist_duration: 456, primary_ttl: 5 } ]) @@ -156,14 +156,14 @@ name: 'replica1', top_level: 'replica value', sticky: true, - blacklist_duration: 123, + blocklist_duration: 123, primary_ttl: 5 }, { name: 'replica2', top_level: 'value', sticky: true, - blacklist_duration: 123, + blocklist_duration: 123, primary_ttl: 5 } ]) diff --git a/spec/connection_wrapper_spec.rb b/spec/connection_wrapper_spec.rb index 0d64efcc..e494c34d 100644 --- a/spec/connection_wrapper_spec.rb +++ b/spec/connection_wrapper_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Makara::ConnectionWrapper do - let(:proxy){ FakeProxy.new({makara: {blacklist_duration: 5, connections: [{role: 'primary'}, {role: 'replica'}, {role: 'replica'}]}}) } + let(:proxy){ FakeProxy.new({makara: {blocklist_duration: 5, connections: [{role: 'primary'}, {role: 'replica'}, {role: 'replica'}]}}) } let(:connection){ subject._makara_connection } subject{ proxy.primary_pool.connections.first } @@ -24,18 +24,18 @@ expect(subject._makara_weight).to eq(1) end - context '#_makara_blacklisted?' do - it 'should store the blacklist status' do - expect(subject._makara_blacklisted?).to eq(false) - subject._makara_blacklist! - expect(subject._makara_blacklisted?).to eq(true) - subject._makara_whitelist! - expect(subject._makara_blacklisted?).to eq(false) + context '#_makara_blocklisted?' do + it 'should store the blocklist status' do + expect(subject._makara_blocklisted?).to eq(false) + subject._makara_blocklist! + expect(subject._makara_blocklisted?).to eq(true) + subject._makara_allowlist! + expect(subject._makara_blocklisted?).to eq(false) end it 'should handle frozen pre-epoch dates' do Timecop.freeze(Date.new(1900)) do - expect(subject._makara_blacklisted?).to eq(false) + expect(subject._makara_blocklisted?).to eq(false) end end end diff --git a/spec/pool_spec.rb b/spec/pool_spec.rb index be490057..0f3a2888 100644 --- a/spec/pool_spec.rb +++ b/spec/pool_spec.rb @@ -3,7 +3,7 @@ describe Makara::Pool do let(:proxy){ FakeProxy.new({makara: pool_config.merge(connections: [])}) } let(:pool){ Makara::Pool.new('test', proxy) } - let(:pool_config){ {blacklist_duration: 5} } + let(:pool_config){ {blocklist_duration: 5} } let(:primary_pool){ Makara::Pool.new('primary', proxy) } it 'should wrap connections with a ConnectionWrapper as theyre added to the pool' do @@ -27,15 +27,15 @@ expect(bs.length).to eq(2) end - it 'should determine if its completely blacklisted' do + it 'should determine if its completely blocklisted' do pool.add(pool_config){ FakeConnection.new } pool.add(pool_config){ FakeConnection.new } - expect(pool).not_to be_completely_blacklisted + expect(pool).not_to be_completely_blocklisted - pool.connections.each(&:_makara_blacklist!) + pool.connections.each(&:_makara_blocklist!) - expect(pool).to be_completely_blacklisted + expect(pool).to be_completely_blocklisted end it 'sends methods to all underlying objects if asked to' do @@ -51,7 +51,7 @@ pool.send_to_all :query, 'test' end - it 'only sends methods to underlying objects which are not blacklisted' do + it 'only sends methods to underlying objects which are not blocklisted' do a = FakeConnection.new b = FakeConnection.new c = FakeConnection.new @@ -64,12 +64,12 @@ expect(b).to receive(:query).with('test').once expect(c).to receive(:query).with('test').never - wrapper_c._makara_blacklist! + wrapper_c._makara_blocklist! pool.send_to_all :query, 'test' end - it 'provides the next connection and blacklists' do + it 'provides the next connection and blocklists' do connection_a = FakeConnection.new(something: 'a') connection_b = FakeConnection.new(something: 'b') @@ -78,16 +78,16 @@ pool.provide do |connection| if connection == wrapper_a - raise Makara::Errors::BlacklistConnection.new(wrapper_a, StandardError.new('failure')) + raise Makara::Errors::BlocklistConnection.new(wrapper_a, StandardError.new('failure')) end end - expect(wrapper_a._makara_blacklisted?).to eq(true) - expect(wrapper_b._makara_blacklisted?).to eq(false) + expect(wrapper_a._makara_blocklisted?).to eq(true) + expect(wrapper_b._makara_blocklisted?).to eq(false) Timecop.travel Time.now + 10 do - expect(wrapper_a._makara_blacklisted?).to eq(false) - expect(wrapper_b._makara_blacklisted?).to eq(false) + expect(wrapper_a._makara_blocklisted?).to eq(false) + expect(wrapper_b._makara_blocklisted?).to eq(false) end end @@ -117,7 +117,7 @@ expect(provided.uniq.length).to eq(2) end - it 'raises an error when all connections are blacklisted' do + it 'raises an error when all connections are blocklisted' do wrapper_a = pool.add(pool_config.dup){ FakeConnection.new } wrapper_b = pool.add(pool_config.dup){ FakeConnection.new } @@ -128,42 +128,42 @@ begin pool.provide do |connection| - raise Makara::Errors::BlacklistConnection.new(connection, StandardError.new('failure')) + raise Makara::Errors::BlocklistConnection.new(connection, StandardError.new('failure')) end - rescue Makara::Errors::AllConnectionsBlacklisted => e + rescue Makara::Errors::AllConnectionsBlocklisted => e expect(e).to be_present - expect(e.message).to eq("[Makara/test] All connections are blacklisted -> [Makara/test/2] failure -> [Makara/test/1] failure") + expect(e.message).to eq("[Makara/test] All connections are blocklisted -> [Makara/test/2] failure -> [Makara/test/1] failure") end end - it 'skips blacklisted connections when choosing the next one' do + it 'skips blocklisted connections when choosing the next one' do pool.add(pool_config){ FakeConnection.new } pool.add(pool_config){ FakeConnection.new } wrapper_b = pool.add(pool_config){ FakeConnection.new } - wrapper_b._makara_blacklist! + wrapper_b._makara_blocklist! 10.times{ pool.provide{|connection| expect(connection).not_to eq(wrapper_b) } } end - it 'should error out while blacklisted in transaction' do + it 'should error out while blocklisted in transaction' do wrapper_a = primary_pool.add(pool_config){ FakeConnection.new(open_transactions: 1) } primary_pool.add(pool_config){ FakeConnection.new } expect { primary_pool.provide do |connection| if connection == wrapper_a - raise Makara::Errors::BlacklistConnection.new(wrapper_a, StandardError.new('failure')) + raise Makara::Errors::BlocklistConnection.new(wrapper_a, StandardError.new('failure')) end end - }.to raise_error(Makara::Errors::BlacklistedWhileInTransaction) + }.to raise_error(Makara::Errors::BlocklistedWhileInTransaction) end - it 'skips blacklisted connections in primary pool when not in transaction' do + it 'skips blocklisted connections in primary pool when not in transaction' do wrapper_a = primary_pool.add(pool_config){ FakeConnection.new(open_transactions: 0) } primary_pool.add(pool_config){ FakeConnection.new } primary_pool.provide do |connection| if connection == wrapper_a - raise Makara::Errors::BlacklistConnection.new(wrapper_a, StandardError.new('failure')) + raise Makara::Errors::BlocklistConnection.new(wrapper_a, StandardError.new('failure')) end end 10.times{ primary_pool.provide{|connection| expect(connection).not_to eq(wrapper_a) } } diff --git a/spec/proxy_spec.rb b/spec/proxy_spec.rb index 98a74dac..bb991d34 100644 --- a/spec/proxy_spec.rb +++ b/spec/proxy_spec.rb @@ -157,23 +157,23 @@ expect(proxy.primary_for?('select * from users')).to eq(false) end - it 'should use primary if all replicas are blacklisted' do - allow(proxy.replica_pool).to receive(:completely_blacklisted?){ true } + it 'should use primary if all replicas are blocklisted' do + allow(proxy.replica_pool).to receive(:completely_blocklisted?){ true } expect(proxy.primary_for?('select * from users')).to eq(true) end - it 'should use primary if all replicas become blacklisted as part of the invocation' do + it 'should use primary if all replicas become blocklisted as part of the invocation' do allow(proxy.replica_pool).to receive(:next).and_return(nil) test = double - expect(test).to receive(:blacklisting).once + expect(test).to receive(:blocklisting).once expect(test).to receive(:using_primary).once proxy.send(:appropriate_pool, :execute, ['select * from users']) do |pool| if pool == proxy.replica_pool - test.blacklisting - pool.instance_variable_get('@blacklist_errors') << StandardError.new('some connection issue') - pool.connections.each(&:_makara_blacklist!) + test.blocklisting + pool.instance_variable_get('@blocklist_errors') << StandardError.new('some connection issue') + pool.connections.each(&:_makara_blocklist!) pool.provide else test.using_primary @@ -181,14 +181,14 @@ end end - it 'should raise the error and whitelist all connections if everything is blacklisted (start over)' do + it 'should raise the error and allowlist all connections if everything is blocklisted (start over)' do proxy.ping # weird setup to allow for the correct - proxy.replica_pool.connections.each(&:_makara_blacklist!) - proxy.replica_pool.instance_variable_get('@blacklist_errors') << StandardError.new('some replica connection issue') - proxy.primary_pool.connections.each(&:_makara_blacklist!) - proxy.primary_pool.instance_variable_get('@blacklist_errors') << StandardError.new('some primary connection issue') + proxy.replica_pool.connections.each(&:_makara_blocklist!) + proxy.replica_pool.instance_variable_get('@blocklist_errors') << StandardError.new('some replica connection issue') + proxy.primary_pool.connections.each(&:_makara_blocklist!) + proxy.primary_pool.instance_variable_get('@blocklist_errors') << StandardError.new('some primary connection issue') allow(proxy).to receive(:_appropriate_pool).and_return(proxy.replica_pool, proxy.primary_pool) @@ -196,12 +196,12 @@ proxy.send(:appropriate_pool, :execute, ['select * from users']) do |pool| pool.provide{|c| c } end - rescue Makara::Errors::AllConnectionsBlacklisted => e - expect(e.message).to eq('[Makara/primary] All connections are blacklisted -> some primary connection issue -> [Makara/replica] All connections are blacklisted -> some replica connection issue') + rescue Makara::Errors::AllConnectionsBlocklisted => e + expect(e.message).to eq('[Makara/primary] All connections are blocklisted -> some primary connection issue -> [Makara/replica] All connections are blocklisted -> some replica connection issue') end - proxy.replica_pool.connections.each{|con| expect(con._makara_blacklisted?).to eq(false) } - proxy.primary_pool.connections.each{|con| expect(con._makara_blacklisted?).to eq(false) } + proxy.replica_pool.connections.each{|con| expect(con._makara_blocklisted?).to eq(false) } + proxy.primary_pool.connections.each{|con| expect(con._makara_blocklisted?).to eq(false) } end end end diff --git a/spec/strategies/priority_failover_spec.rb b/spec/strategies/priority_failover_spec.rb index c1636206..67fe8f04 100644 --- a/spec/strategies/priority_failover_spec.rb +++ b/spec/strategies/priority_failover_spec.rb @@ -3,7 +3,7 @@ describe Makara::Strategies::PriorityFailover do let(:proxy){ FakeProxy.new({makara: pool_config.merge(makara_config).merge(connections: [])}) } let(:pool){ Makara::Pool.new('primary', proxy) } - let(:pool_config){ {blacklist_duration: 5} } + let(:pool_config){ {blocklist_duration: 5} } let(:makara_config) { { primary_strategy: 'failover' } } let(:strategy) { pool.strategy } @@ -37,7 +37,7 @@ pool.provide do |connection| if connection == wrapper_a - raise Makara::Errors::BlacklistConnection.new(wrapper_a, StandardError.new('failure')) + raise Makara::Errors::BlocklistConnection.new(wrapper_a, StandardError.new('failure')) end end diff --git a/spec/strategies/round_robin_spec.rb b/spec/strategies/round_robin_spec.rb index 11e0a7ab..6d08d30c 100644 --- a/spec/strategies/round_robin_spec.rb +++ b/spec/strategies/round_robin_spec.rb @@ -3,7 +3,7 @@ describe Makara::Strategies::RoundRobin do let(:proxy){ FakeProxy.new({makara: pool_config.merge(makara_config).merge(connections: [])}) } let(:pool){ Makara::Pool.new('test', proxy) } - let(:pool_config){ {blacklist_duration: 5} } + let(:pool_config){ {blocklist_duration: 5} } let(:makara_config) { {} } let(:strategy) { pool.strategy } @@ -50,7 +50,7 @@ pool.provide do |connection| if connection == wrapper_a - raise Makara::Errors::BlacklistConnection.new(wrapper_a, StandardError.new('failure')) + raise Makara::Errors::BlocklistConnection.new(wrapper_a, StandardError.new('failure')) end end diff --git a/spec/strategies/shard_aware_spec.rb b/spec/strategies/shard_aware_spec.rb index ded81ba1..1ed31606 100644 --- a/spec/strategies/shard_aware_spec.rb +++ b/spec/strategies/shard_aware_spec.rb @@ -13,7 +13,7 @@ def with_shard(shard_id) describe "failover strategy with shard awareness," do let(:proxy){ FakeProxy.new({makara: pool_config.merge(makara_config).merge(connections: [])}) } let(:pool){ Makara::Pool.new('primary', proxy) } - let(:pool_config){ { blacklist_duration: 5} } + let(:pool_config){ { blocklist_duration: 5} } let(:makara_config) { { primary_strategy: 'failover', primary_shard_aware: true, @@ -87,7 +87,7 @@ def with_shard(shard_id) with_shard('shard1') do pool.provide do |connection| if connection == wrapper_a - raise Makara::Errors::BlacklistConnection.new(wrapper_a, StandardError.new('failure')) + raise Makara::Errors::BlocklistConnection.new(wrapper_a, StandardError.new('failure')) end end expect(strategy.current.something).to eql('b') @@ -110,7 +110,7 @@ def with_shard(shard_id) describe "round_robin strategy with shard awareness," do let(:proxy){ FakeProxy.new({makara: pool_config.merge(makara_config).merge(connections: [])}) } let(:pool){ Makara::Pool.new('primary', proxy) } - let(:pool_config){ { blacklist_duration: 5} } + let(:pool_config){ { blocklist_duration: 5} } let(:makara_config) { { primary_strategy: 'round_robin', primary_shard_aware: true, @@ -162,7 +162,7 @@ def with_shard(shard_id) with_shard('shard1') do pool.provide do |connection| if connection == wrapper_a - raise Makara::Errors::BlacklistConnection.new(wrapper_a, StandardError.new('failure')) + raise Makara::Errors::BlocklistConnection.new(wrapper_a, StandardError.new('failure')) end end expect(strategy.current.something).to eql('b') @@ -187,7 +187,7 @@ def with_shard(shard_id) describe "uses the configured failover strategy when shard_aware set to false," do let(:proxy){ FakeProxy.new({makara: pool_config.merge(makara_config).merge(connections: [])}) } let(:pool){ Makara::Pool.new('primary', proxy) } - let(:pool_config){ { blacklist_duration: 5} } + let(:pool_config){ { blocklist_duration: 5} } let(:makara_config) { { primary_strategy: 'failover', primary_shard_aware: false, @@ -203,7 +203,7 @@ def with_shard(shard_id) describe "uses the configured roundrobin strategy when shard_aware set to false," do let(:proxy){ FakeProxy.new({makara: pool_config.merge(makara_config).merge(connections: [])}) } let(:pool){ Makara::Pool.new('primary', proxy) } - let(:pool_config){ { blacklist_duration: 5} } + let(:pool_config){ { blocklist_duration: 5} } let(:makara_config) { { primary_strategy: 'round_robin', primary_shard_aware: false, diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index 3909065d..21e01346 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -2,9 +2,9 @@ module SpecHelpers def establish_connection(config) connection = ActiveRecord::Base.establish_connection(config) - # make sure these are all reset to not be blacklisted - ActiveRecord::Base.connection.replica_pool.connections.each(&:_makara_whitelist!) - ActiveRecord::Base.connection.primary_pool.connections.each(&:_makara_whitelist!) + # make sure these are all reset to not be blocklisted + ActiveRecord::Base.connection.replica_pool.connections.each(&:_makara_allowlist!) + ActiveRecord::Base.connection.primary_pool.connections.each(&:_makara_allowlist!) ActiveRecord::Base.connection end @@ -17,7 +17,7 @@ def config(primaries = 1, replicas = 2) makara: { # Defaults: # :primary_ttl => 5, - # :blacklist_duration => 30, + # :blocklist_duration => 30, # :sticky => true id: 'mock_mysql', connections: connections