Search in sources :

Example 1 with DataEntry

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

the class GridCacheMapEntry method initialValue.

/**
 * {@inheritDoc}
 */
@SuppressWarnings({ "RedundantTypeArguments" })
@Override
public boolean initialValue(CacheObject val, GridCacheVersion ver, long ttl, long expireTime, boolean preload, AffinityTopologyVersion topVer, GridDrType drType, boolean fromStore) throws IgniteCheckedException, GridCacheEntryRemovedException {
    ensureFreeSpace();
    lockEntry();
    try {
        checkObsolete();
        boolean update;
        boolean walEnabled = !cctx.isNear() && cctx.group().persistenceEnabled() && cctx.group().walEnabled();
        if (cctx.group().persistenceEnabled()) {
            unswap(false);
            if (!isNew()) {
                if (cctx.atomic())
                    update = ATOMIC_VER_COMPARATOR.compare(this.ver, ver) < 0;
                else
                    update = this.ver.compareTo(ver) < 0;
            } else
                update = true;
        } else
            update = isNew() && !cctx.offheap().containsKey(this);
        update |= !preload && deletedUnlocked();
        if (update) {
            long expTime = expireTime < 0 ? CU.toExpireTime(ttl) : expireTime;
            val = cctx.kernalContext().cacheObjects().prepareForCache(val, cctx);
            if (val != null)
                storeValue(val, expTime, ver, null);
            update(val, expTime, ttl, ver, true);
            boolean skipQryNtf = false;
            if (val == null) {
                skipQryNtf = true;
                if (cctx.deferredDelete() && !deletedUnlocked() && !isInternal())
                    deletedUnlocked(true);
            } else if (deletedUnlocked())
                deletedUnlocked(false);
            long updateCntr = 0;
            if (!preload)
                updateCntr = nextPartitionCounter(topVer, true, null);
            if (walEnabled) {
                cctx.shared().wal().log(new DataRecord(new DataEntry(cctx.cacheId(), key, val, val == null ? GridCacheOperation.DELETE : GridCacheOperation.CREATE, null, ver, expireTime, partition(), updateCntr)));
            }
            drReplicate(drType, val, ver, topVer);
            if (!skipQryNtf) {
                cctx.continuousQueries().onEntryUpdated(key, val, null, this.isInternal() || !this.context().userCache(), this.partition(), true, preload, updateCntr, null, topVer);
                cctx.dataStructures().onEntryUpdated(key, false, true);
            }
            onUpdateFinished(updateCntr);
            if (!fromStore && cctx.store().isLocal()) {
                if (val != null)
                    cctx.store().put(null, key, val, ver);
            }
            return true;
        }
        return false;
    } finally {
        unlockEntry();
    }
}
Also used : DataEntry(org.apache.ignite.internal.pagemem.wal.record.DataEntry) DataRecord(org.apache.ignite.internal.pagemem.wal.record.DataRecord)

Example 2 with DataEntry

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

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

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

the class GridCacheDatabaseSharedManager method applyUpdatesOnRecovery.

/**
 * Apply update from some iterator and with specific filters.
 *
 * @param it WalIterator.
 * @param recPredicate Wal record filter.
 * @param entryPredicate Entry filter.
 * @param partStates Partition to restore state.
 */
