Search in sources :

Example 1 with WALRecord

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

the class IgnitePdsCheckpointSimulationWithRealCpDisabledTest method testGetForInitialWrite.

/**
 * @throws Exception if failed.
 */
public void testGetForInitialWrite() throws Exception {
    IgniteEx ig = startGrid(0);
    ig.active(true);
    GridCacheSharedContext<Object, Object> shared = ig.context().cache().context();
    int cacheId = shared.cache().cache(cacheName).context().cacheId();
    GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) shared.database();
    // Disable integrated checkpoint thread.
    dbMgr.enableCheckpoints(false);
    PageMemory mem = shared.database().dataRegion(null).pageMemory();
    IgniteWriteAheadLogManager wal = shared.wal();
    WALPointer start = wal.log(new CheckpointRecord(null));
    final FullPageId[] initWrites = new FullPageId[10];
    ig.context().cache().context().database().checkpointReadLock();
    try {
        for (int i = 0; i < initWrites.length; i++) initWrites[i] = new FullPageId(mem.allocatePage(cacheId, 0, PageIdAllocator.FLAG_DATA), cacheId);
        // Check getForInitialWrite methods.
        for (FullPageId fullId : initWrites) {
            long page = mem.acquirePage(fullId.groupId(), fullId.pageId());
            try {
                long pageAddr = mem.writeLock(fullId.groupId(), fullId.pageId(), page);
                try {
                    DataPageIO.VERSIONS.latest().initNewPage(pageAddr, fullId.pageId(), mem.pageSize());
                    for (int i = PageIO.COMMON_HEADER_END + DataPageIO.ITEMS_OFF; i < mem.pageSize(); i++) PageUtils.putByte(pageAddr, i, (byte) 0xAB);
                    PageIO.printPage(pageAddr, mem.pageSize());
                } finally {
                    mem.writeUnlock(fullId.groupId(), fullId.pageId(), page, null, true);
                }
            } finally {
                mem.releasePage(fullId.groupId(), fullId.pageId(), page);
            }
        }
        wal.fsync(null);
    } finally {
        ig.context().cache().context().database().checkpointReadUnlock();
        stopAllGrids(false);
    }
    ig = startGrid(0);
    ig.active(true);
    shared = ig.context().cache().context();
    dbMgr = (GridCacheDatabaseSharedManager) shared.database();
    dbMgr.enableCheckpoints(false);
    wal = shared.wal();
    try (PartitionMetaStateRecordExcludeIterator it = new PartitionMetaStateRecordExcludeIterator(wal.replay(start))) {
        it.next();
        for (FullPageId initialWrite : initWrites) {
            IgniteBiTuple<WALPointer, WALRecord> tup = it.next();
            assertTrue(String.valueOf(tup.get2()), tup.get2() instanceof PageSnapshot);
            PageSnapshot snap = (PageSnapshot) tup.get2();
            FullPageId actual = snap.fullPageId();
            // there are extra tracking pages, skip them
            if (TrackingPageIO.VERSIONS.latest().trackingPageFor(actual.pageId(), mem.pageSize()) == actual.pageId()) {
                tup = it.next();
                assertTrue(tup.get2() instanceof PageSnapshot);
                actual = ((PageSnapshot) tup.get2()).fullPageId();
            }
            assertEquals(initialWrite, actual);
        }
    }
}
Also used : WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) CheckpointRecord(org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord) IgniteEx(org.apache.ignite.internal.IgniteEx) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) WALPointer(org.apache.ignite.internal.pagemem.wal.WALPointer) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) PageSnapshot(org.apache.ignite.internal.pagemem.wal.record.PageSnapshot)

Example 2 with WALRecord

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

the class IgniteWalSerializerVersionTest method testCheckDifferentSerializerVersionsAndLogTimestamp.

/**
 * @throws Exception If failed.
 */
