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