Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
5.0.10
* Add cqlsh options to override the default consistency levels (CASSANDRA-20626)
* Avoid rebuilding per-SSTable SAI components unless missing or corrupted (CASSANDRA-21515)
* Propagate trickle_fsync settings to compressed SSTable writers (CASSANDRA-21487)
* Allow DatabaseDescriptor.setCompressedReadAheadBufferSizeInKb(0) to disable read-ahead buffer (CASSANDRA-21522)
Expand Down
8 changes: 8 additions & 0 deletions conf/cqlshrc.sample
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@
;; A version of CQL to use (this should almost never be set)
; version = 3.2.1

;; The consistency level to start cqlsh with - ONE by default.
;; This setting can be overridden with the --consistency-level command line option.
; consistency_level = LOCAL_QUORUM

;; The serial consistency level to start cqlsh with - SERIAL by default.
;; This setting can be overridden with the --serial-consistency-level command line option.
; serial_consistency_level = LOCAL_SERIAL



[connection]
Expand Down
6 changes: 6 additions & 0 deletions doc/modules/cassandra/pages/managing/tools/cqlsh.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ Options:
`--request-timeout=REQUEST_TIMEOUT`::
Specify the default request timeout in seconds
(default: 10 seconds).
`--consistency-level=CONSISTENCY_LEVEL`::
Specify the initial consistency level (default: ONE).
A serial consistency level is not valid here.
`--serial-consistency-level=SERIAL_CONSISTENCY_LEVEL`::
Specify the initial serial consistency level
(default: SERIAL). Only SERIAL and LOCAL_SERIAL are valid here.
`-t, --tty`::
Force tty mode (command prompt).
`-v` `--v`::
Expand Down
42 changes: 40 additions & 2 deletions pylib/cqlshlib/cqlshmain.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@
help='Specify the connection timeout in seconds (default: %(default)s seconds).')
parser.add_argument("--request-timeout", default=DEFAULT_REQUEST_TIMEOUT_SECONDS, dest='request_timeout',
help='Specify the default request timeout in seconds (default: %(default)s seconds).')
parser.add_argument("--consistency-level", dest='consistency_level',
help='Specify the initial consistency level.')
parser.add_argument("--serial-consistency-level", dest='serial_consistency_level',
help='Specify the initial serial consistency level.')
parser.add_argument("-t", "--tty", action='store_true', dest='tty',
help='Force tty mode (command prompt).')
parser.add_argument('--disable-history', default=False, action='store_true',
Expand Down Expand Up @@ -360,11 +364,14 @@ class Shell(cmd.Cmd):
use_paging = True

default_page_size = 100
consistency_level = None
serial_consistency_level = None

def __init__(self, hostname, port, color=False,
username=None, encoding=None, stdin=None, tty=True,
completekey=DEFAULT_COMPLETEKEY, browser=None, use_conn=None,
cqlver=None, keyspace=None,
consistency_level=None, serial_consistency_level=None,
tracing_enabled=False, expand_enabled=False,
display_nanotime_format=DEFAULT_NANOTIME_FORMAT,
display_timestamp_format=DEFAULT_TIMESTAMP_FORMAT,
Expand Down Expand Up @@ -399,6 +406,14 @@ def __init__(self, hostname, port, color=False,
self.tracing_enabled = tracing_enabled
self.page_size = self.default_page_size
self.expand_enabled = expand_enabled

if not consistency_level:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to compare to None to make the exception correct, and also this will catch ConsistencyLevel.ANY which is numerically zero.

raise Exception('Argument consistency_level must not be None')
if not serial_consistency_level:
raise Exception('Argument serial_consistency_level must not be None')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Misleading exception here too

self.consistency_level = consistency_level
self.serial_consistency_level = serial_consistency_level

if use_conn:
self.conn = use_conn
else:
Expand Down Expand Up @@ -474,8 +489,6 @@ def __init__(self, hostname, port, color=False,
self.show_line_nums = True
self.stdin = stdin
self.query_out = sys.stdout
self.consistency_level = cassandra.ConsistencyLevel.ONE
self.serial_consistency_level = cassandra.ConsistencyLevel.SERIAL

self.empty_lines = 0
self.statement_error = False
Expand Down Expand Up @@ -1574,6 +1587,8 @@ def do_source(self, parsed):
username=self.username,
encoding=self.encoding, stdin=f, tty=False, use_conn=self.conn,
cqlver=self.cql_version, keyspace=self.current_keyspace,
consistency_level=self.consistency_level,
serial_consistency_level=self.serial_consistency_level,
tracing_enabled=self.tracing_enabled,
display_nanotime_format=self.display_nanotime_format,
display_timestamp_format=self.display_timestamp_format,
Expand Down Expand Up @@ -2108,6 +2123,9 @@ def read_options(cmdlineargs, environment=os.environ):
argvalues.ssl = option_with_default(configs.getboolean, 'connection', 'ssl', DEFAULT_SSL)
argvalues.encoding = option_with_default(configs.get, 'ui', 'encoding', UTF8)

argvalues.consistency_level = option_with_default(configs.get, 'cql', 'consistency_level', 'ONE')
argvalues.serial_consistency_level = option_with_default(configs.get, 'cql', 'serial_consistency_level', 'SERIAL')

argvalues.tty = option_with_default(configs.getboolean, 'ui', 'tty', sys.stdin.isatty())
argvalues.protocol_version = option_with_default(configs.getint, 'protocol', 'version', None)
argvalues.cqlversion = option_with_default(configs.get, 'cql', 'version', None)
Expand Down Expand Up @@ -2164,6 +2182,24 @@ def read_options(cmdlineargs, environment=os.environ):
options.password = maybe_ensure_text(options.password)
options.keyspace = maybe_ensure_text(options.keyspace)

serial_levels = [cassandra.ConsistencyLevel.SERIAL, cassandra.ConsistencyLevel.LOCAL_SERIAL]

try:
cl = cassandra.ConsistencyLevel.name_to_value[options.consistency_level.upper()]
if cl in serial_levels:
raise KeyError
options.consistency_level = cl
except KeyError:
parser.error('"{}" is not a valid consistency level'.format(options.consistency_level))

try:
cl = cassandra.ConsistencyLevel.name_to_value[options.serial_consistency_level.upper()]
if cl not in serial_levels:
raise KeyError
options.serial_consistency_level = cl
except KeyError:
parser.error('"{}" is not a valid serial consistency level'.format(options.serial_consistency_level))

hostname = option_with_default(configs.get, 'connection', 'hostname', DEFAULT_HOST)
port = option_with_default(configs.get, 'connection', 'port', DEFAULT_PORT)

Expand Down Expand Up @@ -2355,6 +2391,8 @@ def main(cmdline, pkgpath):
protocol_version=options.protocol_version,
cqlver=options.cqlversion,
keyspace=options.keyspace,
consistency_level=options.consistency_level,
serial_consistency_level=options.serial_consistency_level,
display_timestamp_format=options.time_format,
display_nanotime_format=options.nanotime_format,
display_date_format=options.date_format,
Expand Down