Search in sources :

Example 1 with LazyDataEntry

use of org.apache.ignite.internal.pagemem.wal.record.LazyDataEntry 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(final WALIterator walIter, @Nullable final IgniteBiInClosure<Object, Object> cacheObjHnd, @Nullable final IgniteInClosure<DataRecord> dataRecordHnd) throws IgniteCheckedException {
    final Map<GridCacheVersion, Integer> entriesUnderTxFound = new HashMap<>();
    try (WALIterator stIt = walIter) {
        while (stIt.hasNextX()) {
            final IgniteBiTuple<WALPointer, WALRecord> next = stIt.nextX();
            final WALRecord walRecord = next.get2();
            if (walRecord.type() == WALRecord.RecordType.DATA_RECORD && walRecord instanceof DataRecord) {
                final DataRecord dataRecord = (DataRecord) walRecord;
                if (dataRecordHnd != null)
                    dataRecordHnd.apply(dataRecord);
                final List<DataEntry> entries = dataRecord.writeEntries();
                for (DataEntry entry : entries) {
                    final GridCacheVersion globalTxId = entry.nearXidVersion();
                    Object unwrappedKeyObj;
                    Object unwrappedValObj;
                    if (entry instanceof UnwrapDataEntry) {
                        UnwrapDataEntry unwrapDataEntry = (UnwrapDataEntry) entry;
                        unwrappedKeyObj = unwrapDataEntry.unwrappedKey();
                        unwrappedValObj = unwrapDataEntry.unwrappedValue();
                    } else if (entry instanceof LazyDataEntry) {
                        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 (dumpRecords)
                        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);
                    final Integer entriesUnderTx = entriesUnderTxFound.get(globalTxId);
                    entriesUnderTxFound.put(globalTxId, entriesUnderTx == null ? 1 : entriesUnderTx + 1);
                }
            } else if (walRecord.type() == WALRecord.RecordType.TX_RECORD && walRecord instanceof TxRecord) {
                final TxRecord txRecord = (TxRecord) walRecord;
                final GridCacheVersion globalTxId = txRecord.nearXidVersion();
                if (dumpRecords)
                    log.info("//Tx Record, state: " + txRecord.state() + "; nearTxVersion" + globalTxId);
            }
        }
    }
    return entriesUnderTxFound;
}
Also used : WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) HashMap(java.util.HashMap) UnwrapDataEntry(org.apache.ignite.internal.pagemem.wal.record.UnwrapDataEntry) TxRecord(org.apache.ignite.internal.pagemem.wal.record.TxRecord) DataEntry(org.apache.ignite.internal.pagemem.wal.record.DataEntry) LazyDataEntry(org.apache.ignite.internal.pagemem.wal.record.LazyDataEntry) UnwrapDataEntry(org.apache.ignite.internal.pagemem.wal.record.UnwrapDataEntry) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) BinaryObject(org.apache.ignite.binary.BinaryObject) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) LazyDataEntry(org.apache.ignite.internal.pagemem.wal.record.LazyDataEntry) 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.pagemem.wal.WALPointer)

Example 2 with LazyDataEntry

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

the class RecordDataV1Serializer method readDataEntry.

/**
 * @param in Input to read from.
 * @return Read entry.
 */
DataEntry readDataEntry(ByteBufferBackedDataInput in) throws IOException, IgniteCheckedException {
    int cacheId = in.readInt();
    int keySize = in.readInt();
    byte keyType = in.readByte();
    byte[] keyBytes = new byte[keySize];
    in.readFully(keyBytes);
    int valSize = in.readInt();
    byte valType = 0;
    byte[] valBytes = null;
    if (valSize >= 0) {
        valType = in.readByte();
        valBytes = new byte[valSize];
        in.readFully(valBytes);
    }
    byte ord = in.readByte();
    GridCacheOperation op = GridCacheOperation.fromOrdinal(ord & 0xFF);
    GridCacheVersion nearXidVer = readVersion(in, true);
    GridCacheVersion writeVer = readVersion(in, false);
    int partId = in.readInt();
    long partCntr = in.readLong();
    long expireTime = in.readLong();
    GridCacheContext cacheCtx = cctx.cacheContext(cacheId);
    if (cacheCtx != null) {
        CacheObjectContext coCtx = cacheCtx.cacheObjectContext();
        KeyCacheObject key = co.toKeyCacheObject(coCtx, keyType, keyBytes);
        CacheObject val = valBytes != null ? co.toCacheObject(coCtx, valType, valBytes) : null;
        return new DataEntry(cacheId, key, val, op, nearXidVer, writeVer, expireTime, partId, partCntr);
    } else
        return new LazyDataEntry(cctx, cacheId, keyType, keyBytes, valType, valBytes, op, nearXidVer, writeVer, expireTime, partId, partCntr);
}
Also used : DataEntry(org.apache.ignite.internal.pagemem.wal.record.DataEntry) LazyDataEntry(org.apache.ignite.internal.pagemem.wal.record.LazyDataEntry) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) LazyDataEntry(org.apache.ignite.internal.pagemem.wal.record.LazyDataEntry) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) GridCacheOperation(org.apache.ignite.internal.processors.cache.GridCacheOperation) CacheObjectContext(org.apache.ignite.internal.processors.cache.CacheObjectContext) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 3 with LazyDataEntry

use of org.apache.ignite.internal.pagemem.wal.record.LazyDataEntry 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 {
    final KeyCacheObject key;
    final CacheObject val;
    final File marshallerMappingFileStoreDir = fakeCacheObjCtx.kernalContext().marshallerContext().getMarshallerMappingFileStoreDir();
    if (dataEntry instanceof LazyDataEntry) {
        final LazyDataEntry lazyDataEntry = (LazyDataEntry) 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 new UnwrapDataEntry(dataEntry.cacheId(), key, val, dataEntry.op(), dataEntry.nearXidVersion(), dataEntry.writeVersion(), dataEntry.expireTime(), dataEntry.partitionId(), dataEntry.partitionCounter(), fakeCacheObjCtx, keepBinary || marshallerMappingFileStoreDir == null);
}
Also used : LazyDataEntry(org.apache.ignite.internal.pagemem.wal.record.LazyDataEntry) UnwrapDataEntry(org.apache.ignite.internal.pagemem.wal.record.UnwrapDataEntry) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) File(java.io.File) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

LazyDataEntry (org.apache.ignite.internal.pagemem.wal.record.LazyDataEntry)3 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)3 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)3 DataEntry (org.apache.ignite.internal.pagemem.wal.record.DataEntry)2 UnwrapDataEntry (org.apache.ignite.internal.pagemem.wal.record.UnwrapDataEntry)2 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)2 File (java.io.File)1 HashMap (java.util.HashMap)1 BinaryObject (org.apache.ignite.binary.BinaryObject)1 WALIterator (org.apache.ignite.internal.pagemem.wal.WALIterator)1 WALPointer (org.apache.ignite.internal.pagemem.wal.WALPointer)1 DataRecord (org.apache.ignite.internal.pagemem.wal.record.DataRecord)1 TxRecord (org.apache.ignite.internal.pagemem.wal.record.TxRecord)1 WALRecord (org.apache.ignite.internal.pagemem.wal.record.WALRecord)1 CacheObjectContext (org.apache.ignite.internal.processors.cache.CacheObjectContext)1 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)1 GridCacheOperation (org.apache.ignite.internal.processors.cache.GridCacheOperation)1 NotNull (org.jetbrains.annotations.NotNull)1