Search in sources :

Example 26 with FileDescriptor

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

the class WalDeletionArchiveAbstractTest method testCorrectDeletedArchivedWalFiles.

/**
 * Correct delete archived wal files.
 */
@Test
public void testCorrectDeletedArchivedWalFiles() throws Exception {
    // given: configured grid with setted max wal archive size
    long maxWalArchiveSize = 2 * 1024 * 1024;
    Ignite ignite = startGrid(dbCfg -> dbCfg.setMaxWalArchiveSize(maxWalArchiveSize));
    GridCacheDatabaseSharedManager dbMgr = gridDatabase(ignite);
    CheckpointHistory hist = dbMgr.checkpointHistory();
    assertNotNull(hist);
    IgniteCache<Integer, Object> cache = ignite.getOrCreateCache(cacheConfiguration());
    // when: put to cache more than 2 MB
    for (int i = 0; i < 500; i++) {
        if (i % 100 == 0)
            forceCheckpoint();
        cache.put(i, i);
    }
    // then: total archive size less than of maxWalArchiveSize(by current logic)
    FileWriteAheadLogManager wal = wal(ignite);
    assertTrue(waitForCondition(() -> wal.lastTruncatedSegment() >= 0, 10_000));
    FileDescriptor[] files = wal.walArchiveFiles();
    long totalSize = wal.totalSize(files);
    assertTrue(files.length >= 1);
    assertTrue(totalSize < maxWalArchiveSize);
    assertFalse(Stream.of(files).anyMatch(desc -> desc.file().getName().endsWith("00001.wal")));
    assertTrue(!hist.checkpoints().isEmpty());
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) FileWriteAheadLogManager(org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) Arrays(java.util.Arrays) GridTestUtils.waitForCondition(org.apache.ignite.testframework.GridTestUtils.waitForCondition) ClusterState(org.apache.ignite.cluster.ClusterState) U(org.apache.ignite.internal.util.typedef.internal.U) IgniteEx(org.apache.ignite.internal.IgniteEx) IGNITE_CHECKPOINT_TRIGGER_ARCHIVE_SIZE_PERCENTAGE(org.apache.ignite.IgniteSystemProperties.IGNITE_CHECKPOINT_TRIGGER_ARCHIVE_SIZE_PERCENTAGE) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) GridTestUtils.getFieldValueHierarchy(org.apache.ignite.testframework.GridTestUtils.getFieldValueHierarchy) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) Checkpointer(org.apache.ignite.internal.processors.cache.persistence.checkpoint.Checkpointer) WALMode(org.apache.ignite.configuration.WALMode) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) CheckpointHistory(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointHistory) Collection(java.util.Collection) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) IGNITE_PDS_MAX_CHECKPOINT_MEMORY_HISTORY_SIZE(org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_MAX_CHECKPOINT_MEMORY_HISTORY_SIZE) File(java.io.File) IgniteCache(org.apache.ignite.IgniteCache) Consumer(java.util.function.Consumer) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Stream(java.util.stream.Stream) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) GB(org.apache.ignite.internal.util.IgniteUtils.GB) MB(org.apache.ignite.internal.util.IgniteUtils.MB) KB(org.apache.ignite.internal.util.IgniteUtils.KB) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) FileDescriptor(org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) CheckpointHistory(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointHistory) FileWriteAheadLogManager(org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager) Ignite(org.apache.ignite.Ignite) FileDescriptor(org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 27 with FileDescriptor

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

the class IgniteWalConverter method getCurrentWalFilePath.

/**
 * Get current wal file path, used in {@code WALIterator}.
 *
 * @param it WALIterator.
 * @return Current wal file path.
 */
private static String getCurrentWalFilePath(WALIterator it) {
    String res = null;
    try {
        WALIterator walIter = it instanceof FilteredWalIterator ? U.field(it, "delegateWalIter") : it;
        Integer curIdx = U.field(walIter, "curIdx");
        List<FileDescriptor> walFileDescriptors = U.field(walIter, "walFileDescriptors");
        if (curIdx != null && walFileDescriptors != null && curIdx < walFileDescriptors.size())
            res = walFileDescriptors.get(curIdx).getAbsolutePath();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return res;
}
Also used : FilteredWalIterator(org.apache.ignite.internal.processors.cache.persistence.wal.reader.FilteredWalIterator) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) FileDescriptor(org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor) IgniteCheckedException(org.apache.ignite.IgniteCheckedException)

Example 28 with FileDescriptor

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

the class IgniteWalConverter method getCurrentWalFilePath.

/**
 * Get current wal file path, used in {@code WALIterator}.
 *
 * @param it WALIterator.
 * @return Current wal file path.
 */
private static String getCurrentWalFilePath(WALIterator it) {
    String res = null;
    try {
        WALIterator walIter = it instanceof FilteredWalIterator ? U.field(it, "delegateWalIter") : it;
        Integer curIdx = U.field(walIter, "curIdx");
        List<FileDescriptor> walFileDescriptors = U.field(walIter, "walFileDescriptors");
        if (curIdx != null && walFileDescriptors != null && curIdx < walFileDescriptors.size())
            res = walFileDescriptors.get(curIdx).getAbsolutePath();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return res;
}
Also used : FilteredWalIterator(org.apache.ignite.internal.processors.cache.persistence.wal.reader.FilteredWalIterator) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) FileDescriptor(org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor) IgniteCheckedException(org.apache.ignite.IgniteCheckedException)

Example 29 with FileDescriptor

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

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 {
        FileWALPointer 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 : FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer) FileNotFoundException(java.io.FileNotFoundException) FileDescriptor(org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor)

Example 30 with FileDescriptor

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

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, FileWALPointer lowBound, FileWALPointer 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)

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