Search in sources :

Example 11 with FileWALPointer

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

the class GridCacheDatabaseSharedManager method nodeStartedPointers.

/**
 */
public List<T2<Long, WALPointer>> nodeStartedPointers() throws IgniteCheckedException {
    List<T2<Long, WALPointer>> res = new ArrayList<>();
    File[] files = cpDir.listFiles(NODE_STARTED_FILE_FILTER);
    Arrays.sort(files, new Comparator<File>() {

        @Override
        public int compare(File o1, File o2) {
            String n1 = o1.getName();
            String n2 = o2.getName();
            Long ts1 = Long.valueOf(n1.substring(0, n1.length() - NODE_STARTED_FILE_NAME_SUFFIX.length()));
            Long ts2 = Long.valueOf(n2.substring(0, n2.length() - NODE_STARTED_FILE_NAME_SUFFIX.length()));
            if (ts1 == ts2)
                return 0;
            else if (ts1 < ts2)
                return -1;
            else
                return 1;
        }
    });
    ByteBuffer buf = ByteBuffer.allocate(20);
    buf.order(ByteOrder.nativeOrder());
    for (File f : files) {
        String name = f.getName();
        Long ts = Long.valueOf(name.substring(0, name.length() - NODE_STARTED_FILE_NAME_SUFFIX.length()));
        try (FileChannel ch = FileChannel.open(f.toPath(), READ)) {
            ch.read(buf);
            buf.flip();
            FileWALPointer ptr = new FileWALPointer(buf.getLong(), buf.getInt(), buf.getInt());
            res.add(new T2<Long, WALPointer>(ts, ptr));
            buf.clear();
        } catch (IOException e) {
            throw new IgniteCheckedException("Failed to read node started marker file: " + f.getAbsolutePath(), e);
        }
    }
    return res;
}
Also used : FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer) FileChannel(java.nio.channels.FileChannel) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) WALPointer(org.apache.ignite.internal.pagemem.wal.WALPointer) FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer) T2(org.apache.ignite.internal.util.typedef.T2)

Example 12 with FileWALPointer

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

the class GridCacheDatabaseSharedManager method writeCheckpointEntry.

/**
 * @param cpId Checkpoint ID.
 * @param ptr Wal pointer of current checkpoint.
 */
private CheckpointEntry writeCheckpointEntry(ByteBuffer tmpWriteBuf, long cpTs, UUID cpId, WALPointer ptr, CheckpointRecord rec, CheckpointEntryType type) throws IgniteCheckedException {
    assert ptr instanceof FileWALPointer;
    FileWALPointer filePtr = (FileWALPointer) ptr;
    String fileName = checkpointFileName(cpTs, cpId, type);
    try (FileChannel ch = FileChannel.open(Paths.get(cpDir.getAbsolutePath(), fileName), StandardOpenOption.CREATE_NEW, StandardOpenOption.APPEND)) {
        tmpWriteBuf.rewind();
        tmpWriteBuf.putLong(filePtr.index());
        tmpWriteBuf.putInt(filePtr.fileOffset());
        tmpWriteBuf.putInt(filePtr.length());
        tmpWriteBuf.flip();
        ch.write(tmpWriteBuf);
        tmpWriteBuf.clear();
        if (!skipSync)
            ch.force(true);
        return createCheckPointEntry(cpTs, ptr, cpId, rec, type);
    } catch (IOException e) {
        throw new IgniteCheckedException(e);
    }
}
Also used : FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) FileChannel(java.nio.channels.FileChannel) IOException(java.io.IOException)

Example 13 with FileWALPointer

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

the class GridCacheDatabaseSharedManager method nodeStart.

/**
 * @param ptr Memory recovery wal pointer.
 */
private void nodeStart(WALPointer ptr) throws IgniteCheckedException {
    FileWALPointer p = (FileWALPointer) ptr;
    String fileName = U.currentTimeMillis() + "-node-started.bin";
    ByteBuffer buf = ByteBuffer.allocate(20);
    buf.order(ByteOrder.nativeOrder());
    try (FileChannel ch = FileChannel.open(Paths.get(cpDir.getAbsolutePath(), fileName), StandardOpenOption.CREATE_NEW, StandardOpenOption.APPEND)) {
        buf.putLong(p.index());
        buf.putInt(p.fileOffset());
        buf.putInt(p.length());
        buf.flip();
        ch.write(buf);
        buf.clear();
        ch.force(true);
    } catch (IOException e) {
        throw new IgniteCheckedException(e);
    }
}
Also used : FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) FileChannel(java.nio.channels.FileChannel) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Example 14 with FileWALPointer

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

the class StandaloneWalRecordsIterator method scanIndexesFromFileHeaders.

/**
 * This methods checks all provided files to be correct WAL segment.
 * Header record and its position is checked. WAL position is used to determine real index.
 * File index from file name is ignored.
 *
 * @param allFiles files to scan.
 * @return list of file descriptors with checked header records, having correct file index is set
 */
