Search in sources :

Example 1 with IteratorParametersBuilder

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

the class IgnitePdsSporadicDataRecordsOnBackupTest method findSporadicDataRecords.

/**
 * Returns a number of {@link DataRecord} that do not have a xid version,
 * in other words, number of records that were created by GridCacheUtils#createBackupPostProcessingClosure().
 *
 * @throws IgniteCheckedException If failed.
 */
private long findSporadicDataRecords(String nodeFolderName) throws IgniteCheckedException {
    File dbDir = new File(U.defaultWorkDirectory(), "db");
    File commonWalDir = new File(dbDir, "wal");
    File walDir = new File(commonWalDir, nodeFolderName);
    File walArchiveDir = new File(new File(commonWalDir, "archive"), nodeFolderName);
    assertTrue(walDir.exists());
    assertTrue(walArchiveDir.exists());
    IteratorParametersBuilder params = new IteratorParametersBuilder();
    params.bufferSize(1024 * 1024);
    params.filesOrDirs(walDir, walArchiveDir);
    params.filter((type, pointer) -> type == WALRecord.RecordType.DATA_RECORD_V2);
    int cacheId = CU.cacheId(TX_CACHE_NAME);
    long createOpCnt = 0;
    try (WALIterator itr = new IgniteWalIteratorFactory().iterator(params)) {
        while (itr.hasNext()) {
            IgniteBiTuple<WALPointer, WALRecord> walEntry = itr.next();
            assertTrue(walEntry.get2() instanceof DataRecord);
            DataRecord rec = (DataRecord) walEntry.get2();
            Predicate<DataEntry> filter = e -> e.cacheId() == cacheId && GridCacheOperation.CREATE == e.op() && e.nearXidVersion() == null;
            for (int i = 0; i < rec.entryCount(); i++) {
                if (filter.test(rec.get(i)))
                    createOpCnt++;
            }
        }
    }
    return createOpCnt;
}
Also used : IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) SERIALIZABLE(org.apache.ignite.transactions.TransactionIsolation.SERIALIZABLE) IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) Transaction(org.apache.ignite.transactions.Transaction) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) U(org.apache.ignite.internal.util.typedef.internal.U) IgniteEx(org.apache.ignite.internal.IgniteEx) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) QueryEntity(org.apache.ignite.cache.QueryEntity) WALMode(org.apache.ignite.configuration.WALMode) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Predicate(java.util.function.Predicate) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) OPTIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.OPTIMISTIC) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) DataRecord(org.apache.ignite.internal.pagemem.wal.record.DataRecord) DataEntry(org.apache.ignite.internal.pagemem.wal.record.DataEntry) FULL_SYNC(org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC) File(java.io.File) IgniteCache(org.apache.ignite.IgniteCache) TRANSACTIONAL(org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL) GridCacheOperation(org.apache.ignite.internal.processors.cache.GridCacheOperation) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IteratorParametersBuilder(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory.IteratorParametersBuilder) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) CU(org.apache.ignite.internal.util.typedef.internal.CU) Collections(java.util.Collections) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) IteratorParametersBuilder(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory.IteratorParametersBuilder) DataEntry(org.apache.ignite.internal.pagemem.wal.record.DataEntry) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) DataRecord(org.apache.ignite.internal.pagemem.wal.record.DataRecord) File(java.io.File) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)

Example 2 with IteratorParametersBuilder

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

the class IgniteWalReaderTest method runRemoveOperationTest.

/**
 * Test if DELETE operation can be found after mixed cache operations including remove().
 *
 * @param mode Cache Atomicity Mode.
 * @throws Exception if failed.
 */
private void runRemoveOperationTest(CacheAtomicityMode mode) throws Exception {
    Ignite ignite = startGrid();
    ignite.cluster().active(true);
    createCache2(ignite, mode);
    ignite.cluster().active(false);
    String subfolderName = genDbSubfolderName(ignite, 0);
    stopGrid();
    String workDir = U.defaultWorkDirectory();
    IgniteWalIteratorFactory factory = new IgniteWalIteratorFactory(log);
    IteratorParametersBuilder params = createIteratorParametersBuilder(workDir, subfolderName);
    params.filesOrDirs(workDir);
    StringBuilder sb = new StringBuilder();
    Map<GridCacheOperation, Integer> operationsFound = new EnumMap<>(GridCacheOperation.class);
    scanIterateAndCount(factory, params, 0, 0, null, dataRecord -> {
        sb.append("{");
        for (int i = 0; i < dataRecord.entryCount(); i++) {
            DataEntry entry = dataRecord.get(i);
            GridCacheOperation op = entry.op();
            Integer cnt = operationsFound.get(op);
            operationsFound.put(op, cnt == null ? 1 : (cnt + 1));
            if (entry instanceof UnwrapDataEntry) {
                UnwrapDataEntry entry1 = (UnwrapDataEntry) entry;
                sb.append(entry1.op()).append(" for ").append(entry1.unwrappedKey());
                GridCacheVersion ver = entry.nearXidVersion();
                sb.append(", ");
                if (ver != null)
                    sb.append("tx=").append(ver).append(", ");
            }
        }
        sb.append("}\n");
    });
    final Integer deletesFound = operationsFound.get(DELETE);
    if (log.isInfoEnabled())
        log.info(sb.toString());
    assertTrue("Delete operations should be found in log: " + operationsFound, deletesFound != null && deletesFound > 0);
}
Also used : IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) IteratorParametersBuilder(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory.IteratorParametersBuilder) UnwrapDataEntry(org.apache.ignite.internal.pagemem.wal.record.UnwrapDataEntry) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DataEntry(org.apache.ignite.internal.pagemem.wal.record.DataEntry) MarshalledDataEntry(org.apache.ignite.internal.pagemem.wal.record.MarshalledDataEntry) UnwrappedDataEntry(org.apache.ignite.internal.pagemem.wal.record.UnwrappedDataEntry) UnwrapDataEntry(org.apache.ignite.internal.pagemem.wal.record.UnwrapDataEntry) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) Ignite(org.apache.ignite.Ignite) GridCacheOperation(org.apache.ignite.internal.processors.cache.GridCacheOperation) EnumMap(java.util.EnumMap)

