Search in sources :

Example 31 with FileDescriptor

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

the class CorruptedCheckpointReservationTest method getFileDescriptor.

/**
 * @param segmentCompressed Segment compressed.
 * @param walMgr Wal manager.
 * @param corruptedCp Corrupted checkpoint.
 */
@NotNull
private Optional<FileDescriptor> getFileDescriptor(boolean segmentCompressed, IgniteWriteAheadLogManager walMgr, FileWALPointer corruptedCp) {
    IgniteWalIteratorFactory iterFactory = new IgniteWalIteratorFactory();
    File walArchiveDir = U.field(walMgr, "walArchiveDir");
    List<FileDescriptor> walFiles = getWalFiles(walArchiveDir, iterFactory);
    String suffix = segmentCompressed ? FilePageStoreManager.ZIP_SUFFIX : FileDescriptor.WAL_SEGMENT_FILE_EXT;
    return walFiles.stream().filter(w -> w.idx() == corruptedCp.index() && w.file().getName().endsWith(suffix)).findFirst();
}
Also used : IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) U(org.apache.ignite.internal.util.typedef.internal.U) IgniteEx(org.apache.ignite.internal.IgniteEx) WALPointer(org.apache.ignite.internal.pagemem.wal.WALPointer) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) Lists(com.google.common.collect.Lists) IGNITE_DISABLE_GRP_STATE_LAZY_STORE(org.apache.ignite.IgniteSystemProperties.IGNITE_DISABLE_GRP_STATE_LAZY_STORE) WalTestUtils(org.apache.ignite.internal.processors.cache.persistence.db.wal.crc.WalTestUtils) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer) WALMode(org.apache.ignite.configuration.WALMode) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) IOException(java.io.IOException) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) FilteredWalIterator(org.apache.ignite.internal.processors.cache.persistence.wal.reader.FilteredWalIterator) Test(org.junit.Test) IGNITE_PDS_WAL_REBALANCE_THRESHOLD(org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_WAL_REBALANCE_THRESHOLD) File(java.io.File) IgniteCache(org.apache.ignite.IgniteCache) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Optional(java.util.Optional) IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) NotNull(org.jetbrains.annotations.NotNull) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) FileDescriptor(org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor) CacheMode(org.apache.ignite.cache.CacheMode) WalFilters(org.apache.ignite.internal.processors.cache.persistence.wal.reader.WalFilters) File(java.io.File) FileDescriptor(org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Example 32 with FileDescriptor

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

the class WriteAheadLogManagerSelfTest method testReservation.

/**
 * Checking the correctness of WAL segment reservation.
 *
 * @throws Exception If failed.
 */
@Test
public void testReservation() throws Exception {
    IgniteEx n = startGrids(1);
    for (int i = 0; walMgr(n).lastArchivedSegment() < 2; i++) n.cache(DEFAULT_CACHE_NAME).put(i, new byte[(int) (10 * U.KB)]);
    forceCheckpoint();
    assertTrue(walMgr(n).lastArchivedSegment() >= 2);
    assertTrue(walMgr(n).lastTruncatedSegment() == -1);
    FileWALPointer segment0WalPtr = new FileWALPointer(0, 0, 0);
    assertTrue(walMgr(n).reserve(segment0WalPtr));
    assertTrue(walMgr(n).reserved(segment0WalPtr));
    FileWALPointer segment1WalPtr = new FileWALPointer(1, 0, 0);
    // Delete segment manually.
    FileDescriptor segment1 = Arrays.stream(walMgr(n).walArchiveFiles()).filter(fd -> fd.idx() == segment1WalPtr.index()).findAny().orElseThrow(AssertionError::new);
    assertTrue(segment1.file().delete());
    assertFalse(walMgr(n).reserve(segment1WalPtr));
    assertTrue(walMgr(n).reserved(segment1WalPtr));
    walMgr(n).release(segment0WalPtr);
    assertFalse(walMgr(n).reserved(segment0WalPtr));
    assertFalse(walMgr(n).reserved(segment1WalPtr));
    assertEquals(1, walMgr(n).truncate(segment1WalPtr));
    assertFalse(walMgr(n).reserve(segment0WalPtr));
    assertFalse(walMgr(n).reserve(segment1WalPtr));
    assertFalse(walMgr(n).reserved(segment0WalPtr));
    assertFalse(walMgr(n).reserved(segment1WalPtr));
    FileWALPointer segmentMaxWalPtr = new FileWALPointer(Long.MAX_VALUE, 0, 0);
    assertFalse(walMgr(n).reserve(segmentMaxWalPtr));
    assertFalse(walMgr(n).reserved(segmentMaxWalPtr));
}
Also used : FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer) IgniteEx(org.apache.ignite.internal.IgniteEx) FileDescriptor(org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 33 with FileDescriptor

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

the class IgniteAbstractWalIteratorInvalidCrcTest method doTest.

/**
 * @param descPicker Function that picks WAL segment to corrupt from archive segments list
 *      and working directory segments list.
 * @param ignoreArchiveDir Do not iterate over archive segments if this flag is true.
 * @param shouldFail Whether iteration is axpected to fail or not.
 * @throws IOException If IO exception.
 * @throws IgniteCheckedException If iterator failed.
 */
protected void doTest(BiFunction<List<FileDescriptor>, List<FileDescriptor>, FileDescriptor> descPicker, boolean ignoreArchiveDir, boolean shouldFail) throws IOException, IgniteCheckedException {
    IgniteWriteAheadLogManager walMgr = ignite.context().cache().context().wal();
    IgniteWalIteratorFactory iterFactory = new IgniteWalIteratorFactory();
    File walArchiveDir = U.field(walMgr, "walArchiveDir");
    List<FileDescriptor> archiveDescs = iterFactory.resolveWalFiles(new IgniteWalIteratorFactory.IteratorParametersBuilder().filesOrDirs(walArchiveDir));
    File walDir = U.field(walMgr, "walWorkDir");
    List<FileDescriptor> descs = iterFactory.resolveWalFiles(new IgniteWalIteratorFactory.IteratorParametersBuilder().filesOrDirs(walDir));
    FileDescriptor corruptedDesc = descPicker.apply(archiveDescs, descs);
    FileWALPointer beforeCorruptedPtr = WalTestUtils.corruptRandomWalRecord(corruptedDesc, iterFactory, random);
    if (shouldFail) {
        FileWALPointer[] lastReadPtrRef = new FileWALPointer[1];
        IgniteException igniteException = (IgniteException) GridTestUtils.assertThrows(log, () -> {
            try (WALIterator iter = getWalIterator(walMgr, ignoreArchiveDir)) {
                for (IgniteBiTuple<WALPointer, WALRecord> tuple : iter) {
                    FileWALPointer ptr = (FileWALPointer) tuple.get1();
                    lastReadPtrRef[0] = ptr;
                }
            }
            return null;
        }, IgniteException.class, "Failed to read WAL record");
        assertTrue(igniteException.hasCause(IgniteDataIntegrityViolationException.class));
        FileWALPointer lastReadPtr = lastReadPtrRef[0];
        assertNotNull(lastReadPtr);
        // WAL iterator advances to the next record and only then returns current one,
        // so next record has to be valid as well.
        assertEquals(lastReadPtr, beforeCorruptedPtr);
    } else
        try (WALIterator iter = getWalIterator(walMgr, ignoreArchiveDir)) {
            while (iter.hasNext()) iter.next();
        }
}
Also used : IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer) IgniteDataIntegrityViolationException(org.apache.ignite.internal.processors.cache.persistence.wal.crc.IgniteDataIntegrityViolationException) IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) IgniteException(org.apache.ignite.IgniteException) File(java.io.File) FileDescriptor(org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor)

