Search in sources :

Example 11 with IteratorParametersBuilder

use of org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory.IteratorParametersBuilder in project ignite by apache.

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);
    WALPointer corruptedPtr = corruptedWAlSegmentFile(descs.get(corruptedIdx), new RandomAccessFileIOFactory(), iteratorFactory);
    log.info("Should fail on ptr " + corruptedPtr);
    WALPointer lastReadPtr = null;
    boolean exception = false;
    try (WALIterator it0 = it) {
        while (it0.hasNextX()) {
            IgniteBiTuple<WALPointer, WALRecord> tup = it0.nextX();
            lastReadPtr = 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) 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.processors.cache.persistence.wal.WALPointer) RandomAccessFileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory)

Example 12 with IteratorParametersBuilder

use of org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory.IteratorParametersBuilder in project ignite by apache.

the class IgniteWalIteratorExceptionDuringReadTest method test.

/**
 * @throws Exception If failed.
 */
@Test
public void test() throws Exception {
    IgniteEx ig = startGrid();
    ig.cluster().state(ClusterState.ACTIVE);
    IgniteCache<Integer, byte[]> cache = ig.cache(DEFAULT_CACHE_NAME);
    for (int i = 0; i < 20 * 4; i++) cache.put(i, new byte[1024 * 1024]);
    ig.cluster().state(ClusterState.INACTIVE);
    IgniteWalIteratorFactory iterFactory = new IgniteWalIteratorFactory(log);
    WALPointer failOnPtr = new WALPointer(3, 1024 * 1024 * 5, 0);
    String failMsg = "test fail message";
    IteratorParametersBuilder builder = new IteratorParametersBuilder().filesOrDirs(U.defaultWorkDirectory()).filter((r, ptr) -> {
        if (ptr.compareTo(failOnPtr) >= 0)
            throw new TestRuntimeException(failMsg);
        return true;
    });
    try (WALIterator it = iterFactory.iterator(builder)) {
        WALPointer ptr = null;
        boolean failed = false;
        try {
            while (it.hasNext()) {
                IgniteBiTuple<WALPointer, WALRecord> tup = it.next();
                ptr = tup.get1();
            }
        } catch (IgniteException e) {
            Assert.assertNotNull(ptr);
            Assert.assertEquals(failOnPtr.index(), ptr.index());
            Assert.assertTrue(ptr.compareTo(failOnPtr) < 0);
            failed = X.hasCause(e, TestRuntimeException.class);
        }
        assertTrue(failed);
    }
}
Also used : IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) IteratorParametersBuilder(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory.IteratorParametersBuilder) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) IgniteException(org.apache.ignite.IgniteException) IgniteEx(org.apache.ignite.internal.IgniteEx) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 13 with IteratorParametersBuilder

use of org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory.IteratorParametersBuilder in project ignite by apache.

the class IgniteWalReaderTest method testTxFillWalAndExtractDataRecords.

/**
 * Places records under transaction, checks its value using WAL.
 *
 * @throws Exception if failed.
 */
