Search in sources :

Example 1 with FileDescriptor

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

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 2 with FileDescriptor

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

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;
        }
        WALPointer 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) IOException(java.io.IOException) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) FileDescriptor(org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor)

Example 3 with FileDescriptor

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

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 FileIOFactory ioFactory = iteratorParametersBuilder.ioFactory;
    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(), ioFactory, descriptors);
                        return FileVisitResult.CONTINUE;
                    }
                });
            } catch (IOException e) {
                U.error(log, "Failed to walk directories from root [" + file + "]. Skipping this directory.", e);
            }
            continue;
        }
        addFileDescriptor(file, ioFactory, descriptors);
    }
    return new ArrayList<>(descriptors);
}
Also used : Path(java.nio.file.Path) FileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory) 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 4 with FileDescriptor

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

the class StandaloneWalRecordsIteratorTest method testStrictBounds.

/**
 * Check correct check bounds.
 *
 * @throws Exception if test failed.
 */
@Test
public void testStrictBounds() throws Exception {
    String dir = createWalFiles();
    WALPointer lowBound = null, highBound = null;
    for (IgniteBiTuple<WALPointer, WALRecord> p : createWalIterator(dir, null, null, false)) {
        if (lowBound == null)
            lowBound = p.get1();
        highBound = p.get1();
    }
    assertNotNull(lowBound);
    assertNotNull(highBound);
    createWalIterator(dir, lowBound, highBound, true);
    final WALPointer lBound = lowBound;
    final WALPointer hBound = highBound;
    // noinspection ThrowableNotThrown
    GridTestUtils.assertThrows(log, () -> {
        createWalIterator(dir, new WALPointer(lBound.index() - 1, 0, 0), hBound, true);
        return 0;
    }, IgniteCheckedException.class, null);
    // noinspection ThrowableNotThrown
    GridTestUtils.assertThrows(log, () -> {
        createWalIterator(dir, lBound, new WALPointer(hBound.index() + 1, 0, 0), true);
        return 0;
    }, IgniteCheckedException.class, null);
    List<FileDescriptor> walFiles = listWalFiles(dir);
    assertNotNull(walFiles);
    assertTrue(!walFiles.isEmpty());
    assertTrue(walFiles.get(new Random().nextInt(walFiles.size())).file().delete());
    // noinspection ThrowableNotThrown
    GridTestUtils.assertThrows(log, () -> {
        createWalIterator(dir, lBound, hBound, true);
        return 0;
    }, IgniteCheckedException.class, null);
}
Also used : WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) Random(java.util.Random) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) FileDescriptor(org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 5 with FileDescriptor

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

the class IgniteWithoutArchiverWalIteratorInvalidCrcTest method nodeShouldStartIfLogicalRecordCorruptedAfterCheckpointOrWalStart.

/**
 *  A logical record was corrupted or just doesn't exist because the end of wal is reached, after start checkpoint without end.
 *  -----||------||----X----> OR ----X----->
 *  We recover all before it, and start the node.
 */
@Test
@WithSystemProperty(key = GridCacheDatabaseSharedManager.IGNITE_PDS_SKIP_CHECKPOINT_ON_NODE_STOP, value = "true")
public void nodeShouldStartIfLogicalRecordCorruptedAfterCheckpointOrWalStart() throws Exception {
    startNodeAndPopulate();
    stopGrid(0);
    IgniteWriteAheadLogManager walMgr = ignite.context().cache().context().wal();
    File walDir = U.field(walMgr, "walWorkDir");
    IgniteWalIteratorFactory iterFactory = new IgniteWalIteratorFactory();
    List<FileDescriptor> walFiles = getWalFiles(walDir, iterFactory);
    FileDescriptor lastWalFile = walFiles.get(walFiles.size() - 1);
    List<WALPointer> pointers = WalTestUtils.getPointers(lastWalFile, iterFactory, LOGICAL);
    WalTestUtils.corruptWalSegmentFile(lastWalFile, pointers.get(pointers.size() - 1));
    IgniteEx ex = startGrid(0);
    ex.cluster().active(true);
}
Also used : IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) IgniteEx(org.apache.ignite.internal.IgniteEx) File(java.io.File) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) FileDescriptor(org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Aggregations

FileDescriptor (org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor)17 File (java.io.File)9 WALPointer (org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)9 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)8 Test (org.junit.Test)8 IgniteWalIteratorFactory (org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory)6 IgniteEx (org.apache.ignite.internal.IgniteEx)5 IgniteWriteAheadLogManager (org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager)5 WithSystemProperty (org.apache.ignite.testframework.junits.WithSystemProperty)4 IOException (java.io.IOException)3 IgniteCache (org.apache.ignite.IgniteCache)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)3 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)3 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)3 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)3 WALMode (org.apache.ignite.configuration.WALMode)3 WALIterator (org.apache.ignite.internal.pagemem.wal.WALIterator)3 GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)3 U (org.apache.ignite.internal.util.typedef.internal.U)3