Example 3 with IteratorParametersBuilder

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

the class IgniteWalReaderTest method testFillWalAndReadRecords.

/**
 * @throws Exception if failed.
 */
@Test
public void testFillWalAndReadRecords() throws Exception {
    setWalAndArchiveToSameVal = false;
    Ignite ignite0 = startGrid();
    ignite0.cluster().active(true);
    Serializable consistentId = (Serializable) ignite0.cluster().localNode().consistentId();
    String subfolderName = genNewStyleSubfolderName(0, (UUID) consistentId);
    int cacheObjectsToWrite = 10_000;
    putDummyRecords(ignite0, cacheObjectsToWrite);
    stopGrid();
    String workDir = U.defaultWorkDirectory();
    File db = U.resolveWorkDirectory(workDir, DFLT_STORE_DIR, false);
    IgniteWalIteratorFactory factory = new IgniteWalIteratorFactory(log);
    IteratorParametersBuilder params = createIteratorParametersBuilder(workDir, subfolderName).filesOrDirs(db);
    // Check iteratorArchiveDirectory and iteratorArchiveFiles are same.
    int cntArchiveDir = iterateAndCount(factory.iterator(params));
    log.info("Total records loaded using directory : " + cntArchiveDir);
    assertTrue(cntArchiveDir > 0);
    // Check iteratorArchiveFiles + iteratorWorkFiles iterate over all entries.
    int[] checkKeyIterArr = new int[cacheObjectsToWrite];
    fill(checkKeyIterArr, 0);
    iterateAndCountDataRecord(factory.iterator(params), (o1, o2) -> checkKeyIterArr[(Integer) o1]++, null);
    for (int i = 0; i < cacheObjectsToWrite; i++) assertTrue("Iterator didn't find key=" + i, checkKeyIterArr[i] > 0);
}
Also used : IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) Serializable(java.io.Serializable) IteratorParametersBuilder(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory.IteratorParametersBuilder) Ignite(org.apache.ignite.Ignite) File(java.io.File) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 4 with IteratorParametersBuilder

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

the class IgniteWalReaderTest method testIteratorWithCurrentKernelContext.

/**
 * Tests WAL iterator which uses shared cache context of currently started Ignite node.
 */
@Test
public void testIteratorWithCurrentKernelContext() throws Exception {
    IgniteEx ignite = startGrid(0);
    ignite.cluster().active(true);
    int cntEntries = 100;
    putDummyRecords(ignite, cntEntries);
    String workDir = U.defaultWorkDirectory();
    IgniteWalIteratorFactory factory = new IgniteWalIteratorFactory(log);
    IteratorParametersBuilder iterParametersBuilder = createIteratorParametersBuilder(workDir, genDbSubfolderName(ignite, 0)).filesOrDirs(workDir).binaryMetadataFileStoreDir(null).marshallerMappingFileStoreDir(null).sharedContext(ignite.context().cache().context());
    AtomicInteger cnt = new AtomicInteger();
    IgniteBiInClosure<Object, Object> objConsumer = (key, val) -> {
        if (val instanceof IndexedObject) {
            assertEquals(key, ((IndexedObject) val).iVal);
            assertEquals(key, cnt.getAndIncrement());
        }
    };
    iterateAndCountDataRecord(factory.iterator(iterParametersBuilder.copy()), objConsumer, null);
    assertEquals(cntEntries, cnt.get());
    // Test without converting non primary types.
    iterParametersBuilder.keepBinary(true);
    cnt.set(0);
    IgniteBiInClosure<Object, Object> binObjConsumer = (key, val) -> {
        if (val instanceof BinaryObject) {
            assertEquals(key, ((BinaryObject) val).field("iVal"));
            assertEquals(key, cnt.getAndIncrement());
        }
    };
    iterateAndCountDataRecord(factory.iterator(iterParametersBuilder.copy()), binObjConsumer, null);
    assertEquals(cntEntries, cnt.get());
}
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) BinaryObject(org.apache.ignite.binary.BinaryObject) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteEx(org.apache.ignite.internal.IgniteEx) IteratorParametersBuilder(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory.IteratorParametersBuilder) BinaryObject(org.apache.ignite.binary.BinaryObject) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 5 with IteratorParametersBuilder

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

the class IgniteWalReaderTest method testReadEmptyWal.

/**
 * Tests reading of empty WAL from non filled cluster.
 *
 * @throws Exception if failed.
 */
@Test
public void testReadEmptyWal() throws Exception {
    customWalMode = WALMode.FSYNC;
    Ignite ignite = startGrid();
    ignite.cluster().active(true);
    ignite.cluster().active(false);
    final String subfolderName = genDbSubfolderName(ignite, 0);
    stopGrid();
    String workDir = U.defaultWorkDirectory();
    IgniteWalIteratorFactory factory = new IgniteWalIteratorFactory(log);
    IteratorParametersBuilder iterParametersBuilder = createIteratorParametersBuilder(workDir, subfolderName).filesOrDirs(workDir);
    scanIterateAndCount(factory, iterParametersBuilder, 0, 0, null, null);
}
Also used : IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) IteratorParametersBuilder(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory.IteratorParametersBuilder) Ignite(org.apache.ignite.Ignite) 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