Search in sources :

Example 16 with FileDescriptor

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

the class StandaloneWalRecordsIteratorTest method testStrictBounds.

/**
 * Check correct check bounds.
 *
 * @throws Exception if test failed.
 */
@Test
public void testStrictBounds() throws Exception {
    String dir = createWalFiles();
    FileWALPointer lowBound = null, highBound = null;
    for (IgniteBiTuple<WALPointer, WALRecord> p : createWalIterator(dir, null, null, false)) {
        if (lowBound == null)
            lowBound = (FileWALPointer) p.get1();
        highBound = (FileWALPointer) p.get1();
    }
    assertNotNull(lowBound);
    assertNotNull(highBound);
    createWalIterator(dir, lowBound, highBound, true);
    final FileWALPointer lBound = lowBound;
    final FileWALPointer hBound = highBound;
    // noinspection ThrowableNotThrown
    GridTestUtils.assertThrows(log, () -> {
        createWalIterator(dir, new FileWALPointer(lBound.index() - 1, 0, 0), hBound, true);
        return 0;
    }, IgniteCheckedException.class, null);
    // noinspection ThrowableNotThrown
    GridTestUtils.assertThrows(log, () -> {
        createWalIterator(dir, lBound, new FileWALPointer(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) FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer) Random(java.util.Random) FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer) WALPointer(org.apache.ignite.internal.pagemem.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 17 with FileDescriptor

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

the class StandaloneWalRecordsIterator method strictCheck.

/**
 * @param walFiles Wal files.
 * @param lowBound Low bound.
 * @param highBound High bound.
 *
 * @throws IgniteCheckedException if failed
 */
private static void strictCheck(List<FileDescriptor> walFiles, WALPointer lowBound, WALPointer highBound) throws IgniteCheckedException {
    int idx = 0;
    if (lowBound.index() > Long.MIN_VALUE) {
        for (; idx < walFiles.size(); idx++) {
            FileDescriptor desc = walFiles.get(idx);
            assert desc != null;
            if (desc.idx() == lowBound.index())
                break;
        }
    }
    if (idx == walFiles.size())
        throw new StrictBoundsCheckException("Wal segments not in bounds. loBoundIndex=" + lowBound.index() + ", indexes=" + printIndexes(walFiles));
    long curWalSegmIdx = walFiles.get(idx).idx();
    for (; idx < walFiles.size() && curWalSegmIdx <= highBound.index(); idx++, curWalSegmIdx++) {
        FileDescriptor desc = walFiles.get(idx);
        assert desc != null;
        if (curWalSegmIdx != desc.idx())
            throw new StrictBoundsCheckException("Wal segment " + curWalSegmIdx + " not found in files " + printIndexes(walFiles));
    }
    if (highBound.index() < Long.MAX_VALUE && curWalSegmIdx <= highBound.index())
        throw new StrictBoundsCheckException("Wal segments not in bounds. hiBoundIndex=" + highBound.index() + ", indexes=" + printIndexes(walFiles));
}
Also used : FileDescriptor(org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor)

Example 18 with FileDescriptor

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

the class IgniteWalIteratorFactory method addFileDescriptor.

/**
 * @param file File.
 * @param ioFactory IO factory.
 * @param descriptors List of descriptors.
 */
private void addFileDescriptor(File file, FileIOFactory ioFactory, TreeSet<FileDescriptor> descriptors) {
    if (file.length() < HEADER_RECORD_SIZE)
        // Filter out this segment as it is too short.
        return;
    String fileName = file.getName();
    if (!WAL_NAME_PATTERN.matcher(fileName).matches() && !WAL_SEGMENT_FILE_COMPACTED_PATTERN.matcher(fileName).matches())
        // Filter out this because it is not segment file.
        return;
    FileDescriptor desc = readFileDescriptor(file, ioFactory);
    if (desc != null)
        descriptors.add(desc);
}
Also used : FileDescriptor(org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor)

Example 19 with FileDescriptor

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

the class StandaloneWalRecordsIterator method advanceSegment.

/**
 * {@inheritDoc}
 */
@Override
protected AbstractReadFileHandle advanceSegment(@Nullable final AbstractReadFileHandle curWalSegment) throws IgniteCheckedException {
    if (curWalSegment != null)
        curWalSegment.close();
    FileDescriptor fd;
    do {
        curWalSegmIdx++;
        curIdx++;
        if (curIdx >= walFileDescriptors.size())
            return null;
        fd = walFileDescriptors.get(curIdx);
    } while (!checkBounds(fd.idx()));
    if (log.isDebugEnabled())
        log.debug("Reading next file [absIdx=" + curWalSegmIdx + ", file=" + fd.file().getAbsolutePath() + ']');
    assert fd != null;
    curRec = null;
    try {
        WALPointer initPtr = null;
        if (lowBound.index() == fd.idx())
            initPtr = lowBound;
        return initReadHandle(fd, initPtr);
    } catch (FileNotFoundException e) {
        if (log.isInfoEnabled())
            log.info("Missing WAL segment in the archive: " + e.getMessage());
        return null;
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) FileDescriptor(org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor)

Example 20 with FileDescriptor

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

the class IgniteWalRebalanceTest method testSwitchHistoricalRebalanceToFullWhileIteratingOverWAL.

/**
 * Tests that demander switches to full rebalance if the previously chosen supplier for a group has failed
 * to perform historical rebalance due to an unexpected error while iterating over reserved wal.
 *
 * @throws Exception If failed
 */
@Test
public void testSwitchHistoricalRebalanceToFullWhileIteratingOverWAL() throws Exception {
    testSwitchHistoricalRebalanceToFull(supplier1 -> {
        try {
            // Corrupt wal record in order to fail historical rebalance from supplier1 node.
            IgniteWriteAheadLogManager walMgr = supplier1.context().cache().context().wal();
            WALPointer ptr = walMgr.log(new DataRecord(new DataEntry(CU.cacheId("test-cache-1"), new KeyCacheObjectImpl(0, null, 0), null, GridCacheOperation.DELETE, new GridCacheVersion(0, 1, 1, 0), new GridCacheVersion(0, 1, 1, 0), 0, 0, 0, DataEntry.EMPTY_FLAGS)));
            File walDir = U.field(walMgr, "walWorkDir");
            List<FileDescriptor> walFiles = new IgniteWalIteratorFactory().resolveWalFiles(new IgniteWalIteratorFactory.IteratorParametersBuilder().filesOrDirs(walDir));
            FileDescriptor lastWalFile = walFiles.get(walFiles.size() - 1);
            WalTestUtils.corruptWalSegmentFile(lastWalFile, ptr);
            IgniteCache<Integer, IndexedObject> c1 = supplier1.cache("test-cache-1");
            for (int i = 0; i < PARTS_CNT * 100; i++) c1.put(i, new IndexedObject(i + PARTS_CNT));
        } catch (IgniteCheckedException | IOException e) {
            throw new RuntimeException(e);
        }
    }, () -> true);
}
Also used : IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) IOException(java.io.IOException) FileDescriptor(org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor) DataEntry(org.apache.ignite.internal.pagemem.wal.record.DataEntry) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) DataRecord(org.apache.ignite.internal.pagemem.wal.record.DataRecord) KeyCacheObjectImpl(org.apache.ignite.internal.processors.cache.KeyCacheObjectImpl) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) File(java.io.File) 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