use of org.apache.ignite.internal.processors.cache.persistence.wal.ByteBufferBackedDataInput 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.ByteBufferBackedDataInput in project ignite by apache.
the class RecordDataV1Serializer method readEncryptedDataEntry.
/**
* @param in Input to read from.
* @param recType Record type.
* @return Read entry.
* @throws IOException If failed.
* @throws IgniteCheckedException If failed.
*/
DataEntry readEncryptedDataEntry(ByteBufferBackedDataInput in, RecordType recType) throws IOException, IgniteCheckedException {
boolean needDecryption = in.readByte() == ENCRYPTED;
RecordType dataRecordType = recType == ENCRYPTED_DATA_RECORD_V3 ? DATA_RECORD_V2 : DATA_RECORD;
if (needDecryption) {
if (encSpi == null) {
skipEncryptedRecord(in, false);
return new EncryptedDataEntry();
}
T3<ByteBufferBackedDataInput, Integer, RecordType> clData = readEncryptedData(in, false, recType == ENCRYPTED_DATA_RECORD_V2 || recType == ENCRYPTED_DATA_RECORD_V3);
if (clData.get1() == null)
return null;
return readPlainDataEntry(clData.get1(), dataRecordType);
}
return readPlainDataEntry(in, dataRecordType);
}
Aggregations