Search in sources :

Example 1 with TimeUUID

use of org.apache.cassandra.utils.TimeUUID in project cassandra by apache.

the class LocalSessions method handleFinalizeProposeMessage.

public void handleFinalizeProposeMessage(InetAddressAndPort from, FinalizePropose propose) {
    logger.trace("received {} from {}", propose, from);
    TimeUUID sessionID = propose.sessionID;
    LocalSession session = getSession(sessionID);
    if (session == null) {
        logger.info("Received FinalizePropose message for unknown repair session {}, responding with failure", sessionID);
        sendMessage(from, Message.out(FAILED_SESSION_MSG, new FailSession(sessionID)));
        return;
    }
    try {
        setStateAndSave(session, FINALIZE_PROMISED);
        /*
             Flushing the repairs table here, *before* responding to the coordinator prevents a scenario where we respond
             with a promise to the coordinator, but there is a failure before the commit log mutation with the
             FINALIZE_PROMISED status is synced to disk. This could cause the state for this session to revert to an
             earlier status on startup, which would prevent the failure recovery mechanism from ever being able to promote
             this session to FINALIZED, likely creating inconsistencies in the repaired data sets across nodes.
             */
        syncTable();
        sendMessage(from, Message.out(FINALIZE_PROMISE_MSG, new FinalizePromise(sessionID, getBroadcastAddressAndPort(), true)));
        logger.info("Received FinalizePropose message for incremental repair session {}, responded with FinalizePromise", sessionID);
    } catch (IllegalArgumentException e) {
        logger.error("Error handling FinalizePropose message for {}", session, e);
        failSession(sessionID);
    }
}
Also used : TimeUUID(org.apache.cassandra.utils.TimeUUID) FinalizePromise(org.apache.cassandra.repair.messages.FinalizePromise) FailSession(org.apache.cassandra.repair.messages.FailSession)

Example 2 with TimeUUID

use of org.apache.cassandra.utils.TimeUUID in project cassandra by apache.

the class LocalSessions method start.

/**
 * Loads sessions out of the repairs table and sets state to started
 */
public synchronized void start() {
    Preconditions.checkArgument(!started, "LocalSessions.start can only be called once");
    Preconditions.checkArgument(sessions.isEmpty(), "No sessions should be added before start");
    UntypedResultSet rows = QueryProcessor.executeInternalWithPaging(String.format("SELECT * FROM %s.%s", keyspace, table), 1000);
    Map<TimeUUID, LocalSession> loadedSessions = new HashMap<>();
    Map<TableId, List<RepairedState.Level>> initialLevels = new HashMap<>();
    for (UntypedResultSet.Row row : rows) {
        try {
            LocalSession session = load(row);
            loadedSessions.put(session.sessionID, session);
            if (shouldStoreSession(session)) {
                for (TableId tid : session.tableIds) initialLevels.computeIfAbsent(tid, (t) -> new ArrayList<>()).add(new RepairedState.Level(session.ranges, session.repairedAt));
            }
        } catch (IllegalArgumentException | NullPointerException e) {
            logger.warn("Unable to load malformed repair session {}, removing", row.has("parent_id") ? row.getTimeUUID("parent_id") : null);
            if (row.has("parent_id"))
                deleteRow(row.getTimeUUID("parent_id"));
        }
    }
    for (Map.Entry<TableId, List<RepairedState.Level>> entry : initialLevels.entrySet()) getRepairedState(entry.getKey()).addAll(entry.getValue());
    sessions = ImmutableMap.copyOf(loadedSessions);
    failOngoingRepairs();
    started = true;
}
Also used : TimeUUID(org.apache.cassandra.utils.TimeUUID) TableId(org.apache.cassandra.schema.TableId) HashMap(java.util.HashMap) UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 3 with TimeUUID

use of org.apache.cassandra.utils.TimeUUID in project cassandra by apache.

the class LocalSessions method cleanup.

