Search in sources :

Example 26 with WALPointer

use of org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer in project ignite by apache.

the class RecordDataV1Serializer method writePlainRecord.

/**
 * Write {@code rec} to {@code buf} without encryption.
 *
 * @param rec Record to serialize.
 * @param buf Output buffer.
 * @throws IgniteCheckedException If failed.
 */
void writePlainRecord(WALRecord rec, ByteBuffer buf) throws IgniteCheckedException {
    switch(rec.type()) {
        case PAGE_RECORD:
            PageSnapshot snap = (PageSnapshot) rec;
            buf.putInt(snap.fullPageId().groupId());
            buf.putLong(snap.fullPageId().pageId());
            buf.put(snap.pageDataBuffer());
            break;
        case MEMORY_RECOVERY:
            MemoryRecoveryRecord memoryRecoveryRecord = (MemoryRecoveryRecord) rec;
            buf.putLong(memoryRecoveryRecord.time());
            break;
        case PARTITION_DESTROY:
            PartitionDestroyRecord partDestroy = (PartitionDestroyRecord) rec;
            buf.putInt(partDestroy.groupId());
            buf.putInt(partDestroy.partitionId());
            break;
        case META_PAGE_INIT:
            MetaPageInitRecord updRootsRec = (MetaPageInitRecord) rec;
            buf.putInt(updRootsRec.groupId());
            buf.putLong(updRootsRec.pageId());
            buf.putShort((short) updRootsRec.ioType());
            buf.putShort((short) updRootsRec.ioVersion());
            buf.putLong(updRootsRec.treeRoot());
            buf.putLong(updRootsRec.reuseListRoot());
            break;
        case INDEX_META_PAGE_DELTA_RECORD:
            ((MetaPageUpdateIndexDataRecord) rec).toBytes(buf);
            break;
        case PARTITION_META_PAGE_UPDATE_COUNTERS:
        case PARTITION_META_PAGE_UPDATE_COUNTERS_V2:
        case PARTITION_META_PAGE_DELTA_RECORD_V3:
            ((MetaPageUpdatePartitionDataRecord) rec).toBytes(buf);
            break;
        case CHECKPOINT_RECORD:
            CheckpointRecord cpRec = (CheckpointRecord) rec;
            WALPointer walPtr = cpRec.checkpointMark();
            UUID cpId = cpRec.checkpointId();
            buf.putLong(cpId.getMostSignificantBits());
            buf.putLong(cpId.getLeastSignificantBits());
            buf.put(walPtr == null ? (byte) 0 : 1);
            if (walPtr != null) {
                buf.putLong(walPtr.index());
                buf.putInt(walPtr.fileOffset());
                buf.putInt(walPtr.length());
            }
            putCacheStates(buf, cpRec.cacheGroupStates());
            buf.put(cpRec.end() ? (byte) 1 : 0);
            break;
        case DATA_RECORD_V2:
            DataRecord dataRec = (DataRecord) rec;
            int entryCnt = dataRec.entryCount();
            buf.putInt(entryCnt);
            boolean encrypted = isDataRecordEncrypted(dataRec);
            for (int i = 0; i < entryCnt; i++) {
                if (encrypted)
                    putEncryptedDataEntry(buf, dataRec.get(i));
                else
                    putPlainDataEntry(buf, dataRec.get(i));
            }
            break;
        case METASTORE_DATA_RECORD:
            MetastoreDataRecord metastoreDataRecord = (MetastoreDataRecord) rec;
            byte[] strBytes = metastoreDataRecord.key().getBytes();
            buf.putInt(strBytes.length);
            buf.put(strBytes);
            if (metastoreDataRecord.value() != null) {
                buf.putInt(metastoreDataRecord.value().length);
                buf.put(metastoreDataRecord.value());
            } else
                buf.putInt(0);
            break;
        case HEADER_RECORD:
            buf.putLong(HeaderRecord.REGULAR_MAGIC);
            buf.putInt(((HeaderRecord) rec).version());
            break;
        case DATA_PAGE_INSERT_RECORD:
            DataPageInsertRecord diRec = (DataPageInsertRecord) rec;
            buf.putInt(diRec.groupId());
            buf.putLong(diRec.pageId());
            buf.putShort((short) diRec.payload().length);
            buf.put(diRec.payload());
            break;
        case DATA_PAGE_UPDATE_RECORD:
            DataPageUpdateRecord uRec = (DataPageUpdateRecord) rec;
            buf.putInt(uRec.groupId());
            buf.putLong(uRec.pageId());
            buf.putInt(uRec.itemId());
            buf.putShort((short) uRec.payload().length);
            buf.put(uRec.payload());
            break;
        case DATA_PAGE_INSERT_FRAGMENT_RECORD:
            final DataPageInsertFragmentRecord difRec = (DataPageInsertFragmentRecord) rec;
            buf.putInt(difRec.groupId());
            buf.putLong(difRec.pageId());
            buf.putLong(difRec.lastLink());
            buf.putInt(difRec.payloadSize());
            buf.put(difRec.payload());
            break;
        case DATA_PAGE_REMOVE_RECORD:
            DataPageRemoveRecord drRec = (DataPageRemoveRecord) rec;
            buf.putInt(drRec.groupId());
            buf.putLong(drRec.pageId());
            buf.put((byte) drRec.itemId());
            break;
        case DATA_PAGE_SET_FREE_LIST_PAGE:
            DataPageSetFreeListPageRecord freeListRec = (DataPageSetFreeListPageRecord) rec;
            buf.putInt(freeListRec.groupId());
            buf.putLong(freeListRec.pageId());
            buf.putLong(freeListRec.freeListPage());
            break;
        case MVCC_DATA_PAGE_MARK_UPDATED_RECORD:
            DataPageMvccMarkUpdatedRecord rmvRec = (DataPageMvccMarkUpdatedRecord) rec;
            buf.putInt(rmvRec.groupId());
            buf.putLong(rmvRec.pageId());
            buf.putInt(rmvRec.itemId());
            buf.putLong(rmvRec.newMvccCrd());
            buf.putLong(rmvRec.newMvccCntr());
            buf.putInt(rmvRec.newMvccOpCntr());
            break;
        case MVCC_DATA_PAGE_TX_STATE_HINT_UPDATED_RECORD:
            DataPageMvccUpdateTxStateHintRecord txStRec = (DataPageMvccUpdateTxStateHintRecord) rec;
            buf.putInt(txStRec.groupId());
            buf.putLong(txStRec.pageId());
            buf.putInt(txStRec.itemId());
            buf.put(txStRec.txState());
            break;
        case MVCC_DATA_PAGE_NEW_TX_STATE_HINT_UPDATED_RECORD:
            DataPageMvccUpdateNewTxStateHintRecord newTxStRec = (DataPageMvccUpdateNewTxStateHintRecord) rec;
            buf.putInt(newTxStRec.groupId());
            buf.putLong(newTxStRec.pageId());
            buf.putInt(newTxStRec.itemId());
            buf.put(newTxStRec.txState());
            break;
        case INIT_NEW_PAGE_RECORD:
            InitNewPageRecord inpRec = (InitNewPageRecord) rec;
            buf.putInt(inpRec.groupId());
            buf.putLong(inpRec.pageId());
            buf.putShort((short) inpRec.ioType());
            buf.putShort((short) inpRec.ioVersion());
            buf.putLong(inpRec.newPageId());
            break;
        case BTREE_META_PAGE_INIT_ROOT:
            MetaPageInitRootRecord imRec = (MetaPageInitRootRecord) rec;
            buf.putInt(imRec.groupId());
            buf.putLong(imRec.pageId());
            buf.putLong(imRec.rootId());
            break;
        case BTREE_META_PAGE_INIT_ROOT2:
            MetaPageInitRootInlineRecord imRec2 = (MetaPageInitRootInlineRecord) rec;
            buf.putInt(imRec2.groupId());
            buf.putLong(imRec2.pageId());
            buf.putLong(imRec2.rootId());
            buf.putShort((short) imRec2.inlineSize());
            break;
        case BTREE_META_PAGE_INIT_ROOT_V3:
            MetaPageInitRootInlineFlagsCreatedVersionRecord imRec3 = (MetaPageInitRootInlineFlagsCreatedVersionRecord) rec;
            buf.putInt(imRec3.groupId());
            buf.putLong(imRec3.pageId());
            buf.putLong(imRec3.rootId());
            buf.putShort((short) imRec3.inlineSize());
            buf.putLong(imRec3.flags());
            // Write created version.
            IgniteProductVersion createdVer = imRec3.createdVersion();
            buf.put(createdVer.major());
            buf.put(createdVer.minor());
            buf.put(createdVer.maintenance());
            buf.putLong(createdVer.revisionTimestamp());
            buf.put(createdVer.revisionHash());
            break;
        case BTREE_META_PAGE_ADD_ROOT:
            MetaPageAddRootRecord arRec = (MetaPageAddRootRecord) rec;
            buf.putInt(arRec.groupId());
            buf.putLong(arRec.pageId());
            buf.putLong(arRec.rootId());
            break;
        case BTREE_META_PAGE_CUT_ROOT:
            MetaPageCutRootRecord crRec = (MetaPageCutRootRecord) rec;
            buf.putInt(crRec.groupId());
            buf.putLong(crRec.pageId());
            break;
        case BTREE_INIT_NEW_ROOT:
            NewRootInitRecord<?> riRec = (NewRootInitRecord<?>) rec;
            buf.putInt(riRec.groupId());
            buf.putLong(riRec.pageId());
            buf.putLong(riRec.rootId());
            buf.putShort((short) riRec.io().getType());
            buf.putShort((short) riRec.io().getVersion());
            buf.putLong(riRec.leftId());
            buf.putLong(riRec.rightId());
            putRow(buf, riRec.rowBytes());
            break;
        case BTREE_PAGE_RECYCLE:
            RecycleRecord recRec = (RecycleRecord) rec;
            buf.putInt(recRec.groupId());
            buf.putLong(recRec.pageId());
            buf.putLong(recRec.newPageId());
            break;
        case BTREE_PAGE_INSERT:
            InsertRecord<?> inRec = (InsertRecord<?>) rec;
            buf.putInt(inRec.groupId());
            buf.putLong(inRec.pageId());
            buf.putShort((short) inRec.io().getType());
            buf.putShort((short) inRec.io().getVersion());
            buf.putShort((short) inRec.index());
            buf.putLong(inRec.rightId());
            putRow(buf, inRec.rowBytes());
            break;
        case BTREE_FIX_LEFTMOST_CHILD:
            FixLeftmostChildRecord flRec = (FixLeftmostChildRecord) rec;
            buf.putInt(flRec.groupId());
            buf.putLong(flRec.pageId());
            buf.putLong(flRec.rightId());
            break;
        case BTREE_FIX_COUNT:
            FixCountRecord fcRec = (FixCountRecord) rec;
            buf.putInt(fcRec.groupId());
            buf.putLong(fcRec.pageId());
            buf.putShort((short) fcRec.count());
            break;
        case BTREE_PAGE_REPLACE:
            ReplaceRecord<?> rRec = (ReplaceRecord<?>) rec;
            buf.putInt(rRec.groupId());
            buf.putLong(rRec.pageId());
            buf.putShort((short) rRec.io().getType());
            buf.putShort((short) rRec.io().getVersion());
            buf.putShort((short) rRec.index());
            putRow(buf, rRec.rowBytes());
            break;
        case BTREE_PAGE_REMOVE:
            RemoveRecord rmRec = (RemoveRecord) rec;
            buf.putInt(rmRec.groupId());
            buf.putLong(rmRec.pageId());
            buf.putShort((short) rmRec.index());
            buf.putShort((short) rmRec.count());
            break;
        case BTREE_PAGE_INNER_REPLACE:
            InnerReplaceRecord<?> irRec = (InnerReplaceRecord<?>) rec;
            buf.putInt(irRec.groupId());
            buf.putLong(irRec.pageId());
            buf.putShort((short) irRec.destinationIndex());
            buf.putLong(irRec.sourcePageId());
            buf.putShort((short) irRec.sourceIndex());
            buf.putLong(irRec.removeId());
            break;
        case BTREE_FORWARD_PAGE_SPLIT:
            SplitForwardPageRecord sfRec = (SplitForwardPageRecord) rec;
            buf.putInt(sfRec.groupId());
            buf.putLong(sfRec.pageId());
            buf.putLong(sfRec.forwardId());
            buf.putShort((short) sfRec.ioType());
            buf.putShort((short) sfRec.ioVersion());
            buf.putLong(sfRec.sourcePageId());
            buf.putShort((short) sfRec.middleIndex());
            buf.putShort((short) sfRec.count());
            break;
        case BTREE_EXISTING_PAGE_SPLIT:
            SplitExistingPageRecord seRec = (SplitExistingPageRecord) rec;
            buf.putInt(seRec.groupId());
            buf.putLong(seRec.pageId());
            buf.putShort((short) seRec.middleIndex());
            buf.putLong(seRec.forwardId());
            break;
        case BTREE_PAGE_MERGE:
            MergeRecord<?> mRec = (MergeRecord<?>) rec;
            buf.putInt(mRec.groupId());
            buf.putLong(mRec.pageId());
            buf.putLong(mRec.parentId());
            buf.putShort((short) mRec.parentIndex());
            buf.putLong(mRec.rightId());
            buf.put((byte) (mRec.isEmptyBranch() ? 1 : 0));
            break;
        case PAGES_LIST_SET_NEXT:
            PagesListSetNextRecord plNextRec = (PagesListSetNextRecord) rec;
            buf.putInt(plNextRec.groupId());
            buf.putLong(plNextRec.pageId());
            buf.putLong(plNextRec.nextPageId());
            break;
        case PAGES_LIST_SET_PREVIOUS:
            PagesListSetPreviousRecord plPrevRec = (PagesListSetPreviousRecord) rec;
            buf.putInt(plPrevRec.groupId());
            buf.putLong(plPrevRec.pageId());
            buf.putLong(plPrevRec.previousPageId());
            break;
        case PAGES_LIST_INIT_NEW_PAGE:
            PagesListInitNewPageRecord plNewRec = (PagesListInitNewPageRecord) rec;
            buf.putInt(plNewRec.groupId());
            buf.putLong(plNewRec.pageId());
            buf.putInt(plNewRec.ioType());
            buf.putInt(plNewRec.ioVersion());
            buf.putLong(plNewRec.newPageId());
            buf.putLong(plNewRec.previousPageId());
            buf.putLong(plNewRec.dataPageId());
            break;
        case PAGES_LIST_ADD_PAGE:
            PagesListAddPageRecord plAddRec = (PagesListAddPageRecord) rec;
            buf.putInt(plAddRec.groupId());
            buf.putLong(plAddRec.pageId());
            buf.putLong(plAddRec.dataPageId());
            break;
        case PAGES_LIST_REMOVE_PAGE:
            PagesListRemovePageRecord plRmvRec = (PagesListRemovePageRecord) rec;
            buf.putInt(plRmvRec.groupId());
            buf.putLong(plRmvRec.pageId());
            buf.putLong(plRmvRec.removedPageId());
            break;
        case BTREE_FIX_REMOVE_ID:
            FixRemoveId frRec = (FixRemoveId) rec;
            buf.putInt(frRec.groupId());
            buf.putLong(frRec.pageId());
            buf.putLong(frRec.removeId());
            break;
        case TRACKING_PAGE_DELTA:
            TrackingPageDeltaRecord tpDelta = (TrackingPageDeltaRecord) rec;
            buf.putInt(tpDelta.groupId());
            buf.putLong(tpDelta.pageId());
            buf.putLong(tpDelta.pageIdToMark());
            buf.putLong(tpDelta.nextSnapshotTag());
            buf.putLong(tpDelta.lastSuccessfulSnapshotTag());
            break;
        case META_PAGE_UPDATE_NEXT_SNAPSHOT_ID:
            MetaPageUpdateNextSnapshotId mpUpdateNextSnapshotId = (MetaPageUpdateNextSnapshotId) rec;
            buf.putInt(mpUpdateNextSnapshotId.groupId());
            buf.putLong(mpUpdateNextSnapshotId.pageId());
            buf.putLong(mpUpdateNextSnapshotId.nextSnapshotId());
            break;
        case META_PAGE_UPDATE_LAST_SUCCESSFUL_FULL_SNAPSHOT_ID:
            MetaPageUpdateLastSuccessfulFullSnapshotId mpUpdateLastSuccFullSnapshotId = (MetaPageUpdateLastSuccessfulFullSnapshotId) rec;
            buf.putInt(mpUpdateLastSuccFullSnapshotId.groupId());
            buf.putLong(mpUpdateLastSuccFullSnapshotId.pageId());
            buf.putLong(mpUpdateLastSuccFullSnapshotId.lastSuccessfulFullSnapshotId());
            break;
        case META_PAGE_UPDATE_LAST_SUCCESSFUL_SNAPSHOT_ID:
            MetaPageUpdateLastSuccessfulSnapshotId mpUpdateLastSuccSnapshotId = (MetaPageUpdateLastSuccessfulSnapshotId) rec;
            buf.putInt(mpUpdateLastSuccSnapshotId.groupId());
            buf.putLong(mpUpdateLastSuccSnapshotId.pageId());
            buf.putLong(mpUpdateLastSuccSnapshotId.lastSuccessfulSnapshotId());
            buf.putLong(mpUpdateLastSuccSnapshotId.lastSuccessfulSnapshotTag());
            break;
        case META_PAGE_UPDATE_LAST_ALLOCATED_INDEX:
            MetaPageUpdateLastAllocatedIndex mpUpdateLastAllocatedIdx = (MetaPageUpdateLastAllocatedIndex) rec;
            buf.putInt(mpUpdateLastAllocatedIdx.groupId());
            buf.putLong(mpUpdateLastAllocatedIdx.pageId());
            buf.putInt(mpUpdateLastAllocatedIdx.lastAllocatedIndex());
            break;
        case PART_META_UPDATE_STATE:
            PartitionMetaStateRecord partMetaStateRecord = (PartitionMetaStateRecord) rec;
            buf.putInt(partMetaStateRecord.groupId());
            buf.putInt(partMetaStateRecord.partitionId());
            buf.put(partMetaStateRecord.state());
            buf.putLong(0);
            break;
        case PAGE_LIST_META_RESET_COUNT_RECORD:
            PageListMetaResetCountRecord pageListMetaResetCntRecord = (PageListMetaResetCountRecord) rec;
            buf.putInt(pageListMetaResetCntRecord.groupId());
            buf.putLong(pageListMetaResetCntRecord.pageId());
            break;
        case ROTATED_ID_PART_RECORD:
            RotatedIdPartRecord rotatedIdPartRecord = (RotatedIdPartRecord) rec;
            buf.putInt(rotatedIdPartRecord.groupId());
            buf.putLong(rotatedIdPartRecord.pageId());
            buf.put(rotatedIdPartRecord.rotatedIdPart());
            break;
        case TX_RECORD:
            txRecordSerializer.write((TxRecord) rec, buf);
            break;
        case SWITCH_SEGMENT_RECORD:
            break;
        case MASTER_KEY_CHANGE_RECORD_V2:
            MasterKeyChangeRecordV2 mkChangeRec = (MasterKeyChangeRecordV2) rec;
            byte[] keyIdBytes = mkChangeRec.getMasterKeyName().getBytes();
            buf.putInt(keyIdBytes.length);
            buf.put(keyIdBytes);
            List<T2<Integer, GroupKeyEncrypted>> grpKeys = mkChangeRec.getGrpKeys();
            buf.putInt(grpKeys.size());
            for (T2<Integer, GroupKeyEncrypted> entry : grpKeys) {
                GroupKeyEncrypted grpKey = entry.get2();
                buf.putInt(entry.get1());
                buf.put((byte) grpKey.id());
                buf.putInt(grpKey.key().length);
                buf.put(grpKey.key());
            }
            break;
        case REENCRYPTION_START_RECORD:
            ReencryptionStartRecord statusRecord = (ReencryptionStartRecord) rec;
            Map<Integer, Byte> grps = statusRecord.groups();
            buf.putInt(grps.size());
            for (Map.Entry<Integer, Byte> e : grps.entrySet()) {
                buf.putInt(e.getKey());
                buf.put(e.getValue());
            }
            break;
        case INDEX_ROOT_PAGE_RENAME_RECORD:
            ((IndexRenameRootPageRecord) rec).writeRecord(buf);
            break;
        case PARTITION_CLEARING_START_RECORD:
            PartitionClearingStartRecord partitionClearingStartRecord = (PartitionClearingStartRecord) rec;
            buf.putInt(partitionClearingStartRecord.partitionId());
            buf.putInt(partitionClearingStartRecord.groupId());
            buf.putLong(partitionClearingStartRecord.clearVersion());
            break;
        default:
            throw new UnsupportedOperationException("Type: " + rec.type());
    }
}
Also used : PagesListSetPreviousRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PagesListSetPreviousRecord) DataPageRemoveRecord(org.apache.ignite.internal.pagemem.wal.record.delta.DataPageRemoveRecord) 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) DataPageMvccUpdateNewTxStateHintRecord(org.apache.ignite.internal.pagemem.wal.record.delta.DataPageMvccUpdateNewTxStateHintRecord) FixLeftmostChildRecord(org.apache.ignite.internal.pagemem.wal.record.delta.FixLeftmostChildRecord) SplitForwardPageRecord(org.apache.ignite.internal.pagemem.wal.record.delta.SplitForwardPageRecord) PagesListAddPageRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PagesListAddPageRecord) MetaPageUpdateNextSnapshotId(org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdateNextSnapshotId) UUID(java.util.UUID) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) ReplaceRecord(org.apache.ignite.internal.pagemem.wal.record.delta.ReplaceRecord) InnerReplaceRecord(org.apache.ignite.internal.pagemem.wal.record.delta.InnerReplaceRecord) PageSnapshot(org.apache.ignite.internal.pagemem.wal.record.PageSnapshot) DataPageSetFreeListPageRecord(org.apache.ignite.internal.pagemem.wal.record.delta.DataPageSetFreeListPageRecord) NewRootInitRecord(org.apache.ignite.internal.pagemem.wal.record.delta.NewRootInitRecord) MetaPageUpdateLastAllocatedIndex(org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdateLastAllocatedIndex) DataPageInsertRecord(org.apache.ignite.internal.pagemem.wal.record.delta.DataPageInsertRecord) InsertRecord(org.apache.ignite.internal.pagemem.wal.record.delta.InsertRecord) PartitionMetaStateRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PartitionMetaStateRecord) GroupKeyEncrypted(org.apache.ignite.internal.managers.encryption.GroupKeyEncrypted) MetaPageCutRootRecord(org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageCutRootRecord) MetaPageAddRootRecord(org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageAddRootRecord) MetaPageInitRootInlineRecord(org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageInitRootInlineRecord) MasterKeyChangeRecordV2(org.apache.ignite.internal.pagemem.wal.record.MasterKeyChangeRecordV2) DataPageMvccMarkUpdatedRecord(org.apache.ignite.internal.pagemem.wal.record.delta.DataPageMvccMarkUpdatedRecord) MetaPageUpdateIndexDataRecord(org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdateIndexDataRecord) MetastoreDataRecord(org.apache.ignite.internal.pagemem.wal.record.MetastoreDataRecord) InnerReplaceRecord(org.apache.ignite.internal.pagemem.wal.record.delta.InnerReplaceRecord) Map(java.util.Map) HashMap(java.util.HashMap) MetaPageInitRootInlineFlagsCreatedVersionRecord(org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageInitRootInlineFlagsCreatedVersionRecord) DataPageUpdateRecord(org.apache.ignite.internal.pagemem.wal.record.delta.DataPageUpdateRecord) PageListMetaResetCountRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PageListMetaResetCountRecord) IgniteProductVersion(org.apache.ignite.lang.IgniteProductVersion) 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) DataPageMvccUpdateTxStateHintRecord(org.apache.ignite.internal.pagemem.wal.record.delta.DataPageMvccUpdateTxStateHintRecord) 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) RotatedIdPartRecord(org.apache.ignite.internal.pagemem.wal.record.delta.RotatedIdPartRecord) MetaPageUpdatePartitionDataRecord(org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdatePartitionDataRecord) MetaPageUpdateLastSuccessfulSnapshotId(org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdateLastSuccessfulSnapshotId) MetaPageUpdateIndexDataRecord(org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdateIndexDataRecord) 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) T2(org.apache.ignite.internal.util.typedef.T2) MergeRecord(org.apache.ignite.internal.pagemem.wal.record.delta.MergeRecord) 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) PartitionClearingStartRecord(org.apache.ignite.internal.pagemem.wal.record.PartitionClearingStartRecord) ReencryptionStartRecord(org.apache.ignite.internal.pagemem.wal.record.ReencryptionStartRecord) IndexRenameRootPageRecord(org.apache.ignite.internal.pagemem.wal.record.IndexRenameRootPageRecord)

