Skip to content

Commit ee515ac

Browse files
ifesdjeenmambocab
authored andcommitted
Add NO_COMPACT version to CQL protocol, patch for CASSANDRA-10857. (apache#846)
* Add `NO_COMPACT` version to CQL protocol, patch for CASSANDRA-10857. * add changelog entry; preserve Connection.__init__ API
1 parent e8b0303 commit ee515ac

4 files changed

Lines changed: 18 additions & 5 deletions

File tree

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Features
99
* Warn on Cluster init if contact points are specified but LBP isn't (legacy mode) (PYTHON-812)
1010
* Warn on Cluster init if contact points are specified but LBP isn't (exection profile mode) (PYTHON-838)
1111
* Include hash of result set metadata in prepared stmt id (PYTHON-808)
12+
* Add NO_COMPACT startup option (PYTHON-839)
1213

1314
Bug Fixes
1415
---------

cassandra/cluster.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,9 @@ class Cluster(object):
395395
"""
396396

397397
allow_beta_protocol_version = False
398+
399+
no_compact = False
400+
398401
"""
399402
Setting true injects a flag in all messages that makes the server accept and use "beta" protocol version.
400403
Used for testing new protocol features incrementally before the new version is complete.
@@ -788,7 +791,8 @@ def __init__(self,
788791
execution_profiles=None,
789792
allow_beta_protocol_version=False,
790793
timestamp_generator=None,
791-
idle_heartbeat_timeout=30):
794+
idle_heartbeat_timeout=30,
795+
no_compact=False):
792796
"""
793797
``executor_threads`` defines the number of threads in a pool for handling asynchronous tasks such as
794798
extablishing connection pools or refreshing metadata.
@@ -821,6 +825,8 @@ def __init__(self,
821825
self._protocol_version_explicit = True
822826
self.allow_beta_protocol_version = allow_beta_protocol_version
823827

828+
self.no_compact = no_compact
829+
824830
self.auth_provider = auth_provider
825831

826832
if load_balancing_policy is not None:
@@ -1204,6 +1210,7 @@ def _make_connection_kwargs(self, address, kwargs_dict):
12041210
kwargs_dict.setdefault('protocol_version', self.protocol_version)
12051211
kwargs_dict.setdefault('user_type_map', self._user_types)
12061212
kwargs_dict.setdefault('allow_beta_protocol_version', self.allow_beta_protocol_version)
1213+
kwargs_dict.setdefault('no_compact', self.no_compact)
12071214

12081215
return kwargs_dict
12091216

cassandra/connection.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ class Connection(object):
203203
out_buffer_size = 4096
204204

205205
cql_version = None
206+
no_compact = False
206207
protocol_version = ProtocolVersion.MAX_SUPPORTED
207208

208209
keyspace = None
@@ -259,7 +260,7 @@ class Connection(object):
259260
def __init__(self, host='127.0.0.1', port=9042, authenticator=None,
260261
ssl_options=None, sockopts=None, compression=True,
261262
cql_version=None, protocol_version=ProtocolVersion.MAX_SUPPORTED, is_control_connection=False,
262-
user_type_map=None, connect_timeout=None, allow_beta_protocol_version=False):
263+
user_type_map=None, connect_timeout=None, allow_beta_protocol_version=False, no_compact=False):
263264
self.host = host
264265
self.port = port
265266
self.authenticator = authenticator
@@ -272,6 +273,7 @@ def __init__(self, host='127.0.0.1', port=9042, authenticator=None,
272273
self.user_type_map = user_type_map
273274
self.connect_timeout = connect_timeout
274275
self.allow_beta_protocol_version = allow_beta_protocol_version
276+
self.no_compact = no_compact
275277
self._push_watchers = defaultdict(set)
276278
self._requests = {}
277279
self._iobuf = io.BytesIO()
@@ -637,7 +639,7 @@ def _send_options_message(self):
637639
"specified", id(self), self.host)
638640
self._compressor = None
639641
self.cql_version = DEFAULT_CQL_VERSION
640-
self._send_startup_message()
642+
self._send_startup_message(no_compact=self.no_compact)
641643
else:
642644
log.debug("Sending initial options message for new connection (%s) to %s", id(self), self.host)
643645
self.send_msg(OptionsMessage(), self.get_request_id(), self._handle_options_response)
@@ -703,14 +705,16 @@ def _handle_options_response(self, options_response):
703705
self._compressor, self.decompressor = \
704706
locally_supported_compressions[compression_type]
705707

706-
self._send_startup_message(compression_type)
708+
self._send_startup_message(compression_type, no_compact=self.no_compact)
707709

708710
@defunct_on_error
709-
def _send_startup_message(self, compression=None):
711+
def _send_startup_message(self, compression=None, no_compact=False):
710712
log.debug("Sending StartupMessage on %s", self)
711713
opts = {}
712714
if compression:
713715
opts['COMPRESSION'] = compression
716+
if no_compact:
717+
opts['NO_COMPACT'] = 'true'
714718
sm = StartupMessage(cqlversion=self.cql_version, options=opts)
715719
self.send_msg(sm, self.get_request_id(), cb=self._handle_startup_response)
716720
log.debug("Sent StartupMessage on %s", self)

cassandra/protocol.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ class StartupMessage(_MessageType):
394394
KNOWN_OPTION_KEYS = set((
395395
'CQL_VERSION',
396396
'COMPRESSION',
397+
'NO_COMPACT'
397398
))
398399

399400
def __init__(self, cqlversion, options):

0 commit comments

Comments
 (0)