mirror of https://github.com/apache/cassandra
add CQLSH command SHOW REPLICAS
patch by Brad Schoening; reviewed by Stefan Miklosovic and Brandon Williams for CASSANDRA-17577
This commit is contained in:
parent
42806047f7
commit
72d5b4d1b1
|
|
@ -1,4 +1,5 @@
|
|||
4.2
|
||||
* Add CQLSH command SHOW REPLICAS (CASSANDRA-17577)
|
||||
* Add guardrail to allow disabling of SimpleStrategy (CASSANDRA-17647)
|
||||
* Change default directory permission to 750 in packaging (CASSANDRA-17470)
|
||||
* Adding support for TLS client authentication for internode communication (CASSANDRA-17513)
|
||||
|
|
|
|||
18
bin/cqlsh.py
18
bin/cqlsh.py
|
|
@ -600,6 +600,13 @@ class Shell(cmd.Cmd):
|
|||
def show_session(self, sessionid, partial_session=False):
|
||||
print_trace_session(self, self.session, sessionid, partial_session)
|
||||
|
||||
def show_replicas(self, token_value, keyspace=None):
|
||||
ks = self.current_keyspace if keyspace is None else keyspace
|
||||
token_map = self.conn.metadata.token_map
|
||||
nodes = token_map.get_replicas(ks, token_map.token_class(token_value))
|
||||
addresses = [x.address for x in nodes]
|
||||
print(f"{addresses}")
|
||||
|
||||
def get_connection_versions(self):
|
||||
result, = self.session.execute("select * from system.local where key = 'local'")
|
||||
vers = {
|
||||
|
|
@ -979,7 +986,7 @@ class Shell(cmd.Cmd):
|
|||
if parsed:
|
||||
self.printerr('Improper %s command (problem at %r).' % (cmdword, parsed.remainder[0]))
|
||||
else:
|
||||
self.printerr('Improper %s command.' % cmdword)
|
||||
self.printerr(f'Improper {cmdword} command.')
|
||||
|
||||
def do_use(self, parsed):
|
||||
ksname = parsed.get_binding('ksname')
|
||||
|
|
@ -1578,6 +1585,11 @@ class Shell(cmd.Cmd):
|
|||
SHOW SESSION <sessionid>
|
||||
|
||||
Pretty-prints the requested tracing session.
|
||||
|
||||
SHOW REPLICAS <token> (<keyspace>)
|
||||
|
||||
Lists the replica nodes by IP address for the given token. The current
|
||||
keyspace is used if one is not specified.
|
||||
"""
|
||||
showwhat = parsed.get_binding('what').lower()
|
||||
if showwhat == 'version':
|
||||
|
|
@ -1588,6 +1600,10 @@ class Shell(cmd.Cmd):
|
|||
elif showwhat.startswith('session'):
|
||||
session_id = parsed.get_binding('sessionid').lower()
|
||||
self.show_session(UUID(session_id))
|
||||
elif showwhat.startswith('replicas'):
|
||||
token_id = parsed.get_binding('token')
|
||||
keyspace = parsed.get_binding('keyspace')
|
||||
self.show_replicas(token_id, keyspace)
|
||||
else:
|
||||
self.printerr('Wait, how do I show %r?' % (showwhat,))
|
||||
|
||||
|
|
|
|||
|
|
@ -181,6 +181,21 @@ cqlsh> SHOW HOST
|
|||
Connected to Prod_Cluster at 192.0.0.1:9042.
|
||||
----
|
||||
|
||||
=== `SHOW REPLICAS`
|
||||
|
||||
Prints the IP addresses of the Cassandra nodes which are replicas for the
|
||||
listed given token and keyspace. This command is available from Cassandra 4.2.
|
||||
|
||||
`Usage`: `SHOW REPLICAS <token> (<keyspace>)`
|
||||
|
||||
Example usage:
|
||||
|
||||
[source,none]
|
||||
----
|
||||
cqlsh> SHOW REPLICAS 95
|
||||
['192.0.0.1', '192.0.0.2']
|
||||
----
|
||||
|
||||
=== `SHOW SESSION`
|
||||
|
||||
Pretty prints a specific tracing session.
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ cqlsh_serial_consistency_level_syntax_rules = r'''
|
|||
'''
|
||||
|
||||
cqlsh_show_cmd_syntax_rules = r'''
|
||||
<showCommand> ::= "SHOW" what=( "VERSION" | "HOST" | "SESSION" sessionid=<uuid> )
|
||||
<showCommand> ::= "SHOW" what=( "VERSION" | "HOST" | "SESSION" sessionid=<uuid> | "REPLICAS" token=<integer> (keyspace=<keyspaceName>)? )
|
||||
;
|
||||
'''
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue