(POOLER-184) Pool manager retry and exit on failure

Adding a reconnect retry for redis, which by default would retry 10 times,
for a total wait time of ~80 seconds
This commit is contained in:
Samuel Beaulieu 2020-09-02 11:12:29 -05:00
parent bdf77a9e33
commit a35d66c606
3 changed files with 14 additions and 5 deletions

View file

@ -9,6 +9,7 @@ redis_port = config[:redis]['port']
redis_password = config[:redis]['password'] redis_password = config[:redis]['password']
redis_connection_pool_size = config[:redis]['connection_pool_size'] redis_connection_pool_size = config[:redis]['connection_pool_size']
redis_connection_pool_timeout = config[:redis]['connection_pool_timeout'] redis_connection_pool_timeout = config[:redis]['connection_pool_timeout']
redis_reconnect_attempts = config[:redis]['reconnect_attempts'] || 10
logger_file = config[:config]['logfile'] logger_file = config[:config]['logfile']
logger = Vmpooler::Logger.new logger_file logger = Vmpooler::Logger.new logger_file
@ -43,7 +44,7 @@ if torun.include? :manager
Vmpooler::PoolManager.new( Vmpooler::PoolManager.new(
config, config,
logger, logger,
Vmpooler.redis_connection_pool(redis_host, redis_port, redis_password, redis_connection_pool_size, redis_connection_pool_timeout, metrics), Vmpooler.redis_connection_pool(redis_host, redis_port, redis_password, redis_connection_pool_size, redis_connection_pool_timeout, metrics, redis_reconnect_attempts),
metrics metrics
).execute! ).execute!
end end

View file

@ -164,7 +164,7 @@ module Vmpooler
pools pools
end end
def self.redis_connection_pool(host, port, password, size, timeout, metrics) def self.redis_connection_pool(host, port, password, size, timeout, metrics, redis_reconnect_attempts = 0)
Vmpooler::PoolManager::GenericConnectionPool.new( Vmpooler::PoolManager::GenericConnectionPool.new(
metrics: metrics, metrics: metrics,
connpool_type: 'redis_connection_pool', connpool_type: 'redis_connection_pool',
@ -173,13 +173,14 @@ module Vmpooler
timeout: timeout timeout: timeout
) do ) do
connection = Concurrent::Hash.new connection = Concurrent::Hash.new
redis = new_redis(host, port, password) redis = new_redis(host, port, password, redis_reconnect_attempts)
connection['connection'] = redis connection['connection'] = redis
end end
end end
def self.new_redis(host = 'localhost', port = nil, password = nil) def self.new_redis(host = 'localhost', port = nil, password = nil, redis_reconnect_attempts = 10)
Redis.new(host: host, port: port, password: password) Redis.new(host: host, port: port, password: password, reconnect_attempts: redis_reconnect_attempts, reconnect_delay: 1.5,
reconnect_delay_max: 10.0)
end end
def self.pools(conf) def self.pools(conf)

View file

@ -25,6 +25,13 @@ describe 'GenericConnectionPool' do
connection: 'connection' connection: 'connection'
}} }}
it 'should error out when connection pool could not establish no nothing' do
newsub = Vmpooler.redis_connection_pool("foo,bar", "1234", "fuba", 1, 1, metrics, 0)
expect { newsub.with_metrics do |conn_pool_object|
conn_pool_object.srem('foo', "bar")
end }.to raise_error Redis::CannotConnectError
end
it 'should return a connection object when grabbing one from the pool' do it 'should return a connection object when grabbing one from the pool' do
subject.with_metrics do |conn_pool_object| subject.with_metrics do |conn_pool_object|
expect(conn_pool_object).to be(connection_object) expect(conn_pool_object).to be(connection_object)