Search in sources :

Example 1 with StreamResultFuture

use of org.apache.cassandra.streaming.StreamResultFuture in project cassandra by apache.

the class RangeStreamer method fetchAsync.

public StreamResultFuture fetchAsync() {
    toFetch.forEach((keyspace, sources) -> {
        logger.debug("Keyspace {} Sources {}", keyspace, sources);
        sources.asMap().forEach((source, fetchReplicas) -> {
            // filter out already streamed ranges
            SystemKeyspace.AvailableRanges available = stateStore.getAvailableRanges(keyspace, metadata.partitioner);
            Predicate<FetchReplica> isAvailable = fetch -> {
                boolean isInFull = available.full.contains(fetch.local.range());
                boolean isInTrans = available.trans.contains(fetch.local.range());
                if (!isInFull && !isInTrans)
                    // Range is unavailable
                    return false;
                if (fetch.local.isFull())
                    // For full, pick only replicas with matching transientness
                    return isInFull == fetch.remote.isFull();
                // Any transient or full will do
                return true;
            };
            List<FetchReplica> remaining = fetchReplicas.stream().filter(not(isAvailable)).collect(Collectors.toList());
            if (remaining.size() < available.full.size() + available.trans.size()) {
                List<FetchReplica> skipped = fetchReplicas.stream().filter(isAvailable).collect(Collectors.toList());
                logger.info("Some ranges of {} are already available. Skipping streaming those ranges. Skipping {}. Fully available {} Transiently available {}", fetchReplicas, skipped, available.full, available.trans);
            }
            if (logger.isTraceEnabled())
                logger.trace("{}ing from {} ranges {}", description, source, StringUtils.join(remaining, ", "));
            InetAddressAndPort self = FBUtilities.getBroadcastAddressAndPort();
            RangesAtEndpoint full = remaining.stream().filter(pair -> pair.remote.isFull()).map(pair -> pair.local).collect(RangesAtEndpoint.collector(self));
            RangesAtEndpoint transientReplicas = remaining.stream().filter(pair -> pair.remote.isTransient()).map(pair -> pair.local).collect(RangesAtEndpoint.collector(self));
            logger.debug("Source and our replicas {}", fetchReplicas);
            logger.debug("Source {} Keyspace {}  streaming full {} transient {}", source, keyspace, full, transientReplicas);
            /* Send messages to respective folks to stream data over to me */
            streamPlan.requestRanges(source, keyspace, full, transientReplicas);
        });
    });
    return streamPlan.execute();
}
Also used : BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) Iterables.all(com.google.common.collect.Iterables.all) StringUtils(org.apache.commons.lang3.StringUtils) Gossiper(org.apache.cassandra.gms.Gossiper) NetworkTopologyStrategy(org.apache.cassandra.locator.NetworkTopologyStrategy) Predicates.and(com.google.common.base.Predicates.and) StreamResultFuture(org.apache.cassandra.streaming.StreamResultFuture) Replica.fullReplica(org.apache.cassandra.locator.Replica.fullReplica) HashMultimap(com.google.common.collect.HashMultimap) Replicas(org.apache.cassandra.locator.Replicas) Endpoints(org.apache.cassandra.locator.Endpoints) Predicates.not(com.google.common.base.Predicates.not) ReplicaCollection(org.apache.cassandra.locator.ReplicaCollection) Map(java.util.Map) EndpointsByRange(org.apache.cassandra.locator.EndpointsByRange) Keyspace(org.apache.cassandra.db.Keyspace) EndpointsForRange(org.apache.cassandra.locator.EndpointsForRange) FBUtilities(org.apache.cassandra.utils.FBUtilities) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) List(java.util.List) Predicate(com.google.common.base.Predicate) Conflict(org.apache.cassandra.locator.ReplicaCollection.Builder.Conflict) Optional(java.util.Optional) FailureDetector(org.apache.cassandra.gms.FailureDetector) Iterables.any(com.google.common.collect.Iterables.any) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) Iterables(com.google.common.collect.Iterables) HashMap(java.util.HashMap) Multimap(com.google.common.collect.Multimap) Function(java.util.function.Function) SystemKeyspace(org.apache.cassandra.db.SystemKeyspace) ArrayList(java.util.ArrayList) IEndpointSnitch(org.apache.cassandra.locator.IEndpointSnitch) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) StreamOperation(org.apache.cassandra.streaming.StreamOperation) Logger(org.slf4j.Logger) Replica(org.apache.cassandra.locator.Replica) IFailureDetector(org.apache.cassandra.gms.IFailureDetector) PreviewKind(org.apache.cassandra.streaming.PreviewKind) AbstractReplicationStrategy(org.apache.cassandra.locator.AbstractReplicationStrategy) StreamPlan(org.apache.cassandra.streaming.StreamPlan) EndpointsByReplica(org.apache.cassandra.locator.EndpointsByReplica) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) LocalStrategy(org.apache.cassandra.locator.LocalStrategy) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) SystemKeyspace(org.apache.cassandra.db.SystemKeyspace)

Example 2 with StreamResultFuture

use of org.apache.cassandra.streaming.StreamResultFuture in project cassandra by apache.

the class CassandraEntireSSTableStreamWriterTest method setupStreamingSessionForTest.

