Skip to content

Commit 94c34fb

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. Authenticated user 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 chosen to execute this request. A connection is chosen based on a request mode: * Mode.ANY chooses any instance. * Mode.RW chooses an RW instance. * Mode.RO chooses an RO instance. * Mode.PREFER_RW chooses an RW instance, if possible, RO instance otherwise. * Mode.PREFER_RO chooses an RO instance, if possible, RW instance otherwise. All requests that are guaranteed to write (insert, replace, delete, upsert, update) use RW mode by default. select uses ANY by default. You can set the mode explicitly. call, eval, execute and ping requests require to set the mode explicitly. Example: pool.call('some_write_procedure', arg, mode=tarantool.Mode.RW) Closes #196
1 parent 31f6d19 commit 94c34fb

File tree

8 files changed

+1120
-8
lines changed

8 files changed

+1120
-8
lines changed

CHANGELOG.md

+29
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,35 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
### Added
1010
- Reusable testing workflow for integration with tarantool artifacts
1111
(PR #192).
12+
- Connection pool with master discovery (PR #211, #196).
13+
14+
ConnectionPool is supported only for Python 3.7 or newer.
15+
Authenticated user must be able to call `box.info` on instances.
16+
17+
ConnectionPool updates information about each server state (RO/RW)
18+
on initial connect and then asynchronously in separate threads.
19+
Application retries must be written considering the asynchronous nature
20+
of cluster state refresh. User does not need to use any synchronization
21+
mechanisms in requests, it's all handled with ConnectionPool methods.
22+
23+
ConnectionPool API is the same as a plain Connection API.
24+
On each request, a connection is chosen to execute this request.
25+
A connection is chosen based on a request mode:
26+
* Mode.ANY chooses any instance.
27+
* Mode.RW chooses an RW instance.
28+
* Mode.RO chooses an RO instance.
29+
* Mode.PREFER_RW chooses an RW instance, if possible, RO instance
30+
otherwise.
31+
* Mode.PREFER_RO chooses an RO instance, if possible, RW instance
32+
otherwise.
33+
All requests that are guaranteed to write (insert, replace, delete,
34+
upsert, update) use RW mode by default. select uses ANY by default. You
35+
can set the mode explicitly. call, eval, execute and ping requests
36+
require to set the mode explicitly.
37+
38+
Example:
39+
40+
pool.call('some_write_procedure', arg, mode=tarantool.Mode.RW)
1241

1342
### Changed
1443
- **Breaking**: drop Python 2 support (PR #207).

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)