Skip to content

Implement reconnection strategy class - #109

Merged
kbelyavs merged 3 commits into
masterfrom
kbelyavs/gh-106
Oct 16, 2018
Merged

kbelyavs merged 3 commits into
masterfrom
kbelyavs/gh-106

Conversation

@kbelyavs

Copy link
Copy Markdown
Contributor

Extend base Connection class to support a list of nodes and an
optional Strategy parameter to choose next item from this list.

Add built-in reconnect strategy class based on Round-Robin alg.
@params:

  • peers

Return next connection or an error if all URIs are unavailable.

Closes #106

@kbelyavs
kbelyavs requested a review from Totktonada September 19, 2018 17:36
Comment thread client.py Resolved
Comment thread client.py Resolved
Comment thread client.py Resolved
Comment thread client.py Resolved
@Totktonada

Copy link
Copy Markdown
Contributor
$ flake8 tarantool/__init__.py tarantool/mesh_connection.py 
tarantool/__init__.py:53:1: E302 expected 2 blank lines, found 1
tarantool/mesh_connection.py:16:1: E302 expected 2 blank lines, found 1
tarantool/mesh_connection.py:26:1: E302 expected 2 blank lines, found 1
tarantool/mesh_connection.py:38:9: F841 local variable 'addr' is assigned to but never used
tarantool/mesh_connection.py:45:33: E128 continuation line under-indented for visual indent
tarantool/mesh_connection.py:46:33: E128 continuation line under-indented for visual indent
tarantool/mesh_connection.py:47:33: E128 continuation line under-indented for visual indent

@Totktonada

Copy link
Copy Markdown
Contributor
$ flake8 test/cluster-py/*.py
test/cluster-py/multi.test.py:18:1: E302 expected 2 blank lines, found 1
test/cluster-py/multi.test.py:30:27: E999 SyntaxError: invalid syntax
test/cluster-py/multi.test.py:41:1: E305 expected 2 blank lines after class or function definition, found 1
test/cluster-py/multi.test.py:52:12: E201 whitespace after '['
test/cluster-py/multi.test.py:52:19: E202 whitespace before ']'
test/cluster-py/multi.test.py:66:67: E251 unexpected spaces around keyword / parameter equals
test/cluster-py/multi.test.py:66:69: E251 unexpected spaces around keyword / parameter equals
test/cluster-py/multi.test.py:100:23: E251 unexpected spaces around keyword / parameter equals
test/cluster-py/multi.test.py:100:25: E251 unexpected spaces around keyword / parameter equals
test/cluster-py/multi.test.py:100:45: E251 unexpected spaces around keyword / parameter equals
test/cluster-py/multi.test.py:100:47: E251 unexpected spaces around keyword / parameter equals

Comment thread tarantool/__init__.py Outdated
'''
Create a connection to the mesh of Tarantool servers.

:param str addrs: A map of server hostname or IP-address and a port.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description is a bit unprecise: it is a tuple / a list of maps.

Comment thread tarantool/mesh_connection.py Outdated
reconnect_delay=RECONNECT_DELAY,
connect_now=True,
encoding=ENCODING_DEFAULT,
Strategy=RoundRobinStrategy):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is unusual to start a parameter name and / or a class field name from an uppercase letter in Python. From the other side, it is a reference to a class, so I don't sure what is better to do.

Comment thread testclient.py Outdated
@@ -0,0 +1,23 @@
#!/usr/bin/env python

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should add and then remove it.

Comment thread test/.tarantoolctl Resolved
Comment thread test/cluster-py/multi.test.py Outdated
import time
import yaml
from lib.tarantool_server import TarantoolServer
from tarantool import MeshConnection

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These imports do not work for me.

Comment thread test/cluster-py/multi.test.py Outdated
while True:
try:
x = con.ping()
print 'ping Ok'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to use python-3-style prints, because it is universal.

Comment thread test/cluster-py/multi.test.py Resolved
Comment thread test/cluster-py/replica.lua Outdated
@@ -0,0 +1,13 @@
#!/usr/bin/env tarantool
box_cfg_done = false

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is not used.

Comment thread test/cluster-py/suite.ini Outdated
[default]
core = tarantool
script = master.lua
description = tarantool/box, replication

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Description seems to be not about the suite we have here.

Extend base Connection class to support a list of nodes and an
optional Strategy parameter to choose next item from this list.

Add built-in reconnect strategy class based on Round-Robin alg.
@params:
- addrs, list of maps {'host':(HOSTNAME|IP_ADDR), 'port':PORT}.

Return next connection or an error if all URIs are unavailable.

Closes #106
@kbelyavs
kbelyavs force-pushed the kbelyavs/gh-106 branch 4 times, most recently from e6634a3 to fb256f1 Compare October 8, 2018 10:23

@Totktonada Totktonada left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments re testing are below.

I think we can setup CI with make install for now (and merge the PR) and file a follow up issue to use the connector from the repository during make test / cd test && ./test-run.py.

Comment thread test/cluster-py/multi.test.py Outdated
host, port = addr.split(':')
addrs.append({'host': host, 'port': int(port)})

thread = Thread(target=check_cluster, args=(addrs, ))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to create purely sequencial test and don't lean on timings. Like so (schematically):

setup instances
setup mesh connection
perform select
stop instance 1
perform select
stop instance 2
start instance 1
perform select
stop instance 1
perform select

Comment thread test/cluster-py/multi.test.py Resolved
Comment thread test/cluster-py/multi.test.py Resolved
Comment thread Makefile Resolved
Comment thread test/cluster-py/replica.lua Outdated
local SOCKET_DIR = require('fio').cwd()

local function instance_uri(instance_id)
return SOCKET_DIR..'/autobootstrap'..instance_id..'.sock';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why replica? Why autobootstrap? Why multi?

I think we should adjust naming.

Comment thread test/cluster-py/multi.test.py Resolved
@Totktonada

Copy link
Copy Markdown
Contributor

I'll ok after:

  • Handle CI somehow (issue at least).
  • Use appropriate naming in the test (replica, multi, autobootstrap → ...).

Also I think we can use default server as the first instance in the test (and setup one more).

Please, proceed with that and merge. I don't think I should look into that again.

@kbelyavs
kbelyavs merged commit 14f52b5 into master Oct 16, 2018
@Totktonada
Totktonada deleted the kbelyavs/gh-106 branch February 19, 2019 10:52
@Totktonada Totktonada mentioned this pull request Feb 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants