Search in sources :

Example 36 with DataEntry

use of org.apache.ignite.internal.pagemem.wal.record.DataEntry in project ignite by apache.

the class IgniteWalReaderTest method testPrimaryFlagOnTwoNodes.

/**
 * Tests transaction generation and WAL for putAll cache operation.
 *
 * @throws Exception if failed.
 */
@Test
public void testPrimaryFlagOnTwoNodes() throws Exception {
    backupCnt = 1;
    IgniteEx ignite = startGrid("node0");
    Ignite ignite1 = startGrid(1);
    ignite.cluster().state(ACTIVE);
    IgniteCache<Integer, IndexedObject> cache = ignite.cache(CACHE_NAME);
    backupCnt = 0;
    int cntEntries = 100;
    List<Integer> keys = findKeys(ignite.localNode(), cache, cntEntries, 0, 0);
    Map<Integer, IndexedObject> map = new TreeMap<>();
    for (Integer key : keys) map.putIfAbsent(key, new IndexedObject(key));
    cache.putAll(map);
    ignite.cluster().active(false);
    String subfolderName1 = genDbSubfolderName(ignite, 0);
    String subfolderName2 = genDbSubfolderName(ignite1, 1);
    stopAllGrids();
    String workDir = U.defaultWorkDirectory();
    IgniteWalIteratorFactory factory = new IgniteWalIteratorFactory(log);
    Map<GridCacheOperation, Integer> operationsFound = new EnumMap<>(GridCacheOperation.class);
    IgniteInClosure<DataRecord> drHnd = dataRecord -> {
        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));
        }
    };
    scanIterateAndCount(factory, createIteratorParametersBuilder(workDir, subfolderName1).filesOrDirs(workDir + "/db/wal/" + subfolderName1, workDir + "/db/wal/archive/" + subfolderName1), 1, 1, null, drHnd);
    primary = false;
    scanIterateAndCount(factory, createIteratorParametersBuilder(workDir, subfolderName2).filesOrDirs(workDir + "/db/wal/" + subfolderName2, workDir + "/db/wal/archive/" + subfolderName2), 1, 1, null, drHnd);
}
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) TreeMap(java.util.TreeMap) 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) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) DataRecord(org.apache.ignite.internal.pagemem.wal.record.DataRecord) GridCacheOperation(org.apache.ignite.internal.processors.cache.GridCacheOperation) EnumMap(java.util.EnumMap) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 37 with DataEntry

use of org.apache.ignite.internal.pagemem.wal.record.DataEntry in project ignite by apache.

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();
            WALPointer ptr = 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.corruptWalSegmentFile(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) 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) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) File(java.io.File) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 38 with DataEntry

use of org.apache.ignite.internal.pagemem.wal.record.DataEntry in project ignite by apache.

the class TxPartitionCounterStateConsistencyTest method checkWAL.

/**
 * @param ig Ignite instance.
 * @param ops Ops queue.
 * @param exp Expected updates.
 */
private void checkWAL(IgniteEx ig, Queue<T2<Integer, GridCacheOperation>> ops, int exp) throws IgniteCheckedException {
    WALIterator iter = walIterator(ig);
    long cntr = 0;
    while (iter.hasNext()) {
        IgniteBiTuple<WALPointer, WALRecord> tup = iter.next();
        if (tup.get2() instanceof DataRecord) {
            T2<Integer, GridCacheOperation> op = ops.poll();
            DataRecord rec = (DataRecord) tup.get2();
            assertEquals(1, rec.entryCount());
            DataEntry entry = rec.get(0);
            assertEquals(op.get1(), entry.key().value(internalCache(ig, DEFAULT_CACHE_NAME).context().cacheObjectContext(), false));
            assertEquals(op.get2(), entry.op());
            assertEquals(entry.partitionCounter(), ++cntr);
        }
    }
    assertEquals(exp, cntr);
    assertTrue(ops.isEmpty());
}
Also used : WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) 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) GridCacheOperation(org.apache.ignite.internal.processors.cache.GridCacheOperation) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)

Example 39 with DataEntry

use of org.apache.ignite.internal.pagemem.wal.record.DataEntry in project ignite by apache.

the class WalStat method registerDataRecord.

/**
 * @param record data record to handle.
 */
private void registerDataRecord(DataRecord record) {
    int entryCnt = record.entryCount();
    if (entryCnt != 0) {
        boolean underTx = false;
        for (int i = 0; i < entryCnt; i++) {
            DataEntry next = record.get(i);
            final int size = entryCnt > 1 ? -1 : record.size();
            incrementStat(next.op().toString(), dataEntryOperation, size);
            incrementStat(next.cacheId(), dataEntryCacheId, size);
            txStat.onDataEntry(next);
            underTx |= next.nearXidVersion() != null;
        }
        incrementStat(underTx, record, dataRecordUnderTx);
    }
    incrementStat(entryCnt, record, dataRecordEntriesCnt);
}
Also used : DataEntry(org.apache.ignite.internal.pagemem.wal.record.DataEntry)

Example 40 with DataEntry

use of org.apache.ignite.internal.pagemem.wal.record.DataEntry in project ignite by apache.

the class IgniteWalConverterSensitiveDataTest method withSensitiveData.

/**
 * Creating {@link WALRecord} instances with sensitive data.
 *
 * @return {@link WALRecord} instances with sensitive data.
 */
private Collection<WALRecord> withSensitiveData() {
    List<WALRecord> walRecords = new ArrayList<>();
    int cacheId = CU.cacheId(DEFAULT_CACHE_NAME);
    DataEntry dataEntry = new DataEntry(cacheId, new KeyCacheObjectImpl(SENSITIVE_DATA_VALUE_PREFIX, null, 0), new CacheObjectImpl(SENSITIVE_DATA_VALUE_PREFIX, null), GridCacheOperation.CREATE, new GridCacheVersion(), new GridCacheVersion(), 0, 0, 0, DataEntry.EMPTY_FLAGS);
    byte[] sensitiveDataBytes = SENSITIVE_DATA_VALUE_PREFIX.getBytes(StandardCharsets.UTF_8);
    walRecords.add(new DataRecord(dataEntry));
    walRecords.add(new MetastoreDataRecord(SENSITIVE_DATA_VALUE_PREFIX, sensitiveDataBytes));
    return walRecords;
}
Also used : WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) DataEntry(org.apache.ignite.internal.pagemem.wal.record.DataEntry) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) MetastoreDataRecord(org.apache.ignite.internal.pagemem.wal.record.MetastoreDataRecord) ArrayList(java.util.ArrayList) KeyCacheObjectImpl(org.apache.ignite.internal.processors.cache.KeyCacheObjectImpl) CacheObjectImpl(org.apache.ignite.internal.processors.cache.CacheObjectImpl) MetastoreDataRecord(org.apache.ignite.internal.pagemem.wal.record.MetastoreDataRecord) DataRecord(org.apache.ignite.internal.pagemem.wal.record.DataRecord) KeyCacheObjectImpl(org.apache.ignite.internal.processors.cache.KeyCacheObjectImpl)

Aggregations

DataEntry (org.apache.ignite.internal.pagemem.wal.record.DataEntry)40 DataRecord (org.apache.ignite.internal.pagemem.wal.record.DataRecord)30 WALRecord (org.apache.ignite.internal.pagemem.wal.record.WALRecord)19 WALPointer (org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)19 ArrayList (java.util.ArrayList)15 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)14 UUID (java.util.UUID)13 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)13 MvccDataEntry (org.apache.ignite.internal.pagemem.wal.record.MvccDataEntry)12 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)12 GridCacheOperation (org.apache.ignite.internal.processors.cache.GridCacheOperation)12 WALIterator (org.apache.ignite.internal.pagemem.wal.WALIterator)11 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)10 CheckpointRecord (org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord)9 IgniteEx (org.apache.ignite.internal.IgniteEx)8 MetastoreDataRecord (org.apache.ignite.internal.pagemem.wal.record.MetastoreDataRecord)8 UnwrapDataEntry (org.apache.ignite.internal.pagemem.wal.record.UnwrapDataEntry)8 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 MarshalledDataEntry (org.apache.ignite.internal.pagemem.wal.record.MarshalledDataEntry)7