public void applyUpdatesOnRecovery(@Nullable WALIterator it, IgnitePredicate<IgniteBiTuple<WALPointer, WALRecord>> recPredicate, IgnitePredicate<DataEntry> entryPredicate, Map<T2<Integer, Integer>, T2<Integer, Long>> partStates) throws IgniteCheckedException {
    if (it != null) {
        while (it.hasNextX()) {
            IgniteBiTuple<WALPointer, WALRecord> next = it.nextX();
            WALRecord rec = next.get2();
            if (!recPredicate.apply(next))
                break;
            switch(rec.type()) {
                case DATA_RECORD:
                    checkpointReadLock();
                    try {
                        DataRecord dataRec = (DataRecord) rec;
                        for (DataEntry dataEntry : dataRec.writeEntries()) {
                            if (entryPredicate.apply(dataEntry)) {
                                checkpointReadLock();
                                try {
                                    int cacheId = dataEntry.cacheId();
                                    GridCacheContext cacheCtx = cctx.cacheContext(cacheId);
                                    if (cacheCtx != null)
                                        applyUpdate(cacheCtx, dataEntry);
                                    else if (log != null)
                                        log.warning("Cache (cacheId=" + cacheId + ") is not started, can't apply updates.");
                                } finally {
                                    checkpointReadUnlock();
                                }
                            }
                        }
                    } finally {
                        checkpointReadUnlock();
                    }
                    break;
                default:
            }
        }
    }
    checkpointReadLock();
    try {
        restorePartitionState(partStates, Collections.emptySet());
    } finally {
        checkpointReadUnlock();
    }
}
Also used : WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) DataEntry(org.apache.ignite.internal.pagemem.wal.record.DataEntry) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) DataRecord(org.apache.ignite.internal.pagemem.wal.record.DataRecord) MetastoreDataRecord(org.apache.ignite.internal.pagemem.wal.record.MetastoreDataRecord) WALPointer(org.apache.ignite.internal.pagemem.wal.WALPointer) FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer)

Example 5 with DataEntry

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

the class GridCacheMapEntry method initialValue.

/**
 * {@inheritDoc}
 */