public CleanupSummary cleanup(TableId tid, Collection<Range<Token>> ranges, boolean force) {
    Iterable<LocalSession> candidates = Iterables.filter(sessions.values(), ls -> ls.isCompleted() && ls.tableIds.contains(tid) && Range.intersects(ls.ranges, ranges));
    ColumnFamilyStore cfs = Schema.instance.getColumnFamilyStoreInstance(tid);
    Set<TimeUUID> sessionIds = Sets.newHashSet(Iterables.transform(candidates, s -> s.sessionID));
    return cfs.releaseRepairData(sessionIds, force);
}
Also used : TimeUUID(org.apache.cassandra.utils.TimeUUID) NoSuchRepairSessionException(org.apache.cassandra.repair.NoSuchRepairSessionException) KeyspaceRepairManager(org.apache.cassandra.repair.KeyspaceRepairManager) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) STATUS_REQ(org.apache.cassandra.net.Verb.STATUS_REQ) CompactionInterruptedException(org.apache.cassandra.db.compaction.CompactionInterruptedException) ByteBuffer(java.nio.ByteBuffer) BooleanSupplier(java.util.function.BooleanSupplier) Map(java.util.Map) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) PendingStats(org.apache.cassandra.repair.consistent.admin.PendingStats) Verify(com.google.common.base.Verify) ImmutableSet(com.google.common.collect.ImmutableSet) FBUtilities(org.apache.cassandra.utils.FBUtilities) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) Collection(java.util.Collection) FinalizeCommit(org.apache.cassandra.repair.messages.FinalizeCommit) Set(java.util.Set) UUID(java.util.UUID) Instant(java.time.Instant) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) FinalizePropose(org.apache.cassandra.repair.messages.FinalizePropose) State(org.apache.cassandra.repair.consistent.ConsistentSession.State) List(java.util.List) FAILED_SESSION_MSG(org.apache.cassandra.net.Verb.FAILED_SESSION_MSG) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Future(org.apache.cassandra.utils.concurrent.Future) Throwables(org.apache.cassandra.utils.Throwables) FINALIZE_PROMISE_MSG(org.apache.cassandra.net.Verb.FINALIZE_PROMISE_MSG) FailureDetector(org.apache.cassandra.gms.FailureDetector) SchemaConstants(org.apache.cassandra.schema.SchemaConstants) DataInputBuffer(org.apache.cassandra.io.util.DataInputBuffer) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) Iterables(com.google.common.collect.Iterables) PendingStat(org.apache.cassandra.repair.consistent.admin.PendingStat) PrepareConsistentResponse(org.apache.cassandra.repair.messages.PrepareConsistentResponse) DataOutputBuffer(org.apache.cassandra.io.util.DataOutputBuffer) TableId(org.apache.cassandra.schema.TableId) PREPARE_CONSISTENT_RSP(org.apache.cassandra.net.Verb.PREPARE_CONSISTENT_RSP) Range(org.apache.cassandra.dht.Range) HashMap(java.util.HashMap) Message(org.apache.cassandra.net.Message) QueryProcessor(org.apache.cassandra.cql3.QueryProcessor) FinalizePromise(org.apache.cassandra.repair.messages.FinalizePromise) SystemKeyspace(org.apache.cassandra.db.SystemKeyspace) ArrayList(java.util.ArrayList) Schema(org.apache.cassandra.schema.Schema) HashSet(java.util.HashSet) UTF8Type(org.apache.cassandra.db.marshal.UTF8Type) Token(org.apache.cassandra.dht.Token) ActiveRepairService(org.apache.cassandra.service.ActiveRepairService) Lists(com.google.common.collect.Lists) CleanupSummary(org.apache.cassandra.repair.consistent.admin.CleanupSummary) STATUS_RSP(org.apache.cassandra.net.Verb.STATUS_RSP) ExecutorService(java.util.concurrent.ExecutorService) Nullable(javax.annotation.Nullable) MessagingService(org.apache.cassandra.net.MessagingService) Logger(org.slf4j.Logger) BytesType(org.apache.cassandra.db.marshal.BytesType) StatusResponse(org.apache.cassandra.repair.messages.StatusResponse) StorageService(org.apache.cassandra.service.StorageService) IOException(java.io.IOException) PrepareConsistentRequest(org.apache.cassandra.repair.messages.PrepareConsistentRequest) UnknownHostException(java.net.UnknownHostException) Ints(com.google.common.primitives.Ints) FutureCallback(com.google.common.util.concurrent.FutureCallback) Replica(org.apache.cassandra.locator.Replica) FailSession(org.apache.cassandra.repair.messages.FailSession) TimeUnit(java.util.concurrent.TimeUnit) RepairMessage(org.apache.cassandra.repair.messages.RepairMessage) UUIDType(org.apache.cassandra.db.marshal.UUIDType) IPartitioner(org.apache.cassandra.dht.IPartitioner) Global.executorFactory(org.apache.cassandra.concurrent.ExecutorFactory.Global.executorFactory) UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) TimeUUID(org.apache.cassandra.utils.TimeUUID) StatusRequest(org.apache.cassandra.repair.messages.StatusRequest) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore)

