cqlsh: make consistency level configurable; patch by Aleksey Yeschenko, reviewed by Brandon Williams
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/9db88279 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/9db88279 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/9db88279 Branch: refs/heads/trunk Commit: 9db882790f1b1a37a590d3b32dcef9ce14dad6ae Parents: c00c6ab Author: Aleksey Yeschenko <alek...@apache.org> Authored: Mon Nov 19 21:54:18 2012 +0300 Committer: Aleksey Yeschenko <alek...@apache.org> Committed: Mon Nov 19 21:54:18 2012 +0300 ---------------------------------------------------------------------- CHANGES.txt | 1 + bin/cqlsh | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 0 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/9db88279/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index 6763ba8..e63350b 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 1.2-rc1 + * make consistency level configurable in cqlsh (CASSANDRA-4829) * fix cqlsh rendering of blob fields (CASSANDRA-4970) * fix cqlsh DESCRIBE command (CASSANDRA-4913) * save truncation position in system table (CASSANDRA-4906) http://git-wip-us.apache.org/repos/asf/cassandra/blob/9db88279/bin/cqlsh ---------------------------------------------------------------------- diff --git a/bin/cqlsh b/bin/cqlsh index 142b036..611f6af 100755 --- a/bin/cqlsh +++ b/bin/cqlsh @@ -172,6 +172,7 @@ SYSTEM_KEYSPACES = ('system', 'system_traces') my_commands_ending_with_newline = ( 'help', '?', + 'consistency', 'describe', 'desc', 'show', @@ -195,7 +196,9 @@ cqlsh_extra_syntax_rules = r''' <cqlshCommand> ::= <CQL_Statement> | <specialCommand> ( ";" | "\n" ) ; + <specialCommand> ::= <describeCommand> + | <consistencyCommand> | <showCommand> | <assumeCommand> | <sourceCommand> @@ -215,6 +218,19 @@ cqlsh_extra_syntax_rules = r''' | "CLUSTER" ) ; +<consistencyCommand> ::= "CONSISTENCY" ( level=<consistencyLevel> )? + ; + +<consistencyLevel> ::= "ANY" + | "ONE" + | "TWO" + | "THREE" + | "QUORUM" + | "ALL" + | "LOCAL_QUORUM" + | "EACH_QUORUM" + ; + <showCommand> ::= "SHOW" what=( "VERSION" | "HOST" | "ASSUMPTIONS" ) ; @@ -1855,6 +1871,36 @@ class Shell(cmd.Cmd): self.tracing_enabled = False print 'Disabled tracing.' + def do_consistency(self, parsed): + """ + CONSISTENCY [cqlsh with CQL3 only] + + Overrides default consistency level (default level is ONE). + + CONSISTENCY <level> + + Sets consistency level for future requests. + + Valid consistency levels: + + ANY, ONE, TWO, THREE, QUORUM, ALL, LOCAL_QUORUM and EACH_QUORUM. + + CONSISTENCY + + CONSISTENCY with no arguments shows the current consistency level. + """ + if not self.cqlver_atleast(3): + self.printerr('CONSISTENCY requires CQL version 3.0.0 or higher.') + return + + level = parsed.get_binding('level') + if level is None: + print 'Current consistency level is %s.' % (self.cursor.consistency_level,) + return + + self.cursor.consistency_level = level.upper() + print 'Consistency level set to %s.' % (level.upper(),) + def do_exit(self, parsed=None): """ EXIT/QUIT [cqlsh only]