Skip to content

Commit dade2d6

Browse files
isapegoivandasch
andauthored
IGNITE-14245 Fix infinite loop while trying to get affinity mapping on failed node (#30)
(cherry picked from commit 6f56a3b) Co-authored-by: Ivan Dashchinskiy <ivandasch@gmail.com>
1 parent c10294e commit dade2d6

4 files changed

Lines changed: 98 additions & 25 deletions

File tree

.travis.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#
2+
# Copyright 2021 GridGain Systems, Inc. and Contributors.
3+
#
4+
# Licensed under the GridGain Community Edition License (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# https://www.gridgain.com/products/software/community-edition/gridgain-community-edition-license
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
language: python
18+
sudo: required
19+
20+
addons:
21+
apt:
22+
packages:
23+
- openjdk-8-jdk
24+
25+
env:
26+
global:
27+
- IGNITE_VERSION=2.9.1
28+
- IGNITE_HOME=/opt/ignite
29+
30+
before_install:
31+
- curl -L https://apache-mirror.rbc.ru/pub/apache/ignite/${IGNITE_VERSION}/apache-ignite-slim-${IGNITE_VERSION}-bin.zip > ignite.zip
32+
- unzip ignite.zip -d /opt
33+
- mv /opt/apache-ignite-slim-${IGNITE_VERSION}-bin /opt/ignite
34+
- mv /opt/ignite/libs/optional/ignite-log4j2 /opt/ignite/libs/
35+
36+
jobs:
37+
include:
38+
- python: '3.6'
39+
arch: amd64
40+
env: TOXENV=py36
41+
- python: '3.7'
42+
arch: amd64
43+
env: TOXENV=py37
44+
- python: '3.8'
45+
arch: amd64
46+
env: TOXENV=py38
47+
- python: '3.9'
48+
arch: amd64
49+
env: TOXENV=py39
50+
51+
install: pip install tox
52+
script: tox

pygridgain/cache.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ def get_best_node(
264264
break
265265
except connection_errors:
266266
# retry if connection failed
267+
conn = self._client.random_node
267268
pass
268269
except CacheError:
269270
# server did not create mapping in time

tests/affinity/conftest.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
from pygridgain.api import cache_create, cache_destroy
2020
from tests.util import start_ignite_gen
2121

22+
# Sometimes on slow testing servers and unstable topology
23+
# default timeout is not enough for cache ops.
24+
CLIENT_SOCKET_TIMEOUT = 20.0
25+
2226

2327
@pytest.fixture(scope='module', autouse=True)
2428
def server1():
@@ -37,7 +41,7 @@ def server3():
3741

3842
@pytest.fixture
3943
def client():
40-
client = Client(partition_aware=True)
44+
client = Client(partition_aware=True, timeout=CLIENT_SOCKET_TIMEOUT)
4145

4246
client.connect([('127.0.0.1', 10800 + i) for i in range(1, 4)])
4347

@@ -48,7 +52,7 @@ def client():
4852

4953
@pytest.fixture
5054
def client_not_connected():
51-
client = Client(partition_aware=True)
55+
client = Client(partition_aware=True, timeout=CLIENT_SOCKET_TIMEOUT)
5256
yield client
5357
client.close()
5458

tests/affinity/test_affinity_bad_servers.py

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,45 +16,61 @@
1616
import pytest
1717

1818
from pygridgain.exceptions import ReconnectError
19-
from tests.util import start_ignite, kill_process_tree
19+
from tests.affinity.conftest import CLIENT_SOCKET_TIMEOUT
20+
from tests.util import start_ignite, kill_process_tree, get_client
2021

22+
@pytest.fixture(params=['with-partition-awareness', 'without-partition-awareness'])
23+
def with_partition_awareness(request):
24+
yield request.param == 'with-partition-awareness'
2125

22-
def test_client_with_multiple_bad_servers(client_not_connected):
26+
27+
def test_client_with_multiple_bad_servers(with_partition_awareness):
2328
with pytest.raises(ReconnectError) as e_info:
24-
client_not_connected.connect([("127.0.0.1", 10900), ("127.0.0.1", 10901)])
29+
with get_client(partition_aware=with_partition_awareness) as client:
30+
client.connect([("127.0.0.1", 10900), ("127.0.0.1", 10901)])
2531
assert str(e_info.value) == "Can not connect."
2632

2733

28-
def test_client_with_failed_server(request, client_not_connected):
34+
def test_client_with_failed_server(request, with_partition_awareness):
2935
srv = start_ignite(idx=4)
3036
try:
31-
client_not_connected.connect([("127.0.0.1", 10804)])
32-
cache = client_not_connected.get_or_create_cache(request.node.name)
33-
cache.put(1, 1)
34-
kill_process_tree(srv.pid)
35-
with pytest.raises(ConnectionResetError):
36-
cache.get(1)
37+
with get_client(partition_aware=with_partition_awareness) as client:
38+
client.connect([("127.0.0.1", 10804)])
39+
cache = client.get_or_create_cache(request.node.name)
40+
cache.put(1, 1)
41+
kill_process_tree(srv.pid)
42+
43+
if with_partition_awareness:
44+
ex_class = (ReconnectError, ConnectionResetError)
45+
else:
46+
ex_class = ConnectionResetError
47+
48+
with pytest.raises(ex_class):
49+
cache.get(1)
3750
finally:
3851
kill_process_tree(srv.pid)
3952

4053

41-
def test_client_with_recovered_server(request, client_not_connected):
54+
def test_client_with_recovered_server(request, with_partition_awareness):
4255
srv = start_ignite(idx=4)
4356
try:
44-
client_not_connected.connect([("127.0.0.1", 10804)])
45-
cache = client_not_connected.get_or_create_cache(request.node.name)
46-
cache.put(1, 1)
57+
with get_client(partition_aware=with_partition_awareness, timeout=CLIENT_SOCKET_TIMEOUT) as client:
58+
client.connect([("127.0.0.1", 10804)])
59+
cache = client.get_or_create_cache(request.node.name)
60+
cache.put(1, 1)
4761

48-
# Kill and restart server
49-
kill_process_tree(srv.pid)
50-
srv = start_ignite(idx=4)
62+
# Kill and restart server
63+
kill_process_tree(srv.pid)
64+
srv = start_ignite(idx=4)
5165

52-
# First request fails
53-
with pytest.raises(Exception):
54-
cache.put(1, 2)
66+
# First request may fail.
67+
try:
68+
cache.put(1, 2)
69+
except:
70+
pass
5571

56-
# Retry succeeds
57-
cache.put(1, 2)
58-
assert cache.get(1) == 2
72+
# Retry succeeds
73+
cache.put(1, 2)
74+
assert cache.get(1) == 2
5975
finally:
6076
kill_process_tree(srv.pid)

0 commit comments

Comments
 (0)