Search in sources :

Example 1 with SegmentHeader

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

the class AbstractWalRecordsIterator method initReadHandle.

/**
 * Assumes file descriptor will be opened in this method. The caller of this method must be responsible for closing
 * opened file descriptor File descriptor will be closed ONLY in case of error occurred.
 *
 * @param desc File descriptor.
 * @param start Optional start pointer. Null means read from the beginning
 * @return Initialized file read header.
 * @throws FileNotFoundException If segment file is missing.
 * @throws IgniteCheckedException If initialized failed due to another unexpected error.
 */
protected AbstractReadFileHandle initReadHandle(@NotNull final AbstractFileDescriptor desc, @Nullable final WALPointer start) throws IgniteCheckedException, FileNotFoundException {
    SegmentIO fileIO = null;
    try {
        fileIO = desc.toReadOnlyIO(ioFactory);
        SegmentHeader segmentHeader;
        try {
            segmentHeader = readSegmentHeader(fileIO, segmentFileInputFactory);
        } catch (SegmentEofException | EOFException ignore) {
            try {
                fileIO.close();
            } catch (IOException ce) {
                throw new IgniteCheckedException(ce);
            }
            return null;
        } catch (IOException | IgniteCheckedException e) {
            U.closeWithSuppressingException(fileIO, e);
            throw e;
        }
        return initReadHandle(desc, start, fileIO, segmentHeader);
    } catch (FileNotFoundException e) {
        U.closeQuiet(fileIO);
        throw e;
    } catch (IOException e) {
        U.closeQuiet(fileIO);
        throw new IgniteCheckedException("Failed to initialize WAL segment: " + desc.file().getAbsolutePath(), e);
    }
}
Also used : SegmentIO(org.apache.ignite.internal.processors.cache.persistence.wal.io.SegmentIO) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) RecordV1Serializer.readSegmentHeader(org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordV1Serializer.readSegmentHeader) SegmentHeader(org.apache.ignite.internal.processors.cache.persistence.wal.serializer.SegmentHeader) EOFException(java.io.EOFException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 2 with SegmentHeader

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

the class StandaloneWalRecordsIterator method initReadHandle.

/**
 * {@inheritDoc}
 */
@Override
protected AbstractReadFileHandle initReadHandle(@NotNull AbstractFileDescriptor desc, @Nullable WALPointer start) throws IgniteCheckedException, FileNotFoundException {
    AbstractFileDescriptor fd = desc;
    SegmentIO fileIO = null;
    SegmentHeader segmentHeader;
    while (true) {
        try {
            fileIO = fd.toReadOnlyIO(ioFactory);
            segmentHeader = readSegmentHeader(fileIO, FILE_INPUT_FACTORY);
            break;
        } catch (IOException | IgniteCheckedException e) {
            log.error("Failed to init segment curWalSegmIdx=" + curWalSegmIdx + ", curIdx=" + curIdx, e);
            U.closeQuiet(fileIO);
            curIdx++;
            if (curIdx >= walFileDescriptors.size())
                return null;
            fd = walFileDescriptors.get(curIdx);
        }
    }
    return initReadHandle(fd, start, fileIO, segmentHeader);
}
Also used : SegmentIO(org.apache.ignite.internal.processors.cache.persistence.wal.io.SegmentIO) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) RecordV1Serializer.readSegmentHeader(org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordV1Serializer.readSegmentHeader) SegmentHeader(org.apache.ignite.internal.processors.cache.persistence.wal.serializer.SegmentHeader) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 SegmentIO (org.apache.ignite.internal.processors.cache.persistence.wal.io.SegmentIO)2 RecordV1Serializer.readSegmentHeader (org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordV1Serializer.readSegmentHeader)2 SegmentHeader (org.apache.ignite.internal.processors.cache.persistence.wal.serializer.SegmentHeader)2 EOFException (java.io.EOFException)1 FileNotFoundException (java.io.FileNotFoundException)1