use of org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory 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.FileIOFactory 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);
}
}
use of org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory in project ignite by apache.
the class MockWalIteratorFactory method iterator.
/**
* Creates iterator
* @param wal WAL directory without node consistent id
* @param walArchive WAL archive without node consistent id
* @return iterator
* @throws IgniteCheckedException if IO failed
*/
@SuppressWarnings("unchecked")
public WALIterator iterator(File wal, File walArchive) throws IgniteCheckedException {
final DataStorageConfiguration persistentCfg1 = Mockito.mock(DataStorageConfiguration.class);
when(persistentCfg1.getWalPath()).thenReturn(wal.getAbsolutePath());
when(persistentCfg1.getWalArchivePath()).thenReturn(walArchive.getAbsolutePath());
when(persistentCfg1.getWalSegments()).thenReturn(segments);
when(persistentCfg1.getWalBufferSize()).thenReturn(DataStorageConfiguration.DFLT_WAL_BUFF_SIZE);
when(persistentCfg1.getWalRecordIteratorBufferSize()).thenReturn(DataStorageConfiguration.DFLT_WAL_RECORD_ITERATOR_BUFFER_SIZE);
when(persistentCfg1.getWalSegmentSize()).thenReturn(DataStorageConfiguration.DFLT_WAL_SEGMENT_SIZE);
final FileIOFactory fileIOFactory = new DataStorageConfiguration().getFileIOFactory();
when(persistentCfg1.getFileIOFactory()).thenReturn(fileIOFactory);
final IgniteConfiguration cfg = Mockito.mock(IgniteConfiguration.class);
when(cfg.getDataStorageConfiguration()).thenReturn(persistentCfg1);
final GridKernalContext ctx = Mockito.mock(GridKernalContext.class);
when(ctx.config()).thenReturn(cfg);
when(ctx.clientNode()).thenReturn(false);
when(ctx.pdsFolderResolver()).thenReturn(new PdsFoldersResolver() {
@Override
public PdsFolderSettings resolveFolders() {
return new PdsFolderSettings(new File("."), subfolderName, consistentId, null, false);
}
});
final GridDiscoveryManager disco = Mockito.mock(GridDiscoveryManager.class);
when(ctx.discovery()).thenReturn(disco);
final IgniteWriteAheadLogManager mgr = new FileWriteAheadLogManager(ctx);
final GridCacheSharedContext sctx = Mockito.mock(GridCacheSharedContext.class);
when(sctx.kernalContext()).thenReturn(ctx);
when(sctx.discovery()).thenReturn(disco);
when(sctx.gridConfig()).thenReturn(cfg);
final GridCacheDatabaseSharedManager db = Mockito.mock(GridCacheDatabaseSharedManager.class);
when(db.pageSize()).thenReturn(pageSize);
when(sctx.database()).thenReturn(db);
when(sctx.logger(any(Class.class))).thenReturn(log);
mgr.start(sctx);
return mgr.replay(null);
}
use of org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory in project ignite by apache.
the class WalTestUtils method corruptWalSegmentFile.
/**
* Put zero CRC in one of records for the specified segment.
*
* @param desc WAL segment descriptor.
* @param pointer WAL pointer.
*/
public static void corruptWalSegmentFile(FileDescriptor desc, WALPointer pointer) throws IOException {
int crc32Off = pointer.fileOffset() + pointer.length() - CRC_SIZE;
// Has 0 value by default.
ByteBuffer zeroCrc32 = allocate(CRC_SIZE);
FileIOFactory ioFactory = new RandomAccessFileIOFactory();
try (FileIO io = ioFactory.create(desc.file(), WRITE)) {
io.write(zeroCrc32, crc32Off);
io.force(true);
}
}
use of org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory in project ignite by apache.
the class DefragmentationMXBeanTest method testDefragmentationCancelInProgress.
/**
* Test that ongong defragmentation can be stopped via JMX bean.
* Description:
* 1. Start one node.
* 2. Put a load of a data on it.
* 3. Schedule defragmentation.
* 4. Make IO factory slow down after 128 partitions are processed, so we have time to stop the defragmentation.
* 5. Stop the defragmentation.
* @throws Exception If failed.
*/
@Test
public void testDefragmentationCancelInProgress() throws Exception {
IgniteEx ig = startGrid(0);
ig.cluster().state(ClusterState.ACTIVE);
IgniteCache<Object, Object> cache = ig.getOrCreateCache(DEFAULT_CACHE_NAME);
for (int i = 0; i < 1024; i++) cache.put(i, i);
forceCheckpoint(ig);
DefragmentationMXBean mxBean = defragmentationMXBean(ig.name());
mxBean.schedule("");
stopGrid(0);
blockCdl = new CountDownLatch(128);
UnaryOperator<IgniteConfiguration> cfgOp = cfg -> {
DataStorageConfiguration dsCfg = cfg.getDataStorageConfiguration();
FileIOFactory delegate = dsCfg.getFileIOFactory();
dsCfg.setFileIOFactory((file, modes) -> {
if (file.getName().contains("dfrg")) {
if (blockCdl.getCount() == 0) {
try {
// Slow down defragmentation process.
// This'll be enough for the test since we have, like, 900 partitions left.
Thread.sleep(100);
} catch (InterruptedException ignore) {
// No-op.
}
} else
blockCdl.countDown();
}
return delegate.create(file, modes);
});
return cfg;
};
IgniteInternalFuture<?> fut = GridTestUtils.runAsync(() -> {
try {
startGrid(0, cfgOp);
} catch (Exception e) {
// No-op.
throw new RuntimeException(e);
}
});
blockCdl.await();
mxBean = defragmentationMXBean(ig.name());
assertTrue(mxBean.cancel());
fut.get();
assertTrue(mxBean.cancel());
}
Aggregations