Search in sources :

Example 1 with MarshalledDataEntry

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

the class IgniteWalReaderTest method iterateAndCountDataRecord.

/**
 * Iterates over data records, checks each DataRecord and its entries, finds out all transactions in WAL.
 *
 * @param walIter iterator to use.
 * @return count of data records observed for each global TX ID. Contains null for non tx updates.
 * @throws IgniteCheckedException if failure.
 */
private Map<GridCacheVersion, Integer> iterateAndCountDataRecord(WALIterator walIter, @Nullable IgniteBiInClosure<Object, Object> cacheObjHnd, @Nullable IgniteInClosure<DataRecord> dataRecordHnd) throws IgniteCheckedException {
    Map<GridCacheVersion, Integer> entriesUnderTxFound = new HashMap<>();
    try (WALIterator stIt = walIter) {
        while (stIt.hasNextX()) {
            IgniteBiTuple<WALPointer, WALRecord> tup = stIt.nextX();
            WALRecord walRecord = tup.get2();
            WALRecord.RecordType type = walRecord.type();
            // noinspection EnumSwitchStatementWhichMissesCases
            switch(type) {
                case DATA_RECORD_V2:
                // Fallthrough.
                case MVCC_DATA_RECORD:
                    {
                        assert walRecord instanceof DataRecord;
                        DataRecord dataRecord = (DataRecord) walRecord;
                        if (dataRecordHnd != null)
                            dataRecordHnd.apply(dataRecord);
                        for (int i = 0; i < dataRecord.entryCount(); i++) {
                            DataEntry entry = dataRecord.get(i);
                            if (walRecord.type() == DATA_RECORD_V2) {
                                assertEquals(primary, (entry.flags() & DataEntry.PRIMARY_FLAG) != 0);
                                assertEquals(rebalance, (entry.flags() & DataEntry.PRELOAD_FLAG) != 0);
                            }
                            GridCacheVersion globalTxId = entry.nearXidVersion();
                            Object unwrappedKeyObj;
                            Object unwrappedValObj;
                            if (entry instanceof UnwrappedDataEntry) {
                                UnwrappedDataEntry unwrapDataEntry = (UnwrappedDataEntry) entry;
                                unwrappedKeyObj = unwrapDataEntry.unwrappedKey();
                                unwrappedValObj = unwrapDataEntry.unwrappedValue();
                            } else if (entry instanceof MarshalledDataEntry) {
                                unwrappedKeyObj = null;
                                unwrappedValObj = null;
                            // can't check value
                            } else {
                                final CacheObject val = entry.value();
                                unwrappedValObj = val instanceof BinaryObject ? val : val.value(null, false);
                                final CacheObject key = entry.key();
                                unwrappedKeyObj = key instanceof BinaryObject ? key : key.value(null, false);
                            }
                            if (DUMP_RECORDS)
                                log.info("//Entry operation " + entry.op() + "; cache Id" + entry.cacheId() + "; " + "under transaction: " + globalTxId + // ; entry " + entry +
                                "; Key: " + unwrappedKeyObj + "; Value: " + unwrappedValObj);
                            if (cacheObjHnd != null && (unwrappedKeyObj != null || unwrappedValObj != null))
                                cacheObjHnd.apply(unwrappedKeyObj, unwrappedValObj);
                            Integer entriesUnderTx = entriesUnderTxFound.get(globalTxId);
                            entriesUnderTxFound.put(globalTxId, entriesUnderTx == null ? 1 : entriesUnderTx + 1);
                        }
                    }
                    break;
                case TX_RECORD:
                // Fallthrough
                case MVCC_TX_RECORD:
                    {
                        assert walRecord instanceof TxRecord;
                        TxRecord txRecord = (TxRecord) walRecord;
                        GridCacheVersion globalTxId = txRecord.nearXidVersion();
                        if (DUMP_RECORDS)
                            log.info("//Tx Record, state: " + txRecord.state() + "; nearTxVersion" + globalTxId);
                    }
            }
        }
    }
    return entriesUnderTxFound;
}
Also used : WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) MarshalledDataEntry(org.apache.ignite.internal.pagemem.wal.record.MarshalledDataEntry) HashMap(java.util.HashMap) TxRecord(org.apache.ignite.internal.pagemem.wal.record.TxRecord) 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) UnwrappedDataEntry(org.apache.ignite.internal.pagemem.wal.record.UnwrappedDataEntry) BinaryObject(org.apache.ignite.binary.BinaryObject) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) BinaryObject(org.apache.ignite.binary.BinaryObject) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) DataRecord(org.apache.ignite.internal.pagemem.wal.record.DataRecord) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)

Example 2 with MarshalledDataEntry

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

the class StandaloneWalRecordsIterator method postProcessDataEntry.

/**
 * Converts entry or lazy data entry into unwrapped entry
 *
 * @param processor cache object processor for de-serializing objects.
 * @param fakeCacheObjCtx cache object context for de-serializing binary and unwrapping objects.
 * @param dataEntry entry to process
 * @return post precessed entry
 * @throws IgniteCheckedException if failed
 */
@NotNull
private DataEntry postProcessDataEntry(final IgniteCacheObjectProcessor processor, final CacheObjectContext fakeCacheObjCtx, final DataEntry dataEntry) throws IgniteCheckedException {
    if (dataEntry instanceof EncryptedDataEntry)
        return dataEntry;
    final KeyCacheObject key;
    final CacheObject val;
    boolean keepBinary = this.keepBinary || !fakeCacheObjCtx.kernalContext().marshallerContext().initialized();
    if (dataEntry instanceof MarshalledDataEntry) {
        final MarshalledDataEntry lazyDataEntry = (MarshalledDataEntry) dataEntry;
        key = processor.toKeyCacheObject(fakeCacheObjCtx, lazyDataEntry.getKeyType(), lazyDataEntry.getKeyBytes());
        final byte type = lazyDataEntry.getValType();
        val = type == 0 ? null : processor.toCacheObject(fakeCacheObjCtx, type, lazyDataEntry.getValBytes());
    } else {
        key = dataEntry.key();
        val = dataEntry.value();
    }
    return unwrapDataEntry(fakeCacheObjCtx, dataEntry, key, val, keepBinary);
}
Also used : EncryptedDataEntry(org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordDataV1Serializer.EncryptedDataEntry) MarshalledDataEntry(org.apache.ignite.internal.pagemem.wal.record.MarshalledDataEntry) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

MarshalledDataEntry (org.apache.ignite.internal.pagemem.wal.record.MarshalledDataEntry)2 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)2 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)2 HashMap (java.util.HashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 BinaryObject (org.apache.ignite.binary.BinaryObject)1 WALIterator (org.apache.ignite.internal.pagemem.wal.WALIterator)1 DataEntry (org.apache.ignite.internal.pagemem.wal.record.DataEntry)1 DataRecord (org.apache.ignite.internal.pagemem.wal.record.DataRecord)1 TxRecord (org.apache.ignite.internal.pagemem.wal.record.TxRecord)1 UnwrapDataEntry (org.apache.ignite.internal.pagemem.wal.record.UnwrapDataEntry)1 UnwrappedDataEntry (org.apache.ignite.internal.pagemem.wal.record.UnwrappedDataEntry)1 WALRecord (org.apache.ignite.internal.pagemem.wal.record.WALRecord)1 WALPointer (org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)1 EncryptedDataEntry (org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordDataV1Serializer.EncryptedDataEntry)1 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)1 NotNull (org.jetbrains.annotations.NotNull)1