private List<FileWriteAheadLogManager.FileDescriptor> scanIndexesFromFileHeaders(@Nullable final File[] allFiles) {
    if (allFiles == null || allFiles.length == 0)
        return Collections.emptyList();
    final List<FileWriteAheadLogManager.FileDescriptor> resultingDescs = new ArrayList<>();
    for (File file : allFiles) {
        if (file.length() < HEADER_RECORD_SIZE)
            // filter out this segment as it is too short
            continue;
        FileWALPointer ptr;
        try (FileIO fileIO = ioFactory.create(file);
            ByteBufferExpander buf = new ByteBufferExpander(HEADER_RECORD_SIZE, ByteOrder.nativeOrder())) {
            final DataInput in = new FileInput(fileIO, buf);
            // Header record must be agnostic to the serializer version.
            final int type = in.readUnsignedByte();
            if (type == WALRecord.RecordType.STOP_ITERATION_RECORD_TYPE) {
                if (log.isInfoEnabled())
                    log.info("Reached logical end of the segment for file " + file);
                // filter out this segment
                continue;
            }
            ptr = RecordV1Serializer.readPosition(in);
        } catch (IOException e) {
            U.warn(log, "Failed to scan index from file [" + file + "]. Skipping this file during iteration", e);
            // filter out this segment
            continue;
        }
        resultingDescs.add(new FileWriteAheadLogManager.FileDescriptor(file, ptr.index()));
    }
    Collections.sort(resultingDescs);
    return resultingDescs;
}
Also used : FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer) ArrayList(java.util.ArrayList) FileInput(org.apache.ignite.internal.processors.cache.persistence.wal.FileInput) IOException(java.io.IOException) FileIO(org.apache.ignite.internal.processors.cache.persistence.file.FileIO) ByteBufferExpander(org.apache.ignite.internal.processors.cache.persistence.wal.ByteBufferExpander) DataInput(java.io.DataInput) FileWriteAheadLogManager(org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager) File(java.io.File)

Example 15 with FileWALPointer

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

the class WalStat method registerRecord.

/**
 * Handles WAL record.
 *
 * @param record record to handle.
 * @param walPointer pointer, used to extract segment index.
 * @param workDir true for work, false for archive folder.
 */
void registerRecord(WALRecord record, WALPointer walPointer, boolean workDir) {
    WALRecord.RecordType type = record.type();
    if (type == WALRecord.RecordType.PAGE_RECORD)
        registerPageSnapshot((PageSnapshot) record);
    else if (type == WALRecord.RecordType.DATA_RECORD)
        registerDataRecord((DataRecord) record);
    else if (type == WALRecord.RecordType.TX_RECORD)
        registerTxRecord((TxRecord) record);
    incrementStat(type.toString(), record, recTypeSizes);
    if (walPointer instanceof FileWALPointer) {
        final FileWALPointer fPtr = (FileWALPointer) walPointer;
        incrementStat(Long.toString(fPtr.index()), record, segmentsIndexes);
        incrementStat(workDir ? "work" : "archive", record, segmentsFolder);
    }
}
Also used : WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer) TxRecord(org.apache.ignite.internal.pagemem.wal.record.TxRecord) PageSnapshot(org.apache.ignite.internal.pagemem.wal.record.PageSnapshot)

Aggregations

FileWALPointer (org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer)15 CheckpointRecord (org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 DataRecord (org.apache.ignite.internal.pagemem.wal.record.DataRecord)5 IOException (java.io.IOException)4 UUID (java.util.UUID)4 DataEntry (org.apache.ignite.internal.pagemem.wal.record.DataEntry)4 PageSnapshot (org.apache.ignite.internal.pagemem.wal.record.PageSnapshot)4 FileChannel (java.nio.channels.FileChannel)3 ArrayList (java.util.ArrayList)3 MetastoreDataRecord (org.apache.ignite.internal.pagemem.wal.record.MetastoreDataRecord)3 DataPageInsertFragmentRecord (org.apache.ignite.internal.pagemem.wal.record.delta.DataPageInsertFragmentRecord)3 DataPageInsertRecord (org.apache.ignite.internal.pagemem.wal.record.delta.DataPageInsertRecord)3 DataPageUpdateRecord (org.apache.ignite.internal.pagemem.wal.record.delta.DataPageUpdateRecord)3 MetaPageUpdatePartitionDataRecord (org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdatePartitionDataRecord)3 File (java.io.File)2 ByteBuffer (java.nio.ByteBuffer)2 ExchangeRecord (org.apache.ignite.internal.pagemem.wal.record.ExchangeRecord)2 LazyDataEntry (org.apache.ignite.internal.pagemem.wal.record.LazyDataEntry)2 MemoryRecoveryRecord (org.apache.ignite.internal.pagemem.wal.record.MemoryRecoveryRecord)2