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);
}
}
Aggregations