Skip to content

Commit 0bd9fb5

Browse files
connection_pool: introduce connection pool
Introduce ConnectionPool class to work with cluster of Tarantool instances. ConnectionPool support master discovery and ro/rw-based requests, so it is most useful while working with a single replicaset of instances. ConnectionPool is supported only for Python 3.7 or newer. User used to connect must be able to call `box.info` on instances. ConnectionPool updates information about each server state (RO/RW) on initial connect and then asynchronously in separate threads. Application retries must be written considering the asynchronous nature of cluster state refresh. User does not need to use any synchronization mechanisms in requests, it's all handled with ConnectionPool methods. ConnectionPool API is the same as a plain Connection API. On each request, a connection is selected to execute this request. Connection is selected based on request mode: * Mode.RW selects an RW instance. * Mode.PREFER_RW selects an RW instance, if possible, RO instance otherwise. * Mode.PREFER_RO selects an RO instance, if possible, RW instance otherwise. All requests that are guaranteed to write (insert, replace, delete, upsert, update) use RW mode. For any other type of request (call, eval, execute, ping, select) mode could be set explicitly. pool.call('some_write_procedure', args, mode=tarantool.Mode.RW) Closes #196
1 parent 3f9983c commit 0bd9fb5

File tree

7 files changed

+812
-9
lines changed

7 files changed

+812
-9
lines changed

Diff for: tarantool/__init__.py

+5
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,8 @@ def connectmesh(addrs=({'host': 'localhost', 'port': 3301},), user=None,
8080
__all__ = ['connect', 'Connection', 'connectmesh', 'MeshConnection', 'Schema',
8181
'Error', 'DatabaseError', 'NetworkError', 'NetworkWarning',
8282
'SchemaError', 'dbapi']
83+
84+
# ConnectionPool is supported only for Python 3.7 or newer.
85+
if sys.version_info.major >= 3 and sys.version_info.minor >= 7:
86+
from tarantool.connection_pool import ConnectionPool, Mode
87+
__all__.extend(['ConnectionPool', 'Mode'])

0 commit comments

Comments
 (0)