Search in sources :

Example 6 with FileDescriptor

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

the class IgniteWithoutArchiverWalIteratorInvalidCrcTest method nodeShouldNotStartIfLastCheckpointRecordCorrupted.

/**
 *  Last start checkpoint record was corrupted.
 *  -----||------|X|-------->
 *  We stop the node.
 */
@Test
public void nodeShouldNotStartIfLastCheckpointRecordCorrupted() throws Exception {
    startNodeAndPopulate();
    stopGrid(0, true);
    IgniteWriteAheadLogManager walMgr = ignite.context().cache().context().wal();
    File walDir = U.field(walMgr, "walWorkDir");
    IgniteWalIteratorFactory iterFactory = new IgniteWalIteratorFactory();
    List<FileDescriptor> walFiles = getWalFiles(walDir, iterFactory);
    Random corruptLastRecord = null;
    FileDescriptor lastWalFile = walFiles.get(walFiles.size() - 1);
    WalTestUtils.corruptWalSegmentFile(lastWalFile, iterFactory, corruptLastRecord);
    GridTestUtils.assertThrows(log, () -> startGrid(0), Exception.class, null);
}
Also used : IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) Random(java.util.Random) File(java.io.File) FileDescriptor(org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 7 with FileDescriptor

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

the class IgniteWalIteratorFactory method resolveWalFiles.

/**
 * 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 iteratorParametersBuilder IteratorParametersBuilder.
 * @return list of file descriptors with checked header records, having correct file index is set
 */
public List<FileDescriptor> resolveWalFiles(IteratorParametersBuilder iteratorParametersBuilder) {
    File[] filesOrDirs = iteratorParametersBuilder.filesOrDirs;
    if (filesOrDirs == null || filesOrDirs.length == 0)
        return Collections.emptyList();
    final TreeSet<FileDescriptor> descriptors = new TreeSet<>();
    for (File file : filesOrDirs) {
        if (file.isDirectory()) {
            try {
                walkFileTree(file.toPath(), new SimpleFileVisitor<Path>() {

                    @Override
                    public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) {
                        addFileDescriptor(path.toFile(), descriptors, iteratorParametersBuilder);
                        return FileVisitResult.CONTINUE;
                    }

                    @Override
                    public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
                        if (exc instanceof NoSuchFileException)
                            return FileVisitResult.CONTINUE;
                        return super.visitFileFailed(file, exc);
                    }
                });
            } catch (IOException e) {
                U.error(log, "Failed to walk directories from root [" + file + "]. Skipping this directory.", e);
            }
            continue;
        }
        addFileDescriptor(file, descriptors, iteratorParametersBuilder);
    }
    return new ArrayList<>(descriptors);
}
Also used : Path(java.nio.file.Path) NoSuchFileException(java.nio.file.NoSuchFileException) ArrayList(java.util.ArrayList) FileVisitResult(java.nio.file.FileVisitResult) IOException(java.io.IOException) FileDescriptor(org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor) TreeSet(java.util.TreeSet) File(java.io.File) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Example 8 with FileDescriptor

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

the class IgniteWalIteratorFactory method hasGaps.

/**
 * @param descriptors File descriptors.
 * @return List of tuples, low and high index segments with gap.
 */
public List<T2<Long, Long>> hasGaps(@NotNull List<FileDescriptor> descriptors) throws IllegalArgumentException {
    List<T2<Long, Long>> gaps = new ArrayList<>();
    Iterator<FileDescriptor> it = descriptors.iterator();
    FileDescriptor prevFd = null;
    while (it.hasNext()) {
        FileDescriptor nextFd = it.next();
        if (prevFd == null) {
            prevFd = nextFd;
            continue;
        }
        if (prevFd.idx() + 1 != nextFd.idx())
            gaps.add(new T2<>(prevFd.idx(), nextFd.idx()));
        prevFd = nextFd;
    }
    return gaps;
}
Also used : ArrayList(java.util.ArrayList) T2(org.apache.ignite.internal.util.typedef.T2) FileDescriptor(org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor)

Example 9 with FileDescriptor

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

the class IgniteWalIteratorFactory method readFileDescriptor.

/**
 * @param file File to read.
 * @param ioFactory IO factory.
 */
private FileDescriptor readFileDescriptor(File file, FileIOFactory ioFactory) {
    FileDescriptor ds = new FileDescriptor(file);
    try (SegmentIO fileIO = ds.toReadOnlyIO(ioFactory);
        ByteBufferExpander buf = new ByteBufferExpander(HEADER_RECORD_SIZE, ByteOrder.nativeOrder())) {
        final DataInput in = segmentFileInputFactory.createFileInput(fileIO, buf);
        // Header record must be agnostic to the serializer version.
        final int type = in.readUnsignedByte();
        if (type == RecordType.STOP_ITERATION_RECORD_TYPE) {
            if (log.isInfoEnabled())
                log.info("Reached logical end of the segment for file " + file);
            return null;
        }
        FileWALPointer ptr = readPosition(in);
        return new FileDescriptor(file, ptr.index());
    } catch (IOException e) {
        U.warn(log, "Failed to scan index from file [" + file + "]. Skipping this file during iteration", e);
        return null;
    }
}
Also used : ByteBufferExpander(org.apache.ignite.internal.processors.cache.persistence.wal.ByteBufferExpander) DataInput(java.io.DataInput) SegmentIO(org.apache.ignite.internal.processors.cache.persistence.wal.io.SegmentIO) FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer) IOException(java.io.IOException) FileDescriptor(org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor)

Example 10 with FileDescriptor

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

the class IgniteWithoutArchiverWalIteratorInvalidCrcTest method nodeShouldNotStartIfLastCheckpointRecordCorrupted.

/**
 *  Last start checkpoint record was corrupted.
 *  -----||------|X|-------->
 *  We stop the node.
 */
@Test
public void nodeShouldNotStartIfLastCheckpointRecordCorrupted() throws Exception {
    startNodeAndPopulate();
    stopGrid(0, true);
    IgniteWriteAheadLogManager walMgr = ignite.context().cache().context().wal();
    File walDir = U.field(walMgr, "walWorkDir");
    IgniteWalIteratorFactory iterFactory = new IgniteWalIteratorFactory();
    List<FileDescriptor> walFiles = getWalFiles(walDir, iterFactory);
    Random corruptLastRecord = null;
    FileDescriptor lastWalFile = walFiles.get(walFiles.size() - 1);
    WalTestUtils.corruptRandomWalRecord(lastWalFile, iterFactory, corruptLastRecord);
    GridTestUtils.assertThrows(log, () -> startGrid(0), Exception.class, null);
}
Also used : IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) Random(java.util.Random) File(java.io.File) FileDescriptor(org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

FileDescriptor (org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor)37 File (java.io.File)20 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)17 Test (org.junit.Test)17 FileWALPointer (org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer)15 IgniteWalIteratorFactory (org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory)14 IgniteWriteAheadLogManager (org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager)13 IgniteEx (org.apache.ignite.internal.IgniteEx)11 WALPointer (org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)9 WithSystemProperty (org.apache.ignite.testframework.junits.WithSystemProperty)9 IgniteCache (org.apache.ignite.IgniteCache)7 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)7 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)7 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)7 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)7 WALMode (org.apache.ignite.configuration.WALMode)7 WALIterator (org.apache.ignite.internal.pagemem.wal.WALIterator)7 U (org.apache.ignite.internal.util.typedef.internal.U)7 GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)6