Search in sources :

Example 1 with FileIODecorator

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

the class GridIoManagerFileTransmissionSelfTest method testFileHandlerReconnectOnReadFail.

/**
 * @throws Exception If fails.
 */
@Test(expected = IgniteCheckedException.class)
public void testFileHandlerReconnectOnReadFail() throws Exception {
    final String chunkDownloadExMsg = "Test exception. Chunk processing error.";
    snd = startGrid(0);
    rcv = startGrid(1);
    File fileToSend = createFileRandomData("testFile", 5 * 1024 * 1024);
    final AtomicInteger readChunks = new AtomicInteger();
    transmissionFileIoFactory(rcv, new FileIOFactory() {

        @Override
        public FileIO create(File file, OpenOption... modes) throws IOException {
            fileIo[0] = IO_FACTORY.create(file, modes);
            // Blocking writer and stopping node FileIo.
            return new FileIODecorator(fileIo[0]) {

                @Override
                public long transferFrom(ReadableByteChannel src, long position, long count) throws IOException {
                    // Read 4 chunks than throw an exception to emulate error processing.
                    if (readChunks.incrementAndGet() == 4)
                        throw new IgniteException(chunkDownloadExMsg);
                    return super.transferFrom(src, position, count);
                }
            };
        }
    });
    rcv.context().io().addTransmissionHandler(topic, new DefaultTransmissionHandler(rcv, fileToSend, tempStore) {

        @Override
        public void onException(UUID nodeId, Throwable err) {
            assertEquals(chunkDownloadExMsg, err.getMessage());
        }
    });
    try (GridIoManager.TransmissionSender sender = snd.context().io().openTransmissionSender(rcv.localNode().id(), topic)) {
        sender.send(fileToSend, TransmissionPolicy.FILE);
    }
}
Also used : RandomAccessFileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory) FileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory) ReadableByteChannel(java.nio.channels.ReadableByteChannel) FileIODecorator(org.apache.ignite.internal.processors.cache.persistence.file.FileIODecorator) IOException(java.io.IOException) FileIO(org.apache.ignite.internal.processors.cache.persistence.file.FileIO) OpenOption(java.nio.file.OpenOption) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteException(org.apache.ignite.IgniteException) UUID(java.util.UUID) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 2 with FileIODecorator

use of org.apache.ignite.internal.processors.cache.persistence.file.FileIODecorator 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 3 with FileIODecorator

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

the class IgnitePdsCorruptedStoreTest method testCheckpointFailure.

/**
 * Test node invalidation due to checkpoint error.
 */
@Test
public void testCheckpointFailure() throws Exception {
    IgniteEx ignite = startGrid(0);
    ignite.cluster().active(true);
    // Trigger empty checkpoint to make sure initial checkpoint on node start will finish.
    forceCheckpoint();
    // Mark some pages as dirty.
    ignite.cache(CACHE_NAME1).put(0, 0);
    AtomicBoolean fail = new AtomicBoolean(true);
    AtomicReference<FileIO> ref = new AtomicReference<>();
    failingFileIOFactory.createClosure(new IgniteBiClosureX<File, OpenOption[], FileIO>() {

        @Override
        public FileIO apply(File file, OpenOption[] options) {
            if (file.getName().contains("-END.bin")) {
                FileIO delegate;
                try {
                    delegate = failingFileIOFactory.delegateFactory().create(file, options);
                } catch (IOException ignore) {
                    return null;
                }
                FileIODecorator dec = new FileIODecorator(delegate) {

                    @Override
                    public void close() throws IOException {
                        if (fail.get())
                            throw new IOException("Checkpoint failed");
                        else
                            super.close();
                    }
                };
                ref.set(dec);
                return dec;
            }
            return null;
        }
    });
    try {
        try {
            forceCheckpoint(ignite);
        } catch (Exception ignore) {
        // No-op.
        }
        waitFailure(IOException.class);
    } finally {
        fail.set(false);
        // Release file for any test outcome.
        ref.get().close();
    }
}
Also used : FileIODecorator(org.apache.ignite.internal.processors.cache.persistence.file.FileIODecorator) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IOException(java.io.IOException) FileIO(org.apache.ignite.internal.processors.cache.persistence.file.FileIO) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OpenOption(java.nio.file.OpenOption) StandardOpenOption(java.nio.file.StandardOpenOption) IgniteEx(org.apache.ignite.internal.IgniteEx) File(java.io.File) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 4 with FileIODecorator

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

the class IgnitePdsCorruptedStoreTest method testWalFsyncWriteHeaderFailure.

/**
 * Test node invalidation due to error on WAL write header.
 */
