Search in sources :

Example 6 with RandomAccessFileIOFactory

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

the class IgnitePdsDiskErrorsRecoveringTest method testRecoveringOnCheckpointBeginFail.

/**
 * Test node stopping & recovering on checkpoint begin fail.
 *
 * @throws Exception If test failed.
 */
@Test
public void testRecoveringOnCheckpointBeginFail() throws Exception {
    // Fail to write checkpoint start marker tmp file at the second checkpoint. Pass only initial checkpoint.
    ioFactory = new FilteringFileIOFactory("START.bin" + FilePageStoreManager.TMP_SUFFIX, new LimitedSizeFileIOFactory(new RandomAccessFileIOFactory(), 20));
    final IgniteEx grid = startGrid(0);
    grid.cluster().active(true);
    for (int i = 0; i < 1000; i++) {
        byte payload = (byte) i;
        byte[] data = new byte[2048];
        Arrays.fill(data, payload);
        grid.cache(CACHE_NAME).put(i, data);
    }
    String errMsg = "Failed to write checkpoint entry";
    boolean checkpointFailed = false;
    try {
        forceCheckpoint();
    } catch (IgniteCheckedException e) {
        if (e.getMessage().contains(errMsg))
            checkpointFailed = true;
    }
    Assert.assertTrue("Checkpoint must be failed by IgniteCheckedException: " + errMsg, checkpointFailed);
    // Grid should be automatically stopped after checkpoint fail.
    awaitStop(grid);
    // Grid should be successfully recovered after stopping.
    ioFactory = null;
    IgniteEx recoveredGrid = startGrid(0);
    recoveredGrid.cluster().active(true);
    for (int i = 0; i < 1000; 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 : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteEx(org.apache.ignite.internal.IgniteEx) RandomAccessFileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 7 with RandomAccessFileIOFactory

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

the class IgnitePdsDiskErrorsRecoveringTest method testRecoveringOnCheckpointWriteFail.

/**
 * Test node stopping & recovering on checkpoint pages write fail.
 */
@Test
public void testRecoveringOnCheckpointWriteFail() throws Exception {
    // Fail write partition and index files at the second checkpoint. Pass only initial checkpoint.
    ioFactory = new FilteringFileIOFactory(".bin", new LimitedSizeFileIOFactory(new RandomAccessFileIOFactory(), 128 * PAGE_SIZE));
    final IgniteEx grid = startGrid(0);
    grid.cluster().active(true);
    for (int i = 0; i < 1000; i++) {
        byte payload = (byte) i;
        byte[] data = new byte[2048];
        Arrays.fill(data, payload);
        grid.cache(CACHE_NAME).put(i, data);
    }
    boolean checkpointFailed = false;
    try {
        forceCheckpoint();
    } catch (IgniteCheckedException e) {
        for (Throwable t : e.getSuppressed()) if (t.getCause() != null && t.getCause().getMessage().equals("Not enough space!"))
            checkpointFailed = true;
    }
    Assert.assertTrue("Checkpoint must be failed by IOException (Not enough space!)", checkpointFailed);
    // Grid should be automatically stopped after checkpoint fail.
    awaitStop(grid);
    // Grid should be successfully recovered after stopping.
    ioFactory = null;
    IgniteEx recoveredGrid = startGrid(0);
    recoveredGrid.cluster().active(true);
    for (int i = 0; i < 1000; 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 : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteEx(org.apache.ignite.internal.IgniteEx) RandomAccessFileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 8 with RandomAccessFileIOFactory

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

the class IgniteWalRebalanceTest method injectFailingIOFactory.

/**
 * Injects a new instance of FailingIOFactory into wal manager for the given supplier node.
 * This allows to break historical rebalance from the supplier.
 *
 * @param supplier Supplier node to be modified.
 * @return Instance of FailingIOFactory that was injected.
 */
private static FailingIOFactory injectFailingIOFactory(IgniteEx supplier) {
    // Inject I/O factory which can throw exception during WAL read on supplier1 node.
    FailingIOFactory ioFactory = new FailingIOFactory(new RandomAccessFileIOFactory());
    ((FileWriteAheadLogManager) supplier.context().cache().context().wal()).setFileIOFactory(ioFactory);
    ioFactory.throwExceptionOnWalRead();
    return ioFactory;
}
Also used : FileWriteAheadLogManager(org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager) RandomAccessFileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory)

Example 9 with RandomAccessFileIOFactory

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

the class IgniteSnapshotManagerSelfTest method testSnapshotLocalPartitionNotEnoughSpace.

/**
 * @throws Exception If fails.
 */
@Test
public void testSnapshotLocalPartitionNotEnoughSpace() throws Exception {
    String err_msg = "Test exception. Not enough space.";
    AtomicInteger throwCntr = new AtomicInteger();
    RandomAccessFileIOFactory ioFactory = new RandomAccessFileIOFactory();
    IgniteEx ig = startGridWithCache(dfltCacheCfg.setAffinity(new ZeroPartitionAffinityFunction()), CACHE_KEYS_RANGE);
    // Change data after backup.
    for (int i = 0; i < CACHE_KEYS_RANGE; i++) ig.cache(DEFAULT_CACHE_NAME).put(i, 2 * i);
    GridCacheSharedContext<?, ?> cctx0 = ig.context().cache().context();
    IgniteSnapshotManager mgr = snp(ig);
    mgr.ioFactory(new FileIOFactory() {

        @Override
        public FileIO create(File file, OpenOption... modes) throws IOException {
            FileIO fileIo = ioFactory.create(file, modes);
            if (file.getName().equals(IgniteSnapshotManager.partDeltaFileName(0)))
                return new FileIODecorator(fileIo) {

                    @Override
                    public int writeFully(ByteBuffer srcBuf) throws IOException {
                        if (throwCntr.incrementAndGet() == 3)
                            throw new IOException(err_msg);
                        return super.writeFully(srcBuf);
                    }
                };
            return fileIo;
        }
    });
    IgniteInternalFuture<?> snpFut = startLocalSnapshotTask(cctx0, SNAPSHOT_NAME, F.asMap(CU.cacheId(DEFAULT_CACHE_NAME), null), encryption, mgr.localSnapshotSenderFactory().apply(SNAPSHOT_NAME));
    // Check the right exception thrown.
    assertThrowsAnyCause(log, snpFut::get, IOException.class, err_msg);
}
Also used : RandomAccessFileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory) FileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory) FileIODecorator(org.apache.ignite.internal.processors.cache.persistence.file.FileIODecorator) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) FileIO(org.apache.ignite.internal.processors.cache.persistence.file.FileIO) OpenOption(java.nio.file.OpenOption) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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 10 with RandomAccessFileIOFactory

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

