Search in sources :

Example 1 with CheckpointHistoryResult

use of org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointHistoryResult in project ignite by apache.

the class ReleaseSegmentOnHistoricalRebalanceTest method testReleaseSegmentAfterSearchAndReserveCheckpoints.

/**
 * Checks that if release the segment after {@link CheckpointHistory#searchAndReserveCheckpoints},
 * there will be no errors and the rebalance will be completed.
 *
 * @throws Exception If failed.
 */
@Test
public void testReleaseSegmentAfterSearchAndReserveCheckpoints() throws Exception {
    checkHistoricalRebalance(n -> {
        CheckpointHistory spy = spy(dbMgr(n).checkpointHistory());
        when(spy.searchAndReserveCheckpoints(any())).thenAnswer(m -> {
            CheckpointHistoryResult res = (CheckpointHistoryResult) m.callRealMethod();
            WALPointer reserved = res.reservedCheckpointMark();
            assertNotNull(reserved);
            release(n, reserved);
            return res;
        });
        checkpointHistory(n, spy);
    });
}
Also used : CheckpointHistoryResult(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointHistoryResult) CheckpointHistory(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointHistory) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) Test(org.junit.Test)

Example 2 with CheckpointHistoryResult

use of org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointHistoryResult in project ignite by apache.

the class GridCacheDatabaseSharedManager method reserveHistoryForExchange.

/**
 * {@inheritDoc}
 */
@Override
public synchronized Map<Integer, Map<Integer, Long>> reserveHistoryForExchange() {
    assert reservedForExchange == null : reservedForExchange;
    Map<Integer, Set<Integer>> /*partId*/
    applicableGroupsAndPartitions = partitionsApplicableForWalRebalance();
    Map<Integer, T2<ReservationReason, Map<Integer, CheckpointEntry>>> /*partId*/
    earliestValidCheckpoints;
    checkpointReadLock();
    WALPointer reservedCheckpointMark;
    try {
        CheckpointHistoryResult checkpointHistoryResult = checkpointHistory().searchAndReserveCheckpoints(applicableGroupsAndPartitions);
        earliestValidCheckpoints = checkpointHistoryResult.earliestValidCheckpoints();
        reservedForExchange = reservedCheckpointMark = checkpointHistoryResult.reservedCheckpointMark();
    } finally {
        checkpointReadUnlock();
    }
    Map<Integer, Map<Integer, Long>> /*updCntr*/
    grpPartsWithCnts = new HashMap<>();
    for (Map.Entry<Integer, T2<ReservationReason, Map<Integer, CheckpointEntry>>> /*partId*/
    e : earliestValidCheckpoints.entrySet()) {
        int grpId = e.getKey();
        if (e.getValue().get2() == null)
            continue;
        for (Map.Entry<Integer, CheckpointEntry> e0 : e.getValue().get2().entrySet()) {
            CheckpointEntry cpEntry = e0.getValue();
            int partId = e0.getKey();
            if (reservedCheckpointMark != null && !cctx.wal().reserved(reservedCheckpointMark)) {
                log.warning("Reservation failed because the segment was released: " + reservedCheckpointMark);
                reservedForExchange = null;
                grpPartsWithCnts.clear();
                return grpPartsWithCnts;
            }
            try {
                Long updCntr = cpEntry.partitionCounter(cctx.wal(), grpId, partId);
                if (updCntr != null)
                    grpPartsWithCnts.computeIfAbsent(grpId, k -> new HashMap<>()).put(partId, updCntr);
            } catch (IgniteCheckedException ex) {
                log.warning("Reservation failed because counters are not available [grpId=" + grpId + ", part=" + partId + ", cp=(" + cpEntry.checkpointId() + ", " + U.format(cpEntry.timestamp()) + ")]", ex);
            }
        }
    }
    if (log.isInfoEnabled() && !F.isEmpty(earliestValidCheckpoints))
        printReservationToLog(earliestValidCheckpoints);
    return grpPartsWithCnts;
}
Also used : CheckpointEntry(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointEntry) Set(java.util.Set) Collectors.toSet(java.util.stream.Collectors.toSet) HashSet(java.util.HashSet) GridConcurrentHashSet(org.apache.ignite.internal.util.GridConcurrentHashSet) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteSystemProperties.getInteger(org.apache.ignite.IgniteSystemProperties.getInteger) CheckpointHistoryResult(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointHistoryResult) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AtomicLong(java.util.concurrent.atomic.AtomicLong) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) T2(org.apache.ignite.internal.util.typedef.T2)

Aggregations

CheckpointHistoryResult (org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointHistoryResult)2 WALPointer (org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteSystemProperties.getInteger (org.apache.ignite.IgniteSystemProperties.getInteger)1 CheckpointEntry (org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointEntry)1 CheckpointHistory (org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointHistory)1 GridConcurrentHashSet (org.apache.ignite.internal.util.GridConcurrentHashSet)1 T2 (org.apache.ignite.internal.util.typedef.T2)1 Test (org.junit.Test)1