Example 27 with WALPointer

use of org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer in project ignite by apache.

the class FilteredWalIterator method nextX.

/**
 * {@inheritDoc}
 */
@Override
public IgniteBiTuple<WALPointer, WALRecord> nextX() throws IgniteCheckedException {
    if (!hasNextX())
        throw new NoSuchElementException();
    IgniteBiTuple<WALPointer, WALRecord> cur = next;
    next = nextFilteredRecord();
    return cur;
}
Also used : WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) NoSuchElementException(java.util.NoSuchElementException)

Example 28 with WALPointer

use of org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer in project ignite by apache.

the class IgniteWalIteratorFactory method readFileDescriptor.

/**
 * @param file File to read.
 * @param ioFactory IO factory.
 */
private FileDescriptor readFileDescriptor(File file, FileIOFactory ioFactory) {
    FileDescriptor ds = new FileDescriptor(file);
    try (SegmentIO fileIO = ds.toReadOnlyIO(ioFactory);
        ByteBufferExpander buf = new ByteBufferExpander(HEADER_RECORD_SIZE, ByteOrder.nativeOrder())) {
        final DataInput in = segmentFileInputFactory.createFileInput(fileIO, buf);
        // Header record must be agnostic to the serializer version.
        final int type = in.readUnsignedByte();
        if (type == RecordType.STOP_ITERATION_RECORD_TYPE) {
            if (log.isInfoEnabled())
                log.info("Reached logical end of the segment for file " + file);
            return null;
        }
        WALPointer ptr = readPosition(in);
        return new FileDescriptor(file, ptr.index());
    } catch (IOException e) {
        U.warn(log, "Failed to scan index from file [" + file + "]. Skipping this file during iteration", e);
        return null;
    }
}
Also used : ByteBufferExpander(org.apache.ignite.internal.processors.cache.persistence.wal.ByteBufferExpander) DataInput(java.io.DataInput) SegmentIO(org.apache.ignite.internal.processors.cache.persistence.wal.io.SegmentIO) IOException(java.io.IOException) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) FileDescriptor(org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor)