@Test
public void testWalFsyncWriteHeaderFailure() throws Exception {
    IgniteEx ignite = startGrid(0);
    ignite.cluster().active(true);
    ignite.cache(CACHE_NAME1).put(0, 0);
    failingFileIOFactory.createClosure((file, options) -> {
        FileIO delegate = failingFileIOFactory.delegateFactory().create(file, options);
        if (file.getName().endsWith(".wal")) {
            return new FileIODecorator(delegate) {

                @Override
                public int write(ByteBuffer srcBuf) throws IOException {
                    throw new IOException("No space left on device");
                }
            };
        }
        return delegate;
    });
    ignite.context().cache().context().database().checkpointReadLock();
    try {
        ignite.context().cache().context().wal().log(new CheckpointRecord(null), RolloverType.NEXT_SEGMENT);
    } catch (StorageException expected) {
    // No-op.
    } finally {
        ignite.context().cache().context().database().checkpointReadUnlock();
    }
    waitFailure(StorageException.class);
}
Also used : FileIODecorator(org.apache.ignite.internal.processors.cache.persistence.file.FileIODecorator) IgniteEx(org.apache.ignite.internal.IgniteEx) CheckpointRecord(org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) FileIO(org.apache.ignite.internal.processors.cache.persistence.file.FileIO) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 5 with FileIODecorator

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

the class GridIoManagerFileTransmissionSelfTest method tesFileHandlerReconnectTimeouted.

/**
 * @throws Exception If fails.
 */
@Test
public void tesFileHandlerReconnectTimeouted() throws Exception {
    rcv = startGrid(1);
    snd = startGrid(0);
    final AtomicInteger chunksCnt = new AtomicInteger();
    final CountDownLatch sndLatch = ((BlockingOpenChannelCommunicationSpi) snd.context().config().getCommunicationSpi()).latch;
    final AtomicReference<Throwable> refErr = new AtomicReference<>();
    File fileToSend = createFileRandomData("testFile", 5 * 1024 * 1024);
    transmissionFileIoFactory(snd, new FileIOFactory() {

        @Override
        public FileIO create(File file, OpenOption... modes) throws IOException {
            FileIO fileIo = IO_FACTORY.create(file, modes);
            return new FileIODecorator(fileIo) {

                /**
                 * {@inheritDoc}
                 */
                @Override
                public long transferTo(long position, long count, WritableByteChannel target) throws IOException {
                    if (chunksCnt.incrementAndGet() == 10) {
                        target.close();
                        ((BlockingOpenChannelCommunicationSpi) snd.context().config().getCommunicationSpi()).block = true;
                    }
                    return super.transferTo(position, count, target);
                }
            };
        }
    });
    rcv.context().io().addTransmissionHandler(topic, new DefaultTransmissionHandler(rcv, fileToSend, tempStore) {

        @Override
        public void onException(UUID nodeId, Throwable err) {
            refErr.compareAndSet(null, err);
            sndLatch.countDown();
        }
    });
    try (GridIoManager.TransmissionSender sender = snd.context().io().openTransmissionSender(rcv.localNode().id(), topic)) {
        sender.send(fileToSend, TransmissionPolicy.FILE);
    } catch (IgniteCheckedException | IOException | InterruptedException e) {
        // Ignore err.
        U.warn(log, e);
    }
    assertNotNull("Timeout exception not occurred", refErr.get());
    assertEquals("Type of timeout exception incorrect: " + refErr.get(), IgniteCheckedException.class, refErr.get().getClass());
}
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) WritableByteChannel(java.nio.channels.WritableByteChannel) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) FileIO(org.apache.ignite.internal.processors.cache.persistence.file.FileIO) OpenOption(java.nio.file.OpenOption) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) UUID(java.util.UUID) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)8 FileIO (org.apache.ignite.internal.processors.cache.persistence.file.FileIO)8 FileIODecorator (org.apache.ignite.internal.processors.cache.persistence.file.FileIODecorator)8 Test (org.junit.Test)8 File (java.io.File)7 OpenOption (java.nio.file.OpenOption)7 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)7 FileIOFactory (org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory)6 RandomAccessFileIOFactory (org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory)6 RandomAccessFile (java.io.RandomAccessFile)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 WritableByteChannel (java.nio.channels.WritableByteChannel)4 UUID (java.util.UUID)4 ByteBuffer (java.nio.ByteBuffer)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 IgniteException (org.apache.ignite.IgniteException)3 IgniteEx (org.apache.ignite.internal.IgniteEx)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 ReadableByteChannel (java.nio.channels.ReadableByteChannel)1 StandardOpenOption (java.nio.file.StandardOpenOption)1