Search in sources :

Example 1 with UnwrapDataEntry

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);
}
Also used : IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) UnwrapDataEntry(org.apache.ignite.internal.pagemem.wal.record.UnwrapDataEntry) 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) Ignite(org.apache.ignite.Ignite) List(java.util.List) DataRecord(org.apache.ignite.internal.pagemem.wal.record.DataRecord) GridCacheOperation(org.apache.ignite.internal.processors.cache.GridCacheOperation) EnumMap(java.util.EnumMap)

Example 2 with UnwrapDataEntry

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;
}
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 3 with UnwrapDataEntry

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

Example 4 with UnwrapDataEntry

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);
}
Also used : IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) UnwrapDataEntry(org.apache.ignite.internal.pagemem.wal.record.UnwrapDataEntry) TreeMap(java.util.TreeMap) 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) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) Ignite(org.apache.ignite.Ignite) 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) GridCacheOperation(org.apache.ignite.internal.processors.cache.GridCacheOperation) EnumMap(java.util.EnumMap)

Aggregations

LazyDataEntry (org.apache.ignite.internal.pagemem.wal.record.LazyDataEntry)4 UnwrapDataEntry (org.apache.ignite.internal.pagemem.wal.record.UnwrapDataEntry)4 DataEntry (org.apache.ignite.internal.pagemem.wal.record.DataEntry)3 DataRecord (org.apache.ignite.internal.pagemem.wal.record.DataRecord)3 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)3 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)3 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)3 EnumMap (java.util.EnumMap)2 Ignite (org.apache.ignite.Ignite)2 BinaryObject (org.apache.ignite.binary.BinaryObject)2 GridCacheOperation (org.apache.ignite.internal.processors.cache.GridCacheOperation)2 IgniteWalIteratorFactory (org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory)2 File (java.io.File)1 HashMap (java.util.HashMap)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1 WALIterator (org.apache.ignite.internal.pagemem.wal.WALIterator)1 WALPointer (org.apache.ignite.internal.pagemem.wal.WALPointer)1 TxRecord (org.apache.ignite.internal.pagemem.wal.record.TxRecord)1 WALRecord (org.apache.ignite.internal.pagemem.wal.record.WALRecord)1