Search in sources :

Example 1 with RecordSerializerFactoryImpl

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

the class FileWriteAheadLogManager 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();
    @Nullable FileArchiver archiver0 = archiver;
    long segNo = archiver0 == null ? absIdx : absIdx % dsCfg.getWalSegments();
    File curFile = new File(walWorkDir, FileDescriptor.fileName(segNo));
    int off = lastReadPtr == null ? 0 : lastReadPtr.fileOffset();
    int len = lastReadPtr == null ? 0 : lastReadPtr.length();
    try {
        FileIO fileIO = ioFactory.create(curFile);
        IgniteInClosure<FileIO> lsnr = createWalFileListener;
        if (lsnr != null)
            lsnr.apply(fileIO);
        try {
            int serVer = serializerVer;
            // If we have existing segment, try to read version from it.
            if (lastReadPtr != null) {
                try {
                    serVer = readSerializerVersionAndCompactedFlag(fileIO).get1();
                } catch (SegmentEofException | EOFException ignore) {
                    serVer = serializerVer;
                }
            }
            RecordSerializer ser = new RecordSerializerFactoryImpl(cctx).createSerializer(serVer);
            if (log.isInfoEnabled())
                log.info("Resuming logging to WAL segment [file=" + curFile.getAbsolutePath() + ", offset=" + off + ", ver=" + serVer + ']');
            SegmentedRingByteBuffer rbuf;
            if (mmap) {
                try {
                    MappedByteBuffer buf = fileIO.map((int) maxWalSegmentSize);
                    rbuf = new SegmentedRingByteBuffer(buf, metrics);
                } catch (IOException e) {
                    throw new IgniteCheckedException(e);
                }
            } else
                rbuf = new SegmentedRingByteBuffer(dsCfg.getWalBufferSize(), maxWalSegmentSize, DIRECT, metrics);
            if (lastReadPtr != null)
                rbuf.init(lastReadPtr.fileOffset() + lastReadPtr.length());
            FileWriteHandle hnd = new FileWriteHandle(fileIO, absIdx, off + len, true, ser, rbuf);
            if (archiver0 != null)
                archiver0.currentWalIndex(absIdx);
            else
                archivedMonitor.setLastArchivedAbsoluteIndex(absIdx - 1);
            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) MappedByteBuffer(java.nio.MappedByteBuffer) RecordSerializerFactoryImpl(org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordSerializerFactoryImpl) EOFException(java.io.EOFException) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable) RecordSerializer(org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordSerializer)

Example 2 with RecordSerializerFactoryImpl

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

the class FileWriteAheadLogManager method start0.

/**
 * {@inheritDoc}
 */
@Override
public void start0() throws IgniteCheckedException {
    if (!cctx.kernalContext().clientNode()) {
        final PdsFolderSettings resolveFolders = cctx.kernalContext().pdsFolderResolver().resolveFolders();
        checkWalConfiguration();
        walWorkDir = initDirectory(dsCfg.getWalPath(), DataStorageConfiguration.DFLT_WAL_PATH, resolveFolders.folderName(), "write ahead log work directory");
        walArchiveDir = initDirectory(dsCfg.getWalArchivePath(), DataStorageConfiguration.DFLT_WAL_ARCHIVE_PATH, resolveFolders.folderName(), "write ahead log archive directory");
        serializer = new RecordSerializerFactoryImpl(cctx).createSerializer(serializerVer);
        GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) cctx.database();
        metrics = dbMgr.persistentStoreMetricsImpl();
        checkOrPrepareFiles();
        IgniteBiTuple<Long, Long> tup = scanMinMaxArchiveIndices();
        lastTruncatedArchiveIdx = tup == null ? -1 : tup.get1() - 1;
        long lastAbsArchivedIdx = tup == null ? -1 : tup.get2();
        if (isArchiverEnabled())
            archiver = new FileArchiver(lastAbsArchivedIdx);
        else
            archiver = null;
        if (lastAbsArchivedIdx > 0)
            archivedMonitor.setLastArchivedAbsoluteIndex(lastAbsArchivedIdx);
        if (dsCfg.isWalCompactionEnabled()) {
            compressor = new FileCompressor();
            decompressor = new FileDecompressor();
            if (!cctx.kernalContext().clientNode())
                decompressor.start();
        }
        if (mode != WALMode.NONE) {
            if (log.isInfoEnabled())
                log.info("Started write-ahead log manager [mode=" + mode + ']');
        } else
            U.quietAndWarn(log, "Started write-ahead log manager in NONE mode, persisted data may be lost in " + "a case of unexpected node failure. Make sure to deactivate the cluster before shutdown.");
    }
}
Also used : RecordSerializerFactoryImpl(org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordSerializerFactoryImpl) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) AtomicLong(java.util.concurrent.atomic.AtomicLong) PdsFolderSettings(org.apache.ignite.internal.processors.cache.persistence.filename.PdsFolderSettings)

