Skip to content

Commit

Permalink
cqlsh: try server-side DESCRIBE, then client-side
Browse files Browse the repository at this point in the history
Since Scylla 5.2 (scylladb/scylladb@e6ffc22)
a support for server-side DESCRIBE was added. However, cqlsh did not
start to use this functionality, since it is only enabled if it detects
CQL version at least 4. Scylla did not increase this version number as
it doesn't support all of its features, so there is a need for a
different detection mechanism for server-side DESCRIBE.

This commit changes the behavior in do_describe: cqlsh will first try
to execute the server-side DESCRIBE. If this fails with SyntaxException,
meaning that Scylla doesn't support that command, cqlsh falls back to
the client-side DESCRIBE behavior.

The other possible solutions were rejected:
- Based on Scylla version: would require ugly hard-coding of versions
- Modifying Scylla to provide some indication that this feature is
  enabled: Scylla 5.2 is already released without it, by implementing
  it in another way, we'll get it out sooner
- Do a trial "DESCRIBE" at the start of connection to detect if the
  server supports it: if cqlsh ever supported connecting to multiple
  nodes (right now it uses WhiteListRoundRobinPolicy) we would have
  to do the check on all of the nodes in case a rolling upgrade is
  currently occurring and some of the nodes don't support server-side
  DESCRIBE.

The change was tested manually on a couple of last Scylla OSS, Scylla
Enterprise and Cassandra releases.

Fixes #17
  • Loading branch information
avelanarius authored and fruch committed May 27, 2024
1 parent 2eaa79c commit 55aff23
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion bin/cqlsh.py
Original file line number Diff line number Diff line change
Expand Up @@ -1589,7 +1589,10 @@ def do_describe(self, parsed):
where object can be either a keyspace or a table or an index or a materialized
view (in this order).
"""
if self.connection_versions['build'][0] < '4':
self._do_describe(parsed, force_client_side_describe=False)

def _do_describe(self, parsed, force_client_side_describe):
if force_client_side_describe:
what = parsed.matched[1][1].lower()
if what == 'functions':
self.describe_functions_client(self.current_keyspace)
Expand Down Expand Up @@ -1665,6 +1668,10 @@ def do_describe(self, parsed):
elif what:
self.describe_element(result)

except cassandra.protocol.SyntaxException:
# Server doesn't support DESCRIBE query, retry with
# client-side DESCRIBE implementation
self._do_describe(parsed, force_client_side_describe=True)
except CQL_ERRORS as err:
err_msg = err.message if hasattr(err, 'message') else str(err)
self.printerr(err_msg.partition("message=")[2].strip('"'))
Expand Down

0 comments on commit 55aff23

Please sign in to comment.