Search in sources :

Example 1 with TruncateRequest

use of org.apache.cassandra.db.TruncateRequest in project cassandra by apache.

the class StorageProxy method truncateBlocking.

/**
 * Performs the truncate operatoin, which effectively deletes all data from
 * the column family cfname
 * @param keyspace
 * @param cfname
 * @throws UnavailableException If some of the hosts in the ring are down.
 * @throws TimeoutException
 */
public static void truncateBlocking(String keyspace, String cfname) throws UnavailableException, TimeoutException {
    logger.debug("Starting a blocking truncate operation on keyspace {}, CF {}", keyspace, cfname);
    if (isAnyStorageHostDown()) {
        logger.info("Cannot perform truncate, some hosts are down");
        // Since the truncate operation is so aggressive and is typically only
        // invoked by an admin, for simplicity we require that all nodes are up
        // to perform the operation.
        int liveMembers = Gossiper.instance.getLiveMembers().size();
        throw UnavailableException.create(ConsistencyLevel.ALL, liveMembers + Gossiper.instance.getUnreachableMembers().size(), liveMembers);
    }
    Set<InetAddressAndPort> allEndpoints = StorageService.instance.getLiveRingMembers(true);
    int blockFor = allEndpoints.size();
    final TruncateResponseHandler responseHandler = new TruncateResponseHandler(blockFor);
    // Send out the truncate calls and track the responses with the callbacks.
    Tracing.trace("Enqueuing truncate messages to hosts {}", allEndpoints);
    Message<TruncateRequest> message = Message.out(TRUNCATE_REQ, new TruncateRequest(keyspace, cfname));
    for (InetAddressAndPort endpoint : allEndpoints) MessagingService.instance().sendWithCallback(message, endpoint, responseHandler);
    // Wait for all
    try {
        responseHandler.get();
    } catch (TimeoutException e) {
        Tracing.trace("Timed out");
        throw e;
    }
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) TruncateRequest(org.apache.cassandra.db.TruncateRequest) Hint(org.apache.cassandra.hints.Hint) CasWriteTimeoutException(org.apache.cassandra.exceptions.CasWriteTimeoutException) RequestTimeoutException(org.apache.cassandra.exceptions.RequestTimeoutException) ReadTimeoutException(org.apache.cassandra.exceptions.ReadTimeoutException) TimeoutException(java.util.concurrent.TimeoutException) WriteTimeoutException(org.apache.cassandra.exceptions.WriteTimeoutException)

Aggregations

TimeoutException (java.util.concurrent.TimeoutException)1 TruncateRequest (org.apache.cassandra.db.TruncateRequest)1 CasWriteTimeoutException (org.apache.cassandra.exceptions.CasWriteTimeoutException)1 ReadTimeoutException (org.apache.cassandra.exceptions.ReadTimeoutException)1 RequestTimeoutException (org.apache.cassandra.exceptions.RequestTimeoutException)1 WriteTimeoutException (org.apache.cassandra.exceptions.WriteTimeoutException)1 Hint (org.apache.cassandra.hints.Hint)1 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)1