Search in sources :

Example 6 with UncheckedInterruptedException

use of org.apache.cassandra.utils.concurrent.UncheckedInterruptedException in project cassandra by apache.

the class StorageProxy method describeSchemaVersions.

/**
 * initiate a request/response session with each live node to check whether or not everybody is using the same
 * migration id. This is useful for determining if a schema change has propagated through the cluster. Disagreement
 * is assumed if any node fails to respond.
 */
public static Map<String, List<String>> describeSchemaVersions(boolean withPort) {
    final String myVersion = Schema.instance.getVersion().toString();
    final Map<InetAddressAndPort, UUID> versions = new ConcurrentHashMap<>();
    final Set<InetAddressAndPort> liveHosts = Gossiper.instance.getLiveMembers();
    final CountDownLatch latch = newCountDownLatch(liveHosts.size());
    RequestCallback<UUID> cb = message -> {
        // record the response from the remote node.
        versions.put(message.from(), message.payload);
        latch.decrement();
    };
    // an empty message acts as a request to the SchemaVersionVerbHandler.
    Message message = out(SCHEMA_VERSION_REQ, noPayload);
    for (InetAddressAndPort endpoint : liveHosts) MessagingService.instance().sendWithCallback(message, endpoint, cb);
    try {
        // wait for as long as possible. timeout-1s if possible.
        latch.await(DatabaseDescriptor.getRpcTimeout(NANOSECONDS), NANOSECONDS);
    } catch (InterruptedException e) {
        throw new UncheckedInterruptedException(e);
    }
    // maps versions to hosts that are on that version.
    Map<String, List<String>> results = new HashMap<String, List<String>>();
    Iterable<InetAddressAndPort> allHosts = concat(Gossiper.instance.getLiveMembers(), Gossiper.instance.getUnreachableMembers());
    for (InetAddressAndPort host : allHosts) {
        UUID version = versions.get(host);
        String stringVersion = version == null ? UNREACHABLE : version.toString();
        List<String> hosts = results.get(stringVersion);
        if (hosts == null) {
            hosts = new ArrayList<String>();
            results.put(stringVersion, hosts);
        }
        hosts.add(host.getHostAddress(withPort));
    }
    // we're done: the results map is ready to return to the client.  the rest is just debug logging:
    if (results.get(UNREACHABLE) != null)
        logger.debug("Hosts not in agreement. Didn't get a response from everybody: {}", join(results.get(UNREACHABLE), ","));
    for (Map.Entry<String, List<String>> entry : results.entrySet()) {
        // check for version disagreement. log the hosts that don't agree.
        if (entry.getKey().equals(UNREACHABLE) || entry.getKey().equals(myVersion))
            continue;
        for (String host : entry.getValue()) logger.debug("{} disagrees ({})", host, entry.getKey());
    }
    if (results.size() == 1)
        logger.debug("Schemas are in agreement.");
    return results;
}
Also used : Arrays(java.util.Arrays) StorageMetrics(org.apache.cassandra.metrics.StorageMetrics) Stage(org.apache.cassandra.concurrent.Stage) EndpointsForToken(org.apache.cassandra.locator.EndpointsForToken) ClientRequestsMetricsHolder.readMetrics(org.apache.cassandra.metrics.ClientRequestsMetricsHolder.readMetrics) ReadResponse(org.apache.cassandra.db.ReadResponse) Global.nanoTime(org.apache.cassandra.utils.Clock.Global.nanoTime) ReadRepairMetrics(org.apache.cassandra.metrics.ReadRepairMetrics) UnfilteredPartitionIterator(org.apache.cassandra.db.partitions.UnfilteredPartitionIterator) Future(java.util.concurrent.Future) OverloadedException(org.apache.cassandra.exceptions.OverloadedException) Replicas(org.apache.cassandra.locator.Replicas) Mutation(org.apache.cassandra.db.Mutation) Pair(org.apache.cassandra.utils.Pair) Map(java.util.Map) HintsService(org.apache.cassandra.hints.HintsService) SinglePartitionReadCommand(org.apache.cassandra.db.SinglePartitionReadCommand) PartitionIterators(org.apache.cassandra.db.partitions.PartitionIterators) ReplicaPlans(org.apache.cassandra.locator.ReplicaPlans) ReplicaPlan(org.apache.cassandra.locator.ReplicaPlan) Keyspace(org.apache.cassandra.db.Keyspace) ReadAbortException(org.apache.cassandra.exceptions.ReadAbortException) PartitionRangeReadCommand(org.apache.cassandra.db.PartitionRangeReadCommand) FBUtilities(org.apache.cassandra.utils.FBUtilities) RejectException(org.apache.cassandra.db.RejectException) CasWriteTimeoutException(org.apache.cassandra.exceptions.CasWriteTimeoutException) Set(java.util.Set) WriteType(org.apache.cassandra.db.WriteType) Verb(org.apache.cassandra.net.Verb) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) UUIDGen(org.apache.cassandra.utils.UUIDGen) CassandraRelevantProperties(org.apache.cassandra.config.CassandraRelevantProperties) WriteFailureException(org.apache.cassandra.exceptions.WriteFailureException) ReplicaLayout(org.apache.cassandra.locator.ReplicaLayout) NoPayload.noPayload(org.apache.cassandra.net.NoPayload.noPayload) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) Iterables(com.google.common.collect.Iterables) TableId(org.apache.cassandra.schema.TableId) PrepareVerbHandler.doPrepare(org.apache.cassandra.service.paxos.PrepareVerbHandler.doPrepare) Global.currentTimeMillis(org.apache.cassandra.utils.Clock.Global.currentTimeMillis) ReadCommand(org.apache.cassandra.db.ReadCommand) Message(org.apache.cassandra.net.Message) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) TruncateRequest(org.apache.cassandra.db.TruncateRequest) Schema(org.apache.cassandra.schema.Schema) IEndpointSnitch(org.apache.cassandra.locator.IEndpointSnitch) Token(org.apache.cassandra.dht.Token) CountDownLatch.newCountDownLatch(org.apache.cassandra.utils.concurrent.CountDownLatch.newCountDownLatch) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) BatchlogManager(org.apache.cassandra.batchlog.BatchlogManager) InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException) RequestTimeoutException(org.apache.cassandra.exceptions.RequestTimeoutException) TriggerExecutor(org.apache.cassandra.triggers.TriggerExecutor) ConsistencyLevel(org.apache.cassandra.db.ConsistencyLevel) MessagingService(org.apache.cassandra.net.MessagingService) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) ReadTimeoutException(org.apache.cassandra.exceptions.ReadTimeoutException) MessageParams(org.apache.cassandra.db.MessageParams) Hint(org.apache.cassandra.hints.Hint) FilteredPartition(org.apache.cassandra.db.partitions.FilteredPartition) RequestFailureReason(org.apache.cassandra.exceptions.RequestFailureReason) AtomicLong(java.util.concurrent.atomic.AtomicLong) ViewUtils(org.apache.cassandra.db.view.ViewUtils) CasWriteUnknownResultException(org.apache.cassandra.exceptions.CasWriteUnknownResultException) Preconditions(com.google.common.base.Preconditions) ClientRequestsMetricsHolder.casReadMetrics(org.apache.cassandra.metrics.ClientRequestsMetricsHolder.casReadMetrics) ClientRequestsMetricsHolder.casWriteMetrics(org.apache.cassandra.metrics.ClientRequestsMetricsHolder.casWriteMetrics) CounterMutation(org.apache.cassandra.db.CounterMutation) BatchlogCleanup(org.apache.cassandra.service.BatchlogResponseHandler.BatchlogCleanup) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) CountDownLatch(org.apache.cassandra.utils.concurrent.CountDownLatch) Message.out(org.apache.cassandra.net.Message.out) ByteBuffer(java.nio.ByteBuffer) Gossiper(org.apache.cassandra.gms.Gossiper) CASClientRequestMetrics(org.apache.cassandra.metrics.CASClientRequestMetrics) DecoratedKey(org.apache.cassandra.db.DecoratedKey) ClientRequestsMetricsHolder.readMetricsForLevel(org.apache.cassandra.metrics.ClientRequestsMetricsHolder.readMetricsForLevel) ReadRepair(org.apache.cassandra.service.reads.repair.ReadRepair) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AbstractReadExecutor(org.apache.cassandra.service.reads.AbstractReadExecutor) Iterables.concat(com.google.common.collect.Iterables.concat) RowIterator(org.apache.cassandra.db.rows.RowIterator) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) Global.randomBallot(org.apache.cassandra.service.paxos.BallotGenerator.Global.randomBallot) UnavailableException(org.apache.cassandra.exceptions.UnavailableException) MessageFlag(org.apache.cassandra.net.MessageFlag) Collection(java.util.Collection) ClientRequestsMetricsHolder.writeMetrics(org.apache.cassandra.metrics.ClientRequestsMetricsHolder.writeMetrics) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) WriteTimeoutException(org.apache.cassandra.exceptions.WriteTimeoutException) UUID(java.util.UUID) NoSpamLogger(org.apache.cassandra.utils.NoSpamLogger) RequestCallback(org.apache.cassandra.net.RequestCallback) Collectors(java.util.stream.Collectors) SERIAL(org.apache.cassandra.db.ConsistencyLevel.SERIAL) Objects(java.util.Objects) CacheLoader(com.google.common.cache.CacheLoader) UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException) List(java.util.List) ProposeVerbHandler.doPropose(org.apache.cassandra.service.paxos.ProposeVerbHandler.doPropose) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) ForwardingInfo(org.apache.cassandra.net.ForwardingInfo) TableMetadata(org.apache.cassandra.schema.TableMetadata) Optional(java.util.Optional) PartitionIterator(org.apache.cassandra.db.partitions.PartitionIterator) ClientRequestsMetricsHolder.writeMetricsForLevel(org.apache.cassandra.metrics.ClientRequestsMetricsHolder.writeMetricsForLevel) SchemaConstants(org.apache.cassandra.schema.SchemaConstants) RangeCommands(org.apache.cassandra.service.reads.range.RangeCommands) org.apache.cassandra.service.paxos(org.apache.cassandra.service.paxos) ReadExecutionController(org.apache.cassandra.db.ReadExecutionController) PartitionDenylist(org.apache.cassandra.schema.PartitionDenylist) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate) NANOSECONDS(java.util.concurrent.TimeUnit.NANOSECONDS) Config(org.apache.cassandra.config.Config) HashMap(java.util.HashMap) TombstoneOverwhelmingException(org.apache.cassandra.db.filter.TombstoneOverwhelmingException) RequestFailureException(org.apache.cassandra.exceptions.RequestFailureException) HashSet(java.util.HashSet) ClientRequestsMetricsHolder.viewWriteMetrics(org.apache.cassandra.metrics.ClientRequestsMetricsHolder.viewWriteMetrics) StringUtils.join(org.apache.commons.lang3.StringUtils.join) IsBootstrappingException(org.apache.cassandra.exceptions.IsBootstrappingException) Clock(org.apache.cassandra.utils.Clock) Global.nextBallotTimestampMicros(org.apache.cassandra.service.paxos.BallotGenerator.Global.nextBallotTimestampMicros) DenylistMetrics(org.apache.cassandra.metrics.DenylistMetrics) Logger(org.slf4j.Logger) ReadFailureException(org.apache.cassandra.exceptions.ReadFailureException) Tracing(org.apache.cassandra.tracing.Tracing) MonotonicClock(org.apache.cassandra.utils.MonotonicClock) Ints(com.google.common.primitives.Ints) Batch(org.apache.cassandra.batchlog.Batch) Replica(org.apache.cassandra.locator.Replica) TimeUnit(java.util.concurrent.TimeUnit) AbstractReplicationStrategy(org.apache.cassandra.locator.AbstractReplicationStrategy) ReadCallback(org.apache.cassandra.service.reads.ReadCallback) MBeanWrapper(org.apache.cassandra.utils.MBeanWrapper) IMutation(org.apache.cassandra.db.IMutation) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) Message(org.apache.cassandra.net.Message) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) CountDownLatch.newCountDownLatch(org.apache.cassandra.utils.concurrent.CountDownLatch.newCountDownLatch) CountDownLatch(org.apache.cassandra.utils.concurrent.CountDownLatch) UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException) UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 7 with UncheckedInterruptedException

