Search in sources :

Example 1 with FetchReplica

use of org.apache.cassandra.dht.RangeStreamer.FetchReplica in project cassandra by apache.

the class StorageService method restoreReplicaCount.

/**
 * Called when an endpoint is removed from the ring. This function checks
 * whether this node becomes responsible for new ranges as a
 * consequence and streams data if needed.
 *
 * This is rather ineffective, but it does not matter so much
 * since this is called very seldom
 *
 * @param endpoint the node that left
 */
private void restoreReplicaCount(InetAddressAndPort endpoint, final InetAddressAndPort notifyEndpoint) {
    Map<String, Multimap<InetAddressAndPort, FetchReplica>> replicasToFetch = new HashMap<>();
    InetAddressAndPort myAddress = FBUtilities.getBroadcastAddressAndPort();
    for (String keyspaceName : Schema.instance.getNonLocalStrategyKeyspaces()) {
        logger.debug("Restoring replica count for keyspace {}", keyspaceName);
        EndpointsByReplica changedReplicas = getChangedReplicasForLeaving(keyspaceName, endpoint, tokenMetadata, Keyspace.open(keyspaceName).getReplicationStrategy());
        Set<LeavingReplica> myNewReplicas = new HashSet<>();
        for (Map.Entry<Replica, Replica> entry : changedReplicas.flattenEntries()) {
            Replica replica = entry.getValue();
            if (replica.endpoint().equals(myAddress)) {
                // Maybe we don't technically need to fetch transient data from somewhere
                // but it's probably not a lot and it probably makes things a hair more resilient to people
                // not running repair when they should.
                myNewReplicas.add(new LeavingReplica(entry.getKey(), entry.getValue()));
            }
        }
        logger.debug("Changed replicas for leaving {}, myNewReplicas {}", changedReplicas, myNewReplicas);
        replicasToFetch.put(keyspaceName, getNewSourceReplicas(keyspaceName, myNewReplicas));
    }
    StreamPlan stream = new StreamPlan(StreamOperation.RESTORE_REPLICA_COUNT);
    replicasToFetch.forEach((keyspaceName, sources) -> {
        logger.debug("Requesting keyspace {} sources", keyspaceName);
        sources.asMap().forEach((sourceAddress, fetchReplicas) -> {
            logger.debug("Source and our replicas are {}", fetchReplicas);
            // Remember whether this node is providing the full or transient replicas for this range. We are going
            // to pass streaming the local instance of Replica for the range which doesn't tell us anything about the source
            // By encoding it as two separate sets we retain this information about the source.
            RangesAtEndpoint full = fetchReplicas.stream().filter(f -> f.remote.isFull()).map(f -> f.local).collect(RangesAtEndpoint.collector(myAddress));
            RangesAtEndpoint transientReplicas = fetchReplicas.stream().filter(f -> f.remote.isTransient()).map(f -> f.local).collect(RangesAtEndpoint.collector(myAddress));
            if (logger.isDebugEnabled())
                logger.debug("Requesting from {} full replicas {} transient replicas {}", sourceAddress, StringUtils.join(full, ", "), StringUtils.join(transientReplicas, ", "));
            stream.requestRanges(sourceAddress, keyspaceName, full, transientReplicas);
        });
    });
    StreamResultFuture future = stream.execute();
    future.addCallback(new FutureCallback<StreamState>() {

        public void onSuccess(StreamState finalState) {
            sendReplicationNotification(notifyEndpoint);
        }

        public void onFailure(Throwable t) {
            logger.warn("Streaming to restore replica count failed", t);
            // We still want to send the notification
            sendReplicationNotification(notifyEndpoint);
        }
    });
}
Also used : TraceKeyspace(org.apache.cassandra.tracing.TraceKeyspace) StorageMetrics(org.apache.cassandra.metrics.StorageMetrics) File(org.apache.cassandra.io.util.File) CommitLog(org.apache.cassandra.db.commitlog.CommitLog) AuthKeyspace(org.apache.cassandra.auth.AuthKeyspace) org.apache.cassandra.utils(org.apache.cassandra.utils) Global.nanoTime(org.apache.cassandra.utils.Clock.Global.nanoTime) StringUtils(org.apache.commons.lang3.StringUtils) TokenFactory(org.apache.cassandra.dht.Token.TokenFactory) VersionAndType(org.apache.cassandra.io.sstable.format.VersionAndType) InetAddress(java.net.InetAddress) SystemDistributedKeyspace(org.apache.cassandra.schema.SystemDistributedKeyspace) SecondaryIndexManager.isIndexColumnFamily(org.apache.cassandra.index.SecondaryIndexManager.isIndexColumnFamily) SecondaryIndexManager.getIndexName(org.apache.cassandra.index.SecondaryIndexManager.getIndexName) Arrays.asList(java.util.Arrays.asList) HintsService(org.apache.cassandra.hints.HintsService) JMXBroadcastExecutor(org.apache.cassandra.utils.progress.jmx.JMXBroadcastExecutor) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) FullQueryLoggerOptions(org.apache.cassandra.fql.FullQueryLoggerOptions) ViewMetadata(org.apache.cassandra.schema.ViewMetadata) Stream(java.util.stream.Stream) Predicate(com.google.common.base.Predicate) CassandraRelevantProperties(org.apache.cassandra.config.CassandraRelevantProperties) FullQueryLogger(org.apache.cassandra.fql.FullQueryLogger) Conflict(org.apache.cassandra.locator.ReplicaCollection.Builder.Conflict) KeyspaceMetadata(org.apache.cassandra.schema.KeyspaceMetadata) LoggingSupportFactory(org.apache.cassandra.utils.logging.LoggingSupportFactory) NoPayload.noPayload(org.apache.cassandra.net.NoPayload.noPayload) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ProgressEvent(org.apache.cassandra.utils.progress.ProgressEvent) java.util(java.util) OpenDataException(javax.management.openmbean.OpenDataException) CompactionManager(org.apache.cassandra.db.compaction.CompactionManager) SSTableLoader(org.apache.cassandra.io.sstable.SSTableLoader) ClientResourceLimits(org.apache.cassandra.transport.ClientResourceLimits) Global.currentTimeMillis(org.apache.cassandra.utils.Clock.Global.currentTimeMillis) Range(org.apache.cassandra.dht.Range) MINUTES(java.util.concurrent.TimeUnit.MINUTES) QueryProcessor(org.apache.cassandra.cql3.QueryProcessor) Supplier(java.util.function.Supplier) REPLICATION_DONE_REQ(org.apache.cassandra.net.Verb.REPLICATION_DONE_REQ) Schema(org.apache.cassandra.schema.Schema) ActiveRepairService(org.apache.cassandra.service.ActiveRepairService) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) FullQueryLoggerOptionsCompositeData(org.apache.cassandra.fql.FullQueryLoggerOptionsCompositeData) Predicates(com.google.common.base.Predicates) BatchlogManager(org.apache.cassandra.batchlog.BatchlogManager) StreamSupport(java.util.stream.StreamSupport) ProgressEventType(org.apache.cassandra.utils.progress.ProgressEventType) Nullable(javax.annotation.Nullable) CompositeData(javax.management.openmbean.CompositeData) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) IOError(java.io.IOError) ExecutionException(java.util.concurrent.ExecutionException) Paths(java.nio.file.Paths) ImmediateFuture(org.apache.cassandra.utils.concurrent.ImmediateFuture) org.apache.cassandra.net(org.apache.cassandra.net) SnapshotManager(org.apache.cassandra.service.snapshot.SnapshotManager) Preconditions(com.google.common.base.Preconditions) org.apache.cassandra.locator(org.apache.cassandra.locator) AuditLogManager(org.apache.cassandra.audit.AuditLogManager) Verifier(org.apache.cassandra.db.compaction.Verifier) org.apache.cassandra.repair(org.apache.cassandra.repair) org.apache.cassandra.streaming(org.apache.cassandra.streaming) Iterables.transform(com.google.common.collect.Iterables.transform) Iterables.tryFind(com.google.common.collect.Iterables.tryFind) MatchResult(java.util.regex.MatchResult) LoggerFactory(org.slf4j.LoggerFactory) org.apache.cassandra.db(org.apache.cassandra.db) ReplicationParams(org.apache.cassandra.schema.ReplicationParams) TimeoutException(java.util.concurrent.TimeoutException) org.apache.cassandra.gms(org.apache.cassandra.gms) com.google.common.util.concurrent(com.google.common.util.concurrent) TabularData(javax.management.openmbean.TabularData) ByteBuffer(java.nio.ByteBuffer) MigrationManager(org.apache.cassandra.schema.MigrationManager) ByteArrayInputStream(java.io.ByteArrayInputStream) Collectors.toMap(java.util.stream.Collectors.toMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SSTableFormat(org.apache.cassandra.io.sstable.format.SSTableFormat) AuthSchemaChangeListener(org.apache.cassandra.auth.AuthSchemaChangeListener) PathUtils(org.apache.cassandra.io.util.PathUtils) com.google.common.collect(com.google.common.collect) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) AuditLogOptions(org.apache.cassandra.audit.AuditLogOptions) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TombstoneOption(org.apache.cassandra.schema.CompactionParams.TombstoneOption) JMXProgressSupport(org.apache.cassandra.utils.progress.jmx.JMXProgressSupport) Instant(java.time.Instant) org.apache.cassandra.dht(org.apache.cassandra.dht) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException) ProgressListener(org.apache.cassandra.utils.progress.ProgressListener) AuthCacheService(org.apache.cassandra.auth.AuthCacheService) DurationSpec(org.apache.cassandra.config.DurationSpec) MigrationManager.evolveSystemKeyspace(org.apache.cassandra.schema.MigrationManager.evolveSystemKeyspace) ParameterizedClass(org.apache.cassandra.config.ParameterizedClass) LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction) Future(org.apache.cassandra.utils.concurrent.Future) org.apache.cassandra.exceptions(org.apache.cassandra.exceptions) FileUtils(org.apache.cassandra.io.util.FileUtils) TableMetadataRef(org.apache.cassandra.schema.TableMetadataRef) TabularDataSupport(javax.management.openmbean.TabularDataSupport) Entry(java.util.Map.Entry) org.apache.cassandra.concurrent(org.apache.cassandra.concurrent) TableMetadata(org.apache.cassandra.schema.TableMetadata) VirtualKeyspaceRegistry(org.apache.cassandra.db.virtual.VirtualKeyspaceRegistry) Pattern(java.util.regex.Pattern) MigrationCoordinator(org.apache.cassandra.schema.MigrationCoordinator) SchemaConstants(org.apache.cassandra.schema.SchemaConstants) Arrays.stream(java.util.Arrays.stream) DataInputStream(java.io.DataInputStream) RepairOption(org.apache.cassandra.repair.messages.RepairOption) NANOSECONDS(java.util.concurrent.TimeUnit.NANOSECONDS) Config(org.apache.cassandra.config.Config) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) QueryHandler(org.apache.cassandra.cql3.QueryHandler) BOOTSTRAP_SKIP_SCHEMA_CHECK(org.apache.cassandra.config.CassandraRelevantProperties.BOOTSTRAP_SKIP_SCHEMA_CHECK) FetchReplica(org.apache.cassandra.dht.RangeStreamer.FetchReplica) ProtocolVersion(org.apache.cassandra.transport.ProtocolVersion) ExecutorService(java.util.concurrent.ExecutorService) Logger(org.slf4j.Logger) javax.management(javax.management) REPLACEMENT_ALLOW_EMPTY(org.apache.cassandra.config.CassandraRelevantProperties.REPLACEMENT_ALLOW_EMPTY) TimeUnit(java.util.concurrent.TimeUnit) Collectors.toList(java.util.stream.Collectors.toList) VisibleForTesting(com.google.common.annotations.VisibleForTesting) BOOTSTRAP_SCHEMA_DELAY_MS(org.apache.cassandra.config.CassandraRelevantProperties.BOOTSTRAP_SCHEMA_DELAY_MS) TableSnapshot(org.apache.cassandra.service.snapshot.TableSnapshot) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) FetchReplica(org.apache.cassandra.dht.RangeStreamer.FetchReplica) Collectors.toMap(java.util.stream.Collectors.toMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 2 with FetchReplica

use of org.apache.cassandra.dht.RangeStreamer.FetchReplica in project cassandra by apache.

the class StorageService method getNewSourceReplicas.

/**
 * Finds living endpoints responsible for the given ranges
 *
 * @param keyspaceName the keyspace ranges belong to
 * @param leavingReplicas the ranges to find sources for
 * @return multimap of addresses to ranges the address is responsible for
 */
private Multimap<InetAddressAndPort, FetchReplica> getNewSourceReplicas(String keyspaceName, Set<LeavingReplica> leavingReplicas) {
    InetAddressAndPort myAddress = FBUtilities.getBroadcastAddressAndPort();
    EndpointsByRange rangeReplicas = Keyspace.open(keyspaceName).getReplicationStrategy().getRangeAddresses(tokenMetadata.cloneOnlyTokenMap());
    Multimap<InetAddressAndPort, FetchReplica> sourceRanges = HashMultimap.create();
    IFailureDetector failureDetector = FailureDetector.instance;
    logger.debug("Getting new source replicas for {}", leavingReplicas);
    // find alive sources for our new ranges
    for (LeavingReplica leaver : leavingReplicas) {
        // We need this to find the replicas from before leaving to supply the data
        Replica leavingReplica = leaver.leavingReplica;
        // We need this to know what to fetch and what the transient status is
        Replica ourReplica = leaver.ourReplica;
        // If we are going to be a full replica only consider full replicas
        Predicate<Replica> replicaFilter = ourReplica.isFull() ? Replica::isFull : Predicates.alwaysTrue();
        Predicate<Replica> notSelf = replica -> !replica.endpoint().equals(myAddress);
        EndpointsForRange possibleReplicas = rangeReplicas.get(leavingReplica.range());
        logger.info("Possible replicas for newReplica {} are {}", ourReplica, possibleReplicas);
        IEndpointSnitch snitch = DatabaseDescriptor.getEndpointSnitch();
        EndpointsForRange sortedPossibleReplicas = snitch.sortedByProximity(myAddress, possibleReplicas);
        logger.info("Sorted possible replicas starts as {}", sortedPossibleReplicas);
        Optional<Replica> myCurrentReplica = tryFind(possibleReplicas, replica -> replica.endpoint().equals(myAddress)).toJavaUtil();
        boolean transientToFull = myCurrentReplica.isPresent() && myCurrentReplica.get().isTransient() && ourReplica.isFull();
        assert !sortedPossibleReplicas.endpoints().contains(myAddress) || transientToFull : String.format("My address %s, sortedPossibleReplicas %s, myCurrentReplica %s, myNewReplica %s", myAddress, sortedPossibleReplicas, myCurrentReplica, ourReplica);
        // Originally this didn't log if it couldn't restore replication and that seems wrong
        boolean foundLiveReplica = false;
        for (Replica possibleReplica : sortedPossibleReplicas.filter(Predicates.and(replicaFilter, notSelf))) {
            if (failureDetector.isAlive(possibleReplica.endpoint())) {
                foundLiveReplica = true;
                sourceRanges.put(possibleReplica.endpoint(), new FetchReplica(ourReplica, possibleReplica));
                break;
            } else {
                logger.debug("Skipping down replica {}", possibleReplica);
            }
        }
        if (!foundLiveReplica) {
            logger.warn("Didn't find live replica to restore replication for " + ourReplica);
        }
    }
    return sourceRanges;
}
Also used : TraceKeyspace(org.apache.cassandra.tracing.TraceKeyspace) StorageMetrics(org.apache.cassandra.metrics.StorageMetrics) File(org.apache.cassandra.io.util.File) CommitLog(org.apache.cassandra.db.commitlog.CommitLog) AuthKeyspace(org.apache.cassandra.auth.AuthKeyspace) org.apache.cassandra.utils(org.apache.cassandra.utils) Global.nanoTime(org.apache.cassandra.utils.Clock.Global.nanoTime) StringUtils(org.apache.commons.lang3.StringUtils) TokenFactory(org.apache.cassandra.dht.Token.TokenFactory) VersionAndType(org.apache.cassandra.io.sstable.format.VersionAndType) InetAddress(java.net.InetAddress) SystemDistributedKeyspace(org.apache.cassandra.schema.SystemDistributedKeyspace) SecondaryIndexManager.isIndexColumnFamily(org.apache.cassandra.index.SecondaryIndexManager.isIndexColumnFamily) SecondaryIndexManager.getIndexName(org.apache.cassandra.index.SecondaryIndexManager.getIndexName) Arrays.asList(java.util.Arrays.asList) HintsService(org.apache.cassandra.hints.HintsService) JMXBroadcastExecutor(org.apache.cassandra.utils.progress.jmx.JMXBroadcastExecutor) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) FullQueryLoggerOptions(org.apache.cassandra.fql.FullQueryLoggerOptions) ViewMetadata(org.apache.cassandra.schema.ViewMetadata) Stream(java.util.stream.Stream) Predicate(com.google.common.base.Predicate) CassandraRelevantProperties(org.apache.cassandra.config.CassandraRelevantProperties) FullQueryLogger(org.apache.cassandra.fql.FullQueryLogger) Conflict(org.apache.cassandra.locator.ReplicaCollection.Builder.Conflict) KeyspaceMetadata(org.apache.cassandra.schema.KeyspaceMetadata) LoggingSupportFactory(org.apache.cassandra.utils.logging.LoggingSupportFactory) NoPayload.noPayload(org.apache.cassandra.net.NoPayload.noPayload) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ProgressEvent(org.apache.cassandra.utils.progress.ProgressEvent) java.util(java.util) OpenDataException(javax.management.openmbean.OpenDataException) CompactionManager(org.apache.cassandra.db.compaction.CompactionManager) SSTableLoader(org.apache.cassandra.io.sstable.SSTableLoader) ClientResourceLimits(org.apache.cassandra.transport.ClientResourceLimits) Global.currentTimeMillis(org.apache.cassandra.utils.Clock.Global.currentTimeMillis) Range(org.apache.cassandra.dht.Range) MINUTES(java.util.concurrent.TimeUnit.MINUTES) QueryProcessor(org.apache.cassandra.cql3.QueryProcessor) Supplier(java.util.function.Supplier) REPLICATION_DONE_REQ(org.apache.cassandra.net.Verb.REPLICATION_DONE_REQ) Schema(org.apache.cassandra.schema.Schema) ActiveRepairService(org.apache.cassandra.service.ActiveRepairService) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) FullQueryLoggerOptionsCompositeData(org.apache.cassandra.fql.FullQueryLoggerOptionsCompositeData) Predicates(com.google.common.base.Predicates) BatchlogManager(org.apache.cassandra.batchlog.BatchlogManager) StreamSupport(java.util.stream.StreamSupport) ProgressEventType(org.apache.cassandra.utils.progress.ProgressEventType) Nullable(javax.annotation.Nullable) CompositeData(javax.management.openmbean.CompositeData) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) IOError(java.io.IOError) ExecutionException(java.util.concurrent.ExecutionException) Paths(java.nio.file.Paths) ImmediateFuture(org.apache.cassandra.utils.concurrent.ImmediateFuture) org.apache.cassandra.net(org.apache.cassandra.net) SnapshotManager(org.apache.cassandra.service.snapshot.SnapshotManager) Preconditions(com.google.common.base.Preconditions) org.apache.cassandra.locator(org.apache.cassandra.locator) AuditLogManager(org.apache.cassandra.audit.AuditLogManager) Verifier(org.apache.cassandra.db.compaction.Verifier) org.apache.cassandra.repair(org.apache.cassandra.repair) org.apache.cassandra.streaming(org.apache.cassandra.streaming) Iterables.transform(com.google.common.collect.Iterables.transform) Iterables.tryFind(com.google.common.collect.Iterables.tryFind) MatchResult(java.util.regex.MatchResult) LoggerFactory(org.slf4j.LoggerFactory) org.apache.cassandra.db(org.apache.cassandra.db) ReplicationParams(org.apache.cassandra.schema.ReplicationParams) TimeoutException(java.util.concurrent.TimeoutException) org.apache.cassandra.gms(org.apache.cassandra.gms) com.google.common.util.concurrent(com.google.common.util.concurrent) TabularData(javax.management.openmbean.TabularData) ByteBuffer(java.nio.ByteBuffer) MigrationManager(org.apache.cassandra.schema.MigrationManager) ByteArrayInputStream(java.io.ByteArrayInputStream) Collectors.toMap(java.util.stream.Collectors.toMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SSTableFormat(org.apache.cassandra.io.sstable.format.SSTableFormat) AuthSchemaChangeListener(org.apache.cassandra.auth.AuthSchemaChangeListener) PathUtils(org.apache.cassandra.io.util.PathUtils) com.google.common.collect(com.google.common.collect) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) AuditLogOptions(org.apache.cassandra.audit.AuditLogOptions) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TombstoneOption(org.apache.cassandra.schema.CompactionParams.TombstoneOption) JMXProgressSupport(org.apache.cassandra.utils.progress.jmx.JMXProgressSupport) Instant(java.time.Instant) org.apache.cassandra.dht(org.apache.cassandra.dht) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException) ProgressListener(org.apache.cassandra.utils.progress.ProgressListener) AuthCacheService(org.apache.cassandra.auth.AuthCacheService) DurationSpec(org.apache.cassandra.config.DurationSpec) MigrationManager.evolveSystemKeyspace(org.apache.cassandra.schema.MigrationManager.evolveSystemKeyspace) ParameterizedClass(org.apache.cassandra.config.ParameterizedClass) LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction) Future(org.apache.cassandra.utils.concurrent.Future) org.apache.cassandra.exceptions(org.apache.cassandra.exceptions) FileUtils(org.apache.cassandra.io.util.FileUtils) TableMetadataRef(org.apache.cassandra.schema.TableMetadataRef) TabularDataSupport(javax.management.openmbean.TabularDataSupport) Entry(java.util.Map.Entry) org.apache.cassandra.concurrent(org.apache.cassandra.concurrent) TableMetadata(org.apache.cassandra.schema.TableMetadata) VirtualKeyspaceRegistry(org.apache.cassandra.db.virtual.VirtualKeyspaceRegistry) Pattern(java.util.regex.Pattern) MigrationCoordinator(org.apache.cassandra.schema.MigrationCoordinator) SchemaConstants(org.apache.cassandra.schema.SchemaConstants) Arrays.stream(java.util.Arrays.stream) DataInputStream(java.io.DataInputStream) RepairOption(org.apache.cassandra.repair.messages.RepairOption) NANOSECONDS(java.util.concurrent.TimeUnit.NANOSECONDS) Config(org.apache.cassandra.config.Config) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) QueryHandler(org.apache.cassandra.cql3.QueryHandler) BOOTSTRAP_SKIP_SCHEMA_CHECK(org.apache.cassandra.config.CassandraRelevantProperties.BOOTSTRAP_SKIP_SCHEMA_CHECK) FetchReplica(org.apache.cassandra.dht.RangeStreamer.FetchReplica) ProtocolVersion(org.apache.cassandra.transport.ProtocolVersion) ExecutorService(java.util.concurrent.ExecutorService) Logger(org.slf4j.Logger) javax.management(javax.management) REPLACEMENT_ALLOW_EMPTY(org.apache.cassandra.config.CassandraRelevantProperties.REPLACEMENT_ALLOW_EMPTY) TimeUnit(java.util.concurrent.TimeUnit) Collectors.toList(java.util.stream.Collectors.toList) VisibleForTesting(com.google.common.annotations.VisibleForTesting) BOOTSTRAP_SCHEMA_DELAY_MS(org.apache.cassandra.config.CassandraRelevantProperties.BOOTSTRAP_SCHEMA_DELAY_MS) TableSnapshot(org.apache.cassandra.service.snapshot.TableSnapshot) FetchReplica(org.apache.cassandra.dht.RangeStreamer.FetchReplica) FetchReplica(org.apache.cassandra.dht.RangeStreamer.FetchReplica)