Example 34 with FileDescriptor

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

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) FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer) 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 35 with FileDescriptor

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

the class WalDeletionArchiveAbstractTest method testCorrectDeletedCheckpointHistoryButKeepWalFiles.

/**
 * Correct delete checkpoint history from memory depends on IGNITE_PDS_MAX_CHECKPOINT_MEMORY_HISTORY_SIZE.
 * WAL files doesn't delete because deleting was disabled.
 */
@Test
@WithSystemProperty(key = IGNITE_PDS_MAX_CHECKPOINT_MEMORY_HISTORY_SIZE, value = "2")
public void testCorrectDeletedCheckpointHistoryButKeepWalFiles() throws Exception {
    // given: configured grid with disabled WAL removing.
    Ignite ignite = startGrid(dbCfg -> dbCfg.setMaxWalArchiveSize(DataStorageConfiguration.UNLIMITED_WAL_ARCHIVE));
    GridCacheDatabaseSharedManager dbMgr = gridDatabase(ignite);
    CheckpointHistory hist = dbMgr.checkpointHistory();
    assertNotNull(hist);
    IgniteCache<Integer, Object> cache = ignite.getOrCreateCache(cacheConfiguration());
    // when: put to cache
    for (int i = 0; i < 500; i++) {
        cache.put(i, i);
        if (i % 10 == 0)
            forceCheckpoint();
    }
    forceCheckpoint();
    // then: WAL files was not deleted but some of checkpoint history was deleted.
    FileWriteAheadLogManager wal = wal(ignite);
    assertNull(getFieldValueHierarchy(wal, "cleaner"));
    FileDescriptor[] files = wal.walArchiveFiles();
    assertTrue(Stream.of(files).anyMatch(desc -> desc.file().getName().endsWith("0001.wal")));
    assertTrue(hist.checkpoints().size() == 2);
}
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) FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer) 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) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

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