Example 29 with WALPointer

use of org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer in project ignite by apache.

the class FileHandleManagerImpl method flush.

/**
 * {@inheritDoc}
 */
@Override
public WALPointer flush(WALPointer ptr, boolean explicitFsync) throws IgniteCheckedException, StorageException {
    if (serializer == null || mode == WALMode.NONE)
        return null;
    FileWriteHandleImpl cur = currentHandle();
    // WAL manager was not started (client node).
    if (cur == null)
        return null;
    WALPointer filePtr;
    if (ptr == null) {
        long pos = cur.buf.tail();
        filePtr = new WALPointer(cur.getSegmentId(), (int) pos, 0);
    } else
        filePtr = ptr;
    if (mode == LOG_ONLY)
        cur.flushOrWait(filePtr);
    if (!explicitFsync && mode != WALMode.FSYNC)
        // No need to sync in LOG_ONLY or BACKGROUND unless explicit fsync is required.
        return filePtr;
    // No need to sync if was rolled over.
    if (!cur.needFsync(filePtr))
        return filePtr;
    cur.fsync(filePtr);
    return filePtr;
}
Also used : WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)

Example 30 with WALPointer

use of org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer in project ignite by apache.

the class FileWriteHandleImpl method addRecord.

/**
 * @param rec Record to be added to write queue.
 * @return Pointer or null if roll over to next segment is required or already started by other thread.
 * @throws StorageException If failed.
 * @throws IgniteCheckedException If failed.
 */