@Override
public boolean initialValue(CacheObject val, GridCacheVersion ver, MvccVersion mvccVer, MvccVersion newMvccVer, byte mvccTxState, byte newMvccTxState, long ttl, long expireTime, boolean preload, AffinityTopologyVersion topVer, GridDrType drType, boolean fromStore, boolean primary, CacheDataRow row) throws IgniteCheckedException, GridCacheEntryRemovedException {
    assert !primary || !(preload || fromStore);
    ensureFreeSpace();
    boolean deferred = false;
    boolean obsolete = false;
    GridCacheVersion oldVer = null;
    lockListenerReadLock();
    lockEntry();
    try {
        checkObsolete();
        boolean walEnabled = !cctx.isNear() && cctx.group().persistenceEnabled() && cctx.group().walEnabled();
        long expTime = expireTime < 0 ? CU.toExpireTime(ttl) : expireTime;
        val = cctx.kernalContext().cacheObjects().prepareForCache(val, cctx);
        final boolean unswapped = ((flags & IS_UNSWAPPED_MASK) != 0);
        boolean update;
        IgnitePredicate<CacheDataRow> p = new IgnitePredicate<CacheDataRow>() {

            @Override
            public boolean apply(@Nullable CacheDataRow row) {
                boolean update0;
                GridCacheVersion currentVer = row != null ? row.version() : GridCacheMapEntry.this.ver;
                boolean isStartVer = cctx.shared().versions().isStartVersion(currentVer);
                if (cctx.group().persistenceEnabled()) {
                    if (!isStartVer) {
                        if (cctx.atomic())
                            update0 = ATOMIC_VER_COMPARATOR.compare(currentVer, ver) < 0;
                        else
                            update0 = currentVer.compareTo(ver) < 0;
                    } else
                        update0 = true;
                } else
                    update0 = isStartVer;
                update0 |= (!preload && deletedUnlocked());
                return update0;
            }
        };
        if (unswapped) {
            update = p.apply(null);
            if (update) {
                // If entry is already unswapped and we are modifying it, we must run deletion callbacks for old value.
                long oldExpTime = expireTimeUnlocked();
                if (oldExpTime > 0 && oldExpTime < U.currentTimeMillis()) {
                    if (onExpired(this.val, null)) {
                        if (cctx.deferredDelete()) {
                            deferred = true;
                            oldVer = this.ver;
                        } else if (val == null)
                            obsolete = true;
                    }
                }
                if (cctx.mvccEnabled()) {
                    assert !preload;
                    cctx.offheap().mvccInitialValue(this, val, ver, expTime, mvccVer, newMvccVer);
                } else
                    storeValue(val, expTime, ver, null, row);
            }
        } else {
            if (cctx.mvccEnabled()) {
                // cannot identify whether the entry is exist on the fly
                unswap(false);
                if (update = p.apply(null)) {
                    // If entry is already unswapped and we are modifying it, we must run deletion callbacks for old value.
                    long oldExpTime = expireTimeUnlocked();
                    long delta = (oldExpTime == 0 ? 0 : oldExpTime - U.currentTimeMillis());
                    if (delta < 0) {
                        if (onExpired(this.val, null)) {
                            if (cctx.deferredDelete()) {
                                deferred = true;
                                oldVer = this.ver;
                            } else if (val == null)
                                obsolete = true;
                        }
                    }
                    assert !preload;
                    cctx.offheap().mvccInitialValue(this, val, ver, expTime, mvccVer, newMvccVer);
                }
            } else
                // Optimization to access storage only once.
                update = storeValue(val, expTime, ver, p, row);
        }
        if (update) {
            update(val, expTime, ttl, ver, true);
            boolean skipQryNtf = false;
            if (val == null) {
                skipQryNtf = true;
                if (cctx.deferredDelete() && !deletedUnlocked() && !isInternal())
                    deletedUnlocked(true);
            } else if (deletedUnlocked())
                deletedUnlocked(false);
            long updateCntr = 0;
            if (!preload)
                updateCntr = nextPartitionCounter(topVer, true, true, null);
            if (walEnabled) {
                if (cctx.mvccEnabled()) {
                    cctx.shared().wal().log(new MvccDataRecord(new MvccDataEntry(cctx.cacheId(), key, val, val == null ? DELETE : GridCacheOperation.CREATE, null, ver, expireTime, partition(), updateCntr, mvccVer == null ? MvccUtils.INITIAL_VERSION : mvccVer)));
                } else {
                    cctx.shared().wal().log(new DataRecord(new DataEntry(cctx.cacheId(), key, val, val == null ? DELETE : GridCacheOperation.CREATE, null, ver, expireTime, partition(), updateCntr, DataEntry.flags(primary, preload, fromStore))));
                }
            }
            drReplicate(drType, val, ver, topVer);
            if (!skipQryNtf) {
                cctx.continuousQueries().onEntryUpdated(key, val, null, this.isInternal() || !this.context().userCache(), this.partition(), true, preload, updateCntr, null, topVer);
            }
            updatePlatformCache(val, topVer);
            onUpdateFinished(updateCntr);
            if (!fromStore && cctx.store().isLocal()) {
                if (val != null)
                    cctx.store().put(null, key, val, ver);
            }
            return true;
        }
        return false;
    } finally {
        unlockEntry();
        unlockListenerReadLock();
        if (obsolete) {
            onMarkedObsolete();
            cctx.cache().removeEntry(this);
        }
        if (deferred) {
            assert oldVer != null;
            cctx.onDeferredDelete(this, oldVer);
        }
    }
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) DataEntry(org.apache.ignite.internal.pagemem.wal.record.DataEntry) MvccDataEntry(org.apache.ignite.internal.pagemem.wal.record.MvccDataEntry) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) MvccDataEntry(org.apache.ignite.internal.pagemem.wal.record.MvccDataEntry) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) MvccDataRecord(org.apache.ignite.internal.pagemem.wal.record.MvccDataRecord) DataRecord(org.apache.ignite.internal.pagemem.wal.record.DataRecord) MvccDataRecord(org.apache.ignite.internal.pagemem.wal.record.MvccDataRecord) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

DataEntry (org.apache.ignite.internal.pagemem.wal.record.DataEntry)40 DataRecord (org.apache.ignite.internal.pagemem.wal.record.DataRecord)30 WALRecord (org.apache.ignite.internal.pagemem.wal.record.WALRecord)19 WALPointer (org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)19 ArrayList (java.util.ArrayList)15 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)14 UUID (java.util.UUID)13 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)13 MvccDataEntry (org.apache.ignite.internal.pagemem.wal.record.MvccDataEntry)12 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)12 GridCacheOperation (org.apache.ignite.internal.processors.cache.GridCacheOperation)12 WALIterator (org.apache.ignite.internal.pagemem.wal.WALIterator)11 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)10 CheckpointRecord (org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord)9 IgniteEx (org.apache.ignite.internal.IgniteEx)8 MetastoreDataRecord (org.apache.ignite.internal.pagemem.wal.record.MetastoreDataRecord)8 UnwrapDataEntry (org.apache.ignite.internal.pagemem.wal.record.UnwrapDataEntry)8 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 MarshalledDataEntry (org.apache.ignite.internal.pagemem.wal.record.MarshalledDataEntry)7