Skip to content

Commit b5a23f2

Browse files
committed
fix: _set_keyspace_for_all_pools passes accumulated errors, not last pool's
When multiple connection pools set keyspace asynchronously, the completion callback was called with host_errors (errors from only the last pool to finish) instead of errors (errors accumulated across all pools). This caused all but the last-finished pool's errors to be silently dropped. Also update response_future unit tests to include the new tablet= keyword argument added to borrow_connection by the tablet lookup optimization commit.
1 parent 66a0953 commit b5a23f2

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

cassandra/cluster.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3438,7 +3438,7 @@ def pool_finished_setting_keyspace(pool, host_errors):
34383438
errors[pool.host] = host_errors
34393439

34403440
if not remaining_callbacks:
3441-
callback(host_errors)
3441+
callback(errors)
34423442

34433443
for pool in tuple(self._pools.values()):
34443444
pool._set_keyspace_for_all_conns(keyspace, pool_finished_setting_keyspace)

tests/unit/test_response_future.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def test_result_message(self):
9393
rf.send_request()
9494

9595
rf.session._pools.get.assert_called_once_with('ip1')
96-
pool.borrow_connection.assert_called_once_with(timeout=ANY, routing_key=ANY, keyspace=ANY, table=ANY)
96+
pool.borrow_connection.assert_called_once_with(timeout=ANY, routing_key=ANY, keyspace=ANY, table=ANY, tablet=ANY)
9797

9898
connection.send_msg.assert_called_once_with(rf.message, 1, cb=ANY, encoder=ProtocolHandler.encode_message, decoder=ProtocolHandler.decode_message, result_metadata=[])
9999

@@ -284,7 +284,7 @@ def test_retry_policy_says_retry(self):
284284
rf.send_request()
285285

286286
rf.session._pools.get.assert_called_once_with('ip1')
287-
pool.borrow_connection.assert_called_once_with(timeout=ANY, routing_key=ANY, keyspace=ANY, table=ANY)
287+
pool.borrow_connection.assert_called_once_with(timeout=ANY, routing_key=ANY, keyspace=ANY, table=ANY, tablet=ANY)
288288
connection.send_msg.assert_called_once_with(rf.message, 1, cb=ANY, encoder=ProtocolHandler.encode_message, decoder=ProtocolHandler.decode_message, result_metadata=[])
289289

290290
result = Mock(spec=UnavailableErrorMessage, info={})
@@ -303,7 +303,7 @@ def test_retry_policy_says_retry(self):
303303
# it should try again with the same host since this was
304304
# an UnavailableException
305305
rf.session._pools.get.assert_called_with(host)
306-
pool.borrow_connection.assert_called_with(timeout=ANY, routing_key=ANY, keyspace=ANY, table=ANY)
306+
pool.borrow_connection.assert_called_with(timeout=ANY, routing_key=ANY, keyspace=ANY, table=ANY, tablet=ANY)
307307
connection.send_msg.assert_called_with(rf.message, 2, cb=ANY, encoder=ProtocolHandler.encode_message, decoder=ProtocolHandler.decode_message, result_metadata=[])
308308

309309
def test_retry_with_different_host(self):
@@ -318,7 +318,7 @@ def test_retry_with_different_host(self):
318318
rf.send_request()
319319

320320
rf.session._pools.get.assert_called_once_with('ip1')
321-
pool.borrow_connection.assert_called_once_with(timeout=ANY, routing_key=ANY, keyspace=ANY, table=ANY)
321+
pool.borrow_connection.assert_called_once_with(timeout=ANY, routing_key=ANY, keyspace=ANY, table=ANY, tablet=ANY)
322322
connection.send_msg.assert_called_once_with(rf.message, 1, cb=ANY, encoder=ProtocolHandler.encode_message, decoder=ProtocolHandler.decode_message, result_metadata=[])
323323
assert ConsistencyLevel.QUORUM == rf.message.consistency_level
324324

@@ -337,7 +337,7 @@ def test_retry_with_different_host(self):
337337

338338
# it should try with a different host
339339
rf.session._pools.get.assert_called_with('ip2')
340-
pool.borrow_connection.assert_called_with(timeout=ANY, routing_key=ANY, keyspace=ANY, table=ANY)
340+
pool.borrow_connection.assert_called_with(timeout=ANY, routing_key=ANY, keyspace=ANY, table=ANY, tablet=ANY)
341341
connection.send_msg.assert_called_with(rf.message, 2, cb=ANY, encoder=ProtocolHandler.encode_message, decoder=ProtocolHandler.decode_message, result_metadata=[])
342342

343343
# the consistency level should be the same
@@ -982,7 +982,7 @@ def test_single_host_query_plan_exhausted_after_one_retry(self):
982982

983983
# Verify initial request was sent
984984
rf.session._pools.get.assert_called_once_with(specific_host)
985-
pool.borrow_connection.assert_called_once_with(timeout=ANY, routing_key=ANY, keyspace=ANY, table=ANY)
985+
pool.borrow_connection.assert_called_once_with(timeout=ANY, routing_key=ANY, keyspace=ANY, table=ANY, tablet=ANY)
986986
connection.send_msg.assert_called_once_with(rf.message, 1, cb=ANY, encoder=ProtocolHandler.encode_message, decoder=ProtocolHandler.decode_message, result_metadata=[])
987987

988988
# Simulate a ServerError response (which triggers RETRY_NEXT_HOST by default)

0 commit comments

Comments
 (0)