Skip to content

Commit

Permalink
Support cluster discovery in MeshConnection
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
denis-ignatenko authored and Totktonada committed Jun 10, 2019
1 parent e98c377 commit 4dfe5f9
Show file tree
Hide file tree
Showing 8 changed files with 587 additions and 27 deletions.
8 changes: 8 additions & 0 deletions doc/api/class-mesh-connection.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

.. currentmodule:: tarantool.mesh_connection

class :class:`MeshConnection`
-----------------------------

.. autoclass:: MeshConnection

1 change: 1 addition & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ API Reference

api/module-tarantool.rst
api/class-connection.rst
api/class-mesh-connection.rst
api/class-space.rst
api/class-response.rst

Expand Down
1 change: 1 addition & 0 deletions doc/index.ru.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

api/module-tarantool.rst
api/class-connection.rst
api/class-mesh-connection.rst
api/class-space.rst
api/class-response.rst

Expand Down
2 changes: 2 additions & 0 deletions tarantool/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,5 @@
RECONNECT_MAX_ATTEMPTS = 10
# Default delay between attempts to reconnect (seconds)
RECONNECT_DELAY = 0.1
# Default cluster nodes list refresh interval (seconds)
CLUSTER_DISCOVERY_DELAY = 60
12 changes: 12 additions & 0 deletions tarantool/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ class InterfaceError(Error):
'''


class ConfigurationError(Error):
'''
Error of initialization with a user-provided configuration.
'''


# Monkey patch os.strerror for win32
if sys.platform == "win32":
# Windows Sockets Error Codes (not all, but related on network errors)
Expand Down Expand Up @@ -152,6 +158,11 @@ class NetworkWarning(UserWarning):
pass


class ClusterDiscoveryWarning(UserWarning):
'''Warning related to cluster discovery'''
pass


# always print this warnings
warnings.filterwarnings("always", category=NetworkWarning)

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


_strerror = {
0: ("ER_UNKNOWN", "Unknown error"),
1: ("ER_ILLEGAL_PARAMS", "Illegal parameters, %s"),
Expand Down
Loading

0 comments on commit 4dfe5f9

Please sign in to comment.