@Test
public void testTxFillWalAndExtractDataRecords() throws Exception {
    Ignite ignite0 = startGrid();
    ignite0.cluster().active(true);
    int cntEntries = 1000;
    int txCnt = 100;
    IgniteCache<Object, Object> entries = txPutDummyRecords(ignite0, cntEntries, txCnt);
    Map<Object, Object> ctrlMap = new HashMap<>();
    for (Cache.Entry<Object, Object> next : entries) ctrlMap.put(next.getKey(), next.getValue());
    String subfolderName = genDbSubfolderName(ignite0, 0);
    stopGrid();
    String workDir = U.defaultWorkDirectory();
    IteratorParametersBuilder params = createIteratorParametersBuilder(workDir, subfolderName);
    params.filesOrDirs(workDir);
    IgniteWalIteratorFactory factory = new IgniteWalIteratorFactory(log);
    IgniteBiInClosure<Object, Object> objConsumer = (key, val) -> {
        boolean rmv = remove(ctrlMap, key, val);
        if (!rmv)
            log.error("Unable to remove Key and value from control Map K:[" + key + "] V: [" + val + "]");
        if (val instanceof IndexedObject) {
            IndexedObject indexedObj = (IndexedObject) val;
            assertEquals(indexedObj.iVal, indexedObj.jVal);
            assertEquals(indexedObj.iVal, key);
            for (byte datum : indexedObj.getData()) assertTrue(datum >= 'A' && datum <= 'A' + 10);
        }
    };
    scanIterateAndCount(factory, params, cntEntries, txCnt, objConsumer, null);
    assertTrue(" Control Map is not empty after reading entries " + ctrlMap, ctrlMap.isEmpty());
}
Also used : IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) BinaryObject(org.apache.ignite.binary.BinaryObject) MVCC_DATA_RECORD(org.apache.ignite.internal.pagemem.wal.record.WALRecord.RecordType.MVCC_DATA_RECORD) ObjectOutput(java.io.ObjectOutput) Transaction(org.apache.ignite.transactions.Transaction) Random(java.util.Random) IgniteEx(org.apache.ignite.internal.IgniteEx) DATA_RECORD_V2(org.apache.ignite.internal.pagemem.wal.record.WALRecord.RecordType.DATA_RECORD_V2) CacheRebalanceMode(org.apache.ignite.cache.CacheRebalanceMode) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) IgniteSystemProperties(org.apache.ignite.IgniteSystemProperties) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NullLogger(org.apache.ignite.logger.NullLogger) TxRecord(org.apache.ignite.internal.pagemem.wal.record.TxRecord) CREATE(org.apache.ignite.internal.processors.cache.GridCacheOperation.CREATE) Map(java.util.Map) Cache(javax.cache.Cache) DELETE(org.apache.ignite.internal.processors.cache.GridCacheOperation.DELETE) PdsFolderResolver.genNewStyleSubfolderName(org.apache.ignite.internal.processors.cache.persistence.filename.PdsFolderResolver.genNewStyleSubfolderName) WALMode(org.apache.ignite.configuration.WALMode) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Externalizable(java.io.Externalizable) EnumMap(java.util.EnumMap) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) UUID(java.util.UUID) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) DataRecord(org.apache.ignite.internal.pagemem.wal.record.DataRecord) DataEntry(org.apache.ignite.internal.pagemem.wal.record.DataEntry) IgniteCache(org.apache.ignite.IgniteCache) Serializable(java.io.Serializable) GridCacheOperation(org.apache.ignite.internal.processors.cache.GridCacheOperation) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) Objects(java.util.Objects) CountDownLatch(java.util.concurrent.CountDownLatch) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IteratorParametersBuilder(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory.IteratorParametersBuilder) EVT_WAL_SEGMENT_COMPACTED(org.apache.ignite.events.EventType.EVT_WAL_SEGMENT_COMPACTED) MvccFeatureChecker(org.apache.ignite.testframework.MvccFeatureChecker) DFLT_STORE_DIR(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.DFLT_STORE_DIR) ObjectInput(java.io.ObjectInput) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) NotNull(org.jetbrains.annotations.NotNull) MarshalledDataEntry(org.apache.ignite.internal.pagemem.wal.record.MarshalledDataEntry) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) ClusterState(org.apache.ignite.cluster.ClusterState) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) U(org.apache.ignite.internal.util.typedef.internal.U) EVT_WAL_SEGMENT_ARCHIVED(org.apache.ignite.events.EventType.EVT_WAL_SEGMENT_ARCHIVED) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) UnwrappedDataEntry(org.apache.ignite.internal.pagemem.wal.record.UnwrappedDataEntry) UnwrapDataEntry(org.apache.ignite.internal.pagemem.wal.record.UnwrapDataEntry) IgniteBiInClosure(org.apache.ignite.lang.IgniteBiInClosure) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) Assume(org.junit.Assume) IgniteEvents(org.apache.ignite.IgniteEvents) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) Arrays.fill(java.util.Arrays.fill) Iterator(java.util.Iterator) IOException(java.io.IOException) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) File(java.io.File) T2(org.apache.ignite.internal.util.typedef.T2) TimeUnit(java.util.concurrent.TimeUnit) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty) AtomicLong(java.util.concurrent.atomic.AtomicLong) TreeMap(java.util.TreeMap) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) RecordUtils(org.apache.ignite.testframework.wal.record.RecordUtils) IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) WalSegmentArchivedEvent(org.apache.ignite.events.WalSegmentArchivedEvent) Assert(org.junit.Assert) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) HashMap(java.util.HashMap) IteratorParametersBuilder(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory.IteratorParametersBuilder) Ignite(org.apache.ignite.Ignite) BinaryObject(org.apache.ignite.binary.BinaryObject) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) Cache(javax.cache.Cache) IgniteCache(org.apache.ignite.IgniteCache) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 14 with IteratorParametersBuilder

use of org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory.IteratorParametersBuilder in project ignite by apache.

the class IgniteWalReaderTest method createIteratorParametersBuilder.

/**
 * @param workDir Work directory.
 * @param subfolderName Subfolder name.
 * @return WAL iterator factory.
 * @throws IgniteCheckedException If failed.
 */
@NotNull
private IteratorParametersBuilder createIteratorParametersBuilder(String workDir, String subfolderName) throws IgniteCheckedException {
    File binaryMeta = U.resolveWorkDirectory(workDir, DataStorageConfiguration.DFLT_BINARY_METADATA_PATH, false);
    File binaryMetaWithConsId = new File(binaryMeta, subfolderName);
    File marshallerMapping = U.resolveWorkDirectory(workDir, DataStorageConfiguration.DFLT_MARSHALLER_PATH, false);
    return new IteratorParametersBuilder().binaryMetadataFileStoreDir(binaryMetaWithConsId).marshallerMappingFileStoreDir(marshallerMapping);
}
Also used : IteratorParametersBuilder(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory.IteratorParametersBuilder) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with IteratorParametersBuilder

use of org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory.IteratorParametersBuilder in project ignite by apache.

the class IgniteWalReaderTest method testCheckBoundsIterator.

/**
 * @throws Exception If failed.
 */
