public static String getRingDetails(List<Host> hosts) { StringBuilder sb = new StringBuilder(); for (Host host : hosts) { sb.append(host.toString()) .append("\n"); for (TokenRange range : host.getTokenRanges()) { sb.append(" ").append(range.toString()).append("\n"); } } return sb.toString(); }
public static String getRingDetails(List<Host> hosts) { StringBuilder sb = new StringBuilder(); for (Host host : hosts) { sb.append(host.toString()) .append("\n"); for (TokenRange range : host.getTokenRanges()) { sb.append(" ").append(range.toString()).append("\n"); } } return sb.toString(); }
@Override public List<Host> get() { Map<BigInteger, List<Host>> tokenHostMap = source.get(); Set<Host> hosts = Sets.newHashSet(); for (Entry<BigInteger, List<Host>> entry : tokenHostMap.entrySet()) { for (Host host : entry.getValue()) { if (!hosts.contains(host)) { hosts.add(host); } String token = entry.getKey().toString(); host.getTokenRanges().add(new TokenRangeImpl(token, token, null)); } } return Lists.newArrayList(hosts); }
@Override public List<Host> get() { Map<BigInteger, List<Host>> tokenHostMap = source.get(); Set<Host> hosts = Sets.newHashSet(); for (Entry<BigInteger, List<Host>> entry : tokenHostMap.entrySet()) { for (Host host : entry.getValue()) { if (!hosts.contains(host)) { hosts.add(host); } String token = entry.getKey().toString(); host.getTokenRanges().add(new TokenRangeImpl(token, token, null)); } } return Lists.newArrayList(hosts); }
@Override public synchronized List<Host> get() { try { Map<String, Host> ipToHost = Maps.newHashMap(); for (TokenRange range : keyspace.describeRing(dc, rack)) { for (String endpoint : range.getEndpoints()) { Host host = ipToHost.get(endpoint); if (host == null) { host = new Host(endpoint, defaultPort); ipToHost.put(endpoint, host); } host.getTokenRanges().add(range); } } previousHosts = Lists.newArrayList(ipToHost.values()); return previousHosts; } catch (ConnectionException e) { if (previousHosts == null) { throw new RuntimeException(e); } LOG.warn("Failed to get hosts from " + keyspace.getKeyspaceName() + " via ring describe. Will use previously known ring instead"); return previousHosts; } }
@Override public boolean apply(Host host) { Host foundHost = lookup.get(host.getHostName()); if (foundHost == null) { for (String addr : host.getAlternateIpAddresses()) { foundHost = lookup.get(addr); if (foundHost != null) { break; } } } if (foundHost != null) { host.setTokenRanges(foundHost.getTokenRanges()); return true; } return false; } }));
public static List<Host> makeRing( int nHosts, int replication_factor, int id, BigInteger minInitialToken, BigInteger maxInitialToken) { List<Host> hosts = Lists.newArrayList(); for (int i = 0; i < nHosts; i++) { hosts.add(new Host("127.0." + id + "." + i + ":" + TestHostType.GOOD_FAST.ordinal(), 9160)); } for (int i = 0; i < nHosts; i++) { String startToken = TokenGenerator.initialToken(nHosts, i, minInitialToken, maxInitialToken); String endToken = TokenGenerator.initialToken(nHosts, i+1, minInitialToken, maxInitialToken); if (endToken.equals(maxInitialToken.toString())) endToken = minInitialToken.toString(); TokenRange range = new TokenRangeImpl(startToken, endToken, null); for (int j = 0; j < replication_factor; j++) { hosts.get((i+j)%nHosts).getTokenRanges().add(range); } } return hosts; }
@Override public boolean apply(Host host) { Host foundHost = lookup.get(host.getHostName()); if (foundHost == null) { for (String addr : host.getAlternateIpAddresses()) { foundHost = lookup.get(addr); if (foundHost != null) { break; } } } if (foundHost != null) { host.setTokenRanges(foundHost.getTokenRanges()); return true; } return false; } }));
public static List<Host> makeRing( int nHosts, int replication_factor, int id, BigInteger minInitialToken, BigInteger maxInitialToken) { List<Host> hosts = Lists.newArrayList(); for (int i = 0; i < nHosts; i++) { hosts.add(new Host("127.0." + id + "." + i + ":" + TestHostType.GOOD_FAST.ordinal(), 9160)); } for (int i = 0; i < nHosts; i++) { String startToken = TokenGenerator.initialToken(nHosts, i, minInitialToken, maxInitialToken); String endToken = TokenGenerator.initialToken(nHosts, i+1, minInitialToken, maxInitialToken); if (endToken.equals(maxInitialToken.toString())) endToken = minInitialToken.toString(); TokenRange range = new TokenRangeImpl(startToken, endToken, null); for (int j = 0; j < replication_factor; j++) { hosts.get((i+j)%nHosts).getTokenRanges().add(range); } } return hosts; }
didChange = true; for (TokenRange range : pool.getHost().getTokenRanges()) { BigInteger endToken = new BigInteger(range.getEndToken()); List<HostConnectionPool<CL>> partition = tokenHostMap.get(endToken);
if (existingHost.getTokenRanges().size() != host.getTokenRanges().size()) { existingHost.setTokenRanges(host.getTokenRanges()); return true; ArrayList<TokenRange> currentTokens = Lists.newArrayList(existingHost.getTokenRanges()); ArrayList<TokenRange> newTokens = Lists.newArrayList(host.getTokenRanges()); Collections.sort(currentTokens, compareByStartToken); Collections.sort(newTokens, compareByStartToken); existingHost.setTokenRanges(host.getTokenRanges()); return true;
if (existingHost.getTokenRanges().size() != host.getTokenRanges().size()) { existingHost.setTokenRanges(host.getTokenRanges()); return true; ArrayList<TokenRange> currentTokens = Lists.newArrayList(existingHost.getTokenRanges()); ArrayList<TokenRange> newTokens = Lists.newArrayList(host.getTokenRanges()); Collections.sort(currentTokens, compareByStartToken); Collections.sort(newTokens, compareByStartToken); existingHost.setTokenRanges(host.getTokenRanges()); return true;
didChange = true; for (TokenRange range : pool.getHost().getTokenRanges()) { RingPosition endToken = partitioner.getRingPositionForToken(range.getEndToken()); List<HostConnectionPool<CL>> partition = tokenHostMap.get(endToken);