mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
allow new connections right away if pool can be increased
This commit is contained in:
parent
56aa10c54d
commit
3a7c801ece
2 changed files with 13 additions and 0 deletions
|
@ -87,4 +87,14 @@ describe DB::Database do
|
|||
DummyDriver::DummyConnection.connections.size.should eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
it "should allow new connections if pool can increased and retry is not allowed" do
|
||||
DummyDriver::DummyConnection.clear_connections
|
||||
DB.open "dummy://localhost:1027?initial_pool_size=1&max_pool_size=2&retry_attempts=0" do |db|
|
||||
db.query("stmt1")
|
||||
DummyDriver::DummyConnection.connections.size.should eq(1)
|
||||
db.query("stmt1")
|
||||
DummyDriver::DummyConnection.connections.size.should eq(2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -80,6 +80,9 @@ module DB
|
|||
# but if a new connection is needed there is a `retry_delay` seconds delay.
|
||||
def retry
|
||||
current_available = @available.size
|
||||
# if the pool hasn't reach the max size, allow 1 attempt
|
||||
# to make a new connection if needed without sleeping
|
||||
current_available += 1 if can_increase_pool
|
||||
|
||||
(current_available + @retry_attempts).times do |i|
|
||||
begin
|
||||
|
|
Loading…
Reference in a new issue