Skip to content

Commit f840bef

Browse files
georgiy-belyaninTotktonada
authored andcommitted
connpool: add method to get conn in internal pool
This patch introduces a supplementary method in the internal pool used within the `experimental.connpool` module. Previously, there was only one method for getting a connection to instance that also tried to reconnect on fail. This commit introduces a method that only gets the existing connections and reuses it in a variety of places where it is meant. It, actually, affects behavior a little bit. For instance, in `connpool.call()` the idle timeout is calculated from the earlier point in the time when it accesses the candidates satisfying the static requirements. It is no longer bumped when `call()` finds a suitable candidate and checks if it satisfies dynamic requirements. Though it does not affect the behavior a lot due to tight timings. It also simplifies the logic of checking dynamic options. They no longer establish a connection to instance. Instead they try to access. Needed for tarantool#10330 NO_CHANGELOG=small behavior change, not released yet NO_TEST=will be tested later NO_DOC=small behavior change
1 parent fa0540b commit f840bef

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/box/lua/connpool.lua

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ function pool_methods._failed_connection_watchdog_wake(self)
159159
self._failed_connection_watchdog_fiber = f
160160
end
161161

162+
--- Get a cached connection to instance. Might be nil.
163+
function pool_methods.get_connection(self, instance_name)
164+
return self._connections[instance_name]
165+
end
166+
162167
--- Connect to an instance or receive a cached connection by
163168
--- name.
164169
---
@@ -443,15 +448,15 @@ local function is_mode_match(mode, instance_name)
443448
if mode == nil then
444449
return true
445450
end
446-
local conn = pool:connect(instance_name, {wait_connected = false})
451+
local conn = pool:get_connection(instance_name)
447452
assert(conn ~= nil and conn:mode() ~= nil)
448453
return conn:mode() == mode
449454
end
450455

451456
local function is_candidate_match_dynamic(instance_name, opts)
452457
assert(opts ~= nil and type(opts) == 'table')
453458

454-
local conn = pool:connect(instance_name, {wait_connected = false})
459+
local conn = pool:get_connection(instance_name)
455460
if not conn or conn:mode() == nil then
456461
return
457462
end
@@ -623,7 +628,7 @@ local function get_connection(opts)
623628
local mode = opts.mode == 'prefer_ro' and 'ro' or 'rw'
624629
local weight_mode = 2
625630
for _, instance_name in pairs(candidates) do
626-
local conn = pool:connect(instance_name, {wait_connected = false})
631+
local conn = pool:get_connection(instance_name)
627632
assert(conn ~= nil)
628633
if conn:mode() == mode then
629634
weights[instance_name] = weights[instance_name] + weight_mode
@@ -656,8 +661,7 @@ local function get_connection(opts)
656661
while #preferred_candidates > 0 do
657662
local n = math.random(#preferred_candidates)
658663
local instance_name = table.remove(preferred_candidates, n)
659-
local conn = pool:connect(instance_name,
660-
{wait_connected = false})
664+
local conn = pool:get_connection(instance_name)
661665
if conn:wait_connected() then
662666
return conn
663667
end

0 commit comments

Comments
 (0)