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;
}
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);
}
Aggregations