Skip to content

control-connection fallback: preserve session keyspace #1013

Description

@dkropachev

Problem

A session created with cluster.connect("ks") stores its keyspace:

def connect(self, keyspace=None, wait_for_all_pools=False):
"""
Creates and returns a new :class:`~.Session` object.
If `keyspace` is specified, that keyspace will be the default keyspace for
operations on the ``Session``.

def __init__(self, cluster, hosts, keyspace=None):
self.cluster = cluster
self.hosts = hosts
self.keyspace = keyspace

When no node pool is available, fallback sends directly through the shared control connection without applying that keyspace:

def _query_control_connection(self, message=None, cb=None, connection=None, host=None):
self._control_connection_query_attempted = True
if message is None:
message = self.message
if connection is None:
control_connection = self.session.cluster.control_connection
connection = control_connection._connection if control_connection else None
if not connection:
self._errors['control connection'] = ConnectionException("Control connection is not connected")
return None
if host is None:
host = self.session.cluster.get_control_connection_host() or connection.endpoint
self._current_host = host
request_id = None
request_sent = False
try:
request_id = self._borrow_control_connection(connection)
self._connection = connection
result_meta = self._bound_result_metadata
if cb is None:
cb = partial(self._set_result, host, connection, None)
cb = partial(self._handle_control_connection_response, connection, cb)
log.debug("No usable node pools; falling back to control connection for host %s", host)
self.request_encoded_size = connection.send_msg(message, request_id, cb=cb,
encoder=self._protocol_handler.encode_message,
decoder=self._protocol_handler.decode_message,
result_metadata=result_meta)

Unqualified queries and prepares can fail or execute against the keyspace selected by another session.

Expected behavior

Preserve each session's keyspace when dispatching through the control connection, without leaking keyspace state between sessions. Add coverage for two sessions using different keyspaces.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingrelease-blockerMust be resolved before the next release.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions