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


Java AbstractReplicationStrategy类代码示例

本文整理汇总了Java中org.apache.cassandra.locator.AbstractReplicationStrategy的典型用法代码示例。如果您正苦于以下问题:Java AbstractReplicationStrategy类的具体用法?Java AbstractReplicationStrategy怎么用?Java AbstractReplicationStrategy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: validate

import org.apache.cassandra.locator.AbstractReplicationStrategy; //导入依赖的package包/类
public void validate(ClientState state) throws RequestValidationException
{
    KSMetaData ksm = Schema.instance.getKSMetaData(name);
    if (ksm == null)
        throw new InvalidRequestException("Unknown keyspace " + name);
    if (ksm.name.equalsIgnoreCase(Keyspace.SYSTEM_KS))
        throw new InvalidRequestException("Cannot alter system keyspace");

    attrs.validate();

    if (attrs.getReplicationStrategyClass() == null && !attrs.getReplicationOptions().isEmpty())
    {
        throw new ConfigurationException("Missing replication strategy class");
    }
    else if (attrs.getReplicationStrategyClass() != null)
    {
        // The strategy is validated through KSMetaData.validate() in announceKeyspaceUpdate below.
        // However, for backward compatibility with thrift, this doesn't validate unexpected options yet,
        // so doing proper validation here.
        AbstractReplicationStrategy.validateReplicationStrategy(name,
                                                                AbstractReplicationStrategy.getClass(attrs.getReplicationStrategyClass()),
                                                                StorageService.instance.getTokenMetadata(),
                                                                DatabaseDescriptor.getEndpointSnitch(),
                                                                attrs.getReplicationOptions());
    }
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:27,代码来源:AlterKeyspaceStatement.java

示例2: validate

import org.apache.cassandra.locator.AbstractReplicationStrategy; //导入依赖的package包/类
/**
 * The <code>CqlParser</code> only goes as far as extracting the keyword arguments
 * from these statements, so this method is responsible for processing and
 * validating.
 *
 * @throws InvalidRequestException if arguments are missing or unacceptable
 */
public void validate(ClientState state) throws RequestValidationException
{
    ThriftValidation.validateKeyspaceNotSystem(name);

    // keyspace name
    if (!name.matches("\\w+"))
        throw new InvalidRequestException(String.format("\"%s\" is not a valid keyspace name", name));
    if (name.length() > Schema.NAME_LENGTH)
        throw new InvalidRequestException(String.format("Keyspace names shouldn't be more than %s characters long (got \"%s\")", Schema.NAME_LENGTH, name));

    attrs.validate();

    if (attrs.getReplicationStrategyClass() == null)
        throw new ConfigurationException("Missing mandatory replication strategy class");

    // The strategy is validated through KSMetaData.validate() in announceNewKeyspace below.
    // However, for backward compatibility with thrift, this doesn't validate unexpected options yet,
    // so doing proper validation here.
    AbstractReplicationStrategy.validateReplicationStrategy(name,
                                                            AbstractReplicationStrategy.getClass(attrs.getReplicationStrategyClass()),
                                                            StorageService.instance.getTokenMetadata(),
                                                            DatabaseDescriptor.getEndpointSnitch(),
                                                            attrs.getReplicationOptions());
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:32,代码来源:CreateKeyspaceStatement.java

示例3: getAllRangesWithSourcesFor

import org.apache.cassandra.locator.AbstractReplicationStrategy; //导入依赖的package包/类
/**
 * Get a map of all ranges and their respective sources that are candidates for streaming the given ranges
 * to us. For each range, the list of sources is sorted by proximity relative to the given destAddress.
 */
private Multimap<Range<Token>, InetAddress> getAllRangesWithSourcesFor(String keyspaceName, Collection<Range<Token>> desiredRanges)
{
    AbstractReplicationStrategy strat = Keyspace.open(keyspaceName).getReplicationStrategy();
    Multimap<Range<Token>, InetAddress> rangeAddresses = strat.getRangeAddresses(metadata.cloneOnlyTokenMap());

    Multimap<Range<Token>, InetAddress> rangeSources = ArrayListMultimap.create();
    for (Range<Token> desiredRange : desiredRanges)
    {
        for (Range<Token> range : rangeAddresses.keySet())
        {
            if (range.contains(desiredRange))
            {
                List<InetAddress> preferred = DatabaseDescriptor.getEndpointSnitch().getSortedListByProximity(address, rangeAddresses.get(range));
                rangeSources.putAll(desiredRange, preferred);
                break;
            }
        }

        if (!rangeSources.keySet().contains(desiredRange))
            throw new IllegalStateException("No sources found for " + desiredRange);
    }

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

示例4: performWrite

import org.apache.cassandra.locator.AbstractReplicationStrategy; //导入依赖的package包/类
/**
 * Perform the write of a mutation given a WritePerformer.
 * Gather the list of write endpoints, apply locally and/or forward the mutation to
 * said write endpoint (deletaged to the actual WritePerformer) and wait for the
 * responses based on consistency level.
 *
 * @param mutation the mutation to be applied
 * @param consistency_level the consistency level for the write operation
 * @param performer the WritePerformer in charge of appliying the mutation
 * given the list of write endpoints (either standardWritePerformer for
 * standard writes or counterWritePerformer for counter writes).
 * @param callback an optional callback to be run if and when the write is
 * successful.
 */
public static AbstractWriteResponseHandler performWrite(IMutation mutation,
                                                        ConsistencyLevel consistency_level,
                                                        String localDataCenter,
                                                        WritePerformer performer,
                                                        Runnable callback,
                                                        WriteType writeType)
throws UnavailableException, OverloadedException
{
    String keyspaceName = mutation.getKeyspaceName();
    AbstractReplicationStrategy rs = Keyspace.open(keyspaceName).getReplicationStrategy();

    Token tk = StorageService.getPartitioner().getToken(mutation.key());
    List<InetAddress> naturalEndpoints = StorageService.instance.getNaturalEndpoints(keyspaceName, tk);
    Collection<InetAddress> pendingEndpoints = StorageService.instance.getTokenMetadata().pendingEndpointsFor(tk, keyspaceName);

    AbstractWriteResponseHandler responseHandler = rs.getWriteResponseHandler(naturalEndpoints, pendingEndpoints, consistency_level, callback, writeType);

    // exit early if we can't fulfill the CL at this time
    responseHandler.assureSufficientLiveNodes();

    performer.apply(mutation, Iterables.concat(naturalEndpoints, pendingEndpoints), responseHandler, localDataCenter, consistency_level);
    return responseHandler;
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:38,代码来源:StorageProxy.java

示例5: apply

import org.apache.cassandra.locator.AbstractReplicationStrategy; //导入依赖的package包/类
public String apply(String name)
{
    String strategy = null;
    for (String fullname : new String[] { name, "org.apache.cassandra.locator." + name })
    {
        try
        {
            Class<?> clazz = Class.forName(fullname);
            if (!AbstractReplicationStrategy.class.isAssignableFrom(clazz))
                throw new IllegalArgumentException(clazz + " is not a replication strategy");
            strategy = fullname;
            break;
        } catch (Exception ignore)
        {
        }
    }
    if (strategy == null)
        throw new IllegalArgumentException("Invalid replication strategy: " + name);
    return strategy;
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:21,代码来源:OptionReplication.java

示例6: testGetNeighborsTimesTwo

import org.apache.cassandra.locator.AbstractReplicationStrategy; //导入依赖的package包/类
@Test
public void testGetNeighborsTimesTwo() throws Throwable
{
    TokenMetadata tmd = StorageService.instance.getTokenMetadata();

    // generate rf*2 nodes, and ensure that only neighbors specified by the ARS are returned
    addTokens(2 * Keyspace.open(keyspaceName).getReplicationStrategy().getReplicationFactor());
    AbstractReplicationStrategy ars = Keyspace.open(keyspaceName).getReplicationStrategy();
    Set<InetAddress> expected = new HashSet<InetAddress>();
    for (Range<Token> replicaRange : ars.getAddressRanges().get(FBUtilities.getBroadcastAddress()))
    {
        expected.addAll(ars.getRangeAddresses(tmd.cloneOnlyTokenMap()).get(replicaRange));
    }
    expected.remove(FBUtilities.getBroadcastAddress());
    Collection<Range<Token>> ranges = StorageService.instance.getLocalRanges(keyspaceName);
    Set<InetAddress> neighbors = new HashSet<InetAddress>();
    for (Range<Token> range : ranges)
    {
        neighbors.addAll(ActiveRepairService.getNeighbors(keyspaceName, range, null, null));
    }
    assertEquals(expected, neighbors);
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:23,代码来源:AntiEntropyServiceTestAbstract.java

示例7: testGetNeighborsTimesTwoInSpecifiedHosts

import org.apache.cassandra.locator.AbstractReplicationStrategy; //导入依赖的package包/类
@Test
public void testGetNeighborsTimesTwoInSpecifiedHosts() throws Throwable
{
    TokenMetadata tmd = StorageService.instance.getTokenMetadata();

    // generate rf*2 nodes, and ensure that only neighbors specified by the hosts are returned
    addTokens(2 * Keyspace.open(keyspaceName).getReplicationStrategy().getReplicationFactor());
    AbstractReplicationStrategy ars = Keyspace.open(keyspaceName).getReplicationStrategy();
    List<InetAddress> expected = new ArrayList<>();
    for (Range<Token> replicaRange : ars.getAddressRanges().get(FBUtilities.getBroadcastAddress()))
    {
        expected.addAll(ars.getRangeAddresses(tmd.cloneOnlyTokenMap()).get(replicaRange));
    }

    expected.remove(FBUtilities.getBroadcastAddress());
    Collection<String> hosts = Arrays.asList(FBUtilities.getBroadcastAddress().getCanonicalHostName(),expected.get(0).getCanonicalHostName());

   assertEquals(expected.get(0), ActiveRepairService.getNeighbors(keyspaceName, StorageService.instance.getLocalRanges(keyspaceName).iterator().next(), null, hosts).iterator().next());
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:20,代码来源:AntiEntropyServiceTestAbstract.java

示例8: commitPaxos

import org.apache.cassandra.locator.AbstractReplicationStrategy; //导入依赖的package包/类
private static void commitPaxos(Commit proposal, ConsistencyLevel consistencyLevel) throws WriteTimeoutException
{
    Keyspace keyspace = Keyspace.open(proposal.update.metadata().ksName);

    Token tk = StorageService.getPartitioner().getToken(proposal.key);
    List<InetAddress> naturalEndpoints = StorageService.instance.getNaturalEndpoints(keyspace.getName(), tk);
    Collection<InetAddress> pendingEndpoints = StorageService.instance.getTokenMetadata().pendingEndpointsFor(tk, keyspace.getName());

    AbstractReplicationStrategy rs = keyspace.getReplicationStrategy();
    AbstractWriteResponseHandler responseHandler = rs.getWriteResponseHandler(naturalEndpoints, pendingEndpoints, consistencyLevel, null, WriteType.SIMPLE);

    MessageOut<Commit> message = new MessageOut<Commit>(MessagingService.Verb.PAXOS_COMMIT, proposal, Commit.serializer);
    for (InetAddress destination : Iterables.concat(naturalEndpoints, pendingEndpoints))
    {
        if (FailureDetector.instance.isAlive(destination))
            MessagingService.instance().sendRR(message, destination, responseHandler);
    }

    responseHandler.get();
}
 
开发者ID:pgaref,项目名称:ACaZoo,代码行数:21,代码来源:StorageProxy.java

示例9: testGetNeighborsTimesTwo

import org.apache.cassandra.locator.AbstractReplicationStrategy; //导入依赖的package包/类
@Test
public void testGetNeighborsTimesTwo() throws Throwable
{
    TokenMetadata tmd = StorageService.instance.getTokenMetadata();

    // generate rf*2 nodes, and ensure that only neighbors specified by the ARS are returned
    addTokens(2 * Keyspace.open(keyspaceName).getReplicationStrategy().getReplicationFactor());
    AbstractReplicationStrategy ars = Keyspace.open(keyspaceName).getReplicationStrategy();
    Set<InetAddress> expected = new HashSet<InetAddress>();
    for (Range<Token> replicaRange : ars.getAddressRanges().get(FBUtilities.getBroadcastAddress()))
    {
        expected.addAll(ars.getRangeAddresses(tmd.cloneOnlyTokenMap()).get(replicaRange));
    }
    expected.remove(FBUtilities.getBroadcastAddress());
    Collection<Range<Token>> ranges = StorageService.instance.getLocalRanges(keyspaceName);
    Set<InetAddress> neighbors = new HashSet<InetAddress>();
    for (Range<Token> range : ranges)
    {
        neighbors.addAll(ActiveRepairService.getNeighbors(keyspaceName, range, false));
    }
    assertEquals(expected, neighbors);
}
 
开发者ID:pgaref,项目名称:ACaZoo,代码行数:23,代码来源:AntiEntropyServiceTestAbstract.java

示例10: getAllRangesWithSourcesFor

import org.apache.cassandra.locator.AbstractReplicationStrategy; //导入依赖的package包/类
/**
 * Get a map of all ranges and their respective sources that are candidates for streaming the given ranges
 * to us. For each range, the list of sources is sorted by proximity relative to the given destAddress.
 *
 * @throws java.lang.IllegalStateException when there is no source to get data streamed
 */
private Multimap<Range<Token>, InetAddress> getAllRangesWithSourcesFor(String keyspaceName, Collection<Range<Token>> desiredRanges)
{
    AbstractReplicationStrategy strat = Keyspace.open(keyspaceName).getReplicationStrategy();
    Multimap<Range<Token>, InetAddress> rangeAddresses = strat.getRangeAddresses(metadata.cloneOnlyTokenMap());

    Multimap<Range<Token>, InetAddress> rangeSources = ArrayListMultimap.create();
    for (Range<Token> desiredRange : desiredRanges)
    {
        for (Range<Token> range : rangeAddresses.keySet())
        {
            if (range.contains(desiredRange))
            {
                List<InetAddress> preferred = snitch.getSortedListByProximity(address, rangeAddresses.get(range));
                rangeSources.putAll(desiredRange, preferred);
                break;
            }
        }

        if (!rangeSources.keySet().contains(desiredRange))
            throw new IllegalStateException("No sources found for " + desiredRange);
    }

    return rangeSources;
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:31,代码来源:RangeStreamer.java

示例11: allocateTokens

import org.apache.cassandra.locator.AbstractReplicationStrategy; //导入依赖的package包/类
public static Collection<Token> allocateTokens(final TokenMetadata tokenMetadata,
                                               final AbstractReplicationStrategy rs,
                                               final InetAddress endpoint,
                                               int numTokens)
{
    StrategyAdapter strategy = getStrategy(tokenMetadata, rs, endpoint);
    Collection<Token> tokens = create(tokenMetadata, strategy).addUnit(endpoint, numTokens);
    tokens = adjustForCrossDatacenterClashes(tokenMetadata, strategy, tokens);

    if (logger.isWarnEnabled())
    {
        logger.warn("Selected tokens {}", tokens);
        SummaryStatistics os = replicatedOwnershipStats(tokenMetadata, rs, endpoint);
        TokenMetadata tokenMetadataCopy = tokenMetadata.cloneOnlyTokenMap();
        tokenMetadataCopy.updateNormalTokens(tokens, endpoint);
        SummaryStatistics ns = replicatedOwnershipStats(tokenMetadataCopy, rs, endpoint);
        logger.warn("Replicated node load in datacentre before allocation " + statToString(os));
        logger.warn("Replicated node load in datacentre after allocation " + statToString(ns));

        // TODO: Is it worth doing the replicated ownership calculation always to be able to raise this alarm?
        if (ns.getStandardDeviation() > os.getStandardDeviation())
            logger.warn("Unexpected growth in standard deviation after allocation.");
    }
    return tokens;
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:26,代码来源:TokenAllocation.java

示例12: apply

import org.apache.cassandra.locator.AbstractReplicationStrategy; //导入依赖的package包/类
public String apply(String name)
{
    String strategy = null;
    for (String fullname : new String[] { name, "org.apache.cassandra.locator." + name })
    {
        try
        {
            Class<?> clazz = Class.forName(fullname);
            if (!AbstractReplicationStrategy.class.isAssignableFrom(clazz))
                throw new IllegalArgumentException(clazz + " is not a replication strategy");
            strategy = fullname;
            break;
        } catch (Exception ignore)
        {
            // will throw below if strategy is still null
        }
    }
    if (strategy == null)
        throw new IllegalArgumentException("Invalid replication strategy: " + name);
    return strategy;
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:22,代码来源:OptionReplication.java

示例13: testGetNeighborsTimesTwo

import org.apache.cassandra.locator.AbstractReplicationStrategy; //导入依赖的package包/类
@Test
public void testGetNeighborsTimesTwo() throws Throwable
{
    TokenMetadata tmd = StorageService.instance.getTokenMetadata();

    // generate rf*2 nodes, and ensure that only neighbors specified by the ARS are returned
    addTokens(2 * Keyspace.open(KEYSPACE5).getReplicationStrategy().getReplicationFactor());
    AbstractReplicationStrategy ars = Keyspace.open(KEYSPACE5).getReplicationStrategy();
    Set<InetAddress> expected = new HashSet<>();
    for (Range<Token> replicaRange : ars.getAddressRanges().get(FBUtilities.getBroadcastAddress()))
    {
        expected.addAll(ars.getRangeAddresses(tmd.cloneOnlyTokenMap()).get(replicaRange));
    }
    expected.remove(FBUtilities.getBroadcastAddress());
    Collection<Range<Token>> ranges = StorageService.instance.getLocalRanges(KEYSPACE5);
    Set<InetAddress> neighbors = new HashSet<>();
    for (Range<Token> range : ranges)
    {
        neighbors.addAll(ActiveRepairService.getNeighbors(KEYSPACE5, ranges, range, null, null));
    }
    assertEquals(expected, neighbors);
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:23,代码来源:ActiveRepairServiceTest.java

示例14: testGetNeighborsTimesTwoInSpecifiedHosts

import org.apache.cassandra.locator.AbstractReplicationStrategy; //导入依赖的package包/类
@Test
public void testGetNeighborsTimesTwoInSpecifiedHosts() throws Throwable
{
    TokenMetadata tmd = StorageService.instance.getTokenMetadata();

    // generate rf*2 nodes, and ensure that only neighbors specified by the hosts are returned
    addTokens(2 * Keyspace.open(KEYSPACE5).getReplicationStrategy().getReplicationFactor());
    AbstractReplicationStrategy ars = Keyspace.open(KEYSPACE5).getReplicationStrategy();
    List<InetAddress> expected = new ArrayList<>();
    for (Range<Token> replicaRange : ars.getAddressRanges().get(FBUtilities.getBroadcastAddress()))
    {
        expected.addAll(ars.getRangeAddresses(tmd.cloneOnlyTokenMap()).get(replicaRange));
    }

    expected.remove(FBUtilities.getBroadcastAddress());
    Collection<String> hosts = Arrays.asList(FBUtilities.getBroadcastAddress().getCanonicalHostName(),expected.get(0).getCanonicalHostName());
    Collection<Range<Token>> ranges = StorageService.instance.getLocalRanges(KEYSPACE5);

    assertEquals(expected.get(0), ActiveRepairService.getNeighbors(KEYSPACE5, ranges,
                                                                   ranges.iterator().next(),
                                                                   null, hosts).iterator().next());
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:23,代码来源:ActiveRepairServiceTest.java

示例15: testGetNeighborsTimesTwo

import org.apache.cassandra.locator.AbstractReplicationStrategy; //导入依赖的package包/类
@Test
public void testGetNeighborsTimesTwo() throws Throwable
{
    TokenMetadata tmd = StorageService.instance.getTokenMetadata();

    // generate rf*2 nodes, and ensure that only neighbors specified by the ARS are returned
    addTokens(2 * Table.open(tablename).getReplicationStrategy().getReplicationFactor());
    AbstractReplicationStrategy ars = Table.open(tablename).getReplicationStrategy();
    Set<InetAddress> expected = new HashSet<InetAddress>();
    for (Range<Token> replicaRange : ars.getAddressRanges().get(FBUtilities.getBroadcastAddress()))
    {
        expected.addAll(ars.getRangeAddresses(tmd.cloneOnlyTokenMap()).get(replicaRange));
    }
    expected.remove(FBUtilities.getBroadcastAddress());
    Collection<Range<Token>> ranges = StorageService.instance.getLocalRanges(tablename);
    Set<InetAddress> neighbors = new HashSet<InetAddress>();
    for (Range<Token> range : ranges)
    {
        neighbors.addAll(AntiEntropyService.getNeighbors(tablename, range, false));
    }
    assertEquals(expected, neighbors);
}
 
开发者ID:jackliu8722,项目名称:cassandra-1.2.16,代码行数:23,代码来源:AntiEntropyServiceTestAbstract.java


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