当前位置: 首页>>代码示例>>Java>>正文


Java IEndpointSnitch.sortByProximity方法代码示例

本文整理汇总了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()));
    }
}
 
开发者ID:devdattakulkarni,项目名称:Cassandra-KVPM,代码行数:35,代码来源:StorageProxy.java

示例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()));
    }
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:37,代码来源:StorageProxy.java

示例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;
}
 
开发者ID:pgaref,项目名称:ACaZoo,代码行数:39,代码来源:StorageProxy.java

示例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()));
    }
}
 
开发者ID:pgaref,项目名称:ACaZoo,代码行数:37,代码来源:StorageProxy.java

示例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;
}
 
开发者ID:dprguiuc,项目名称:Cassandra-Wasef,代码行数:34,代码来源:StorageProxy.java

示例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()));
    }
}
 
开发者ID:dprguiuc,项目名称:Cassandra-Wasef,代码行数:37,代码来源:StorageProxy.java


注:本文中的org.apache.cassandra.locator.IEndpointSnitch.sortByProximity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。