Example 3 with FetchReplica

use of org.apache.cassandra.dht.RangeStreamer.FetchReplica in project cassandra by apache.

the class BootStrapperTest method testSourceTargetComputation.

private RangeStreamer testSourceTargetComputation(String keyspaceName, int numOldNodes, int replicationFactor) throws UnknownHostException {
    StorageService ss = StorageService.instance;
    TokenMetadata tmd = ss.getTokenMetadata();
    generateFakeEndpoints(numOldNodes);
    Token myToken = tmd.partitioner.getRandomToken();
    InetAddressAndPort myEndpoint = InetAddressAndPort.getByName("127.0.0.1");
    assertEquals(numOldNodes, tmd.sortedTokens().size());
    IFailureDetector mockFailureDetector = new IFailureDetector() {

        public boolean isAlive(InetAddressAndPort ep) {
            return true;
        }

        public void interpret(InetAddressAndPort ep) {
            throw new UnsupportedOperationException();
        }

        public void report(InetAddressAndPort ep) {
            throw new UnsupportedOperationException();
        }

        public void registerFailureDetectionEventListener(IFailureDetectionEventListener listener) {
            throw new UnsupportedOperationException();
        }

        public void unregisterFailureDetectionEventListener(IFailureDetectionEventListener listener) {
            throw new UnsupportedOperationException();
        }

        public void remove(InetAddressAndPort ep) {
            throw new UnsupportedOperationException();
        }

        public void forceConviction(InetAddressAndPort ep) {
            throw new UnsupportedOperationException();
        }
    };
    RangeStreamer s = new RangeStreamer(tmd, null, myEndpoint, StreamOperation.BOOTSTRAP, true, DatabaseDescriptor.getEndpointSnitch(), new StreamStateStore(), mockFailureDetector, false, 1);
    assertNotNull(Keyspace.open(keyspaceName));
    s.addRanges(keyspaceName, Keyspace.open(keyspaceName).getReplicationStrategy().getPendingAddressRanges(tmd, myToken, myEndpoint));
    Multimap<InetAddressAndPort, FetchReplica> toFetch = s.toFetch().get(keyspaceName);
    // Check we get get RF new ranges in total
    assertEquals(replicationFactor, toFetch.size());
    // is used, they will vary.
    assert toFetch.values().size() > 0;
    assert toFetch.keys().stream().noneMatch(myEndpoint::equals);
    return s;
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) FetchReplica(org.apache.cassandra.dht.RangeStreamer.FetchReplica) IFailureDetector(org.apache.cassandra.gms.IFailureDetector) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) IFailureDetectionEventListener(org.apache.cassandra.gms.IFailureDetectionEventListener) StorageService(org.apache.cassandra.service.StorageService)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Preconditions (com.google.common.base.Preconditions)2 Predicate (com.google.common.base.Predicate)2 Predicates (com.google.common.base.Predicates)2 com.google.common.collect (com.google.common.collect)2 Iterables.transform (com.google.common.collect.Iterables.transform)2 Iterables.tryFind (com.google.common.collect.Iterables.tryFind)2 com.google.common.util.concurrent (com.google.common.util.concurrent)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DataInputStream (java.io.DataInputStream)2 IOError (java.io.IOError)2 IOException (java.io.IOException)2 InetAddress (java.net.InetAddress)2 InetSocketAddress (java.net.InetSocketAddress)2 UnknownHostException (java.net.UnknownHostException)2 ByteBuffer (java.nio.ByteBuffer)2 Paths (java.nio.file.Paths)2 Instant (java.time.Instant)2 java.util (java.util)2 Arrays.asList (java.util.Arrays.asList)2