Github user aweisberg commented on a diff in the pull request:
https://github.com/apache/cassandra/pull/184#discussion_r163094078
--- Diff: src/java/org/apache/cassandra/tools/nodetool/Ring.java ---
@@ -51,72 +51,116 @@
@Override
public void execute(NodeProbe probe)
{
- Map<String, String> tokensToEndpoints =
probe.getTokenToEndpointMap();
- LinkedHashMultimap<String, String> endpointsToTokens =
LinkedHashMultimap.create();
- boolean haveVnodes = false;
- for (Map.Entry<String, String> entry :
tokensToEndpoints.entrySet())
- {
- haveVnodes |= endpointsToTokens.containsKey(entry.getValue());
- endpointsToTokens.put(entry.getValue(), entry.getKey());
- }
-
- int maxAddressLength = Collections.max(endpointsToTokens.keys(),
new Comparator<String>()
+ try
{
- @Override
- public int compare(String first, String second)
+ Map<String, String> tokensToEndpoints =
probe.getTokenToEndpointMap(withPort);
+ LinkedHashMultimap<String, String> endpointsToTokens =
LinkedHashMultimap.create();
+ boolean haveVnodes = false;
+ for (Map.Entry<String, String> entry :
tokensToEndpoints.entrySet())
{
- return Integer.compare(first.length(), second.length());
+ haveVnodes |=
endpointsToTokens.containsKey(entry.getValue());
+ endpointsToTokens.put(entry.getValue(), entry.getKey());
}
- }).length();
- String formatPlaceholder = "%%-%ds
%%-12s%%-7s%%-8s%%-16s%%-20s%%-44s%%n";
- String format = format(formatPlaceholder, maxAddressLength);
+ int maxAddressLength =
Collections.max(endpointsToTokens.keys(), new Comparator<String>()
+ {
+ @Override
+ public int compare(String first, String second)
+ {
+ return Integer.compare(first.length(),
second.length());
+ }
+ }).length();
- StringBuilder errors = new StringBuilder();
- boolean showEffectiveOwnership = true;
- // Calculate per-token ownership of the ring
- Map<InetAddress, Float> ownerships;
- try
- {
- ownerships = probe.effectiveOwnership(keyspace);
- }
- catch (IllegalStateException ex)
- {
- ownerships = probe.getOwnership();
- errors.append("Note: ").append(ex.getMessage()).append("%n");
- showEffectiveOwnership = false;
- }
- catch (IllegalArgumentException ex)
- {
- System.out.printf("%nError: %s%n", ex.getMessage());
- return;
- }
+ String formatPlaceholder = "%%-%ds
%%-12s%%-7s%%-8s%%-16s%%-20s%%-44s%%n";
+ String format = format(formatPlaceholder, maxAddressLength);
+ StringBuilder errors = new StringBuilder();
+ boolean showEffectiveOwnership = true;
- System.out.println();
- for (Entry<String, SetHostStat> entry :
NodeTool.getOwnershipByDc(probe, resolveIp, tokensToEndpoints,
ownerships).entrySet())
- printDc(probe, format, entry.getKey(), endpointsToTokens,
entry.getValue(),showEffectiveOwnership);
+ if (withPort)
+ {
+ // Calculate per-token ownership of the ring
+ Map<String, Float> ownerships;
+ try
+ {
+ ownerships =
probe.effectiveOwnershipWithPort(keyspace);
+ }
+ catch (IllegalStateException ex)
+ {
+ ownerships = probe.getOwnershipWithPort();
+ errors.append("Note:
").append(ex.getMessage()).append("%n");
+ showEffectiveOwnership = false;
+ }
+ catch (IllegalArgumentException ex)
+ {
+ System.out.printf("%nError: %s%n", ex.getMessage());
+ return;
+ }
+
+
+ System.out.println();
+ for (Entry<String, SetHostStatWithPort> entry :
NodeTool.getOwnershipByDcWithPort(probe, resolveIp, tokensToEndpoints,
ownerships).entrySet())
+ printDc(probe, format, entry.getKey(),
endpointsToTokens, entry.getValue(), showEffectiveOwnership);
+
+ if (haveVnodes)
+ {
+ System.out.println(" Warning: \"nodetool ring\" is
used to output all the tokens of a node.");
+ System.out.println(" To view status related info of a
node use \"nodetool status\" instead.\n");
+ }
+
+ System.out.printf("%n " + errors.toString());
+ }
+ else
+ {
+ // Calculate per-token ownership of the ring
+ Map<InetAddress, Float> ownerships;
+ try
+ {
+ ownerships = probe.effectiveOwnership(keyspace);
+ }
+ catch (IllegalStateException ex)
+ {
+ ownerships = probe.getOwnership();
+ errors.append("Note:
").append(ex.getMessage()).append("%n");
+ showEffectiveOwnership = false;
+ }
+ catch (IllegalArgumentException ex)
+ {
+ System.out.printf("%nError: %s%n", ex.getMessage());
+ return;
+ }
- if (haveVnodes)
+
+ System.out.println();
+ for (Entry<String, SetHostStat> entry :
NodeTool.getOwnershipByDc(probe, resolveIp, tokensToEndpoints,
ownerships).entrySet())
+ printDc(probe, format, entry.getKey(),
endpointsToTokens, entry.getValue(), showEffectiveOwnership);
+
+ if (haveVnodes)
+ {
+ System.out.println(" Warning: \"nodetool ring\" is
used to output all the tokens of a node.");
+ System.out.println(" To view status related info of a
node use \"nodetool status\" instead.\n");
+ }
+
+ System.out.printf("%n " + errors.toString());
+ }
+ } catch (Exception e)
{
- System.out.println(" Warning: \"nodetool ring\" is used to
output all the tokens of a node.");
- System.out.println(" To view status related info of a node
use \"nodetool status\" instead.\n");
+ e.printStackTrace();
+ throw e;
}
-
- System.out.printf("%n " + errors.toString());
}
private void printDc(NodeProbe probe, String format,
String dc,
LinkedHashMultimap<String, String>
endpointsToTokens,
SetHostStat hoststats,boolean
showEffectiveOwnership)
{
- Collection<String> liveNodes = probe.getLiveNodes();
- Collection<String> deadNodes = probe.getUnreachableNodes();
- Collection<String> joiningNodes = probe.getJoiningNodes();
- Collection<String> leavingNodes = probe.getLeavingNodes();
- Collection<String> movingNodes = probe.getMovingNodes();
- Map<String, String> loadMap = probe.getLoadMap();
+ Collection<String> liveNodes = probe.getLiveNodes(false);
--- End diff --
I know it's ugly, but eventually we can just get rid of the old way. It's
going to converge on what we want soon enough.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]