Search in sources :

Example 1 with RandomAccessFileIOFactory

use of org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory in project ignite by apache.

the class IgnitePdsDiskErrorsRecoveringTest method emulateRecoveringOnWALWritingError.

/**
 */
private void emulateRecoveringOnWALWritingError() throws Exception {
    final IgniteEx grid = startGrid(0);
    FileWriteAheadLogManager wal = (FileWriteAheadLogManager) grid.context().cache().context().wal();
    wal.setFileIOFactory(new LimitedSizeFileIOFactory(new RandomAccessFileIOFactory(), diskSpaceBytes));
    grid.active(true);
    int failedPosition = -1;
    for (int i = 0; i < 1000; i++) {
        byte payload = (byte) i;
        byte[] data = new byte[2048];
        Arrays.fill(data, payload);
        try {
            grid.cache(CACHE_NAME).put(i, data);
        } catch (Exception e) {
            failedPosition = i;
            break;
        }
    }
    // We must be able to put something into cache before fail.
    Assert.assertTrue(failedPosition > 0);
    // Grid should be automatically stopped after WAL fail.
    awaitStop(grid);
    // Grid should be successfully recovered after stopping.
    IgniteEx recoveredGrid = startGrid(0);
    recoveredGrid.active(true);
    for (int i = 0; i < failedPosition; i++) {
        byte payload = (byte) i;
        byte[] data = new byte[2048];
        Arrays.fill(data, payload);
        byte[] actualData = (byte[]) recoveredGrid.cache(CACHE_NAME).get(i);
        Assert.assertArrayEquals(data, actualData);
    }
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) FileWriteAheadLogManager(org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IOException(java.io.IOException) RandomAccessFileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory)

Example 2 with RandomAccessFileIOFactory

use of org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory in project ignite by apache.

the class CacheGroupReencryptionTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String name) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(name);
    cfg.setConsistentId(name);
    cfg.setIncludeEventTypes(EventType.EVT_CACHE_REBALANCE_STOPPED);
    EncryptionConfiguration encCfg = new EncryptionConfiguration().setReencryptionBatchSize(pageScanBatchSize).setReencryptionRateLimit(pageScanRate);
    DataStorageConfiguration memCfg = new DataStorageConfiguration().setDefaultDataRegionConfiguration(new DataRegionConfiguration().setMaxSize(1024 * 1024 * 1024L).setPersistenceEnabled(true)).setPageSize(4 * 1024).setWalSegmentSize(10 * 1024 * 1024).setWalSegments(4).setMaxWalArchiveSize(100 * 1024 * 1024L).setCheckpointFrequency(TimeUnit.SECONDS.toMillis(checkpointFreq)).setWalMode(LOG_ONLY).setFileIOFactory(new FailingFileIOFactory(new RandomAccessFileIOFactory(), failFileIO)).setEncryptionConfiguration(encCfg);
    cfg.setDataStorageConfiguration(memCfg);
    return cfg;
}
Also used : DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) EncryptionConfiguration(org.apache.ignite.configuration.EncryptionConfiguration) RandomAccessFileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory)

Example 3 with RandomAccessFileIOFactory

use of org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory in project ignite by apache.

the class IgnitePdsCorruptedIndexTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    cfg.setConsistentId(igniteInstanceName);
    DataStorageConfiguration dsCfg = new DataStorageConfiguration().setWalMode(WALMode.LOG_ONLY).setCheckpointFrequency(10 * 60 * 1000).setDefaultDataRegionConfiguration(new DataRegionConfiguration().setMaxSize(256 * 1024 * 1024).setPersistenceEnabled(true));
    if (haltFileIO)
        dsCfg.setFileIOFactory(new HaltOnTruncateFileIOFactory(new RandomAccessFileIOFactory()));
    cfg.setDataStorageConfiguration(dsCfg);
    CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>(CACHE).setBackups(1).setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC).setIndexedTypes(Integer.class, IndexedObject.class, Long.class, IndexedObject.class).setAffinity(new RendezvousAffinityFunction(false, 32));
    cfg.setCacheConfiguration(ccfg);
    return cfg;
}
Also used : DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) RandomAccessFileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory)

Example 4 with RandomAccessFileIOFactory

use of org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory in project ignite by apache.

the class IgniteClusterSnapshotSelfTest method testRecoveryClusterSnapshotJvmHalted.

