Search in sources :

Example 11 with Token

use of org.apache.cassandra.dht.Token in project cassandra by apache.

the class TokenAllocation method allocateTokens.

public static Collection<Token> allocateTokens(final TokenMetadata tokenMetadata, final AbstractReplicationStrategy rs, final InetAddress endpoint, int numTokens) {
    TokenMetadata tokenMetadataCopy = tokenMetadata.cloneOnlyTokenMap();
    StrategyAdapter strategy = getStrategy(tokenMetadataCopy, 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(tokenMetadataCopy, rs, endpoint);
        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;
}
Also used : SummaryStatistics(org.apache.commons.math3.stat.descriptive.SummaryStatistics) Token(org.apache.cassandra.dht.Token) TokenMetadata(org.apache.cassandra.locator.TokenMetadata)

Example 12 with Token

use of org.apache.cassandra.dht.Token in project cassandra by apache.

the class TokenAllocation method adjustForCrossDatacenterClashes.

private static Collection<Token> adjustForCrossDatacenterClashes(final TokenMetadata tokenMetadata, StrategyAdapter strategy, Collection<Token> tokens) {
    List<Token> filtered = Lists.newArrayListWithCapacity(tokens.size());
    for (Token t : tokens) {
        while (tokenMetadata.getEndpoint(t) != null) {
            InetAddress other = tokenMetadata.getEndpoint(t);
            if (strategy.inAllocationRing(other))
                throw new ConfigurationException(String.format("Allocated token %s already assigned to node %s. Is another node also allocating tokens?", t, other));
            t = t.increaseSlightly();
        }
        filtered.add(t);
    }
    return filtered;
}
Also used : ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) Token(org.apache.cassandra.dht.Token) InetAddress(java.net.InetAddress)

Example 13 with Token

use of org.apache.cassandra.dht.Token in project cassandra by apache.

the class NoReplicationTokenAllocator method createTokenInfos.

/**
     * Construct the token ring as a CircularList of TokenInfo,
     * and populate the ownership of the UnitInfo's provided
     */
private TokenInfo<Unit> createTokenInfos(Map<Unit, UnitInfo<Unit>> units) {
    if (units.isEmpty())
        return null;
    // build the circular list
    TokenInfo<Unit> prev = null;
    TokenInfo<Unit> first = null;
    for (Map.Entry<Token, Unit> en : sortedTokens.entrySet()) {
        Token t = en.getKey();
        UnitInfo<Unit> ni = units.get(en.getValue());
        TokenInfo<Unit> ti = new TokenInfo<>(t, ni);
        first = ti.insertAfter(first, prev);
        prev = ti;
    }
    TokenInfo<Unit> curr = first;
    tokensInUnits.clear();
    sortedUnits.clear();
    do {
        populateTokenInfoAndAdjustUnit(curr);
        curr = curr.next;
    } while (curr != first);
    for (UnitInfo<Unit> unitInfo : units.values()) {
        sortedUnits.add(new Weighted<UnitInfo>(unitInfo.ownership, unitInfo));
    }
    return first;
}
Also used : Token(org.apache.cassandra.dht.Token) NavigableMap(java.util.NavigableMap) Map(java.util.Map)

Example 14 with Token

use of org.apache.cassandra.dht.Token in project cassandra by apache.

the class ReplicationAwareTokenAllocator method createTokenInfos.

/**
     * Construct the token ring as a CircularList of TokenInfo,
     * and populate the ownership of the UnitInfo's provided
     */
private TokenInfo<Unit> createTokenInfos(Map<Unit, UnitInfo<Unit>> units, GroupInfo newUnitGroup) {
    // build the circular list
    TokenInfo<Unit> prev = null;
    TokenInfo<Unit> first = null;
    for (Map.Entry<Token, Unit> en : sortedTokens.entrySet()) {
        Token t = en.getKey();
        UnitInfo<Unit> ni = units.get(en.getValue());
        TokenInfo<Unit> ti = new TokenInfo<>(t, ni);
        first = ti.insertAfter(first, prev);
        prev = ti;
    }
    TokenInfo<Unit> curr = first;
    do {
        populateTokenInfoAndAdjustUnit(curr, newUnitGroup);
        curr = curr.next;
    } while (curr != first);
    return first;
}
Also used : Token(org.apache.cassandra.dht.Token)

Example 15 with Token

use of org.apache.cassandra.dht.Token in project cassandra by apache.

the class SSTableLoader method stream.

public StreamResultFuture stream(Set<InetAddress> toIgnore, StreamEventHandler... listeners) {
    client.init(keyspace);
    outputHandler.output("Established connection to initial hosts");
    StreamPlan plan = new StreamPlan("Bulk Load", 0, connectionsPerHost, false, false, false, null).connectionFactory(client.getConnectionFactory());
    Map<InetAddress, Collection<Range<Token>>> endpointToRanges = client.getEndpointToRangesMap();
    openSSTables(endpointToRanges);
    if (sstables.isEmpty()) {
        // return empty result
        return plan.execute();
    }
    outputHandler.output(String.format("Streaming relevant part of %sto %s", names(sstables), endpointToRanges.keySet()));
    for (Map.Entry<InetAddress, Collection<Range<Token>>> entry : endpointToRanges.entrySet()) {
        InetAddress remote = entry.getKey();
        if (toIgnore.contains(remote))
            continue;
        List<StreamSession.SSTableStreamingSections> endpointDetails = new LinkedList<>();
        // references are acquired when constructing the SSTableStreamingSections above
        for (StreamSession.SSTableStreamingSections details : streamingDetails.get(remote)) {
            endpointDetails.add(details);
        }
        plan.transferFiles(remote, endpointDetails);
    }
    plan.listeners(this, listeners);
    return plan.execute();
}
Also used : Token(org.apache.cassandra.dht.Token) InetAddress(java.net.InetAddress)

Aggregations

Token (org.apache.cassandra.dht.Token)173 Range (org.apache.cassandra.dht.Range)73 InetAddress (java.net.InetAddress)66 Test (org.junit.Test)65 BigIntegerToken (org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken)27 TokenMetadata (org.apache.cassandra.locator.TokenMetadata)27 IPartitioner (org.apache.cassandra.dht.IPartitioner)26 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)23 ArrayList (java.util.ArrayList)16 UUID (java.util.UUID)16 VersionedValue (org.apache.cassandra.gms.VersionedValue)15 StringToken (org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken)14 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)9 IOException (java.io.IOException)8 ByteBuffer (java.nio.ByteBuffer)8 BytesToken (org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken)8 AbstractReplicationStrategy (org.apache.cassandra.locator.AbstractReplicationStrategy)8 Set (java.util.Set)7 LongToken (org.apache.cassandra.dht.Murmur3Partitioner.LongToken)7 HashSet (java.util.HashSet)6