From 6bb585bf5db106322c9569d76f3178c79ed53d5c Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Thu, 17 Aug 2023 13:23:47 -0500 Subject: [PATCH] Warn when cqlsh does not match the server version it was built with Patch by brandonwilliams; reviewed by bereng for CASSANDRA-18745 --- .build/build-cqlsh.xml | 24 ++++++++++++++++++++++++ CHANGES.txt | 1 + bin/cqlsh.py | 11 +++++++++++ build.xml | 3 ++- 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 .build/build-cqlsh.xml diff --git a/.build/build-cqlsh.xml b/.build/build-cqlsh.xml new file mode 100644 index 0000000000..45e0e46a49 --- /dev/null +++ b/.build/build-cqlsh.xml @@ -0,0 +1,24 @@ + + + + + version = "${base.version}"${line.separator} + + diff --git a/CHANGES.txt b/CHANGES.txt index ea9b1024e3..702733eaaf 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 3.0.30 + * CQLSH emits a warning when the server version doesn't match (CASSANDRA-18745) * Fix missing speculative retries in tablestats (CASSANDRA-18767) * Fix Requires for Java for RPM package (CASSANDRA-18751) * Fix CQLSH online help topic link (CASSANDRA-17534) diff --git a/bin/cqlsh.py b/bin/cqlsh.py index 3e5cac1470..f9fcc656d5 100644 --- a/bin/cqlsh.py +++ b/bin/cqlsh.py @@ -171,6 +171,7 @@ from cqlshlib.formatting import (DEFAULT_DATE_FORMAT, DEFAULT_NANOTIME_FORMAT, formatter_for) from cqlshlib.tracing import print_trace, print_trace_session from cqlshlib.util import get_file_encoding_bomsize, trim_if_present +from cqlshlib.serverversion import version as build_version DEFAULT_HOST = '127.0.0.1' DEFAULT_PORT = 9042 @@ -797,6 +798,8 @@ class Shell(cmd.Cmd): if stdin is None: stdin = sys.stdin + self.check_build_versions() + if tty: self.reset_prompt() self.report_connection() @@ -816,6 +819,14 @@ class Shell(cmd.Cmd): def batch_mode(self): return not self.tty + def check_build_versions(self): + baseversion = self.connection_versions['build'] + extra = baseversion.rfind('-') + if extra: + baseversion = baseversion[0:extra] + if baseversion != build_version: + print("WARNING: cqlsh was built against {}, but this server is {}. All features may not work!".format(baseversion, build_version)) + @property def is_using_utf8(self): # utf8 encodings from https://docs.python.org/{2,3}/library/codecs.html diff --git a/build.xml b/build.xml index dd75f1746c..76525e35d4 100644 --- a/build.xml +++ b/build.xml @@ -684,7 +684,7 @@ - + @@ -1970,4 +1970,5 @@ +