Skip to content

Commit 4dfe5f9

Browse files
denis-ignatenkoTotktonada
authored andcommitted
Support cluster discovery in MeshConnection
This feature adds the new optional arguments to the MeshConnection contructor: * `cluster_discovery_function` -- a name of the function which will be periodically called on a currently connected tarantool instance to update a list of MeshConnection addresses. * `cluster_discovery_delay` -- minimal amount of seconds between address list updates (default is 60 seconds). The update of addresses is performed right after successful connecting and before performing a request (if a minimal time passes). This commits changes the round robin retry strategy. Before it performs two attempts to connect to each address reconnect_max_attempts times (3 by default), now it do that only once. The new type of error is added: ConfigurationError. It is risen when a user provides incorrect configuration: say, one of provided addresses is not correct. The new type of warning is added: ClusterDiscoveryWarning. This warning is shown when a something went wrong during cluster discovery: say, one of returned addresses is not correct. Note the difference: a user provided configuration verified strictly, while a cluster discovery function result is filtered (with warnings) and good addresses are applied (if the list is not empty). Aside of the new functionality this commit improves compatibility of MeshConnection API with Connection. The following arguments are added to the MeshConnection constructor: `host`, `port`, `call_16`, `connection_timeout`. An address from `host` / `port` arguments is added to `addrs` (if provided) as the first item. Fixes #134.
1 parent e98c377 commit 4dfe5f9

File tree

8 files changed

+587
-27
lines changed

8 files changed

+587
-27
lines changed

doc/api/class-mesh-connection.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
.. currentmodule:: tarantool.mesh_connection
3+
4+
class :class:`MeshConnection`
5+
-----------------------------
6+
7+
.. autoclass:: MeshConnection
8+

doc/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ API Reference
4040

4141
api/module-tarantool.rst
4242
api/class-connection.rst
43+
api/class-mesh-connection.rst
4344
api/class-space.rst
4445
api/class-response.rst
4546

doc/index.ru.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
api/module-tarantool.rst
4242
api/class-connection.rst
43+
api/class-mesh-connection.rst
4344
api/class-space.rst
4445
api/class-response.rst
4546

tarantool/const.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,5 @@
8686
RECONNECT_MAX_ATTEMPTS = 10
8787
# Default delay between attempts to reconnect (seconds)
8888
RECONNECT_DELAY = 0.1
89+
# Default cluster nodes list refresh interval (seconds)
90+
CLUSTER_DISCOVERY_DELAY = 60

tarantool/error.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ class InterfaceError(Error):
4343
'''
4444

4545

46+
class ConfigurationError(Error):
47+
'''
48+
Error of initialization with a user-provided configuration.
49+
'''
50+
51+
4652
# Monkey patch os.strerror for win32
4753
if sys.platform == "win32":
4854
# Windows Sockets Error Codes (not all, but related on network errors)
@@ -152,6 +158,11 @@ class NetworkWarning(UserWarning):
152158
pass
153159

154160

161+
class ClusterDiscoveryWarning(UserWarning):
162+
'''Warning related to cluster discovery'''
163+
pass
164+
165+
155166
# always print this warnings
156167
warnings.filterwarnings("always", category=NetworkWarning)
157168

@@ -166,6 +177,7 @@ def warn(message, warning_class):
166177
line_no = frame.f_lineno
167178
warnings.warn_explicit(message, warning_class, module_name, line_no)
168179

180+
169181
_strerror = {
170182
0: ("ER_UNKNOWN", "Unknown error"),
171183
1: ("ER_ILLEGAL_PARAMS", "Illegal parameters, %s"),

0 commit comments

Comments
 (0)