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


Java Range.intersects方法代码示例

本文整理汇总了Java中org.apache.cassandra.dht.Range.intersects方法的典型用法代码示例。如果您正苦于以下问题:Java Range.intersects方法的具体用法?Java Range.intersects怎么用?Java Range.intersects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.cassandra.dht.Range的用法示例。


在下文中一共展示了Range.intersects方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: intersecting

import org.apache.cassandra.dht.Range; //导入方法依赖的package包/类
public static Collection<SSTableReader> intersecting(Collection<SSTableReader> sstables, Collection<Range<Token>> ranges)
{
    if (ranges == null)
        return Lists.newArrayList(sstables);

    Set<SSTableReader> filtered = new HashSet<>();
    for (Range<Token> range : ranges)
    {
        for (SSTableReader sstable : sstables)
        {
            Range<Token> sstableRange = new Range<>(sstable.first.getToken(), sstable.last.getToken());
            if (range == null || sstableRange.intersects(range))
                filtered.add(sstable);
        }
    }
    return filtered;
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:18,代码来源:LeveledCompactionStrategy.java

示例2: intersecting

import org.apache.cassandra.dht.Range; //导入方法依赖的package包/类
public static List<SSTableReader> intersecting(Collection<SSTableReader> sstables, Range<Token> range)
{
    ArrayList<SSTableReader> filtered = new ArrayList<SSTableReader>();
    for (SSTableReader sstable : sstables)
    {
        Range<Token> sstableRange = new Range<Token>(sstable.first.getToken(), sstable.last.getToken(), sstable.partitioner);
        if (range == null || sstableRange.intersects(range))
            filtered.add(sstable);
    }
    return filtered;
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:12,代码来源:LeveledCompactionStrategy.java

示例3: getNeighbors

import org.apache.cassandra.dht.Range; //导入方法依赖的package包/类
/**
 * Return all of the neighbors with whom we share the provided range.
 *
 * @param keyspaceName keyspace to repair
 * @param toRepair token to repair
 * @param isLocal need to use only nodes from local datacenter
 *
 * @return neighbors with whom we share the provided range
 */
public static Set<InetAddress> getNeighbors(String keyspaceName, Range<Token> toRepair, boolean isLocal)
{
    StorageService ss = StorageService.instance;
    Map<Range<Token>, List<InetAddress>> replicaSets = ss.getRangeToAddressMap(keyspaceName);
    Range<Token> rangeSuperSet = null;
    for (Range<Token> range : ss.getLocalRanges(keyspaceName))
    {
        if (range.contains(toRepair))
        {
            rangeSuperSet = range;
            break;
        }
        else if (range.intersects(toRepair))
        {
            throw new IllegalArgumentException("Requested range intersects a local range but is not fully contained in one; this would lead to imprecise repair");
        }
    }
    if (rangeSuperSet == null || !replicaSets.containsKey(rangeSuperSet))
        return Collections.emptySet();

    Set<InetAddress> neighbors = new HashSet<>(replicaSets.get(rangeSuperSet));
    neighbors.remove(FBUtilities.getBroadcastAddress());

    if (isLocal)
    {
        TokenMetadata.Topology topology = ss.getTokenMetadata().cloneOnlyTokenMap().getTopology();
        Set<InetAddress> localEndpoints = Sets.newHashSet(topology.getDatacenterEndpoints().get(DatabaseDescriptor.getLocalDataCenter()));
        return Sets.intersection(neighbors, localEndpoints);
    }

    return neighbors;
}
 
开发者ID:pgaref,项目名称:ACaZoo,代码行数:42,代码来源:ActiveRepairService.java

示例4: hash

import org.apache.cassandra.dht.Range; //导入方法依赖的package包/类
@VisibleForTesting
public byte[] hash(Range<Token> range)
{
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    boolean hashed = false;

    try
    {
        for (Range<Token> rt : merkleTrees.keySet())
        {
            if (rt.intersects(range))
            {
                byte[] bytes = merkleTrees.get(rt).hash(range);
                if (bytes != null)
                {
                    baos.write(bytes);
                    hashed = true;
                }
            }
        }
    }
    catch (IOException e)
    {
        throw new RuntimeException("Unable to append merkle tree hash to result");
    }
    
    return hashed ? baos.toByteArray() : null;
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:29,代码来源:MerkleTrees.java

示例5: getNeighbors

import org.apache.cassandra.dht.Range; //导入方法依赖的package包/类
/**
 * Return all of the neighbors with whom we share the provided range.
 *
 * @param keyspaceName keyspace to repair
 * @param toRepair token to repair
 * @param dataCenters the data centers to involve in the repair
 *
 * @return neighbors with whom we share the provided range
 */
public static Set<InetAddress> getNeighbors(String keyspaceName, Range<Token> toRepair, Collection<String> dataCenters, Collection<String> hosts)
{
    StorageService ss = StorageService.instance;
    Map<Range<Token>, List<InetAddress>> replicaSets = ss.getRangeToAddressMap(keyspaceName);
    Range<Token> rangeSuperSet = null;
    for (Range<Token> range : ss.getLocalRanges(keyspaceName))
    {
        if (range.contains(toRepair))
        {
            rangeSuperSet = range;
            break;
        }
        else if (range.intersects(toRepair))
        {
            throw new IllegalArgumentException("Requested range intersects a local range but is not fully contained in one; this would lead to imprecise repair");
        }
    }
    if (rangeSuperSet == null || !replicaSets.containsKey(rangeSuperSet))
        return Collections.emptySet();

    Set<InetAddress> neighbors = new HashSet<>(replicaSets.get(rangeSuperSet));
    neighbors.remove(FBUtilities.getBroadcastAddress());

    if (dataCenters != null)
    {
        TokenMetadata.Topology topology = ss.getTokenMetadata().cloneOnlyTokenMap().getTopology();
        Set<InetAddress> dcEndpoints = Sets.newHashSet();
        Multimap<String,InetAddress> dcEndpointsMap = topology.getDatacenterEndpoints();
        for (String dc : dataCenters)
        {
            Collection<InetAddress> c = dcEndpointsMap.get(dc);
            if (c != null)
               dcEndpoints.addAll(c);
        }
        return Sets.intersection(neighbors, dcEndpoints);
    }
    else if (hosts != null)
    {
        Set<InetAddress> specifiedHost = new HashSet<>();
        for (final String host : hosts)
        {
            try
            {
                final InetAddress endpoint = InetAddress.getByName(host.trim());
                if (endpoint.equals(FBUtilities.getBroadcastAddress()) || neighbors.contains(endpoint))
                    specifiedHost.add(endpoint);
            }
            catch (UnknownHostException e)
            {
                throw new IllegalArgumentException("Unknown host specified " + host, e);
            }
        }

        if (!specifiedHost.contains(FBUtilities.getBroadcastAddress()))
            throw new IllegalArgumentException("The current host must be part of the repair");

        if (specifiedHost.size() <= 1)
        {
            String msg = "Repair requires at least two endpoints that are neighbours before it can continue, the endpoint used for this repair is %s, " +
                         "other available neighbours are %s but these neighbours were not part of the supplied list of hosts to use during the repair (%s).";
            throw new IllegalArgumentException(String.format(msg, specifiedHost, neighbors, hosts));
        }

        specifiedHost.remove(FBUtilities.getBroadcastAddress());
        return specifiedHost;

    }

    return neighbors;
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:80,代码来源:ActiveRepairService.java

示例6: performAnticompaction

import org.apache.cassandra.dht.Range; //导入方法依赖的package包/类
/**
 * Make sure the {validatedForRepair} are marked for compaction before calling this.
 *
 * Caller must reference the validatedForRepair sstables (via ParentRepairSession.getAndReferenceSSTables(..)).
 *
 * @param cfs
 * @param ranges Ranges that the repair was carried out on
 * @param validatedForRepair SSTables containing the repaired ranges. Should be referenced before passing them.
 * @throws InterruptedException, ExecutionException, IOException
 */
public void performAnticompaction(ColumnFamilyStore cfs,
                                  Collection<Range<Token>> ranges,
                                  Refs<SSTableReader> validatedForRepair,
                                  long repairedAt) throws InterruptedException, ExecutionException, IOException
{
    logger.info("Starting anticompaction for {}.{} on {}/{} sstables", cfs.keyspace.getName(), cfs.getColumnFamilyName(), validatedForRepair.size(), cfs.getSSTables().size());
    logger.debug("Starting anticompaction for ranges {}", ranges);
    Set<SSTableReader> sstables = new HashSet<>(validatedForRepair);
    Set<SSTableReader> mutatedRepairStatuses = new HashSet<>();
    Set<SSTableReader> nonAnticompacting = new HashSet<>();
    Iterator<SSTableReader> sstableIterator = sstables.iterator();
    try
    {
        while (sstableIterator.hasNext())
        {
            SSTableReader sstable = sstableIterator.next();
            for (Range<Token> r : Range.normalize(ranges))
            {
                Range<Token> sstableRange = new Range<>(sstable.first.getToken(), sstable.last.getToken(), sstable.partitioner);
                if (r.contains(sstableRange))
                {
                    logger.info("SSTable {} fully contained in range {}, mutating repairedAt instead of anticompacting", sstable, r);
                    sstable.descriptor.getMetadataSerializer().mutateRepairedAt(sstable.descriptor, repairedAt);
                    sstable.reloadSSTableMetadata();
                    mutatedRepairStatuses.add(sstable);
                    sstableIterator.remove();
                    break;
                }
                else if (!sstableRange.intersects(r))
                {
                    logger.info("SSTable {} ({}) does not intersect repaired range {}, not touching repairedAt.", sstable, sstableRange, r);
                    nonAnticompacting.add(sstable);
                    sstableIterator.remove();
                    break;
                }
                else
                {
                    logger.info("SSTable {} ({}) will be anticompacted on range {}", sstable, sstableRange, r);
                }
            }
        }
        cfs.getDataTracker().notifySSTableRepairedStatusChanged(mutatedRepairStatuses);
        cfs.getDataTracker().unmarkCompacting(Sets.union(nonAnticompacting, mutatedRepairStatuses));
        validatedForRepair.release(Sets.union(nonAnticompacting, mutatedRepairStatuses));
        if (!sstables.isEmpty())
            doAntiCompaction(cfs, ranges, sstables, repairedAt);
    }
    finally
    {
        validatedForRepair.release();
        cfs.getDataTracker().unmarkCompacting(sstables);
    }

    logger.info(String.format("Completed anticompaction successfully"));
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:66,代码来源:CompactionManager.java


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