@Test
public void testCheckBoundsIterator() throws Exception {
    Ignite ignite = startGrid("node0");
    ignite.cluster().active(true);
    try (IgniteDataStreamer<Integer, IndexedObject> st = ignite.dataStreamer(CACHE_NAME)) {
        st.allowOverwrite(true);
        for (int i = 0; i < 10_000; i++) st.addData(i, new IndexedObject(i));
    }
    stopAllGrids();
    List<WALPointer> wal = new ArrayList<>();
    String workDir = U.defaultWorkDirectory();
    IgniteWalIteratorFactory factory = new IgniteWalIteratorFactory();
    try (WALIterator it = factory.iterator(workDir)) {
        while (it.hasNext()) {
            IgniteBiTuple<WALPointer, WALRecord> tup = it.next();
            wal.add(tup.get1());
        }
    }
    Random rnd = new Random();
    int from0 = rnd.nextInt(wal.size() - 2) + 1;
    int to0 = wal.size() - 1;
    // +1 for skip first record.
    WALPointer exp0First = wal.get(from0);
    WALPointer exp0Last = wal.get(to0);
    T2<WALPointer, WALRecord> actl0First = null;
    T2<WALPointer, WALRecord> actl0Last = null;
    int records0 = 0;
    try (WALIterator it = factory.iterator(exp0First, workDir)) {
        while (it.hasNext()) {
            IgniteBiTuple<WALPointer, WALRecord> tup = it.next();
            if (actl0First == null)
                actl0First = new T2<>(tup.get1(), tup.get2());
            actl0Last = new T2<>(tup.get1(), tup.get2());
            records0++;
        }
    }
    log.info("Check REPLAY FROM:" + exp0First + "\n" + "expFirst=" + exp0First + " actlFirst=" + actl0First + ", " + "expLast=" + exp0Last + " actlLast=" + actl0Last);
    // +1 because bound include.
    Assert.assertEquals(to0 - from0 + 1, records0);
    Assert.assertNotNull(actl0First);
    Assert.assertNotNull(actl0Last);
    Assert.assertEquals(exp0First, actl0First.get1());
    Assert.assertEquals(exp0Last, actl0Last.get1());
    int from1 = 0;
    int to1 = rnd.nextInt(wal.size() - 3) + 1;
    // -3 for skip last record.
    WALPointer exp1First = wal.get(from1);
    WALPointer exp1Last = wal.get(to1);
    T2<WALPointer, WALRecord> actl1First = null;
    T2<WALPointer, WALRecord> actl1Last = null;
    int records1 = 0;
    try (WALIterator it = factory.iterator(new IteratorParametersBuilder().filesOrDirs(workDir).to(exp1Last))) {
        while (it.hasNext()) {
            IgniteBiTuple<WALPointer, WALRecord> tup = it.next();
            if (actl1First == null)
                actl1First = new T2<>(tup.get1(), tup.get2());
            actl1Last = new T2<>(tup.get1(), tup.get2());
            records1++;
        }
    }
    log.info("Check REPLAY TO:" + exp1Last + "\n" + "expFirst=" + exp1First + " actlFirst=" + actl1First + ", " + "expLast=" + exp1Last + " actlLast=" + actl1Last);
    // +1 because bound include.
    Assert.assertEquals(to1 - from1 + 1, records1);
    Assert.assertNotNull(actl1First);
    Assert.assertNotNull(actl1Last);
    Assert.assertEquals(exp1First, actl1First.get1());
    Assert.assertEquals(exp1Last, actl1Last.get1());
    int from2 = rnd.nextInt(wal.size() - 2);
    int to2 = rnd.nextInt((wal.size() - 1) - from2) + from2;
    WALPointer exp2First = wal.get(from2);
    WALPointer exp2Last = wal.get(to2);
    T2<WALPointer, WALRecord> actl2First = null;
    T2<WALPointer, WALRecord> actl2Last = null;
    int records2 = 0;
    try (WALIterator it = factory.iterator(new IteratorParametersBuilder().filesOrDirs(workDir).from(exp2First).to(exp2Last))) {
        while (it.hasNext()) {
            IgniteBiTuple<WALPointer, WALRecord> tup = it.next();
            if (actl2First == null)
                actl2First = new T2<>(tup.get1(), tup.get2());
            actl2Last = new T2<>(tup.get1(), tup.get2());
            records2++;
        }
    }
    log.info("Check REPLAY BETWEEN:" + exp2First + " " + exp2Last + "\n" + "expFirst=" + exp2First + " actlFirst=" + actl2First + ", " + "expLast=" + exp2Last + " actlLast=" + actl2Last);
    // +1 because bound include.
    Assert.assertEquals(to2 - from2 + 1, records2);
    Assert.assertNotNull(actl2First);
    Assert.assertNotNull(actl2Last);
    Assert.assertEquals(exp2First, actl2First.get1());
    Assert.assertEquals(exp2Last, actl2Last.get1());
}
Also used : IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) ArrayList(java.util.ArrayList) IteratorParametersBuilder(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory.IteratorParametersBuilder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Random(java.util.Random) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) Ignite(org.apache.ignite.Ignite) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) T2(org.apache.ignite.internal.util.typedef.T2) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

IteratorParametersBuilder (org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory.IteratorParametersBuilder)17 IgniteWalIteratorFactory (org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory)13 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)11 Test (org.junit.Test)11 Ignite (org.apache.ignite.Ignite)10 WALIterator (org.apache.ignite.internal.pagemem.wal.WALIterator)8 WALRecord (org.apache.ignite.internal.pagemem.wal.record.WALRecord)8 WALPointer (org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)8 File (java.io.File)7 IgniteEx (org.apache.ignite.internal.IgniteEx)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 Serializable (java.io.Serializable)4 ArrayList (java.util.ArrayList)4 EnumMap (java.util.EnumMap)4 HashMap (java.util.HashMap)4 DataEntry (org.apache.ignite.internal.pagemem.wal.record.DataEntry)4 GridCacheOperation (org.apache.ignite.internal.processors.cache.GridCacheOperation)4 Externalizable (java.io.Externalizable)3 IOException (java.io.IOException)3