public void testCheckDifferentSerializerVersionsAndLogTimestamp() throws Exception {
    IgniteCallable<List<WALRecord>> recordsFactory = new IgniteCallable<List<WALRecord>>() {

        @Override
        public List<WALRecord> call() throws Exception {
            WALRecord rec0 = new DataRecord(Collections.<DataEntry>emptyList());
            WALRecord rec1 = new TxRecord(PREPARED, null, null, null);
            return Arrays.asList(rec0, rec1);
        }
    };
    long time0 = U.currentTimeMillis();
    check(new Checker(1, RecordV1Serializer.class, recordsFactory, Arrays.asList(0L, time0)));
    long time1 = U.currentTimeMillis();
    check(new Checker(2, RecordV2Serializer.class, recordsFactory, Arrays.asList(time1, time1)));
}
Also used : WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) RecordV1Serializer(org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordV1Serializer) IgniteCallable(org.apache.ignite.lang.IgniteCallable) List(java.util.List) DataRecord(org.apache.ignite.internal.pagemem.wal.record.DataRecord) TxRecord(org.apache.ignite.internal.pagemem.wal.record.TxRecord) RecordV2Serializer(org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordV2Serializer)

Example 3 with WALRecord

use of org.apache.ignite.internal.pagemem.wal.record.WALRecord 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 4 with WALRecord

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

the class RecordDataV1Serializer method readRecord.

/**
 * {@inheritDoc}
 */
@Override
public WALRecord readRecord(WALRecord.RecordType type, ByteBufferBackedDataInput in) throws IOException, IgniteCheckedException {
    WALRecord res;
    switch(type) {
        case PAGE_RECORD:
            byte[] arr = new byte[pageSize];
            int cacheId = in.readInt();
            long pageId = in.readLong();
            in.readFully(arr);
            res = new PageSnapshot(new FullPageId(pageId, cacheId), arr);
            break;
        case CHECKPOINT_RECORD:
            long msb = in.readLong();
            long lsb = in.readLong();
            boolean hasPtr = in.readByte() != 0;
            int idx = hasPtr ? in.readInt() : 0;
            int off = hasPtr ? in.readInt() : 0;
            int len = hasPtr ? in.readInt() : 0;
            Map<Integer, CacheState> states = readPartitionStates(in);
            boolean end = in.readByte() != 0;
            FileWALPointer walPtr = hasPtr ? new FileWALPointer(idx, off, len) : null;
            CheckpointRecord cpRec = new CheckpointRecord(new UUID(msb, lsb), walPtr, end);
            cpRec.cacheGroupStates(states);
            res = cpRec;
            break;
        case META_PAGE_INIT:
            cacheId = in.readInt();
            pageId = in.readLong();
            int ioType = in.readUnsignedShort();
            int ioVer = in.readUnsignedShort();
            long treeRoot = in.readLong();
            long reuseListRoot = in.readLong();
            res = new MetaPageInitRecord(cacheId, pageId, ioType, ioVer, treeRoot, reuseListRoot);
            break;
        case PARTITION_META_PAGE_UPDATE_COUNTERS:
            cacheId = in.readInt();
            pageId = in.readLong();
            long updCntr = in.readLong();
            long rmvId = in.readLong();
            int partSize = in.readInt();
            long countersPageId = in.readLong();
            byte state = in.readByte();
            int allocatedIdxCandidate = in.readInt();
            res = new MetaPageUpdatePartitionDataRecord(cacheId, pageId, updCntr, rmvId, partSize, countersPageId, state, allocatedIdxCandidate);
            break;
        case MEMORY_RECOVERY:
            long ts = in.readLong();
            res = new MemoryRecoveryRecord(ts);
            break;
        case PARTITION_DESTROY:
            cacheId = in.readInt();
            int partId = in.readInt();
            res = new PartitionDestroyRecord(cacheId, partId);
            break;
        case DATA_RECORD:
            int entryCnt = in.readInt();
            List<DataEntry> entries = new ArrayList<>(entryCnt);
            for (int i = 0; i < entryCnt; i++) entries.add(readDataEntry(in));
            res = new DataRecord(entries, 0L);
            break;
        case METASTORE_DATA_RECORD:
            int strLen = in.readInt();
            byte[] strBytes = new byte[strLen];
            in.readFully(strBytes);
            String key = new String(strBytes);
            int valLen = in.readInt();
            assert valLen >= 0;
            byte[] val;
            if (valLen > 0) {
                val = new byte[valLen];
                in.readFully(val);
            } else
                val = null;
            return new MetastoreDataRecord(key, val);
        case HEADER_RECORD:
            long magic = in.readLong();
            if (magic != HeaderRecord.REGULAR_MAGIC && magic != HeaderRecord.COMPACTED_MAGIC)
                throw new EOFException("Magic is corrupted [actual=" + U.hexLong(magic) + ']');
            int ver = in.readInt();
            res = new HeaderRecord(ver);
            break;
        case DATA_PAGE_INSERT_RECORD:
            {
                cacheId = in.readInt();
                pageId = in.readLong();
                int size = in.readUnsignedShort();
                in.ensure(size);
                byte[] payload = new byte[size];
                in.readFully(payload);
                res = new DataPageInsertRecord(cacheId, pageId, payload);
                break;
            }
        case DATA_PAGE_UPDATE_RECORD:
            {
                cacheId = in.readInt();
                pageId = in.readLong();
                int itemId = in.readInt();
                int size = in.readUnsignedShort();
                in.ensure(size);
                byte[] payload = new byte[size];
                in.readFully(payload);
                res = new DataPageUpdateRecord(cacheId, pageId, itemId, payload);
                break;
            }
        case DATA_PAGE_INSERT_FRAGMENT_RECORD:
            {
                cacheId = in.readInt();
                pageId = in.readLong();
                final long lastLink = in.readLong();
                final int payloadSize = in.readInt();
                final byte[] payload = new byte[payloadSize];
                in.readFully(payload);
                res = new DataPageInsertFragmentRecord(cacheId, pageId, payload, lastLink);
                break;
            }
        case DATA_PAGE_REMOVE_RECORD:
            cacheId = in.readInt();
            pageId = in.readLong();
            int itemId = in.readUnsignedByte();
            res = new DataPageRemoveRecord(cacheId, pageId, itemId);
            break;
        case DATA_PAGE_SET_FREE_LIST_PAGE:
            cacheId = in.readInt();
            pageId = in.readLong();
            long freeListPage = in.readLong();
            res = new DataPageSetFreeListPageRecord(cacheId, pageId, freeListPage);
            break;
        case INIT_NEW_PAGE_RECORD:
            cacheId = in.readInt();
            pageId = in.readLong();
            ioType = in.readUnsignedShort();
            ioVer = in.readUnsignedShort();
            long virtualPageId = in.readLong();
            res = new InitNewPageRecord(cacheId, pageId, ioType, ioVer, virtualPageId);
            break;
        case BTREE_META_PAGE_INIT_ROOT:
            cacheId = in.readInt();
            pageId = in.readLong();
            long rootId = in.readLong();
            res = new MetaPageInitRootRecord(cacheId, pageId, rootId);
            break;
        case BTREE_META_PAGE_INIT_ROOT2:
            cacheId = in.readInt();
            pageId = in.readLong();
            long rootId2 = in.readLong();
            int inlineSize = in.readShort();
            res = new MetaPageInitRootInlineRecord(cacheId, pageId, rootId2, inlineSize);
            break;
        case BTREE_META_PAGE_ADD_ROOT:
            cacheId = in.readInt();
            pageId = in.readLong();
            rootId = in.readLong();
            res = new MetaPageAddRootRecord(cacheId, pageId, rootId);
            break;
        case BTREE_META_PAGE_CUT_ROOT:
            cacheId = in.readInt();
            pageId = in.readLong();
            res = new MetaPageCutRootRecord(cacheId, pageId);
            break;
        case BTREE_INIT_NEW_ROOT:
            cacheId = in.readInt();
            pageId = in.readLong();
            rootId = in.readLong();
            ioType = in.readUnsignedShort();
            ioVer = in.readUnsignedShort();
            long leftId = in.readLong();
            long rightId = in.readLong();
            BPlusIO<?> io = BPlusIO.getBPlusIO(ioType, ioVer);
            byte[] rowBytes = new byte[io.getItemSize()];
            in.readFully(rowBytes);
            res = new NewRootInitRecord<>(cacheId, pageId, rootId, (BPlusInnerIO<?>) io, leftId, rowBytes, rightId);
            break;
        case BTREE_PAGE_RECYCLE:
            cacheId = in.readInt();
            pageId = in.readLong();
            long newPageId = in.readLong();
            res = new RecycleRecord(cacheId, pageId, newPageId);
            break;
        case BTREE_PAGE_INSERT:
            cacheId = in.readInt();
            pageId = in.readLong();
            ioType = in.readUnsignedShort();
            ioVer = in.readUnsignedShort();
            int itemIdx = in.readUnsignedShort();
            rightId = in.readLong();
            io = BPlusIO.getBPlusIO(ioType, ioVer);
            rowBytes = new byte[io.getItemSize()];
            in.readFully(rowBytes);
            res = new InsertRecord<>(cacheId, pageId, io, itemIdx, rowBytes, rightId);
            break;
        case BTREE_FIX_LEFTMOST_CHILD:
            cacheId = in.readInt();
            pageId = in.readLong();
            rightId = in.readLong();
            res = new FixLeftmostChildRecord(cacheId, pageId, rightId);
            break;
        case BTREE_FIX_COUNT:
            cacheId = in.readInt();
            pageId = in.readLong();
            int cnt = in.readUnsignedShort();
            res = new FixCountRecord(cacheId, pageId, cnt);
            break;
        case BTREE_PAGE_REPLACE:
            cacheId = in.readInt();
            pageId = in.readLong();
            ioType = in.readUnsignedShort();
            ioVer = in.readUnsignedShort();
            itemIdx = in.readUnsignedShort();
            io = BPlusIO.getBPlusIO(ioType, ioVer);
            rowBytes = new byte[io.getItemSize()];
            in.readFully(rowBytes);
            res = new ReplaceRecord<>(cacheId, pageId, io, rowBytes, itemIdx);
            break;
        case BTREE_PAGE_REMOVE:
            cacheId = in.readInt();
            pageId = in.readLong();
            itemIdx = in.readUnsignedShort();
            cnt = in.readUnsignedShort();
            res = new RemoveRecord(cacheId, pageId, itemIdx, cnt);
            break;
        case BTREE_PAGE_INNER_REPLACE:
            cacheId = in.readInt();
            pageId = in.readLong();
            int dstIdx = in.readUnsignedShort();
            long srcPageId = in.readLong();
            int srcIdx = in.readUnsignedShort();
            rmvId = in.readLong();
            res = new InnerReplaceRecord<>(cacheId, pageId, dstIdx, srcPageId, srcIdx, rmvId);
            break;
        case BTREE_FORWARD_PAGE_SPLIT:
            cacheId = in.readInt();
            pageId = in.readLong();
            long fwdId = in.readLong();
            ioType = in.readUnsignedShort();
            ioVer = in.readUnsignedShort();
            srcPageId = in.readLong();
            int mid = in.readUnsignedShort();
            cnt = in.readUnsignedShort();
            res = new SplitForwardPageRecord(cacheId, pageId, fwdId, ioType, ioVer, srcPageId, mid, cnt);
            break;
        case BTREE_EXISTING_PAGE_SPLIT:
            cacheId = in.readInt();
            pageId = in.readLong();
            mid = in.readUnsignedShort();
            fwdId = in.readLong();
            res = new SplitExistingPageRecord(cacheId, pageId, mid, fwdId);
            break;
        case BTREE_PAGE_MERGE:
            cacheId = in.readInt();
            pageId = in.readLong();
            long prntId = in.readLong();
            int prntIdx = in.readUnsignedShort();
            rightId = in.readLong();
            boolean emptyBranch = in.readBoolean();
            res = new MergeRecord<>(cacheId, pageId, prntId, prntIdx, rightId, emptyBranch);
            break;
        case BTREE_FIX_REMOVE_ID:
            cacheId = in.readInt();
            pageId = in.readLong();
            rmvId = in.readLong();
            res = new FixRemoveId(cacheId, pageId, rmvId);
            break;
        case PAGES_LIST_SET_NEXT:
            cacheId = in.readInt();
            pageId = in.readLong();
            long nextPageId = in.readLong();
            res = new PagesListSetNextRecord(cacheId, pageId, nextPageId);
            break;
        case PAGES_LIST_SET_PREVIOUS:
            cacheId = in.readInt();
            pageId = in.readLong();
            long prevPageId = in.readLong();
            res = new PagesListSetPreviousRecord(cacheId, pageId, prevPageId);
            break;
        case PAGES_LIST_INIT_NEW_PAGE:
            cacheId = in.readInt();
            pageId = in.readLong();
            ioType = in.readInt();
            ioVer = in.readInt();
            newPageId = in.readLong();
            prevPageId = in.readLong();
            long addDataPageId = in.readLong();
            res = new PagesListInitNewPageRecord(cacheId, pageId, ioType, ioVer, newPageId, prevPageId, addDataPageId);
            break;
        case PAGES_LIST_ADD_PAGE:
            cacheId = in.readInt();
            pageId = in.readLong();
            long dataPageId = in.readLong();
            res = new PagesListAddPageRecord(cacheId, pageId, dataPageId);
            break;
        case PAGES_LIST_REMOVE_PAGE:
            cacheId = in.readInt();
            pageId = in.readLong();
            long rmvdPageId = in.readLong();
            res = new PagesListRemovePageRecord(cacheId, pageId, rmvdPageId);
            break;
        case TRACKING_PAGE_DELTA:
            cacheId = in.readInt();
            pageId = in.readLong();
            long pageIdToMark = in.readLong();
            long nextSnapshotId0 = in.readLong();
            long lastSuccessfulSnapshotId0 = in.readLong();
            res = new TrackingPageDeltaRecord(cacheId, pageId, pageIdToMark, nextSnapshotId0, lastSuccessfulSnapshotId0);
            break;
        case META_PAGE_UPDATE_NEXT_SNAPSHOT_ID:
            cacheId = in.readInt();
            pageId = in.readLong();
            long nextSnapshotId = in.readLong();
            res = new MetaPageUpdateNextSnapshotId(cacheId, pageId, nextSnapshotId);
            break;
        case META_PAGE_UPDATE_LAST_SUCCESSFUL_FULL_SNAPSHOT_ID:
            cacheId = in.readInt();
            pageId = in.readLong();
            long lastSuccessfulFullSnapshotId = in.readLong();
            res = new MetaPageUpdateLastSuccessfulFullSnapshotId(cacheId, pageId, lastSuccessfulFullSnapshotId);
            break;
        case META_PAGE_UPDATE_LAST_SUCCESSFUL_SNAPSHOT_ID:
            cacheId = in.readInt();
            pageId = in.readLong();
            long lastSuccessfulSnapshotId = in.readLong();
            long lastSuccessfulSnapshotTag = in.readLong();
            res = new MetaPageUpdateLastSuccessfulSnapshotId(cacheId, pageId, lastSuccessfulSnapshotId, lastSuccessfulSnapshotTag);
            break;
        case META_PAGE_UPDATE_LAST_ALLOCATED_INDEX:
            cacheId = in.readInt();
            pageId = in.readLong();
            int lastAllocatedIdx = in.readInt();
            res = new MetaPageUpdateLastAllocatedIndex(cacheId, pageId, lastAllocatedIdx);
            break;
        case PART_META_UPDATE_STATE:
            cacheId = in.readInt();
            partId = in.readInt();
            state = in.readByte();
            long updateCntr = in.readLong();
            GridDhtPartitionState partState = GridDhtPartitionState.fromOrdinal(state);
            res = new PartitionMetaStateRecord(cacheId, partId, partState, updateCntr);
            break;
        case PAGE_LIST_META_RESET_COUNT_RECORD:
            cacheId = in.readInt();
            pageId = in.readLong();
            res = new PageListMetaResetCountRecord(cacheId, pageId);
            break;
        case SWITCH_SEGMENT_RECORD:
            throw new EOFException("END OF SEGMENT");
        case TX_RECORD:
            res = txRecordSerializer.read(in);
            break;
        default:
            throw new UnsupportedOperationException("Type: " + type);
    }
    return res;
}
Also used : PagesListSetPreviousRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PagesListSetPreviousRecord) DataPageRemoveRecord(org.apache.ignite.internal.pagemem.wal.record.delta.DataPageRemoveRecord) ArrayList(java.util.ArrayList) RecycleRecord(org.apache.ignite.internal.pagemem.wal.record.delta.RecycleRecord) MetaPageInitRecord(org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageInitRecord) MetaPageUpdateLastSuccessfulFullSnapshotId(org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdateLastSuccessfulFullSnapshotId) FixLeftmostChildRecord(org.apache.ignite.internal.pagemem.wal.record.delta.FixLeftmostChildRecord) DataEntry(org.apache.ignite.internal.pagemem.wal.record.DataEntry) LazyDataEntry(org.apache.ignite.internal.pagemem.wal.record.LazyDataEntry) SplitForwardPageRecord(org.apache.ignite.internal.pagemem.wal.record.delta.SplitForwardPageRecord) HeaderRecord(org.apache.ignite.internal.processors.cache.persistence.wal.record.HeaderRecord) PagesListAddPageRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PagesListAddPageRecord) EOFException(java.io.EOFException) MetaPageUpdateNextSnapshotId(org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdateNextSnapshotId) UUID(java.util.UUID) PageSnapshot(org.apache.ignite.internal.pagemem.wal.record.PageSnapshot) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer) DataPageSetFreeListPageRecord(org.apache.ignite.internal.pagemem.wal.record.delta.DataPageSetFreeListPageRecord) MetaPageUpdateLastAllocatedIndex(org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdateLastAllocatedIndex) PartitionMetaStateRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PartitionMetaStateRecord) BPlusInnerIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusInnerIO) MetaPageCutRootRecord(org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageCutRootRecord) CacheState(org.apache.ignite.internal.pagemem.wal.record.CacheState) MetaPageAddRootRecord(org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageAddRootRecord) MetaPageInitRootInlineRecord(org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageInitRootInlineRecord) MetastoreDataRecord(org.apache.ignite.internal.pagemem.wal.record.MetastoreDataRecord) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState) WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) DataPageUpdateRecord(org.apache.ignite.internal.pagemem.wal.record.delta.DataPageUpdateRecord) PageListMetaResetCountRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PageListMetaResetCountRecord) PagesListRemovePageRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PagesListRemovePageRecord) TrackingPageDeltaRecord(org.apache.ignite.internal.pagemem.wal.record.delta.TrackingPageDeltaRecord) RemoveRecord(org.apache.ignite.internal.pagemem.wal.record.delta.RemoveRecord) DataPageRemoveRecord(org.apache.ignite.internal.pagemem.wal.record.delta.DataPageRemoveRecord) MemoryRecoveryRecord(org.apache.ignite.internal.pagemem.wal.record.MemoryRecoveryRecord) FixRemoveId(org.apache.ignite.internal.pagemem.wal.record.delta.FixRemoveId) PartitionDestroyRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PartitionDestroyRecord) PagesListInitNewPageRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PagesListInitNewPageRecord) InitNewPageRecord(org.apache.ignite.internal.pagemem.wal.record.delta.InitNewPageRecord) MetaPageUpdatePartitionDataRecord(org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdatePartitionDataRecord) MetaPageUpdateLastSuccessfulSnapshotId(org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdateLastSuccessfulSnapshotId) DataRecord(org.apache.ignite.internal.pagemem.wal.record.DataRecord) MetastoreDataRecord(org.apache.ignite.internal.pagemem.wal.record.MetastoreDataRecord) MetaPageUpdatePartitionDataRecord(org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdatePartitionDataRecord) DataPageInsertRecord(org.apache.ignite.internal.pagemem.wal.record.delta.DataPageInsertRecord) PagesListInitNewPageRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PagesListInitNewPageRecord) SplitExistingPageRecord(org.apache.ignite.internal.pagemem.wal.record.delta.SplitExistingPageRecord) DataPageInsertFragmentRecord(org.apache.ignite.internal.pagemem.wal.record.delta.DataPageInsertFragmentRecord) PagesListSetNextRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PagesListSetNextRecord) CheckpointRecord(org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord) FixCountRecord(org.apache.ignite.internal.pagemem.wal.record.delta.FixCountRecord) MetaPageInitRootRecord(org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageInitRootRecord)

