diff --git a/swh/storage/cassandra/cql.py b/swh/storage/cassandra/cql.py --- a/swh/storage/cassandra/cql.py +++ b/swh/storage/cassandra/cql.py @@ -23,7 +23,7 @@ Union, ) -from cassandra import CoordinationFailure +from cassandra import CoordinationFailure, ProtocolVersion from cassandra.cluster import EXEC_PROFILE_DEFAULT, Cluster, ExecutionProfile, ResultSet from cassandra.policies import DCAwareRoundRobinPolicy, TokenAwarePolicy from cassandra.query import BoundStatement, PreparedStatement, dict_factory @@ -75,6 +75,9 @@ logger = logging.getLogger(__name__) +# Get the maximum non beta protocol version supported by the driver: +# 4 for cassandra-driver < 3.25.0, 5 otherwise +_protocol_version = ProtocolVersion.get_lower_supported(previous_version=10) _execution_profiles = { EXEC_PROFILE_DEFAULT: ExecutionProfile( @@ -91,7 +94,12 @@ def create_keyspace( hosts: List[str], keyspace: str, port: int = 9042, *, durable_writes=True ): - cluster = Cluster(hosts, port=port, execution_profiles=_execution_profiles) + cluster = Cluster( + hosts, + port=port, + execution_profiles=_execution_profiles, + protocol_version=_protocol_version, + ) session = cluster.connect() extra_params = "" if not durable_writes: @@ -224,7 +232,10 @@ def __init__(self, hosts: List[str], keyspace: str, port: int): self._cluster = Cluster( - hosts, port=port, execution_profiles=_execution_profiles + hosts, + port=port, + execution_profiles=_execution_profiles, + protocol_version=_protocol_version, ) self._session = self._cluster.connect(keyspace) self._cluster.register_user_type(