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);
});
}
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;
}
Aggregations