private StreamSession setupStreamingSessionForTest() {
    StreamCoordinator streamCoordinator = new StreamCoordinator(StreamOperation.BOOTSTRAP, 1, new NettyStreamingConnectionFactory(), false, false, null, PreviewKind.NONE);
    StreamResultFuture future = StreamResultFuture.createInitiator(UUID.randomUUID(), StreamOperation.BOOTSTRAP, Collections.<StreamEventHandler>emptyList(), streamCoordinator);
    InetAddressAndPort peer = FBUtilities.getBroadcastAddressAndPort();
    streamCoordinator.addSessionInfo(new SessionInfo(peer, 0, peer, Collections.emptyList(), Collections.emptyList(), StreamSession.State.INITIALIZED));
    StreamSession session = streamCoordinator.getOrCreateOutboundSession(peer);
    session.init(future);
    return session;
}
Also used : StreamResultFuture(org.apache.cassandra.streaming.StreamResultFuture) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) NettyStreamingConnectionFactory(org.apache.cassandra.streaming.async.NettyStreamingConnectionFactory) StreamSession(org.apache.cassandra.streaming.StreamSession) StreamCoordinator(org.apache.cassandra.streaming.StreamCoordinator) SessionInfo(org.apache.cassandra.streaming.SessionInfo)

Example 3 with StreamResultFuture

use of org.apache.cassandra.streaming.StreamResultFuture in project cassandra by apache.

the class StreamingInboundHandlerTest method StreamDeserializingTask_deserialize_ISM_HasSession.

@Test
public void StreamDeserializingTask_deserialize_ISM_HasSession() {
    UUID planId = UUID.randomUUID();
    StreamResultFuture future = StreamResultFuture.createFollower(0, planId, StreamOperation.REPAIR, REMOTE_ADDR, streamingChannel, streamingChannel.messagingVersion, UUID.randomUUID(), PreviewKind.ALL);
    StreamManager.instance.registerFollower(future);
    StreamMessageHeader header = new StreamMessageHeader(TableId.generate(), REMOTE_ADDR, planId, false, 0, 0, 0, UUID.randomUUID());
    // IncomingStreamMessage.serializer.deserialize
    StreamSession session = StreamManager.instance.findSession(header.sender, header.planId, header.sessionIndex, header.sendByFollower);
    Assert.assertNotNull(session);
    session = StreamManager.instance.findSession(header.sender, header.planId, header.sessionIndex, !header.sendByFollower);
    Assert.assertNull(session);
}
Also used : StreamResultFuture(org.apache.cassandra.streaming.StreamResultFuture) StreamSession(org.apache.cassandra.streaming.StreamSession) UUID(java.util.UUID) StreamMessageHeader(org.apache.cassandra.streaming.messages.StreamMessageHeader) Test(org.junit.Test)

Example 4 with StreamResultFuture

use of org.apache.cassandra.streaming.StreamResultFuture in project cassandra by apache.

the class StreamingMultiplexedChannelTest method setUp.

@Before
public void setUp() {
    channel = new TestChannel();
    streamingChannel = new NettyStreamingChannel(current_version, channel, StreamingChannel.Kind.CONTROL);
    UUID pendingRepair = UUID.randomUUID();
    session = new StreamSession(StreamOperation.BOOTSTRAP, REMOTE_ADDR, new NettyStreamingConnectionFactory(), streamingChannel, current_version, true, 0, pendingRepair, PreviewKind.ALL);
    StreamResultFuture future = StreamResultFuture.createFollower(0, UUID.randomUUID(), StreamOperation.REPAIR, REMOTE_ADDR, streamingChannel, current_version, pendingRepair, session.getPreviewKind());
    session.init(future);
    session.attachOutbound(streamingChannel);
    sender = session.getChannel();
    sender.setControlChannel(streamingChannel);
}
Also used : StreamResultFuture(org.apache.cassandra.streaming.StreamResultFuture) StreamSession(org.apache.cassandra.streaming.StreamSession) UUID(java.util.UUID) TestChannel(org.apache.cassandra.net.TestChannel) Before(org.junit.Before)

Example 5 with StreamResultFuture

use of org.apache.cassandra.streaming.StreamResultFuture in project cassandra by apache.

the class EntireSSTableStreamConcurrentComponentMutationTest method setupStreamingSessionForTest.

private StreamSession setupStreamingSessionForTest() {
    StreamCoordinator streamCoordinator = new StreamCoordinator(StreamOperation.BOOTSTRAP, 1, new NettyStreamingConnectionFactory(), false, false, null, PreviewKind.NONE);
    StreamResultFuture future = StreamResultFuture.createInitiator(UUID.randomUUID(), StreamOperation.BOOTSTRAP, Collections.emptyList(), streamCoordinator);
    InetAddressAndPort peer = FBUtilities.getBroadcastAddressAndPort();
    streamCoordinator.addSessionInfo(new SessionInfo(peer, 0, peer, Collections.emptyList(), Collections.emptyList(), StreamSession.State.INITIALIZED));
    StreamSession session = streamCoordinator.getOrCreateOutboundSession(peer);
    session.init(future);
    return session;
}
Also used : StreamResultFuture(org.apache.cassandra.streaming.StreamResultFuture) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) NettyStreamingConnectionFactory(org.apache.cassandra.streaming.async.NettyStreamingConnectionFactory) StreamSession(org.apache.cassandra.streaming.StreamSession) StreamCoordinator(org.apache.cassandra.streaming.StreamCoordinator) SessionInfo(org.apache.cassandra.streaming.SessionInfo)

Aggregations

StreamResultFuture (org.apache.cassandra.streaming.StreamResultFuture)5 StreamSession (org.apache.cassandra.streaming.StreamSession)4 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)3 UUID (java.util.UUID)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions (com.google.common.base.Preconditions)1 Predicate (com.google.common.base.Predicate)1 Predicates.and (com.google.common.base.Predicates.and)1 Predicates.not (com.google.common.base.Predicates.not)1 HashMultimap (com.google.common.collect.HashMultimap)1 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 Iterables (com.google.common.collect.Iterables)1 Iterables.all (com.google.common.collect.Iterables.all)1 Iterables.any (com.google.common.collect.Iterables.any)1 Multimap (com.google.common.collect.Multimap)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1