Skip to content

Implement reconnection strategy class #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 16, 2018
Merged

Implement reconnection strategy class #109

merged 3 commits into from
Oct 16, 2018

Conversation

kbelyavs
Copy link
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
@Totktonada
Copy link
Member

$ 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
Member

$ 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

'''
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
Member

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.

reconnect_delay=RECONNECT_DELAY,
connect_now=True,
encoding=ENCODING_DEFAULT,
Strategy=RoundRobinStrategy):
Copy link
Member

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.

testclient.py Outdated
@@ -0,0 +1,23 @@
#!/usr/bin/env python
Copy link
Member

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.

import time
import yaml
from lib.tarantool_server import TarantoolServer
from tarantool import MeshConnection
Copy link
Member

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.

while True:
try:
x = con.ping()
print 'ping Ok'
Copy link
Member

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.

@@ -0,0 +1,13 @@
#!/usr/bin/env tarantool
box_cfg_done = false
Copy link
Member

Choose a reason for hiding this comment

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

Is not used.

[default]
core = tarantool
script = master.lua
description = tarantool/box, replication
Copy link
Member

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
Copy link
Member

@Totktonada Totktonada left a comment

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.

host, port = addr.split(':')
addrs.append({'host': host, 'port': int(port)})

thread = Thread(target=check_cluster, args=(addrs, ))
Copy link
Member

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

local SOCKET_DIR = require('fio').cwd()

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

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.

@Totktonada
Copy link
Member

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