Search in sources :

Example 1 with WalSegmentTailReachedException

use of org.apache.ignite.internal.processors.cache.persistence.wal.WalSegmentTailReachedException 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 WalSegmentTailReachedException

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

the class RecordV2Serializer method readPositionAndCheckPoint.

/**
 * @param in Data input to read pointer from.
 * @param skipPositionCheck Flag for skipping position check.
 * @return Read file WAL pointer.
 * @throws IOException If failed to write.
 */
@SuppressWarnings("UnusedReturnValue")
private static FileWALPointer readPositionAndCheckPoint(DataInput in, WALPointer expPtr, boolean skipPositionCheck) throws IgniteCheckedException, IOException {
    long idx = in.readLong();
    int fileOff = in.readInt();
    int len = in.readInt();
    FileWALPointer p = (FileWALPointer) expPtr;
    if (!F.eq(idx, p.index()) || (!skipPositionCheck && !F.eq(fileOff, p.fileOffset())))
        throw new WalSegmentTailReachedException("WAL segment tail is reached. [ " + "Expected next state: {Index=" + p.index() + ",Offset=" + p.fileOffset() + "}, " + "Actual state : {Index=" + idx + ",Offset=" + fileOff + "} ]", null);
    return new FileWALPointer(idx, fileOff, len);
}
Also used : FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer) WalSegmentTailReachedException(org.apache.ignite.internal.processors.cache.persistence.wal.WalSegmentTailReachedException)

Aggregations

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