use of org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer in project ignite by apache.
the class RecordDataV2Serializer method writePlainRecord.
/**
* {@inheritDoc}
*/
@Override
protected void writePlainRecord(WALRecord rec, ByteBuffer buf) throws IgniteCheckedException {
if (rec instanceof HeaderRecord)
throw new UnsupportedOperationException("Writing header records is forbidden since version 2 of serializer");
switch(rec.type()) {
case CHECKPOINT_RECORD:
CheckpointRecord cpRec = (CheckpointRecord) rec;
WALPointer walPtr = cpRec.checkpointMark();
UUID cpId = cpRec.checkpointId();
buf.putLong(cpId.getMostSignificantBits());
buf.putLong(cpId.getLeastSignificantBits());
buf.put(walPtr == null ? (byte) 0 : 1);
if (walPtr != null) {
buf.putLong(walPtr.index());
buf.putInt(walPtr.fileOffset());
buf.putInt(walPtr.length());
}
putCacheStates(buf, cpRec.cacheGroupStates());
buf.put(cpRec.end() ? (byte) 1 : 0);
break;
case MVCC_DATA_RECORD:
case DATA_RECORD_V2:
DataRecord dataRec = (DataRecord) rec;
int entryCnt = dataRec.entryCount();
buf.putInt(entryCnt);
buf.putLong(dataRec.timestamp());
boolean encrypted = isDataRecordEncrypted(dataRec);
for (int i = 0; i < entryCnt; i++) {
DataEntry dataEntry = dataRec.get(i);
if (encrypted)
putEncryptedDataEntry(buf, dataEntry);
else
putPlainDataEntry(buf, dataEntry);
}
break;
case SNAPSHOT:
SnapshotRecord snpRec = (SnapshotRecord) rec;
buf.putLong(snpRec.getSnapshotId());
buf.put(snpRec.isFull() ? (byte) 1 : 0);
break;
case EXCHANGE:
ExchangeRecord r = (ExchangeRecord) rec;
buf.putInt(r.getType().ordinal());
buf.putShort(r.getConstId());
buf.putLong(r.timestamp());
break;
case TX_RECORD:
txRecordSerializer.write((TxRecord) rec, buf);
break;
case MVCC_TX_RECORD:
txRecordSerializer.write((MvccTxRecord) rec, buf);
break;
case ROLLBACK_TX_RECORD:
RollbackRecord rb = (RollbackRecord) rec;
buf.putInt(rb.groupId());
buf.putInt(rb.partitionId());
buf.putLong(rb.start());
buf.putLong(rb.range());
break;
case TRACKING_PAGE_REPAIR_DELTA:
TrackingPageRepairDeltaRecord tprDelta = (TrackingPageRepairDeltaRecord) rec;
buf.putInt(tprDelta.groupId());
buf.putLong(tprDelta.pageId());
break;
default:
super.writePlainRecord(rec, buf);
}
}
use of org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer in project ignite by apache.
the class RecordDataV2Serializer method plainSize.
/**
* {@inheritDoc}
*/
@Override
protected int plainSize(WALRecord rec) throws IgniteCheckedException {
switch(rec.type()) {
case HEADER_RECORD:
return HEADER_RECORD_DATA_SIZE;
case CHECKPOINT_RECORD:
CheckpointRecord cpRec = (CheckpointRecord) rec;
int cacheStatesSize = cacheStatesSize(cpRec.cacheGroupStates());
WALPointer walPtr = cpRec.checkpointMark();
return 18 + cacheStatesSize + (walPtr == null ? 0 : 16);
case MVCC_DATA_RECORD:
return 4 + /*entry count*/
8 + /*timestamp*/
dataSize((DataRecord) rec);
case DATA_RECORD_V2:
return super.plainSize(rec) + 8;
case SNAPSHOT:
return 8 + 1;
case EXCHANGE:
return 4 + /*type*/
8 + /*timestamp*/
2;
case TX_RECORD:
return txRecordSerializer.size((TxRecord) rec);
case MVCC_TX_RECORD:
return txRecordSerializer.size((MvccTxRecord) rec);
case ROLLBACK_TX_RECORD:
return 4 + 4 + 8 + 8;
case TRACKING_PAGE_REPAIR_DELTA:
return 4 + 8;
case PARTITION_CLEARING_START_RECORD:
return 4 + 4 + 8;
default:
return super.plainSize(rec);
}
}
use of org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer in project ignite by apache.
the class RecordV1Serializer method readSegmentHeader.
/**
* Reads stored record from provided {@code io}.
* NOTE: Method mutates position of {@code io}.
*
* @param io I/O interface for file.
* @param segmentFileInputFactory File input factory.
* @return Instance of {@link SegmentHeader} extracted from the file.
* @throws IgniteCheckedException If failed to read serializer version.
*/
public static SegmentHeader readSegmentHeader(SegmentIO io, SegmentFileInputFactory segmentFileInputFactory) throws IgniteCheckedException, IOException {
try (ByteBufferExpander buf = new ByteBufferExpander(HEADER_RECORD_SIZE, ByteOrder.nativeOrder())) {
ByteBufferBackedDataInput in = segmentFileInputFactory.createFileInput(io, buf);
in.ensure(HEADER_RECORD_SIZE);
int recordType = in.readUnsignedByte();
if (recordType == WALRecord.RecordType.STOP_ITERATION_RECORD_TYPE)
throw new SegmentEofException("Reached logical end of the segment", null);
WALRecord.RecordType type = WALRecord.RecordType.fromIndex(recordType - 1);
if (type != WALRecord.RecordType.HEADER_RECORD)
throw new IOException("Can't read serializer version", null);
// Read file pointer.
WALPointer ptr = readPosition(in);
if (io.getSegmentId() != ptr.index())
throw new SegmentEofException("Reached logical end of the segment by pointer", null);
assert ptr.fileOffset() == 0 : "Header record should be placed at the beginning of file " + ptr;
long hdrMagicNum = in.readLong();
boolean compacted;
if (hdrMagicNum == HeaderRecord.REGULAR_MAGIC)
compacted = false;
else if (hdrMagicNum == HeaderRecord.COMPACTED_MAGIC)
compacted = true;
else {
throw new IOException("Magic is corrupted [exp=" + U.hexLong(HeaderRecord.REGULAR_MAGIC) + ", actual=" + U.hexLong(hdrMagicNum) + ']');
}
// Read serializer version.
int ver = in.readInt();
// Read and skip CRC.
in.readInt();
return new SegmentHeader(ver, compacted);
}
}
use of org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer 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.wal.WALPointer 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