Fix cqlsh CAPTURE command to save query results without trace details when TRACING is ON

This patch also opportunistically fixes CAPTURE OFF.

patch by Gottipati Gautam; reviewed by Stefan Miklosovic, Brad Schoening for CASSANDRA-19105
This commit is contained in:
Gottipati Gautam 2024-07-16 01:20:04 -05:00 committed by Stefan Miklosovic
parent 32d1335654
commit 510c20fec1
No known key found for this signature in database
GPG Key ID: 32F35CB2F546D93E
4 changed files with 16 additions and 2 deletions

View File

@ -1,4 +1,5 @@
5.1
* Fix cqlsh CAPTURE command to save query results without trace details when TRACING is ON (CASSANDRA-19105)
* Optionally prevent tombstone purging during repair (CASSANDRA-20071)
* Add post-filtering support for the IN operator in SAI queries (CASSANDRA-20025)
* Dont finish ongoing decommission and move operations during startup (CASSANDRA-20040)

View File

@ -145,7 +145,7 @@ cqlsh_source_cmd_syntax_rules = r'''
'''
cqlsh_capture_cmd_syntax_rules = r'''
<captureCommand> ::= "CAPTURE" ( fname=( <stringLiteral>) | "OFF" )?
<captureCommand> ::= "CAPTURE" ( switch=( <stringLiteral> | "OFF" ) )?
;
'''

View File

@ -1524,7 +1524,8 @@ class Shell(cmd.Cmd):
To inspect the current capture configuration, use CAPTURE with no
arguments.
"""
fname = parsed.get_binding('fname')
fname = parsed.get_binding('switch')
if fname is None:
if self.shunted_query_out is not None:
print("Currently capturing query output to %r." % (self.query_out.name,))

View File

@ -38,6 +38,14 @@ def print_trace(shell, trace):
"""
Print an already populated cassandra.query.QueryTrace instance.
"""
temp_query = None
temp_color = None
if shell.shunted_query_out is not None:
temp_query = shell.query_out
shell.query_out = shell.shunted_query_out
temp_color = shell.color
shell.color = shell.shunted_color
rows = make_trace_rows(trace)
if not rows:
shell.printerr("No rows for session %s found." % (trace.trace_id,))
@ -54,6 +62,10 @@ def print_trace(shell, trace):
shell.print_formatted_result(formatted_names, formatted_values, with_header=True, tty=shell.tty)
shell.writeresult('')
if temp_query is not None:
shell.query_out = temp_query
shell.color = temp_color
def make_trace_rows(trace):
if not trace.events: