Search in sources :

Example 31 with InetAddressAndPort

use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.

the class TokenRange method create.

public static TokenRange create(Token.TokenFactory tokenFactory, Range<Token> range, List<InetAddressAndPort> endpoints, boolean withPorts) {
    List<EndpointDetails> details = new ArrayList<>(endpoints.size());
    IEndpointSnitch snitch = DatabaseDescriptor.getEndpointSnitch();
    for (InetAddressAndPort ep : endpoints) details.add(new EndpointDetails(ep, StorageService.instance.getNativeaddress(ep, withPorts), snitch.getDatacenter(ep), snitch.getRack(ep)));
    return new TokenRange(tokenFactory, range, details);
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) IEndpointSnitch(org.apache.cassandra.locator.IEndpointSnitch)

Example 32 with InetAddressAndPort

use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.

the class BatchlogManagerTest method setUp.

@Before
public void setUp() throws Exception {
    TokenMetadata metadata = StorageService.instance.getTokenMetadata();
    InetAddressAndPort localhost = InetAddressAndPort.getByName("127.0.0.1");
    metadata.updateNormalToken(Util.token("A"), localhost);
    metadata.updateHostId(UUIDGen.getTimeUUID(), localhost);
    Keyspace.open(SchemaConstants.SYSTEM_KEYSPACE_NAME).getColumnFamilyStore(SystemKeyspace.BATCHES).truncateBlocking();
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) TokenMetadata(org.apache.cassandra.locator.TokenMetadata)

Example 33 with InetAddressAndPort

use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.

the class RangeStreamer method useStrictSourcesForRanges.

/**
 * @param strat AbstractReplicationStrategy of keyspace to check
 * @return true when the node is bootstrapping, useStrictConsistency is true and # of nodes in the cluster is more than # of replica
 */
private boolean useStrictSourcesForRanges(AbstractReplicationStrategy strat) {
    boolean res = useStrictConsistency && tokens != null;
    if (res) {
        int nodes = 0;
        if (strat instanceof NetworkTopologyStrategy) {
            ImmutableMultimap<String, InetAddressAndPort> dc2Nodes = metadata.getDC2AllEndpoints(snitch);
            NetworkTopologyStrategy ntps = (NetworkTopologyStrategy) strat;
            for (String dc : dc2Nodes.keySet()) nodes += ntps.getReplicationFactor(dc).allReplicas > 0 ? dc2Nodes.get(dc).size() : 0;
        } else
            nodes = metadata.getSizeOfAllEndpoints();
        res = nodes > strat.getReplicationFactor().allReplicas;
    }
    return res;
}
Also used : NetworkTopologyStrategy(org.apache.cassandra.locator.NetworkTopologyStrategy) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint)

Example 34 with InetAddressAndPort

use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.

the class RangeStreamer method getOptimizedWorkMap.

/**
 * Optimized version that also outputs the final work map
 */
private static Multimap<InetAddressAndPort, FetchReplica> getOptimizedWorkMap(EndpointsByReplica rangesWithSources, Collection<SourceFilter> sourceFilters, String keyspace) {
    // For now we just aren't going to use the optimized range fetch map with transient replication to shrink
    // the surface area to test and introduce bugs.
    // In the future it's possible we could run it twice once for full ranges with only full replicas
    // and once with transient ranges and all replicas. Then merge the result.
    EndpointsByRange.Builder unwrapped = new EndpointsByRange.Builder();
    for (Map.Entry<Replica, Replica> entry : rangesWithSources.flattenEntries()) {
        Replicas.temporaryAssertFull(entry.getValue());
        unwrapped.put(entry.getKey().range(), entry.getValue());
    }
    EndpointsByRange unwrappedView = unwrapped.build();
    RangeFetchMapCalculator calculator = new RangeFetchMapCalculator(unwrappedView, sourceFilters, keyspace);
    Multimap<InetAddressAndPort, Range<Token>> rangeFetchMapMap = calculator.getRangeFetchMap();
    logger.info("Output from RangeFetchMapCalculator for keyspace {}", keyspace);
    validateRangeFetchMap(unwrappedView, rangeFetchMapMap, keyspace);
    // Need to rewrap as Replicas
    Multimap<InetAddressAndPort, FetchReplica> wrapped = HashMultimap.create();
    for (Map.Entry<InetAddressAndPort, Range<Token>> entry : rangeFetchMapMap.entries()) {
        Replica toFetch = null;
        for (Replica r : rangesWithSources.keySet()) {
            if (r.range().equals(entry.getValue())) {
                if (toFetch != null)
                    throw new AssertionError(String.format("There shouldn't be multiple replicas for range %s, replica %s and %s here", r.range(), r, toFetch));
                toFetch = r;
            }
        }
        if (toFetch == null)
            throw new AssertionError("Shouldn't be possible for the Replica we fetch to be null here");
        // Committing the cardinal sin of synthesizing a Replica, but it's ok because we assert earlier all of them
        // are full and optimized range fetch map doesn't support transient replication yet.
        wrapped.put(entry.getKey(), new FetchReplica(toFetch, fullReplica(entry.getKey(), entry.getValue())));
    }
    return wrapped;
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) EndpointsByRange(org.apache.cassandra.locator.EndpointsByRange) EndpointsByRange(org.apache.cassandra.locator.EndpointsByRange) EndpointsForRange(org.apache.cassandra.locator.EndpointsForRange) Replica.fullReplica(org.apache.cassandra.locator.Replica.fullReplica) Replica(org.apache.cassandra.locator.Replica) EndpointsByReplica(org.apache.cassandra.locator.EndpointsByReplica) Map(java.util.Map) HashMap(java.util.HashMap)

Example 35 with InetAddressAndPort

use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.

the class RangeStreamer method convertPreferredEndpointsToWorkMap.

/**
 * The preferred endpoint list is the wrong format because it is keyed by Replica (this node) rather than the source
 * endpoint we will fetch from which streaming wants.
 */
public static Multimap<InetAddressAndPort, FetchReplica> convertPreferredEndpointsToWorkMap(EndpointsByReplica preferredEndpoints) {
    Multimap<InetAddressAndPort, FetchReplica> workMap = HashMultimap.create();
    for (Map.Entry<Replica, EndpointsForRange> e : preferredEndpoints.entrySet()) {
        for (Replica source : e.getValue()) {
            assert (e.getKey()).isSelf();
            assert !source.isSelf();
            workMap.put(source.endpoint(), new FetchReplica(e.getKey(), source));
        }
    }
    logger.debug("Work map {}", workMap);
    return workMap;
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) EndpointsForRange(org.apache.cassandra.locator.EndpointsForRange) Map(java.util.Map) HashMap(java.util.HashMap) Replica.fullReplica(org.apache.cassandra.locator.Replica.fullReplica) Replica(org.apache.cassandra.locator.Replica) EndpointsByReplica(org.apache.cassandra.locator.EndpointsByReplica)

Aggregations

InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)281 Test (org.junit.Test)129 Token (org.apache.cassandra.dht.Token)65 TokenMetadata (org.apache.cassandra.locator.TokenMetadata)43 EndpointsForRange (org.apache.cassandra.locator.EndpointsForRange)39 Range (org.apache.cassandra.dht.Range)28 Replica (org.apache.cassandra.locator.Replica)25 ArrayList (java.util.ArrayList)24 ByteBuffer (java.nio.ByteBuffer)23 HashMap (java.util.HashMap)23 UUID (java.util.UUID)22 HashSet (java.util.HashSet)20 Map (java.util.Map)20 Mutation (org.apache.cassandra.db.Mutation)17 PartitionIterator (org.apache.cassandra.db.partitions.PartitionIterator)17 UnfilteredPartitionIterator (org.apache.cassandra.db.partitions.UnfilteredPartitionIterator)16 VersionedValue (org.apache.cassandra.gms.VersionedValue)16 VisibleForTesting (com.google.common.annotations.VisibleForTesting)15 IPartitioner (org.apache.cassandra.dht.IPartitioner)15 BigIntegerToken (org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken)15