/**
 * @throws Exception If fails.
 */
@Test
public void testRecoveryClusterSnapshotJvmHalted() throws Exception {
    IgniteEx ignite = startGridsWithCache(2, dfltCacheCfg, CACHE_KEYS_RANGE);
    String grid0Dir = folderName(ignite);
    String grid1Dir = folderName(grid(1));
    File locSnpDir = snp(ignite).snapshotLocalDir(SNAPSHOT_NAME);
    jvm = true;
    IgniteConfiguration cfg2 = optimize(getConfiguration(getTestIgniteInstanceName(2)));
    cfg2.getDataStorageConfiguration().setFileIOFactory(new HaltJvmFileIOFactory(new RandomAccessFileIOFactory(), (Predicate<File> & Serializable) file -> {
        return file.getAbsolutePath().contains(SNAPSHOT_NAME);
    }));
    startGrid(cfg2);
    String grid2Dir = U.maskForFileName(cfg2.getConsistentId().toString());
    jvm = false;
    ignite.cluster().setBaselineTopology(ignite.cluster().topologyVersion());
    awaitPartitionMapExchange();
    assertThrowsAnyCause(log, () -> ignite.snapshot().createSnapshot(SNAPSHOT_NAME).get(), ClusterTopologyException.class, "Snapshot operation interrupted, because baseline node left the cluster");
    assertTrue("Snapshot directory must be empty: " + grid0Dir, !searchDirectoryRecursively(locSnpDir.toPath(), grid0Dir).isPresent());
    assertTrue("Snapshot directory must be empty: " + grid1Dir, !searchDirectoryRecursively(locSnpDir.toPath(), grid1Dir).isPresent());
    assertTrue("Snapshot directory must exist due to grid2 has been halted and cleanup not fully performed: " + grid2Dir, searchDirectoryRecursively(locSnpDir.toPath(), grid2Dir).isPresent());
    IgniteEx grid2 = startGrid(2);
    assertTrue("Snapshot directory must be empty after recovery: " + grid2Dir, !searchDirectoryRecursively(locSnpDir.toPath(), grid2Dir).isPresent());
    awaitPartitionMapExchange();
    assertTrue("Snapshot directory must be empty", grid2.context().cache().context().snapshotMgr().localSnapshotNames().isEmpty());
    ignite.snapshot().createSnapshot(SNAPSHOT_NAME).get();
    stopAllGrids();
    IgniteEx snp = startGridsFromSnapshot(2, SNAPSHOT_NAME);
    assertSnapshotCacheKeys(snp.cache(dfltCacheCfg.getName()));
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteEx(org.apache.ignite.internal.IgniteEx) File(java.io.File) RandomAccessFileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory) Test(org.junit.Test)

Example 5 with RandomAccessFileIOFactory

use of org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory in project ignite by apache.

the class IgnitePdsDiskErrorsRecoveringTest method testRecoveringOnWALWritingFail1.

/**
 * Test node stopping & recovering on WAL writing fail with enabled MMAP (Batch allocation for WAL segments).
 */
@Test
public void testRecoveringOnWALWritingFail1() throws Exception {
    // Allow to allocate only 1 wal segment, fail on write to second.
    ioFactory = new FilteringFileIOFactory(".wal", new LimitedSizeFileIOFactory(new RandomAccessFileIOFactory(), WAL_SEGMENT_SIZE));
    System.setProperty(IGNITE_WAL_MMAP, "true");
    doTestRecoveringOnWALWritingFail();
}
Also used : RandomAccessFileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

RandomAccessFileIOFactory (org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory)28 Test (org.junit.Test)13 File (java.io.File)10 IgniteEx (org.apache.ignite.internal.IgniteEx)10 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)9 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)8 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)8 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)7 FileIOFactory (org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory)7 FileIO (org.apache.ignite.internal.processors.cache.persistence.file.FileIO)6 IOException (java.io.IOException)5 ByteBuffer (java.nio.ByteBuffer)5 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)5 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)5 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)4 FileWriteAheadLogManager (org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager)4 WALIterator (org.apache.ignite.internal.pagemem.wal.WALIterator)3 WALRecord (org.apache.ignite.internal.pagemem.wal.record.WALRecord)3 WALPointer (org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)3 IteratorParametersBuilder (org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory.IteratorParametersBuilder)3