Search in sources :

Example 26 with RandomAccessFileIOFactory

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

the class IgniteDataIntegrityTests method setUp.

/**
 */
@Before
public void setUp() throws Exception {
    File file = File.createTempFile("integrity", "dat");
    file.deleteOnExit();
    expBuf = new ByteBufferExpander(1024, ByteOrder.BIG_ENDIAN);
    FileIOFactory factory = new RandomAccessFileIOFactory();
    fileInput = new SimpleFileInput(factory.create(file), expBuf);
    ByteBuffer buf = ByteBuffer.allocate(1024);
    ThreadLocalRandom curr = ThreadLocalRandom.current();
    for (int i = 0; i < 1024; i += 16) {
        buf.putInt(curr.nextInt());
        buf.putInt(curr.nextInt());
        buf.putInt(curr.nextInt());
        buf.position(i);
        buf.putInt(FastCrc.calcCrc(buf, 12));
    }
    buf.rewind();
    fileInput.io().writeFully(buf);
    fileInput.io().force();
}
Also used : ByteBufferExpander(org.apache.ignite.internal.processors.cache.persistence.wal.ByteBufferExpander) RandomAccessFileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory) FileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) SimpleFileInput(org.apache.ignite.internal.processors.cache.persistence.wal.io.SimpleFileInput) File(java.io.File) ByteBuffer(java.nio.ByteBuffer) RandomAccessFileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory) Before(org.junit.Before)

Example 27 with RandomAccessFileIOFactory

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

the class IgniteWalConverterArgumentsTest method testCorruptedPagesFile.

/**
 * Checks that the file generated by the diagnostics is correct for the "pages" argument.
 *
 * @throws IOException If failed.
 */
@Test
public void testCorruptedPagesFile() throws IOException {
    File tmpDir = new File(System.getProperty("java.io.tmpdir"), getName());
    try {
        int grpId = 10;
        long[] pageIds = { 20, 40 };
        File f = corruptedPagesFile(tmpDir.toPath(), new RandomAccessFileIOFactory(), grpId, pageIds);
        assertTrue(f.exists());
        assertTrue(f.isFile());
        assertTrue(f.length() > 0);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PrintStream ps = new PrintStream(baos);
        IgniteWalConverterArguments args = parse(ps, "walDir=" + tmpDir.getAbsolutePath(), "pages=" + f.getAbsolutePath());
        assertNotNull(args.getPages());
        assertEqualsCollections(LongStream.of(pageIds).mapToObj(pageId -> new T2<>(grpId, pageId)).collect(toList()), args.getPages());
    } finally {
        if (tmpDir.exists())
            assertTrue(U.delete(tmpDir));
    }
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) DiagnosticProcessor.corruptedPagesFile(org.apache.ignite.internal.processors.diagnostic.DiagnosticProcessor.corruptedPagesFile) RandomAccessFileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 28 with RandomAccessFileIOFactory

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

the class IgniteClusterSnapshotRestoreMetricsTest method testRestoreSnapshotError.

/**
 * @throws Exception If fails.
 */
@Test
public void testRestoreSnapshotError() throws Exception {
    dfltCacheCfg.setCacheMode(CacheMode.REPLICATED);
    IgniteEx ignite = startGridsWithSnapshot(2, CACHE_KEYS_RANGE);
    String failingFilePath = Paths.get(FilePageStoreManager.cacheDirName(dfltCacheCfg), PART_FILE_PREFIX + (dfltCacheCfg.getAffinity().partitions() / 2) + FILE_SUFFIX).toString();
    FileIOFactory ioFactory = new RandomAccessFileIOFactory();
    String testErrMsg = "Test exception";
    ignite.context().cache().context().snapshotMgr().ioFactory((file, modes) -> {
        FileIO delegate = ioFactory.create(file, modes);
        if (file.getPath().endsWith(failingFilePath))
            throw new RuntimeException(testErrMsg);
        return delegate;
    });
    checkMetricsDefaults();
    ignite.snapshot().restoreSnapshot(SNAPSHOT_NAME, null);
    for (Ignite grid : G.allGrids()) {
        DynamicMBean mReg = metricRegistry(grid.name(), null, SNAPSHOT_RESTORE_METRICS);
        String nodeNameMsg = "node=" + grid.name();
        assertTrue(nodeNameMsg, GridTestUtils.waitForCondition(() -> getNumMetric("endTime", mReg) > 0, TIMEOUT));
        long startTime = getNumMetric("startTime", mReg);
        long endTime = getNumMetric("endTime", mReg);
        assertEquals(nodeNameMsg, SNAPSHOT_NAME, mReg.getAttribute("snapshotName"));
        assertFalse(nodeNameMsg, ((String) mReg.getAttribute("requestId")).isEmpty());
        assertTrue(nodeNameMsg, startTime > 0);
        assertTrue(nodeNameMsg, endTime >= startTime);
        assertTrue(nodeNameMsg, ((String) mReg.getAttribute("error")).contains(testErrMsg));
    }
}
Also used : FileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory) RandomAccessFileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory) DynamicMBean(javax.management.DynamicMBean) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) RandomAccessFileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory) FileIO(org.apache.ignite.internal.processors.cache.persistence.file.FileIO) 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