Example 5 with WALRecord

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

the class RecordV1Serializer method readWithCrc.

/**
 * Reads record from file {@code in0} and validates CRC of record.
 *
 * @param in0 File input.
 * @param expPtr Expected WAL pointer for record. Used to validate actual position against expected from the file.
 * @param reader Record reader I/O interface.
 * @return WAL record.
 * @throws EOFException In case of end of file.
 * @throws IgniteCheckedException If it's unable to read record.
 */
static WALRecord readWithCrc(FileInput in0, WALPointer expPtr, RecordIO reader) throws EOFException, IgniteCheckedException {
    long startPos = -1;
    try (FileInput.Crc32CheckingFileInput in = in0.startRead(skipCrc)) {
        startPos = in0.position();
        WALRecord res = reader.readWithHeaders(in, expPtr);
        assert res != null;
        // Account for CRC which will be read afterwards.
        res.size((int) (in0.position() - startPos + CRC_SIZE));
        return res;
    } catch (EOFException | SegmentEofException | WalSegmentTailReachedException e) {
        throw e;
    } catch (Exception e) {
        throw new IgniteCheckedException("Failed to read WAL record at position: " + startPos, e);
    }
}
Also used : WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) WalSegmentTailReachedException(org.apache.ignite.internal.processors.cache.persistence.wal.WalSegmentTailReachedException) EOFException(java.io.EOFException) FileInput(org.apache.ignite.internal.processors.cache.persistence.wal.FileInput) SegmentEofException(org.apache.ignite.internal.processors.cache.persistence.wal.SegmentEofException) SegmentEofException(org.apache.ignite.internal.processors.cache.persistence.wal.SegmentEofException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IOException(java.io.IOException) WalSegmentTailReachedException(org.apache.ignite.internal.processors.cache.persistence.wal.WalSegmentTailReachedException) EOFException(java.io.EOFException)

Aggregations

WALRecord (org.apache.ignite.internal.pagemem.wal.record.WALRecord)19 WALPointer (org.apache.ignite.internal.pagemem.wal.WALPointer)14 DataRecord (org.apache.ignite.internal.pagemem.wal.record.DataRecord)9 WALIterator (org.apache.ignite.internal.pagemem.wal.WALIterator)8 DataEntry (org.apache.ignite.internal.pagemem.wal.record.DataEntry)8 PageSnapshot (org.apache.ignite.internal.pagemem.wal.record.PageSnapshot)8 CheckpointRecord (org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord)7 IgniteEx (org.apache.ignite.internal.IgniteEx)6 FullPageId (org.apache.ignite.internal.pagemem.FullPageId)6 HashMap (java.util.HashMap)5 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)5 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)5 FileWALPointer (org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer)5 ArrayList (java.util.ArrayList)4 UUID (java.util.UUID)4 IgniteWriteAheadLogManager (org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager)4 MemoryRecoveryRecord (org.apache.ignite.internal.pagemem.wal.record.MemoryRecoveryRecord)4 MetastoreDataRecord (org.apache.ignite.internal.pagemem.wal.record.MetastoreDataRecord)4 TxRecord (org.apache.ignite.internal.pagemem.wal.record.TxRecord)4 GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)4