use of org.apache.cassandra.utils.concurrent.UncheckedInterruptedException in project cassandra by apache.

the class StorageService method rebuild.

public void rebuild(String sourceDc, String keyspace, String tokens, String specificSources) {
    // check ongoing rebuild
    if (!isRebuilding.compareAndSet(false, true)) {
        throw new IllegalStateException("Node is still rebuilding. Check nodetool netstats.");
    }
    // check the arguments
    if (keyspace == null && tokens != null) {
        throw new IllegalArgumentException("Cannot specify tokens without keyspace.");
    }
    logger.info("rebuild from dc: {}, {}, {}", sourceDc == null ? "(any dc)" : sourceDc, keyspace == null ? "(All keyspaces)" : keyspace, tokens == null ? "(All tokens)" : tokens);
    try {
        RangeStreamer streamer = new RangeStreamer(tokenMetadata, null, FBUtilities.getBroadcastAddressAndPort(), StreamOperation.REBUILD, useStrictConsistency && !replacing, DatabaseDescriptor.getEndpointSnitch(), streamStateStore, false, DatabaseDescriptor.getStreamingConnectionsPerHost());
        if (sourceDc != null)
            streamer.addSourceFilter(new RangeStreamer.SingleDatacenterFilter(DatabaseDescriptor.getEndpointSnitch(), sourceDc));
        if (keyspace == null) {
            for (String keyspaceName : Schema.instance.getNonLocalStrategyKeyspaces()) streamer.addRanges(keyspaceName, getLocalReplicas(keyspaceName));
        } else if (tokens == null) {
            streamer.addRanges(keyspace, getLocalReplicas(keyspace));
        } else {
            Token.TokenFactory factory = getTokenFactory();
            List<Range<Token>> ranges = new ArrayList<>();
            Pattern rangePattern = Pattern.compile("\\(\\s*(-?\\w+)\\s*,\\s*(-?\\w+)\\s*\\]");
            try (Scanner tokenScanner = new Scanner(tokens)) {
                while (tokenScanner.findInLine(rangePattern) != null) {
                    MatchResult range = tokenScanner.match();
                    Token startToken = factory.fromString(range.group(1));
                    Token endToken = factory.fromString(range.group(2));
                    logger.info("adding range: ({},{}]", startToken, endToken);
                    ranges.add(new Range<>(startToken, endToken));
                }
                if (tokenScanner.hasNext())
                    throw new IllegalArgumentException("Unexpected string: " + tokenScanner.next());
            }
            // Ensure all specified ranges are actually ranges owned by this host
            RangesAtEndpoint localReplicas = getLocalReplicas(keyspace);
            RangesAtEndpoint.Builder streamRanges = new RangesAtEndpoint.Builder(FBUtilities.getBroadcastAddressAndPort(), ranges.size());
            for (Range<Token> specifiedRange : ranges) {
                boolean foundParentRange = false;
                for (Replica localReplica : localReplicas) {
                    if (localReplica.contains(specifiedRange)) {
                        streamRanges.add(localReplica.decorateSubrange(specifiedRange));
                        foundParentRange = true;
                        break;
                    }
                }
                if (!foundParentRange) {
                    throw new IllegalArgumentException(String.format("The specified range %s is not a range that is owned by this node. Please ensure that all token ranges specified to be rebuilt belong to this node.", specifiedRange.toString()));
                }
            }
            if (specificSources != null) {
                String[] stringHosts = specificSources.split(",");
                Set<InetAddressAndPort> sources = new HashSet<>(stringHosts.length);
                for (String stringHost : stringHosts) {
                    try {
                        InetAddressAndPort endpoint = InetAddressAndPort.getByName(stringHost);
                        if (FBUtilities.getBroadcastAddressAndPort().equals(endpoint)) {
                            throw new IllegalArgumentException("This host was specified as a source for rebuilding. Sources for a rebuild can only be other nodes in the cluster.");
                        }
                        sources.add(endpoint);
                    } catch (UnknownHostException ex) {
                        throw new IllegalArgumentException("Unknown host specified " + stringHost, ex);
                    }
                }
                streamer.addSourceFilter(new RangeStreamer.AllowedSourcesFilter(sources));
            }
            streamer.addRanges(keyspace, streamRanges.build());
        }
        StreamResultFuture resultFuture = streamer.fetchAsync();
        // wait for result
        resultFuture.get();
    } catch (InterruptedException e) {
        throw new UncheckedInterruptedException(e);
    } catch (ExecutionException e) {
        // This is used exclusively through JMX, so log the full trace but only throw a simple RTE
        logger.error("Error while rebuilding node", e.getCause());
        throw new RuntimeException("Error while rebuilding node: " + e.getCause().getMessage());
    } finally {
        // rebuild is done (successfully or not)
        isRebuilding.set(false);
    }
}
Also used : MatchResult(java.util.regex.MatchResult) UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException) Arrays.asList(java.util.Arrays.asList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Collectors.toList(java.util.stream.Collectors.toList) ExecutionException(java.util.concurrent.ExecutionException) Pattern(java.util.regex.Pattern) UnknownHostException(java.net.UnknownHostException) Range(org.apache.cassandra.dht.Range) FetchReplica(org.apache.cassandra.dht.RangeStreamer.FetchReplica) UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException) TokenFactory(org.apache.cassandra.dht.Token.TokenFactory)