Example 4 with TimeUUID

use of org.apache.cassandra.utils.TimeUUID in project cassandra by apache.

the class LocalSessions method handleFinalizeCommitMessage.

/**
 * Finalizes the repair session, completing it as successful.
 *
 * This only changes the state of the session, it doesn't promote the siloed sstables to repaired. That will happen
 * as part of the compaction process, and avoids having to worry about in progress compactions interfering with the
 * promotion.
 */
public void handleFinalizeCommitMessage(InetAddressAndPort from, FinalizeCommit commit) {
    logger.trace("received {} from {}", commit, from);
    TimeUUID sessionID = commit.sessionID;
    LocalSession session = getSession(sessionID);
    if (session == null) {
        logger.warn("Ignoring FinalizeCommit message for unknown repair session {}", sessionID);
        return;
    }
    setStateAndSave(session, FINALIZED);
    logger.info("Finalized local repair session {}", sessionID);
}
Also used : TimeUUID(org.apache.cassandra.utils.TimeUUID)

Example 5 with TimeUUID

use of org.apache.cassandra.utils.TimeUUID in project cassandra by apache.

the class LocalSessions method handlePrepareMessage.

/**
 * The PrepareConsistentRequest promotes the parent repair session to a consistent incremental
 * session, and isolates the data to be repaired from the rest of the table's data
 *
 * No response is sent to the repair coordinator until the data preparation / isolation has completed
 * successfully. If the data preparation fails, a failure message is sent to the coordinator,
 * cancelling the session.
 */
