Search in sources :

Example 11 with FileDescriptor

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();
}
Also used : IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) NullLogger(org.apache.ignite.logger.NullLogger) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) File(java.io.File) WALPointer(org.apache.ignite.internal.pagemem.wal.WALPointer) FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer) FileDescriptor(org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor)

Example 12 with FileDescriptor

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);
}
Also used : IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer) IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) IOException(java.io.IOException) FileDescriptor(org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor) DataEntry(org.apache.ignite.internal.pagemem.wal.record.DataEntry) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) DataRecord(org.apache.ignite.internal.pagemem.wal.record.DataRecord) KeyCacheObjectImpl(org.apache.ignite.internal.processors.cache.KeyCacheObjectImpl) File(java.io.File) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 13 with FileDescriptor

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);
    }
}
Also used : FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer) IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) FileDescriptor(org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor)

Example 14 with FileDescriptor

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());
}
Also used : FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer) IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) FileDescriptor(org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor)

Example 15 with FileDescriptor

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);
    }
}
Also used : IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer) IteratorParametersBuilder(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory.IteratorParametersBuilder) FileDescriptor(org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) File(java.io.File) WALPointer(org.apache.ignite.internal.pagemem.wal.WALPointer) FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer) RandomAccessFileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory)

Aggregations

FileDescriptor (org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor)37 File (java.io.File)20 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)17 Test (org.junit.Test)17 FileWALPointer (org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer)15 IgniteWalIteratorFactory (org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory)14 IgniteWriteAheadLogManager (org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager)13 IgniteEx (org.apache.ignite.internal.IgniteEx)11 WALPointer (org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)9 WithSystemProperty (org.apache.ignite.testframework.junits.WithSystemProperty)9 IgniteCache (org.apache.ignite.IgniteCache)7 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)7 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)7 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)7 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)7 WALMode (org.apache.ignite.configuration.WALMode)7 WALIterator (org.apache.ignite.internal.pagemem.wal.WALIterator)7 U (org.apache.ignite.internal.util.typedef.internal.U)7 GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)6