Skip to content

Commit

Permalink
cqlsh: handle schema mismatch on startup
Browse files Browse the repository at this point in the history
Patch by Tyler Hobbs; reviewed by Aleksey Yeschenko for CASSANDRA-8512
  • Loading branch information
thobbs committed Jan 2, 2015
1 parent 4e1e92b commit aeb7d3f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
2.1.3
* (cqlsh) Handle a schema mismatch being detected on startup (CASSANDRA-8512)
* Properly calculate expected write size during compaction (CASSANDRA-8532)
* Invalidate affected prepared statements when a table's columns
are altered (CASSANDRA-7910)
Expand Down
25 changes: 21 additions & 4 deletions bin/cqlsh
Original file line number Diff line number Diff line change
Expand Up @@ -562,15 +562,32 @@ class Shell(cmd.Cmd):
self.session = self.conn.connect(keyspace)
else:
self.session = self.conn.connect()

self.color = color
self.display_time_format = display_time_format
self.display_float_precision = display_float_precision

# Workaround for CASSANDRA-8521 until PYTHON-205 is resolved.
# If there is no schema metadata present (due to a schema mismatch),
# get rid of the code that checks for a schema mismatch and force
# the schema metadata to be built.
if not self.conn.metadata.keyspaces:
self.printerr("Warning: schema version mismatch detected; check the schema versions of your "
"nodes in system.local and system.peers.")
original_method = self.conn.control_connection._get_schema_mismatches
try:
self.conn.control_connection._get_schema_mismatches = lambda *args, **kwargs: None
future = self.conn.submit_schema_refresh()
future.result(timeout=10)
finally:
self.conn.control_connection._get_schema_mismatches = original_method

self.session.default_timeout = client_timeout
self.session.row_factory = ordered_dict_factory
self.get_connection_versions()

self.current_keyspace = keyspace

self.color = color
self.display_time_format = display_time_format
self.display_float_precision = display_float_precision
self.max_trace_wait = max_trace_wait
self.session.max_trace_wait = max_trace_wait
if encoding is None:
Expand Down Expand Up @@ -980,7 +997,7 @@ class Shell(cmd.Cmd):
rows = self.session.execute(statement, trace=self.tracing_enabled)
break
except CQL_ERRORS, err:
self.printerr(str(err))
self.printerr(str(err.__class__.__name__) + ": " + str(err))
return False
except Exception, err:
import traceback
Expand Down

0 comments on commit aeb7d3f

Please sign in to comment.