Skip to content

Commit 115bdbd

Browse files
authored
Merge pull request apache#690 from mambocab/timer-logic
PYTHON-644 - Timer logic
2 parents ae39242 + 8aeb926 commit 115bdbd

2 files changed

Lines changed: 7 additions & 10 deletions

File tree

cassandra/cluster.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3285,6 +3285,7 @@ def __init__(self, session, message, query, timeout, metrics=None, prepared_stat
32853285
self._errbacks = []
32863286
self._spec_execution_plan = speculative_execution_plan or self._spec_execution_plan
32873287
self.attempted_hosts = []
3288+
self._start_timer()
32883289

32893290
def _start_timer(self):
32903291
if self._timer is None:
@@ -3339,11 +3340,6 @@ def send_request(self, error_no_hosts=True):
33393340
req_id = self._query(host)
33403341
if req_id is not None:
33413342
self._req_id = req_id
3342-
3343-
# timer is only started here, after we have at least one message queued
3344-
# this is done to avoid overrun of timers with unfettered client requests
3345-
# in the case of full disconnect, where no hosts will be available
3346-
self._start_timer()
33473343
return True
33483344
if self.timeout is not None and time.time() - self._start_time > self.timeout:
33493345
self._on_timeout()
@@ -3462,7 +3458,7 @@ def start_fetching_next_page(self):
34623458
self._event.clear()
34633459
self._final_result = _NOT_SET
34643460
self._final_exception = None
3465-
self._timer = None # clear cancelled timer; new one will be set when request is queued
3461+
self._start_timer()
34663462
self.send_request()
34673463

34683464
def _reprepare(self, prepare_message, host, connection, pool):
@@ -3620,6 +3616,7 @@ def _set_result(self, host, connection, pool, response):
36203616
# we got some other kind of response message
36213617
msg = "Got unexpected message: %r" % (response,)
36223618
exc = ConnectionException(msg, host)
3619+
self._cancel_timer()
36233620
self._connection.defunct(exc)
36243621
self._set_final_exception(exc)
36253622
except Exception as exc:

tests/unit/test_cluster.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def test_default_legacy(self):
184184
self._verify_response_future_profile(rf, expected_profile)
185185

186186
def test_default_profile(self):
187-
non_default_profile = ExecutionProfile(RoundRobinPolicy(), *[object() for _ in range(5)])
187+
non_default_profile = ExecutionProfile(RoundRobinPolicy(), *[object() for _ in range(3)])
188188
cluster = Cluster(execution_profiles={'non-default': non_default_profile})
189189
session = Session(cluster, hosts=[])
190190

@@ -218,7 +218,7 @@ def test_statement_params_override_legacy(self):
218218
self._verify_response_future_profile(rf, expected_profile)
219219

220220
def test_statement_params_override_profile(self):
221-
non_default_profile = ExecutionProfile(RoundRobinPolicy(), *[object() for _ in range(5)])
221+
non_default_profile = ExecutionProfile(RoundRobinPolicy(), *[object() for _ in range(3)])
222222
cluster = Cluster(execution_profiles={'non-default': non_default_profile})
223223
session = Session(cluster, hosts=[])
224224

@@ -284,15 +284,15 @@ def test_no_legacy_with_profile(self):
284284

285285
def test_profile_name_value(self):
286286

287-
internalized_profile = ExecutionProfile(RoundRobinPolicy(), *[object() for _ in range(5)])
287+
internalized_profile = ExecutionProfile(RoundRobinPolicy(), *[object() for _ in range(3)])
288288
cluster = Cluster(execution_profiles={'by-name': internalized_profile})
289289
session = Session(cluster, hosts=[])
290290
self.assertEqual(cluster._config_mode, _ConfigMode.PROFILES)
291291

292292
rf = session.execute_async("query", execution_profile='by-name')
293293
self._verify_response_future_profile(rf, internalized_profile)
294294

295-
by_value = ExecutionProfile(RoundRobinPolicy(), *[object() for _ in range(5)])
295+
by_value = ExecutionProfile(RoundRobinPolicy(), *[object() for _ in range(3)])
296296
rf = session.execute_async("query", execution_profile=by_value)
297297
self._verify_response_future_profile(rf, by_value)
298298

0 commit comments

Comments
 (0)