Example 8 with UncheckedInterruptedException

use of org.apache.cassandra.utils.concurrent.UncheckedInterruptedException in project cassandra by apache.

the class FullQueryLogger method stop.

public synchronized void stop() {
    try {
        BinLog binLog = this.binLog;
        if (binLog != null) {
            logger.info("Stopping full query logging to {}", binLog.path);
            binLog.stop();
        } else {
            logger.info("Full query log already stopped");
        }
    } catch (InterruptedException e) {
        throw new UncheckedInterruptedException(e);
    } finally {
        QueryEvents.instance.unregisterListener(this);
        this.binLog = null;
    }
}
Also used : BinLog(org.apache.cassandra.utils.binlog.BinLog) UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException) UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException)

Example 9 with UncheckedInterruptedException

use of org.apache.cassandra.utils.concurrent.UncheckedInterruptedException in project cassandra by apache.

the class BinLog method logRecord.

// todo: refactor to helper class?
public void logRecord(ReleaseableWriteMarshallable record) {
    boolean putInQueue = false;
    try {
        if (blocking) {
            try {
                put(record);
                putInQueue = true;
            } catch (InterruptedException e) {
                throw new UncheckedInterruptedException(e);
            }
        } else {
            if (!offer(record)) {
                logDroppedSample();
            } else {
                putInQueue = true;
            }
        }
    } finally {
        if (!putInQueue) {
            record.release();
        }
    }
}
Also used : UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException) UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException)

