Search in sources :

Example 1 with SegmentEofException

use of org.apache.ignite.internal.processors.cache.persistence.wal.SegmentEofException in project ignite by apache.

the class RecordV1Serializer method readWithCrc.

/**
 * Reads record from file {@code in0} and validates CRC of record.
 *
 * @param in0 File input.
 * @param expPtr Expected WAL pointer for record. Used to validate actual position against expected from the file.
 * @param reader Record reader I/O interface.
 * @return WAL record.
 * @throws EOFException In case of end of file.
 * @throws IgniteCheckedException If it's unable to read record.
 */
static WALRecord readWithCrc(FileInput in0, WALPointer expPtr, RecordIO reader) throws EOFException, IgniteCheckedException {
    long startPos = -1;
    try (FileInput.Crc32CheckingFileInput in = in0.startRead(skipCrc)) {
        startPos = in0.position();
        WALRecord res = reader.readWithHeaders(in, expPtr);
        assert res != null;
        // Account for CRC which will be read afterwards.
        res.size((int) (in0.position() - startPos + CRC_SIZE));
        return res;
    } catch (EOFException | SegmentEofException | WalSegmentTailReachedException e) {
        throw e;
    } catch (Exception e) {
        throw new IgniteCheckedException("Failed to read WAL record at position: " + startPos, e);
    }
}
Also used : WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) WalSegmentTailReachedException(org.apache.ignite.internal.processors.cache.persistence.wal.WalSegmentTailReachedException) EOFException(java.io.EOFException) FileInput(org.apache.ignite.internal.processors.cache.persistence.wal.FileInput) SegmentEofException(org.apache.ignite.internal.processors.cache.persistence.wal.SegmentEofException) SegmentEofException(org.apache.ignite.internal.processors.cache.persistence.wal.SegmentEofException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IOException(java.io.IOException) WalSegmentTailReachedException(org.apache.ignite.internal.processors.cache.persistence.wal.WalSegmentTailReachedException) EOFException(java.io.EOFException)

Example 2 with SegmentEofException

use of org.apache.ignite.internal.processors.cache.persistence.wal.SegmentEofException in project ignite by apache.

the class RecordV1Serializer method readRecordType.

/**
 * Reads record type from given {@code in}.
 *
 * @param in Buffer to read record type.
 * @return Record type.
 * @throws IgniteCheckedException If logical end of segment is reached.
 * @throws IOException In case of I/O problems.
 */
static RecordType readRecordType(DataInput in) throws IgniteCheckedException, IOException {
    int type = in.readUnsignedByte();
    if (type == WALRecord.RecordType.STOP_ITERATION_RECORD_TYPE)
        throw new SegmentEofException("Reached logical end of the segment", null);
    RecordType recType = RecordType.fromOrdinal(type - 1);
    if (recType == null)
        throw new IOException("Unknown record type: " + type);
    return recType;
}
Also used : RecordType(org.apache.ignite.internal.pagemem.wal.record.WALRecord.RecordType) SegmentEofException(org.apache.ignite.internal.processors.cache.persistence.wal.SegmentEofException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)2 SegmentEofException (org.apache.ignite.internal.processors.cache.persistence.wal.SegmentEofException)2 EOFException (java.io.EOFException)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 WALRecord (org.apache.ignite.internal.pagemem.wal.record.WALRecord)1 RecordType (org.apache.ignite.internal.pagemem.wal.record.WALRecord.RecordType)1 FileInput (org.apache.ignite.internal.processors.cache.persistence.wal.FileInput)1 WalSegmentTailReachedException (org.apache.ignite.internal.processors.cache.persistence.wal.WalSegmentTailReachedException)1