Example 3 with RecordSerializerFactoryImpl

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

the class FileWriteAheadLogManager method replay.

/**
 * {@inheritDoc}
 */
@Override
public WALIterator replay(WALPointer start) throws IgniteCheckedException, StorageException {
    assert start == null || start instanceof FileWALPointer : "Invalid start pointer: " + start;
    FileWriteHandle hnd = currentHandle();
    FileWALPointer end = null;
    if (hnd != null)
        end = hnd.position();
    return new RecordsIterator(cctx, walWorkDir, walArchiveDir, (FileWALPointer) start, end, dsCfg, new RecordSerializerFactoryImpl(cctx), ioFactory, archiver, decompressor, log);
}
Also used : RecordSerializerFactoryImpl(org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordSerializerFactoryImpl)

Example 4 with RecordSerializerFactoryImpl

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

the class FsyncModeFileWriteAheadLogManager method start0.

/**
 * {@inheritDoc}
 */
@Override
public void start0() throws IgniteCheckedException {
    if (!cctx.kernalContext().clientNode()) {
        final PdsFolderSettings resolveFolders = cctx.kernalContext().pdsFolderResolver().resolveFolders();
        checkWalConfiguration();
        walWorkDir = initDirectory(dsCfg.getWalPath(), DataStorageConfiguration.DFLT_WAL_PATH, resolveFolders.folderName(), "write ahead log work directory");
        walArchiveDir = initDirectory(dsCfg.getWalArchivePath(), DataStorageConfiguration.DFLT_WAL_ARCHIVE_PATH, resolveFolders.folderName(), "write ahead log archive directory");
        serializer = new RecordSerializerFactoryImpl(cctx).createSerializer(serializerVersion);
        GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) cctx.database();
        metrics = dbMgr.persistentStoreMetricsImpl();
        checkOrPrepareFiles();
        IgniteBiTuple<Long, Long> tup = scanMinMaxArchiveIndices();
        lastTruncatedArchiveIdx = tup == null ? -1 : tup.get1() - 1;
        archiver = new FileArchiver(tup == null ? -1 : tup.get2());
        if (dsCfg.isWalCompactionEnabled()) {
            compressor = new FileCompressor();
            decompressor = new FileDecompressor();
        }
        if (mode != WALMode.NONE) {
            if (log.isInfoEnabled())
                log.info("Started write-ahead log manager [mode=" + mode + ']');
        } else
            U.quietAndWarn(log, "Started write-ahead log manager in NONE mode, persisted data may be lost in " + "a case of unexpected node failure. Make sure to deactivate the cluster before shutdown.");
    }
}
Also used : RecordSerializerFactoryImpl(org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordSerializerFactoryImpl) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) AtomicLong(java.util.concurrent.atomic.AtomicLong) PdsFolderSettings(org.apache.ignite.internal.processors.cache.persistence.filename.PdsFolderSettings)

Example 5 with RecordSerializerFactoryImpl

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

the class FsyncModeFileWriteAheadLogManager method replay.

/**
 * {@inheritDoc}
 */
@Override
public WALIterator replay(WALPointer start) throws IgniteCheckedException, StorageException {
    assert start == null || start instanceof FileWALPointer : "Invalid start pointer: " + start;
    FileWriteHandle hnd = currentHandle();
    FileWALPointer end = null;
    if (hnd != null)
        end = hnd.position();
    return new RecordsIterator(cctx, walWorkDir, walArchiveDir, (FileWALPointer) start, end, dsCfg, new RecordSerializerFactoryImpl(cctx), ioFactory, archiver, decompressor, log);
}
Also used : RecordSerializerFactoryImpl(org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordSerializerFactoryImpl)

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