Example 10 with UncheckedInterruptedException

use of org.apache.cassandra.utils.concurrent.UncheckedInterruptedException in project cassandra by apache.

the class ExternalArchiver method stop.

/**
 * Stops the archiver thread and tries to archive all existing files
 *
 * this handles the case where a user explicitly disables full/audit log and would expect all log files to be archived
 * rolled or not
 */
public void stop() {
    shouldContinue = false;
    try {
        // wait for the archiver thread to stop;
        executor.submit(() -> {
        }).get();
        // and try to archive all remaining files before exiting
        archiveExisting(path);
    } catch (InterruptedException e) {
        throw new UncheckedInterruptedException(e);
    } catch (ExecutionException e) {
        throw new RuntimeException(e);
    }
}
Also used : UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException) ExecutionException(java.util.concurrent.ExecutionException) UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException)

Aggregations

UncheckedInterruptedException (org.apache.cassandra.utils.concurrent.UncheckedInterruptedException)28 ExecutionException (java.util.concurrent.ExecutionException)9 TimeoutException (java.util.concurrent.TimeoutException)4 WriteTimeoutException (org.apache.cassandra.exceptions.WriteTimeoutException)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 IOException (java.io.IOException)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 ScheduledFuture (java.util.concurrent.ScheduledFuture)2 WriteFailureException (org.apache.cassandra.exceptions.WriteFailureException)2 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)2 Preconditions (com.google.common.base.Preconditions)1 CacheLoader (com.google.common.cache.CacheLoader)1 Iterables (com.google.common.collect.Iterables)1 Iterables.concat (com.google.common.collect.Iterables.concat)1 Ints (com.google.common.primitives.Ints)1 Uninterruptibles (com.google.common.util.concurrent.Uninterruptibles)1 BufferedReader (java.io.BufferedReader)1 FileNotFoundException (java.io.FileNotFoundException)1 IOError (java.io.IOError)1 InputStreamReader (java.io.InputStreamReader)1