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 scylladb#17
  • Loading branch information
avelanarius authored and sylwiaszunejko committed May 14, 2024
1 parent 91eda23 commit 3a0f12b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions bin/cqlsh.py
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,7 @@ def describe_schema_client(self, include_system=False):
self.print_recreate_keyspace(k, sys.stdout)
print('')

def do_describe(self, parsed):
def do_describe(self, parsed, client_side=False):

"""
DESCRIBE [cqlsh only]
Expand Down Expand Up @@ -1589,7 +1589,7 @@ 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':
if client_side:
what = parsed.matched[1][1].lower()
if what == 'functions':
self.describe_functions_client(self.current_keyspace)
Expand Down Expand Up @@ -1665,6 +1665,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, client_side=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 3a0f12b

Please sign in to comment.