the class IgnitePdsTaskCancelingTest method testFilePageStoreInterruptThreads.

/**
 * Test FilePageStore with multiple interrupted threads.
 */
@Test
public void testFilePageStoreInterruptThreads() throws Exception {
    failure.set(false);
    FileIOFactory factory = new RandomAccessFileIOFactory();
    File file = new File(U.defaultWorkDirectory(), "file.bin");
    file.deleteOnExit();
    DataStorageConfiguration dbCfg = getDataStorageConfiguration();
    FilePageStore pageStore = new FilePageStore(PageMemory.FLAG_DATA, file::toPath, factory, dbCfg.getPageSize(), val -> {
    });
    int pageSize = dbCfg.getPageSize();
    PageIO pageIO = PageIO.getPageIO(PageIO.T_DATA, 1);
    long ptr = GridUnsafe.allocateMemory(NUM_TASKS * pageSize);
    try {
        List<Thread> threadList = new ArrayList<>(NUM_TASKS);
        AtomicBoolean stopThreads = new AtomicBoolean(false);
        for (int i = 0; i < NUM_TASKS; i++) {
            long pageId = PageIdUtils.pageId(0, PageMemory.FLAG_DATA, (int) pageStore.allocatePage());
            long pageAdr = ptr + i * pageSize;
            pageIO.initNewPage(pageAdr, pageId, pageSize, null);
            ByteBuffer buf = GridUnsafe.wrapPointer(pageAdr, pageSize);
            pageStore.write(pageId, buf, 0, true);
            threadList.add(new Thread(new Runnable() {

                @Override
                public void run() {
                    Random random = new Random();
                    while (!stopThreads.get()) {
                        buf.position(0);
                        try {
                            if (random.nextBoolean()) {
                                log.info(">>> Read page " + U.hexLong(pageId));
                                pageStore.read(pageId, buf, false);
                            } else {
                                log.info(">>> Write page " + U.hexLong(pageId));
                                pageStore.write(pageId, buf, 0, true);
                            }
                            Thread.interrupted();
                        } catch (Exception e) {
                            log.error("Error while reading/writing page", e);
                            failure.set(true);
                        }
                    }
                }
            }));
        }
        for (Thread thread : threadList) thread.start();
        for (int i = 0; i < 10; i++) {
            for (Thread thread : threadList) {
                doSleep(10L);
                log.info("Interrupting " + thread.getName());
                thread.interrupt();
            }
        }
        stopThreads.set(true);
        for (Thread thread : threadList) thread.join();
        assertFalse(failure.get());
    } finally {
        GridUnsafe.freeMemory(ptr);
    }
}
Also used : FileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory) RandomAccessFileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory) ArrayList(java.util.ArrayList) FilePageStore(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore) ByteBuffer(java.nio.ByteBuffer) IOException(java.io.IOException) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Random(java.util.Random) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) File(java.io.File) RandomAccessFileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory) PageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO) 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