use of org.apache.ignite.internal.pagemem.wal.record.UnwrapDataEntry in project ignite by apache.
the class IgniteWalReaderTest method runRemoveOperationTest.
/**
* Test if DELETE operation can be found after mixed cache operations including remove().
*
* @throws Exception if failed.
* @param mode Cache Atomicity Mode.
*/
private void runRemoveOperationTest(CacheAtomicityMode mode) throws Exception {
final Ignite ignite = startGrid("node0");
ignite.active(true);
createCache2(ignite, mode);
ignite.active(false);
final String subfolderName = genDbSubfolderName(ignite, 0);
stopGrid("node0");
final String workDir = U.defaultWorkDirectory();
final IgniteWalIteratorFactory factory = createWalIteratorFactory(workDir, subfolderName);
final StringBuilder builder = new StringBuilder();
final Map<GridCacheOperation, Integer> operationsFound = new EnumMap<>(GridCacheOperation.class);
scanIterateAndCount(factory, workDir, subfolderName, 0, 0, null, new IgniteInClosure<DataRecord>() {
@Override
public void apply(DataRecord dataRecord) {
final List<DataEntry> entries = dataRecord.writeEntries();
builder.append("{");
for (DataEntry entry : entries) {
final GridCacheOperation op = entry.op();
final Integer cnt = operationsFound.get(op);
operationsFound.put(op, cnt == null ? 1 : (cnt + 1));
if (entry instanceof UnwrapDataEntry) {
final UnwrapDataEntry entry1 = (UnwrapDataEntry) entry;
builder.append(entry1.op()).append(" for ").append(entry1.unwrappedKey());
final GridCacheVersion ver = entry.nearXidVersion();
builder.append(", ");
if (ver != null)
builder.append("tx=").append(ver).append(", ");
}
}
builder.append("}\n");
}
});
final Integer deletesFound = operationsFound.get(DELETE);
if (log.isInfoEnabled())
log.info(builder.toString());
assertTrue("Delete operations should be found in log: " + operationsFound, deletesFound != null && deletesFound > 0);
}
use of org.apache.ignite.internal.pagemem.wal.record.UnwrapDataEntry 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;
}
use of org.apache.ignite.internal.pagemem.wal.record.UnwrapDataEntry 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);
}
use of org.apache.ignite.internal.pagemem.wal.record.UnwrapDataEntry in project ignite by apache.
the class IgniteWalReaderTest method testPutAllTxIntoTwoNodes.
/**
* Tests transaction generation and WAL for putAll cache operation.
* @throws Exception if failed.
*/
public void testPutAllTxIntoTwoNodes() throws Exception {
final Ignite ignite = startGrid("node0");
final Ignite ignite1 = startGrid(1);
ignite.active(true);
final Map<Object, IndexedObject> map = new TreeMap<>();
final int cntEntries = 1000;
for (int i = 0; i < cntEntries; i++) map.put(i, new IndexedObject(i));
ignite.cache(CACHE_NAME).putAll(map);
ignite.active(false);
final String subfolderName = genDbSubfolderName(ignite, 0);
final String subfolderName1 = genDbSubfolderName(ignite1, 1);
stopAllGrids();
final String workDir = U.defaultWorkDirectory();
final IgniteWalIteratorFactory factory = createWalIteratorFactory(workDir, subfolderName);
final StringBuilder builder = new StringBuilder();
final Map<GridCacheOperation, Integer> operationsFound = new EnumMap<>(GridCacheOperation.class);
final IgniteInClosure<DataRecord> drHnd = new IgniteInClosure<DataRecord>() {
@Override
public void apply(DataRecord dataRecord) {
final List<DataEntry> entries = dataRecord.writeEntries();
builder.append("{");
for (DataEntry entry : entries) {
final GridCacheOperation op = entry.op();
final Integer cnt = operationsFound.get(op);
operationsFound.put(op, cnt == null ? 1 : (cnt + 1));
if (entry instanceof UnwrapDataEntry) {
final UnwrapDataEntry entry1 = (UnwrapDataEntry) entry;
builder.append(entry1.op()).append(" for ").append(entry1.unwrappedKey());
final GridCacheVersion ver = entry.nearXidVersion();
builder.append(", ");
if (ver != null)
builder.append("tx=").append(ver).append(", ");
}
}
builder.append("}\n");
}
};
scanIterateAndCount(factory, workDir, subfolderName, 1, 1, null, drHnd);
scanIterateAndCount(factory, workDir, subfolderName1, 1, 1, null, drHnd);
final Integer createsFound = operationsFound.get(CREATE);
if (log.isInfoEnabled())
log.info(builder.toString());
assertTrue("Create operations should be found in log: " + operationsFound, createsFound != null && createsFound > 0);
assertTrue("Create operations count should be at least " + cntEntries + " in log: " + operationsFound, createsFound != null && createsFound >= cntEntries);
}
Aggregations