@Override
@Nullable
public WALPointer addRecord(WALRecord rec) throws StorageException, IgniteCheckedException {
    assert rec.size() > 0 : rec;
    for (; ; ) {
        checkNode();
        SegmentedRingByteBuffer.WriteSegment seg;
        // Buffer can be in open state in case of resuming with different serializer version.
        if (rec.type() == SWITCH_SEGMENT_RECORD && !resume)
            seg = buf.offerSafe(rec.size());
        else
            seg = buf.offer(rec.size());
        WALPointer ptr = null;
        if (seg != null) {
            try {
                int pos = (int) (seg.position() - rec.size());
                ByteBuffer buf = seg.buffer();
                if (buf == null)
                    // Can not write to this segment, need to switch to the next one.
                    return null;
                ptr = new WALPointer(getSegmentId(), pos, rec.size());
                rec.position(ptr);
                fillBuffer(buf, rec);
                if (mmap) {
                    // earlier than segment with smaller position.
                    while (true) {
                        long written0 = written;
                        if (seg.position() > written0) {
                            if (WRITTEN_UPD.compareAndSet(this, written0, seg.position()))
                                break;
                        } else
                            break;
                    }
                }
                return ptr;
            } finally {
                seg.release();
                if (mode == WALMode.BACKGROUND && rec instanceof CheckpointRecord)
                    flushOrWait(ptr);
            }
        } else
            walWriter.flushAll();
    }
}
Also used : SegmentedRingByteBuffer(org.apache.ignite.internal.processors.cache.persistence.wal.SegmentedRingByteBuffer) CheckpointRecord(org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) ByteBuffer(java.nio.ByteBuffer) SegmentedRingByteBuffer(org.apache.ignite.internal.processors.cache.persistence.wal.SegmentedRingByteBuffer) MappedByteBuffer(java.nio.MappedByteBuffer) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

WALPointer (org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)122 WALRecord (org.apache.ignite.internal.pagemem.wal.record.WALRecord)44 Test (org.junit.Test)41 IgniteEx (org.apache.ignite.internal.IgniteEx)38 WALIterator (org.apache.ignite.internal.pagemem.wal.WALIterator)36 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)30 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)27 CheckpointRecord (org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord)24 IgniteWriteAheadLogManager (org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager)23 DataRecord (org.apache.ignite.internal.pagemem.wal.record.DataRecord)23 ArrayList (java.util.ArrayList)20 IgniteWalIteratorFactory (org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory)20 FullPageId (org.apache.ignite.internal.pagemem.FullPageId)19 DataEntry (org.apache.ignite.internal.pagemem.wal.record.DataEntry)19 PageSnapshot (org.apache.ignite.internal.pagemem.wal.record.PageSnapshot)19 File (java.io.File)18 T2 (org.apache.ignite.internal.util.typedef.T2)16 ByteBuffer (java.nio.ByteBuffer)15 UUID (java.util.UUID)15 IOException (java.io.IOException)14