Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion cassandra/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -4313,7 +4313,7 @@
if task:
log.debug("Not executing scheduled task due to Scheduler shutdown")
return
if run_at <= time.time():

Check failure on line 4316 in cassandra/cluster.py

View workflow job for this annotation

GitHub Actions / test libev (3.11)

cannot schedule new futures after shutdown

Check failure on line 4316 in cassandra/cluster.py

View workflow job for this annotation

GitHub Actions / test asyncio (3.12)

cannot schedule new futures after shutdown
self._scheduled_tasks.discard(task)
fn, args, kwargs = task
kwargs = dict(kwargs)
Expand Down Expand Up @@ -4776,14 +4776,21 @@
self.query, retry_num=self._query_retries, **response.info)
elif isinstance(response, (OverloadedErrorMessage,
IsBootstrappingErrorMessage,
TruncateError, ServerError)):
ServerError)):
log.warning("Host %s error: %s.", host, response.summary)
if self._metrics is not None:
self._metrics.on_other_error()
cl = getattr(self.message, 'consistency_level', None)
retry = retry_policy.on_request_error(
self.query, cl, error=response,
retry_num=self._query_retries)
elif isinstance(response, TruncateError):
# TruncateError should not be retried as it indicates a permanent failure
log.warning("Host %s truncate error: %s.", host, response.summary)
if self._metrics is not None:
self._metrics.on_other_error()
self._set_final_exception(response.to_exception())
return
elif isinstance(response, PreparedQueryNotFound):
if self.prepared_statement:
query_id = self.prepared_statement.query_id
Expand Down
31 changes: 26 additions & 5 deletions tests/integration/simulacron/test_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,14 +424,13 @@ def test_retry_policy_on_request_error(self):
"message": "server_error"
}

# Test the on_request_error call
# Test the on_request_error call for errors that should retry
retry_policy = CounterRetryPolicy()
self.set_cluster(retry_policy)

for prime_error, exc in [
(overloaded_error, OverloadedErrorMessage),
(bootstrapping_error, IsBootstrappingErrorMessage),
(truncate_error, TruncateError),
(server_error, ServerError)]:

clear_queries()
Expand All @@ -444,13 +443,24 @@ def test_retry_policy_on_request_error(self):

assert len(rf.attempted_hosts) == 1 # no retry

assert next(retry_policy.request_error) == 4
assert next(retry_policy.request_error) == 3 # 3 calls (excludes TruncateError)

# Test that by default, retry on next host
# Test TruncateError is not retried (no on_request_error call)
clear_queries()
query_to_prime = "SELECT * from simulacron_keyspace.simulacron_table;"
prime_query(query_to_prime, then=truncate_error, rows=None, column_types=None)
rf = self.session.execute_async(query_to_prime)

with pytest.raises(TruncateError):
rf.result()

assert len(rf.attempted_hosts) == 1 # no retry

# Test that by default, errors retry on next host (except TruncateError)
retry_policy = RetryPolicy()
self.set_cluster(retry_policy)

for e in [overloaded_error, bootstrapping_error, truncate_error, server_error]:
for e in [overloaded_error, bootstrapping_error, server_error]:
clear_queries()
query_to_prime = "SELECT * from simulacron_keyspace.simulacron_table;"
prime_query(query_to_prime, then=e, rows=None, column_types=None)
Expand All @@ -460,3 +470,14 @@ def test_retry_policy_on_request_error(self):
rf.result()

assert len(rf.attempted_hosts) == 3 # all 3 nodes failed

# Test TruncateError does not retry even with default RetryPolicy
clear_queries()
query_to_prime = "SELECT * from simulacron_keyspace.simulacron_table;"
prime_query(query_to_prime, then=truncate_error, rows=None, column_types=None)
rf = self.session.execute_async(query_to_prime)

with pytest.raises(TruncateError):
rf.result()

assert len(rf.attempted_hosts) == 1 # no retry for TruncateError
59 changes: 59 additions & 0 deletions tests/unit/test_truncate_error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright DataStax, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest
from cassandra.protocol import TruncateError


class TruncateErrorTest(unittest.TestCase):
"""
Test TruncateError exception behavior
"""

def test_truncate_error_message_includes_server_message(self):
"""
Verify that TruncateError includes the server-provided error message
in addition to the generic summary.

This addresses the issue where the error message was thought to be ignored.
The server message should always be included in the error string representation.
"""
server_message = "unconfigured table test_table"
error = TruncateError(code=0x1003, message=server_message, info=None)
error_str = str(error)

# Verify both the summary and server message are in the error string
self.assertIn("Error during truncate", error_str,
"Generic summary should be in error string")
self.assertIn(server_message, error_str,
"Server-provided message should be in error string")

def test_truncate_error_code(self):
"""
Verify that TruncateError has the correct error code (0x1003)
"""
error = TruncateError(code=0x1003, message="test", info=None)
self.assertEqual(error.code, 0x1003)
self.assertEqual(error.error_code, 0x1003)

def test_truncate_error_summary(self):
"""
Verify that TruncateError has the correct summary message
"""
error = TruncateError(code=0x1003, message="test", info=None)
self.assertEqual(error.summary, "Error during truncate")


if __name__ == '__main__':
unittest.main()
Loading