Search in sources :

Example 6 with RecordSerializerFactoryImpl

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

the class FsyncModeFileWriteAheadLogManager method restoreWriteHandle.

/**
 * @param lastReadPtr Last read WAL file pointer.
 * @return Initialized file write handle.
 * @throws IgniteCheckedException If failed to initialize WAL write handle.
 */
private FileWriteHandle restoreWriteHandle(FileWALPointer lastReadPtr) throws IgniteCheckedException {
    long absIdx = lastReadPtr == null ? 0 : lastReadPtr.index();
    long segNo = absIdx % dsCfg.getWalSegments();
    File curFile = new File(walWorkDir, FileDescriptor.fileName(segNo));
    int offset = lastReadPtr == null ? 0 : lastReadPtr.fileOffset();
    int len = lastReadPtr == null ? 0 : lastReadPtr.length();
    try {
        FileIO fileIO = ioFactory.create(curFile);
        try {
            int serVer = serializerVersion;
            // If we have existing segment, try to read version from it.
            if (lastReadPtr != null) {
                try {
                    serVer = readSerializerVersionAndCompactedFlag(fileIO).get1();
                } catch (SegmentEofException | EOFException ignore) {
                    serVer = serializerVersion;
                }
            }
            RecordSerializer ser = new RecordSerializerFactoryImpl(cctx).createSerializer(serVer);
            if (log.isInfoEnabled())
                log.info("Resuming logging to WAL segment [file=" + curFile.getAbsolutePath() + ", offset=" + offset + ", ver=" + serVer + ']');
            FileWriteHandle hnd = new FileWriteHandle(fileIO, absIdx, offset + len, maxWalSegmentSize, ser);
            // For new handle write serializer version to it.
            if (lastReadPtr == null)
                hnd.writeSerializerVersion();
            archiver.currentWalIndex(absIdx);
            return hnd;
        } catch (IgniteCheckedException | IOException e) {
            fileIO.close();
            throw e;
        }
    } catch (IOException e) {
        throw new IgniteCheckedException("Failed to restore WAL write handle: " + curFile.getAbsolutePath(), e);
    }
}
Also used : IOException(java.io.IOException) FileIO(org.apache.ignite.internal.processors.cache.persistence.file.FileIO) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) RecordSerializerFactoryImpl(org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordSerializerFactoryImpl) EOFException(java.io.EOFException) File(java.io.File) RecordSerializer(org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordSerializer)

Aggregations

RecordSerializerFactoryImpl (org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordSerializerFactoryImpl)6 EOFException (java.io.EOFException)2 File (java.io.File)2 IOException (java.io.IOException)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)2 FileIO (org.apache.ignite.internal.processors.cache.persistence.file.FileIO)2 PdsFolderSettings (org.apache.ignite.internal.processors.cache.persistence.filename.PdsFolderSettings)2 RecordSerializer (org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordSerializer)2 MappedByteBuffer (java.nio.MappedByteBuffer)1 Nullable (org.jetbrains.annotations.Nullable)1