use of org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor in project gridgain by gridgain.
the class WalTestUtils method corruptWalRecordInCompressedSegment.
/**
* Put zero CRC in one of records for the specified compressed segment.
*
* @param desc WAL segment descriptor.
* @param pointer WAL pointer.
*/
public static void corruptWalRecordInCompressedSegment(FileDescriptor desc, FileWALPointer pointer) throws IOException, IgniteCheckedException {
File tmp = Files.createTempDirectory("temp-dir").toFile();
U.unzip(desc.file(), tmp, new NullLogger());
File walFile = tmp.listFiles()[0];
String walFileName = desc.file().getName().replace(FilePageStoreManager.ZIP_SUFFIX, "");
// reanaming is needed because unzip removes leading zeros from archived wal segment file name,
// but strict name pattern of wal file is needed for WALIterator
walFile.renameTo(new File(tmp.getPath() + "/" + walFileName));
walFile = tmp.listFiles()[0];
final IgniteWalIteratorFactory factory = new IgniteWalIteratorFactory(new NullLogger());
IgniteWalIteratorFactory.IteratorParametersBuilder builder = new IgniteWalIteratorFactory.IteratorParametersBuilder().filesOrDirs(walFile);
try (WALIterator stIt = factory.iterator(builder)) {
while (stIt.hasNextX()) {
IgniteBiTuple<WALPointer, WALRecord> next = stIt.nextX();
final WALRecord record = next.get2();
if (pointer.equals(record.position())) {
corruptWalRecord(new FileDescriptor(walFile), (FileWALPointer) next.get1());
break;
}
}
}
byte[] fileBytes = U.zip(Files.readAllBytes(walFile.toPath()));
Files.write(desc.file().toPath(), fileBytes);
walFile.delete();
tmp.delete();
}
use of org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor in project gridgain by gridgain.
the class IgniteWalRebalanceTest method testSwitchHistoricalRebalanceToFullWhileIteratingOverWAL.
/**
* Tests that demander switches to full rebalance if the previously chosen supplier for a group has failed
* to perform historical rebalance due to an unexpected error while iterating over reserved wal.
*
* @throws Exception If failed
*/
@Test
public void testSwitchHistoricalRebalanceToFullWhileIteratingOverWAL() throws Exception {
testSwitchHistoricalRebalanceToFull(supplier1 -> {
try {
// Corrupt wal record in order to fail historical rebalance from supplier1 node.
IgniteWriteAheadLogManager walMgr = supplier1.context().cache().context().wal();
FileWALPointer ptr = (FileWALPointer) walMgr.log(new DataRecord(new DataEntry(CU.cacheId("test-cache-1"), new KeyCacheObjectImpl(0, null, 0), null, GridCacheOperation.DELETE, new GridCacheVersion(0, 1, 1, 0), new GridCacheVersion(0, 1, 1, 0), 0, 0, 0, DataEntry.EMPTY_FLAGS)));
File walDir = U.field(walMgr, "walWorkDir");
List<FileDescriptor> walFiles = new IgniteWalIteratorFactory().resolveWalFiles(new IgniteWalIteratorFactory.IteratorParametersBuilder().filesOrDirs(walDir));
FileDescriptor lastWalFile = walFiles.get(walFiles.size() - 1);
WalTestUtils.corruptWalRecord(lastWalFile, ptr);
IgniteCache<Integer, IndexedObject> c1 = supplier1.cache("test-cache-1");
for (int i = 0; i < PARTS_CNT * 100; i++) c1.put(i, new IndexedObject(i + PARTS_CNT));
} catch (IgniteCheckedException | IOException e) {
throw new RuntimeException(e);
}
}, () -> true);
}
use of org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor in project gridgain by gridgain.
the class CorruptedCheckpointReservationTest method corruptWalRecord.
/**
* @param ig Ignite.
* @param cpIdx Checkpoint index.
*/
private void corruptWalRecord(IgniteEx ig, int cpIdx, boolean segmentCompressed) throws IgniteCheckedException, IOException {
IgniteWriteAheadLogManager walMgr = ig.context().cache().context().wal();
FileWALPointer corruptedCp = getCp(ig, cpIdx);
Optional<FileDescriptor> cpSegment = getFileDescriptor(segmentCompressed, walMgr, corruptedCp);
if (segmentCompressed) {
assertTrue("Cannot find " + FilePageStoreManager.ZIP_SUFFIX + " segment for checkpoint.", cpSegment.isPresent());
WalTestUtils.corruptWalRecordInCompressedSegment(cpSegment.get(), corruptedCp);
} else {
assertTrue("Cannot find " + FileDescriptor.WAL_SEGMENT_FILE_EXT + " segment for checkpoint.", cpSegment.isPresent());
WalTestUtils.corruptWalRecord(cpSegment.get(), corruptedCp);
}
}
use of org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor in project gridgain by gridgain.
the class CorruptedCheckpointReservationTest method corruptCompressedWalSegment.
/**
* @param ig Ignite.
* @param cpIdx Checkpoint index.
*/
private void corruptCompressedWalSegment(IgniteEx ig, int cpIdx) throws IgniteCheckedException, IOException {
IgniteWriteAheadLogManager walMgr = ig.context().cache().context().wal();
FileWALPointer corruptedCp = getCp(ig, cpIdx);
Optional<FileDescriptor> cpSegment = getFileDescriptor(true, walMgr, corruptedCp);
assertTrue("Cannot find " + FilePageStoreManager.ZIP_SUFFIX + " segment for checkpoint.", cpSegment.isPresent());
WalTestUtils.corruptCompressedFile(cpSegment.get());
}
use of org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor in project gridgain by gridgain.
the class IgniteWALTailIsReachedDuringIterationOverArchiveTest method doTest.
/**
* @param walMgr WAL manager.
* @param it WAL iterator.
* @throws IOException If IO exception.
* @throws IgniteCheckedException If WAL iterator failed.
*/
private void doTest(IgniteWriteAheadLogManager walMgr, WALIterator it) throws IOException, IgniteCheckedException {
File walArchiveDir = U.field(walMgr, "walArchiveDir");
IgniteWalIteratorFactory iteratorFactory = new IgniteWalIteratorFactory();
List<FileDescriptor> descs = iteratorFactory.resolveWalFiles(new IteratorParametersBuilder().filesOrDirs(walArchiveDir));
int maxIndex = descs.size() - 1;
int minIndex = 1;
int corruptedIdx = current().nextInt(minIndex, maxIndex);
log.info("Corrupted segment with idx:" + corruptedIdx);
FileWALPointer corruptedPtr = corruptedWAlSegmentFile(descs.get(corruptedIdx), new RandomAccessFileIOFactory(), iteratorFactory);
log.info("Should fail on ptr " + corruptedPtr);
FileWALPointer lastReadPtr = null;
boolean exception = false;
try (WALIterator it0 = it) {
while (it0.hasNextX()) {
IgniteBiTuple<WALPointer, WALRecord> tup = it0.nextX();
lastReadPtr = (FileWALPointer) tup.get1();
}
} catch (IgniteCheckedException e) {
if (e.getMessage().contains("WAL tail reached in archive directory, WAL segment file is corrupted") || e.getMessage().contains("WAL tail reached not in the last available segment"))
exception = true;
}
Assert.assertNotNull(lastReadPtr);
if (!exception) {
fail("Last read ptr=" + lastReadPtr + ", corruptedPtr=" + corruptedPtr);
}
}
Aggregations