本文整理汇总了Java中org.apache.cassandra.locator.IEndpointSnitch.sortByProximity方法的典型用法代码示例。如果您正苦于以下问题:Java IEndpointSnitch.sortByProximity方法的具体用法?Java IEndpointSnitch.sortByProximity怎么用?Java IEndpointSnitch.sortByProximity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.cassandra.locator.IEndpointSnitch
的用法示例。
在下文中一共展示了IEndpointSnitch.sortByProximity方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findSuitableEndpoint
import org.apache.cassandra.locator.IEndpointSnitch; //导入方法依赖的package包/类
/**
* Find a suitable replica as leader for counter update.
* For now, we pick a random replica in the local DC (or ask the snitch if
* there is no replica alive in the local DC).
* TODO: if we track the latency of the counter writes (which makes sense
* contrarily to standard writes since there is a read involved), we could
* trust the dynamic snitch entirely, which may be a better solution. It
* is unclear we want to mix those latencies with read latencies, so this
* may be a bit involved.
*/
private static InetAddress findSuitableEndpoint(String table, ByteBuffer key, String localDataCenter) throws UnavailableException
{
IEndpointSnitch snitch = DatabaseDescriptor.getEndpointSnitch();
List<InetAddress> endpoints = StorageService.instance.getLiveNaturalEndpoints(table, key);
if (endpoints.isEmpty())
throw new UnavailableException();
List<InetAddress> localEndpoints = new ArrayList<InetAddress>();
for (InetAddress endpoint : endpoints)
{
if (snitch.getDatacenter(endpoint).equals(localDataCenter))
localEndpoints.add(endpoint);
}
if (localEndpoints.isEmpty())
{
// No endpoint in local DC, pick the closest endpoint according to the snitch
snitch.sortByProximity(FBUtilities.getLocalAddress(), endpoints);
return endpoints.get(0);
}
else
{
return localEndpoints.get(FBUtilities.threadLocalRandom().nextInt(localEndpoints.size()));
}
}
示例2: findSuitableEndpoint
import org.apache.cassandra.locator.IEndpointSnitch; //导入方法依赖的package包/类
/**
* Find a suitable replica as leader for counter update.
* For now, we pick a random replica in the local DC (or ask the snitch if
* there is no replica alive in the local DC).
* TODO: if we track the latency of the counter writes (which makes sense
* contrarily to standard writes since there is a read involved), we could
* trust the dynamic snitch entirely, which may be a better solution. It
* is unclear we want to mix those latencies with read latencies, so this
* may be a bit involved.
*/
private static InetAddress findSuitableEndpoint(String keyspaceName, ByteBuffer key, String localDataCenter, ConsistencyLevel cl) throws UnavailableException
{
Keyspace keyspace = Keyspace.open(keyspaceName);
IEndpointSnitch snitch = DatabaseDescriptor.getEndpointSnitch();
List<InetAddress> endpoints = StorageService.instance.getLiveNaturalEndpoints(keyspace, key);
if (endpoints.isEmpty())
// TODO have a way to compute the consistency level
throw new UnavailableException(cl, cl.blockFor(keyspace), 0);
List<InetAddress> localEndpoints = new ArrayList<InetAddress>();
for (InetAddress endpoint : endpoints)
{
if (snitch.getDatacenter(endpoint).equals(localDataCenter))
localEndpoints.add(endpoint);
}
if (localEndpoints.isEmpty())
{
// No endpoint in local DC, pick the closest endpoint according to the snitch
snitch.sortByProximity(FBUtilities.getBroadcastAddress(), endpoints);
return endpoints.get(0);
}
else
{
return localEndpoints.get(ThreadLocalRandom.current().nextInt(localEndpoints.size()));
}
}
示例3: getBatchlogEndpoints
import org.apache.cassandra.locator.IEndpointSnitch; //导入方法依赖的package包/类
private static Collection<InetAddress> getBatchlogEndpoints(String localDataCenter, ConsistencyLevel consistencyLevel) throws UnavailableException
{
// will include every known node in the DC, including localhost.
TokenMetadata.Topology topology = StorageService.instance.getTokenMetadata().cloneOnlyTokenMap().getTopology();
Collection<InetAddress> localMembers = topology.getDatacenterEndpoints().get(localDataCenter);
// special case for single-node datacenters
if (localMembers.size() == 1)
return localMembers;
// not a single-node cluster - don't count the local node.
localMembers.remove(FBUtilities.getBroadcastAddress());
// include only alive nodes
List<InetAddress> candidates = new ArrayList<InetAddress>(localMembers.size());
for (InetAddress member : localMembers)
{
if (FailureDetector.instance.isAlive(member))
candidates.add(member);
}
if (candidates.isEmpty())
{
if (consistencyLevel == ConsistencyLevel.ANY)
return Collections.singleton(FBUtilities.getBroadcastAddress());
throw new UnavailableException(ConsistencyLevel.ONE, 1, 0);
}
if (candidates.size() > 2)
{
IEndpointSnitch snitch = DatabaseDescriptor.getEndpointSnitch();
snitch.sortByProximity(FBUtilities.getBroadcastAddress(), candidates);
candidates = candidates.subList(0, 2);
}
return candidates;
}
示例4: findSuitableEndpoint
import org.apache.cassandra.locator.IEndpointSnitch; //导入方法依赖的package包/类
/**
* Find a suitable replica as leader for counter update.
* For now, we pick a random replica in the local DC (or ask the snitch if
* there is no replica alive in the local DC).
* TODO: if we track the latency of the counter writes (which makes sense
* contrarily to standard writes since there is a read involved), we could
* trust the dynamic snitch entirely, which may be a better solution. It
* is unclear we want to mix those latencies with read latencies, so this
* may be a bit involved.
*/
private static InetAddress findSuitableEndpoint(String keyspaceName, ByteBuffer key, String localDataCenter, ConsistencyLevel cl) throws UnavailableException
{
Keyspace keyspace = Keyspace.open(keyspaceName);
IEndpointSnitch snitch = DatabaseDescriptor.getEndpointSnitch();
List<InetAddress> endpoints = StorageService.instance.getLiveNaturalEndpoints(keyspace, key);
if (endpoints.isEmpty())
// TODO have a way to compute the consistency level
throw new UnavailableException(cl, cl.blockFor(keyspace), 0);
List<InetAddress> localEndpoints = new ArrayList<InetAddress>();
for (InetAddress endpoint : endpoints)
{
if (snitch.getDatacenter(endpoint).equals(localDataCenter))
localEndpoints.add(endpoint);
}
if (localEndpoints.isEmpty())
{
// No endpoint in local DC, pick the closest endpoint according to the snitch
snitch.sortByProximity(FBUtilities.getBroadcastAddress(), endpoints);
return endpoints.get(0);
}
else
{
return localEndpoints.get(FBUtilities.threadLocalRandom().nextInt(localEndpoints.size()));
}
}
示例5: getBatchlogEndpoints
import org.apache.cassandra.locator.IEndpointSnitch; //导入方法依赖的package包/类
private static Collection<InetAddress> getBatchlogEndpoints(String localDataCenter) throws UnavailableException
{
// will include every known node in the DC, including localhost.
TokenMetadata.Topology topology = StorageService.instance.getTokenMetadata().cloneOnlyTokenMap().getTopology();
Collection<InetAddress> localMembers = topology.getDatacenterEndpoints().get(localDataCenter);
// special case for single-node datacenters
if (localMembers.size() == 1)
return localMembers;
// not a single-node cluster - don't count the local node.
localMembers.remove(FBUtilities.getBroadcastAddress());
// include only alive nodes
List<InetAddress> candidates = new ArrayList<InetAddress>(localMembers.size());
for (InetAddress member : localMembers)
{
if (FailureDetector.instance.isAlive(member))
candidates.add(member);
}
if (candidates.isEmpty())
throw new UnavailableException(ConsistencyLevel.ONE, 1, 0);
if (candidates.size() > 2)
{
IEndpointSnitch snitch = DatabaseDescriptor.getEndpointSnitch();
snitch.sortByProximity(FBUtilities.getBroadcastAddress(), candidates);
candidates = candidates.subList(0, 2);
}
return candidates;
}
示例6: findSuitableEndpoint
import org.apache.cassandra.locator.IEndpointSnitch; //导入方法依赖的package包/类
/**
* Find a suitable replica as leader for counter update.
* For now, we pick a random replica in the local DC (or ask the snitch if
* there is no replica alive in the local DC).
* TODO: if we track the latency of the counter writes (which makes sense
* contrarily to standard writes since there is a read involved), we could
* trust the dynamic snitch entirely, which may be a better solution. It
* is unclear we want to mix those latencies with read latencies, so this
* may be a bit involved.
*/
private static InetAddress findSuitableEndpoint(String tableName, ByteBuffer key, String localDataCenter, ConsistencyLevel cl) throws UnavailableException
{
Table table = Table.open(tableName);
IEndpointSnitch snitch = DatabaseDescriptor.getEndpointSnitch();
List<InetAddress> endpoints = StorageService.instance.getLiveNaturalEndpoints(table, key);
if (endpoints.isEmpty())
// TODO have a way to compute the consistency level
throw new UnavailableException(cl, cl.blockFor(table), 0);
List<InetAddress> localEndpoints = new ArrayList<InetAddress>();
for (InetAddress endpoint : endpoints)
{
if (snitch.getDatacenter(endpoint).equals(localDataCenter))
localEndpoints.add(endpoint);
}
if (localEndpoints.isEmpty())
{
// No endpoint in local DC, pick the closest endpoint according to the snitch
snitch.sortByProximity(FBUtilities.getBroadcastAddress(), endpoints);
return endpoints.get(0);
}
else
{
return localEndpoints.get(FBUtilities.threadLocalRandom().nextInt(localEndpoints.size()));
}
}