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);
}
}
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);
}
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();
}
}
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);
}
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());
}
Aggregations