use of org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore in project ignite by apache.
the class PagesPossibleCorruptionDiagnosticTest method testCorruptedNodeFailsOnStart.
/**
* Tests that node with corrupted partition fails on start.
*/
@Test
public void testCorruptedNodeFailsOnStart() throws Exception {
IgniteEx ignite = startGrid(0);
ignite.cluster().state(ClusterState.ACTIVE);
IgniteCache<Integer, Integer> cache = ignite.getOrCreateCache(new CacheConfiguration<Integer, Integer>(DEFAULT_CACHE_NAME).setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL).setAffinity(new RendezvousAffinityFunction(false, 1)));
cache.put(1, 1);
PartitionUpdateCounter counter = counter(0, DEFAULT_CACHE_NAME, ignite.name());
counter.update(10, 5);
forceCheckpoint();
FilePageStore store = filePageStore(ignite, 0);
stopAllGrids();
store.ensure();
// Index of meta page is always 0.
int metaPageIdx = 0;
long offset = store.headerSize() + metaPageIdx * PAGE_SIZE + PART_META_REUSE_LIST_ROOT_OFF;
writeLongToFileByOffset(store.getFileAbsolutePath(), offset, 0L);
try {
startGrid(0);
} catch (Exception ignored) {
/* No-op. */
}
assertTrue(correctFailure);
}
use of org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore in project ignite by apache.
the class IgniteClusterSnapshotCheckTest method corruptPartitionFile.
/**
* @param ignite Ignite instance.
* @param snpName Snapshot name.
* @param ccfg Cache configuration.
* @param partId Partition id to corrupt.
* @throws IgniteCheckedException If fails.
* @throws IOException If partition file failed to be changed.
*/
private static void corruptPartitionFile(IgniteEx ignite, String snpName, CacheConfiguration<?, ?> ccfg, int partId) throws IgniteCheckedException, IOException {
Path cachePath = Paths.get(snp(ignite).snapshotLocalDir(snpName).getAbsolutePath(), databaseRelativePath(ignite.context().pdsFolderResolver().resolveFolders().folderName()), cacheDirName(ccfg));
Path part0 = U.searchFileRecursively(cachePath, getPartitionFileName(partId));
int grpId = CU.cacheId(ccfg.getName());
try (FilePageStore pageStore = (FilePageStore) ((FilePageStoreManager) ignite.context().cache().context().pageStore()).getPageStoreFactory(grpId, ignite.context().cache().isEncrypted(grpId)).createPageStore(getTypeByPartId(partId), () -> part0, val -> {
})) {
ByteBuffer buff = ByteBuffer.allocateDirect(ignite.configuration().getDataStorageConfiguration().getPageSize()).order(ByteOrder.nativeOrder());
pageStore.read(0, buff, false);
pageStore.beginRecover();
PageIO.setCrc(buff, 1);
buff.flip();
pageStore.write(PageIO.getPageId(buff), buff, 0, false);
pageStore.finishRecover();
}
}
use of org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore in project ignite by apache.
the class IgnitePdsRecoveryAfterFileCorruptionTest method eraseDataFromDisk.
/**
* @param pageStore Page store.
* @param cacheId Cache id.
* @param page Page.
*/
private void eraseDataFromDisk(FilePageStoreManager pageStore, int cacheId, FullPageId page) throws IgniteCheckedException, IOException {
PageStore store = pageStore.getStore(cacheId, PageIdUtils.partId(page.pageId()));
FilePageStore filePageStore = (FilePageStore) store;
FileIO fileIO = U.field(filePageStore, "fileIO");
long size = fileIO.size();
fileIO.writeFully(ByteBuffer.allocate((int) size - filePageStore.headerSize()), filePageStore.headerSize());
fileIO.force();
}
use of org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore 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.FilePageStore in project ignite by apache.
the class IgniteSnapshotManager method partitionRowIterator.
/**
* @param snpName Snapshot name.
* @param folderName The node folder name, usually it's the same as the U.maskForFileName(consistentId).
* @param grpName Cache group name.
* @param partId Partition id.
* @return Iterator over partition.
* @throws IgniteCheckedException If and error occurs.
*/
public GridCloseableIterator<CacheDataRow> partitionRowIterator(GridKernalContext ctx, String snpName, String folderName, String grpName, int partId) throws IgniteCheckedException {
File snpDir = resolveSnapshotDir(snpName);
File nodePath = new File(snpDir, databaseRelativePath(folderName));
if (!nodePath.exists())
throw new IgniteCheckedException("Consistent id directory doesn't exists: " + nodePath.getAbsolutePath());
List<File> grps = cacheDirectories(nodePath, name -> name.equals(grpName));
if (F.isEmpty(grps)) {
throw new IgniteCheckedException("The snapshot cache group not found [dir=" + snpDir.getAbsolutePath() + ", grpName=" + grpName + ']');
}
if (grps.size() > 1) {
throw new IgniteCheckedException("The snapshot cache group directory cannot be uniquely identified [dir=" + snpDir.getAbsolutePath() + ", grpName=" + grpName + ']');
}
File snpPart = getPartitionFile(new File(snapshotLocalDir(snpName), databaseRelativePath(folderName)), grps.get(0).getName(), partId);
int grpId = CU.cacheId(grpName);
FilePageStore pageStore = (FilePageStore) storeMgr.getPageStoreFactory(grpId, cctx.cache().isEncrypted(grpId)).createPageStore(getTypeByPartId(partId), snpPart::toPath, val -> {
});
GridCloseableIterator<CacheDataRow> partIter = partitionRowIterator(ctx, grpName, partId, pageStore);
return new GridCloseableIteratorAdapter<CacheDataRow>() {
/**
* {@inheritDoc}
*/
@Override
protected CacheDataRow onNext() throws IgniteCheckedException {
return partIter.nextX();
}
/**
* {@inheritDoc}
*/
@Override
protected boolean onHasNext() throws IgniteCheckedException {
return partIter.hasNextX();
}
/**
* {@inheritDoc}
*/
@Override
protected void onClose() {
U.closeQuiet(pageStore);
}
};
}
Aggregations