public void handlePrepareMessage(InetAddressAndPort from, PrepareConsistentRequest request) {
    logger.trace("received {} from {}", request, from);
    TimeUUID sessionID = request.parentSession;
    InetAddressAndPort coordinator = request.coordinator;
    Set<InetAddressAndPort> peers = request.participants;
    ActiveRepairService.ParentRepairSession parentSession;
    try {
        parentSession = getParentRepairSession(sessionID);
    } catch (Throwable e) {
        logger.error("Error retrieving ParentRepairSession for session {}, responding with failure", sessionID);
        sendMessage(coordinator, Message.out(PREPARE_CONSISTENT_RSP, new PrepareConsistentResponse(sessionID, getBroadcastAddressAndPort(), false)));
        return;
    }
    LocalSession session = createSessionUnsafe(sessionID, parentSession, peers);
    putSessionUnsafe(session);
    logger.info("Beginning local incremental repair session {}", session);
    ExecutorService executor = executorFactory().pooled("Repair-" + sessionID, parentSession.getColumnFamilyStores().size());
    KeyspaceRepairManager repairManager = parentSession.getKeyspace().getRepairManager();
    RangesAtEndpoint tokenRanges = filterLocalRanges(parentSession.getKeyspace().getName(), parentSession.getRanges());
    Future<List<Void>> repairPreparation = prepareSession(repairManager, sessionID, parentSession.getColumnFamilyStores(), tokenRanges, executor, () -> session.getState() != PREPARING);
    repairPreparation.addCallback(new FutureCallback<List<Void>>() {

        public void onSuccess(@Nullable List<Void> result) {
            try {
                logger.info("Prepare phase for incremental repair session {} completed", sessionID);
                if (!prepareSessionExceptFailed(session))
                    logger.info("Session {} failed before anticompaction completed", sessionID);
                Message<PrepareConsistentResponse> message = Message.out(PREPARE_CONSISTENT_RSP, new PrepareConsistentResponse(sessionID, getBroadcastAddressAndPort(), session.getState() != FAILED));
                sendMessage(coordinator, message);
            } finally {
                executor.shutdown();
            }
        }

        public void onFailure(Throwable t) {
            try {
                if (Throwables.anyCauseMatches(t, (throwable) -> throwable instanceof CompactionInterruptedException))
                    logger.info("Anticompaction interrupted for session {}: {}", sessionID, t.getMessage());
                else if (Throwables.anyCauseMatches(t, (throwable) -> throwable instanceof NoSuchRepairSessionException))
                    logger.warn("No such repair session: {}", sessionID);
                else
                    logger.error("Prepare phase for incremental repair session {} failed", sessionID, t);
                sendMessage(coordinator, Message.out(PREPARE_CONSISTENT_RSP, new PrepareConsistentResponse(sessionID, getBroadcastAddressAndPort(), false)));
                failSession(sessionID, false);
            } finally {
                executor.shutdown();
            }
        }
    });
}
Also used : TimeUUID(org.apache.cassandra.utils.TimeUUID) NoSuchRepairSessionException(org.apache.cassandra.repair.NoSuchRepairSessionException) KeyspaceRepairManager(org.apache.cassandra.repair.KeyspaceRepairManager) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) STATUS_REQ(org.apache.cassandra.net.Verb.STATUS_REQ) CompactionInterruptedException(org.apache.cassandra.db.compaction.CompactionInterruptedException) ByteBuffer(java.nio.ByteBuffer) BooleanSupplier(java.util.function.BooleanSupplier) Map(java.util.Map) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) PendingStats(org.apache.cassandra.repair.consistent.admin.PendingStats) Verify(com.google.common.base.Verify) ImmutableSet(com.google.common.collect.ImmutableSet) FBUtilities(org.apache.cassandra.utils.FBUtilities) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) Collection(java.util.Collection) FinalizeCommit(org.apache.cassandra.repair.messages.FinalizeCommit) Set(java.util.Set) UUID(java.util.UUID) Instant(java.time.Instant) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) FinalizePropose(org.apache.cassandra.repair.messages.FinalizePropose) State(org.apache.cassandra.repair.consistent.ConsistentSession.State) List(java.util.List) FAILED_SESSION_MSG(org.apache.cassandra.net.Verb.FAILED_SESSION_MSG) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Future(org.apache.cassandra.utils.concurrent.Future) Throwables(org.apache.cassandra.utils.Throwables) FINALIZE_PROMISE_MSG(org.apache.cassandra.net.Verb.FINALIZE_PROMISE_MSG) FailureDetector(org.apache.cassandra.gms.FailureDetector) SchemaConstants(org.apache.cassandra.schema.SchemaConstants) DataInputBuffer(org.apache.cassandra.io.util.DataInputBuffer) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) Iterables(com.google.common.collect.Iterables) PendingStat(org.apache.cassandra.repair.consistent.admin.PendingStat) PrepareConsistentResponse(org.apache.cassandra.repair.messages.PrepareConsistentResponse) DataOutputBuffer(org.apache.cassandra.io.util.DataOutputBuffer) TableId(org.apache.cassandra.schema.TableId) PREPARE_CONSISTENT_RSP(org.apache.cassandra.net.Verb.PREPARE_CONSISTENT_RSP) Range(org.apache.cassandra.dht.Range) HashMap(java.util.HashMap) Message(org.apache.cassandra.net.Message) QueryProcessor(org.apache.cassandra.cql3.QueryProcessor) FinalizePromise(org.apache.cassandra.repair.messages.FinalizePromise) SystemKeyspace(org.apache.cassandra.db.SystemKeyspace) ArrayList(java.util.ArrayList) Schema(org.apache.cassandra.schema.Schema) HashSet(java.util.HashSet) UTF8Type(org.apache.cassandra.db.marshal.UTF8Type) Token(org.apache.cassandra.dht.Token) ActiveRepairService(org.apache.cassandra.service.ActiveRepairService) Lists(com.google.common.collect.Lists) CleanupSummary(org.apache.cassandra.repair.consistent.admin.CleanupSummary) STATUS_RSP(org.apache.cassandra.net.Verb.STATUS_RSP) ExecutorService(java.util.concurrent.ExecutorService) Nullable(javax.annotation.Nullable) MessagingService(org.apache.cassandra.net.MessagingService) Logger(org.slf4j.Logger) BytesType(org.apache.cassandra.db.marshal.BytesType) StatusResponse(org.apache.cassandra.repair.messages.StatusResponse) StorageService(org.apache.cassandra.service.StorageService) IOException(java.io.IOException) PrepareConsistentRequest(org.apache.cassandra.repair.messages.PrepareConsistentRequest) UnknownHostException(java.net.UnknownHostException) Ints(com.google.common.primitives.Ints) FutureCallback(com.google.common.util.concurrent.FutureCallback) Replica(org.apache.cassandra.locator.Replica) FailSession(org.apache.cassandra.repair.messages.FailSession) TimeUnit(java.util.concurrent.TimeUnit) RepairMessage(org.apache.cassandra.repair.messages.RepairMessage) UUIDType(org.apache.cassandra.db.marshal.UUIDType) IPartitioner(org.apache.cassandra.dht.IPartitioner) Global.executorFactory(org.apache.cassandra.concurrent.ExecutorFactory.Global.executorFactory) UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) TimeUUID(org.apache.cassandra.utils.TimeUUID) StatusRequest(org.apache.cassandra.repair.messages.StatusRequest) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) ActiveRepairService(org.apache.cassandra.service.ActiveRepairService) PrepareConsistentResponse(org.apache.cassandra.repair.messages.PrepareConsistentResponse) Message(org.apache.cassandra.net.Message) RepairMessage(org.apache.cassandra.repair.messages.RepairMessage) CompactionInterruptedException(org.apache.cassandra.db.compaction.CompactionInterruptedException) KeyspaceRepairManager(org.apache.cassandra.repair.KeyspaceRepairManager) ExecutorService(java.util.concurrent.ExecutorService) NoSuchRepairSessionException(org.apache.cassandra.repair.NoSuchRepairSessionException) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

TimeUUID (org.apache.cassandra.utils.TimeUUID)161 Generator.nextTimeUUID (org.apache.cassandra.utils.TimeUUID.Generator.nextTimeUUID)120 Test (org.junit.Test)113 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)54 AbstractRepairTest (org.apache.cassandra.repair.AbstractRepairTest)41 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)24 Range (org.apache.cassandra.dht.Range)23 Token (org.apache.cassandra.dht.Token)23 ArrayList (java.util.ArrayList)19 List (java.util.List)15 ActiveRepairService (org.apache.cassandra.service.ActiveRepairService)15 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)13 HashSet (java.util.HashSet)12 FailSession (org.apache.cassandra.repair.messages.FailSession)12 StatusResponse (org.apache.cassandra.repair.messages.StatusResponse)12 HashMap (java.util.HashMap)11 RangesAtEndpoint (org.apache.cassandra.locator.RangesAtEndpoint)11 IOException (java.io.IOException)10 UUID (java.util.UUID)10 ExecutorService (java.util.concurrent.ExecutorService)10