From 09a4dc055237185c0bcb9a5b3855b85ef0861fb2 Mon Sep 17 00:00:00 2001 From: Aleksey Yeschenko Date: Mon, 12 Aug 2013 17:06:14 +0200 Subject: [PATCH] cqlsh: add DESCRIBE FULL SCHEMA variant patch by Aleksey Yeschenko; reviewed by Jonathan Ellis for CASSANDRA-5880 --- CHANGES.txt | 1 + NEWS.txt | 2 ++ bin/cqlsh | 27 +++++++++++++----------- pylib/cqlshlib/test/test_cqlsh_output.py | 2 +- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 396459b8c9..5b6d62cf7f 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -3,6 +3,7 @@ * fix CAS contention timeout (CASSANDRA-5830) * fix HsHa to respect max frame size (CASSANDRA-4573) * Fix (some) 2i on composite components omissions (CASSANDRA-5851) + * cqlsh: add DESCRIBE FULL SCHEMA variant (CASSANDRA-5880) Merged from 1.2: * Correctly validate sparse composite cells in scrub (CASSANDRA-5855) * Add KeyCacheHitRate metric to CF metrics (CASSANDRA-5868) diff --git a/NEWS.txt b/NEWS.txt index b8079733a8..c608e035e4 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -70,6 +70,8 @@ Operations - A new hints created metric is tracked per target, replacing countPendingHints - After performance testing for CASSANDRA-5727, the default LCS filesize has been changed from 5MB to 160MB. + - cqlsh DESCRIBE SCHEMA no longer outputs the schema of system_* keyspaces; + use DESCRIBE FULL SCHEMA if you need the schema of system_* keyspaces. Features -------- diff --git a/bin/cqlsh b/bin/cqlsh index 5343a47a70..0f51c7f353 100755 --- a/bin/cqlsh +++ b/bin/cqlsh @@ -178,7 +178,7 @@ else: debug_completion = bool(os.environ.get('CQLSH_DEBUG_COMPLETION', '') == 'YES') -SYSTEM_KEYSPACES = ('system', 'system_traces') +SYSTEM_KEYSPACES = ('system', 'system_traces', 'system_auth') # we want the cql parser to understand our cqlsh-specific commands too my_commands_ending_with_newline = ( @@ -227,7 +227,7 @@ cqlsh_extra_syntax_rules = r''' | "KEYSPACE" ksname=? | ( "COLUMNFAMILY" | "TABLE" ) cf= | ( "COLUMNFAMILIES" | "TABLES" ) - | "SCHEMA" + | "FULL"? "SCHEMA" | "CLUSTER" ) ; @@ -635,7 +635,7 @@ class Shell(cmd.Cmd): return self.make_hacktastic_thrift_call('describe_version') def get_ring(self): - if self.current_keyspace is None or self.current_keyspace in SYSTEM_KEYSPACES: + if self.current_keyspace is None or self.current_keyspace == 'system': raise NoKeyspaceError("Ring view requires a current non-system keyspace") return self.make_hacktastic_thrift_call('describe_ring', self.current_keyspace) @@ -1235,18 +1235,19 @@ class Shell(cmd.Cmd): snitch = trim_if_present(self.get_snitch(), 'org.apache.cassandra.locator.') print 'Snitch: %s\n' % snitch if self.current_keyspace is not None \ - and self.current_keyspace not in SYSTEM_KEYSPACES: + and self.current_keyspace != 'system': print "Range ownership:" ring = self.get_ring() for entry in ring: print ' %39s [%s]' % (entry.start_token, ', '.join(entry.endpoints)) print - def describe_schema(self): + def describe_schema(self, include_system=False): print for k in self.get_keyspaces(): - self.print_recreate_keyspace(k, sys.stdout) - print + if include_system or not k.name in SYSTEM_KEYSPACES: + self.print_recreate_keyspace(k, sys.stdout) + print def do_describe(self, parsed): """ @@ -1289,11 +1290,11 @@ class Shell(cmd.Cmd): connected to a non-system keyspace, also shows endpoint-range ownership information for the Cassandra ring. - DESCRIBE SCHEMA + DESCRIBE [FULL] SCHEMA - Output CQL commands that could be used to recreate the entire schema. - Works as though "DESCRIBE KEYSPACE k" was invoked for each keyspace - k. + Output CQL commands that could be used to recreate the entire (non-system) schema. + Works as though "DESCRIBE KEYSPACE k" was invoked for each non-system keyspace + k. Use DESCRIBE FULL SCHEMA to include the system keyspaces. """ what = parsed.matched[1][1].lower() if what == 'keyspaces': @@ -1315,7 +1316,9 @@ class Shell(cmd.Cmd): elif what == 'cluster': self.describe_cluster() elif what == 'schema': - self.describe_schema() + self.describe_schema(False) + elif what == 'full' and parsed.matched[2][1].lower() == 'schema': + self.describe_schema(True) do_desc = do_describe def do_copy(self, parsed): diff --git a/pylib/cqlshlib/test/test_cqlsh_output.py b/pylib/cqlshlib/test/test_cqlsh_output.py index 11ad949898..f89127d221 100644 --- a/pylib/cqlshlib/test/test_cqlsh_output.py +++ b/pylib/cqlshlib/test/test_cqlsh_output.py @@ -761,7 +761,7 @@ class TestCqlshOutput(BaseTestCase): def test_describe_schema_output(self): with testrun_cqlsh(tty=True) as c: for semicolon in ('', ';'): - output = c.cmd_and_response('desc schema' + semicolon) + output = c.cmd_and_response('desc full schema' + semicolon) self.assertNoHasColors(output) self.assertRegexpMatches(output, '^\nCREATE KEYSPACE') self.assertIn("\nCREATE KEYSPACE system WITH replication = {\n 'class': 'LocalStrategy'\n};\n",