Search in sources :

Example 6 with FileWALPointer

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

the class GridCacheOffheapManager method historicalIterator.

/**
 * {@inheritDoc}
 */
@Override
@Nullable
protected IgniteHistoricalIterator historicalIterator(CachePartitionPartialCountersMap partCntrs) throws IgniteCheckedException {
    if (partCntrs == null || partCntrs.isEmpty())
        return null;
    GridCacheDatabaseSharedManager database = (GridCacheDatabaseSharedManager) grp.shared().database();
    FileWALPointer minPtr = null;
    for (int i = 0; i < partCntrs.size(); i++) {
        int p = partCntrs.partitionAt(i);
        long initCntr = partCntrs.initialUpdateCounterAt(i);
        FileWALPointer startPtr = (FileWALPointer) database.searchPartitionCounter(grp.groupId(), p, initCntr);
        if (startPtr == null)
            throw new IgniteCheckedException("Could not find start pointer for partition [part=" + p + ", partCntrSince=" + initCntr + "]");
        if (minPtr == null || startPtr.compareTo(minPtr) == -1)
            minPtr = startPtr;
    }
    WALIterator it = grp.shared().wal().replay(minPtr);
    return new WALIteratorAdapter(grp, partCntrs, it);
}
Also used : FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with FileWALPointer

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

the class RecordDataV1Serializer method size.

/**
 * {@inheritDoc}
 */
@Override
public int size(WALRecord record) throws IgniteCheckedException {
    switch(record.type()) {
        case PAGE_RECORD:
            assert record instanceof PageSnapshot;
            PageSnapshot pageRec = (PageSnapshot) record;
            return pageRec.pageData().length + 12;
        case CHECKPOINT_RECORD:
            CheckpointRecord cpRec = (CheckpointRecord) record;
            assert cpRec.checkpointMark() == null || cpRec.checkpointMark() instanceof FileWALPointer : "Invalid WAL record: " + cpRec;
            int cacheStatesSize = cacheStatesSize(cpRec.cacheGroupStates());
            FileWALPointer walPtr = (FileWALPointer) cpRec.checkpointMark();
            return 18 + cacheStatesSize + (walPtr == null ? 0 : 16);
        case META_PAGE_INIT:
            return /*cache ID*/
            4 + /*page ID*/
            8 + /*ioType*/
            2 + /*ioVer*/
            2 + /*tree root*/
            8 + /*reuse root*/
            8;
        case PARTITION_META_PAGE_UPDATE_COUNTERS:
            return /*cache ID*/
            4 + /*page ID*/
            8 + /*upd cntr*/
            8 + /*rmv id*/
            8 + /*part size*/
            4 + /*counters page id*/
            8 + /*state*/
            1 + /*allocatedIdxCandidate*/
            4;
        case MEMORY_RECOVERY:
            return 8;
        case PARTITION_DESTROY:
            return /*cacheId*/
            4 + /*partId*/
            4;
        case DATA_RECORD:
            DataRecord dataRec = (DataRecord) record;
            return 4 + dataSize(dataRec);
        case METASTORE_DATA_RECORD:
            MetastoreDataRecord metastoreDataRec = (MetastoreDataRecord) record;
            return 4 + metastoreDataRec.key().getBytes().length + 4 + (metastoreDataRec.value() != null ? metastoreDataRec.value().length : 0);
        case HEADER_RECORD:
            return HEADER_RECORD_DATA_SIZE;
        case DATA_PAGE_INSERT_RECORD:
            DataPageInsertRecord diRec = (DataPageInsertRecord) record;
            return 4 + 8 + 2 + diRec.payload().length;
        case DATA_PAGE_UPDATE_RECORD:
            DataPageUpdateRecord uRec = (DataPageUpdateRecord) record;
            return 4 + 8 + 2 + 4 + uRec.payload().length;
        case DATA_PAGE_INSERT_FRAGMENT_RECORD:
            final DataPageInsertFragmentRecord difRec = (DataPageInsertFragmentRecord) record;
            return 4 + 8 + 8 + 4 + difRec.payloadSize();
        case DATA_PAGE_REMOVE_RECORD:
            return 4 + 8 + 1;
        case DATA_PAGE_SET_FREE_LIST_PAGE:
            return 4 + 8 + 8;
        case INIT_NEW_PAGE_RECORD:
            return 4 + 8 + 2 + 2 + 8;
        case BTREE_META_PAGE_INIT_ROOT:
            return 4 + 8 + 8;
        case BTREE_META_PAGE_INIT_ROOT2:
            return 4 + 8 + 8 + 2;
        case BTREE_META_PAGE_ADD_ROOT:
            return 4 + 8 + 8;
        case BTREE_META_PAGE_CUT_ROOT:
            return 4 + 8;
        case BTREE_INIT_NEW_ROOT:
            NewRootInitRecord<?> riRec = (NewRootInitRecord<?>) record;
            return 4 + 8 + 8 + 2 + 2 + 8 + 8 + riRec.io().getItemSize();
        case BTREE_PAGE_RECYCLE:
            return 4 + 8 + 8;
        case BTREE_PAGE_INSERT:
            InsertRecord<?> inRec = (InsertRecord<?>) record;
            return 4 + 8 + 2 + 2 + 2 + 8 + inRec.io().getItemSize();
        case BTREE_FIX_LEFTMOST_CHILD:
            return 4 + 8 + 8;
        case BTREE_FIX_COUNT:
            return 4 + 8 + 2;
        case BTREE_PAGE_REPLACE:
            ReplaceRecord<?> rRec = (ReplaceRecord<?>) record;
            return 4 + 8 + 2 + 2 + 2 + rRec.io().getItemSize();
        case BTREE_PAGE_REMOVE:
            return 4 + 8 + 2 + 2;
        case BTREE_PAGE_INNER_REPLACE:
            return 4 + 8 + 2 + 8 + 2 + 8;
        case BTREE_FORWARD_PAGE_SPLIT:
            return 4 + 8 + 8 + 2 + 2 + 8 + 2 + 2;
        case BTREE_EXISTING_PAGE_SPLIT:
            return 4 + 8 + 2 + 8;
        case BTREE_PAGE_MERGE:
            return 4 + 8 + 8 + 2 + 8 + 1;
        case BTREE_FIX_REMOVE_ID:
            return 4 + 8 + 8;
        case PAGES_LIST_SET_NEXT:
            return 4 + 8 + 8;
        case PAGES_LIST_SET_PREVIOUS:
            return 4 + 8 + 8;
        case PAGES_LIST_INIT_NEW_PAGE:
            return 4 + 8 + 4 + 4 + 8 + 8 + 8;
        case PAGES_LIST_ADD_PAGE:
            return 4 + 8 + 8;
        case PAGES_LIST_REMOVE_PAGE:
            return 4 + 8 + 8;
        case TRACKING_PAGE_DELTA:
            return 4 + 8 + 8 + 8 + 8;
        case META_PAGE_UPDATE_LAST_SUCCESSFUL_SNAPSHOT_ID:
            return 4 + 8 + 8 + 8;
        case META_PAGE_UPDATE_LAST_SUCCESSFUL_FULL_SNAPSHOT_ID:
            return 4 + 8 + 8;
        case META_PAGE_UPDATE_NEXT_SNAPSHOT_ID:
            return 4 + 8 + 8;
        case META_PAGE_UPDATE_LAST_ALLOCATED_INDEX:
            return 4 + 8 + 4;
        case PART_META_UPDATE_STATE:
            return /*cacheId*/
            4 + /*partId*/
            4 + /*State*/
            1 + /*Update Counter*/
            8;
        case PAGE_LIST_META_RESET_COUNT_RECORD:
            return /*cacheId*/
            4 + /*pageId*/
            8;
        case SWITCH_SEGMENT_RECORD:
            return 0;
        case TX_RECORD:
            return txRecordSerializer.size((TxRecord) record);
        default:
            throw new UnsupportedOperationException("Type: " + record.type());
    }
}
Also used : DataPageInsertFragmentRecord(org.apache.ignite.internal.pagemem.wal.record.delta.DataPageInsertFragmentRecord) FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer) NewRootInitRecord(org.apache.ignite.internal.pagemem.wal.record.delta.NewRootInitRecord) DataPageInsertRecord(org.apache.ignite.internal.pagemem.wal.record.delta.DataPageInsertRecord) InsertRecord(org.apache.ignite.internal.pagemem.wal.record.delta.InsertRecord) DataPageUpdateRecord(org.apache.ignite.internal.pagemem.wal.record.delta.DataPageUpdateRecord) CheckpointRecord(org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord) MetastoreDataRecord(org.apache.ignite.internal.pagemem.wal.record.MetastoreDataRecord) 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) 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)

Example 8 with FileWALPointer

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

the class RecordDataV2Serializer method writeRecord.

/**
 * {@inheritDoc}
 */
@Override
public void writeRecord(WALRecord rec, ByteBuffer buf) throws IgniteCheckedException {
    if (rec instanceof HeaderRecord)
        throw new UnsupportedOperationException("Writing header records is forbidden since version 2 of serializer");
    switch(rec.type()) {
        case CHECKPOINT_RECORD:
            CheckpointRecord cpRec = (CheckpointRecord) rec;
            assert cpRec.checkpointMark() == null || cpRec.checkpointMark() instanceof FileWALPointer : "Invalid WAL record: " + cpRec;
            FileWALPointer walPtr = (FileWALPointer) 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:
            DataRecord dataRec = (DataRecord) rec;
            buf.putInt(dataRec.writeEntries().size());
            buf.putLong(dataRec.timestamp());
            for (DataEntry dataEntry : dataRec.writeEntries()) RecordDataV1Serializer.putDataEntry(buf, dataEntry);
            break;
        case SNAPSHOT:
            SnapshotRecord snpRec = (SnapshotRecord) rec;
            buf.putLong(snpRec.getSnapshotId());
            buf.put(snpRec.isFull() ? (byte) 1 : 0);
            break;
        case EXCHANGE:
            ExchangeRecord r = (ExchangeRecord) rec;
            buf.putInt(r.getType().ordinal());
            buf.putShort(r.getConstId());
            buf.putLong(r.timestamp());
            break;
        case TX_RECORD:
            txRecordSerializer.write((TxRecord) rec, buf);
            break;
        case BASELINE_TOP_RECORD:
            bltRecSerializer.write((BaselineTopologyRecord) rec, buf);
            break;
        default:
            delegateSerializer.writeRecord(rec, buf);
    }
}
Also used : DataEntry(org.apache.ignite.internal.pagemem.wal.record.DataEntry) FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer) HeaderRecord(org.apache.ignite.internal.processors.cache.persistence.wal.record.HeaderRecord) ExchangeRecord(org.apache.ignite.internal.pagemem.wal.record.ExchangeRecord) CheckpointRecord(org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord) DataRecord(org.apache.ignite.internal.pagemem.wal.record.DataRecord) SnapshotRecord(org.apache.ignite.internal.pagemem.wal.record.SnapshotRecord) UUID(java.util.UUID)

Example 9 with FileWALPointer

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

the class RecordDataV2Serializer method readRecord.

/**
 * {@inheritDoc}
 */
@Override
public WALRecord readRecord(WALRecord.RecordType type, ByteBufferBackedDataInput in) throws IOException, IgniteCheckedException {
    switch(type) {
        case CHECKPOINT_RECORD:
            long msb = in.readLong();
            long lsb = in.readLong();
            boolean hasPtr = in.readByte() != 0;
            int idx0 = 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(idx0, off, len) : null;
            CheckpointRecord cpRec = new CheckpointRecord(new UUID(msb, lsb), walPtr, end);
            cpRec.cacheGroupStates(states);
            return cpRec;
        case DATA_RECORD:
            int entryCnt = in.readInt();
            long timeStamp = in.readLong();
            List<DataEntry> entries = new ArrayList<>(entryCnt);
            for (int i = 0; i < entryCnt; i++) entries.add(delegateSerializer.readDataEntry(in));
            return new DataRecord(entries, timeStamp);
        case SNAPSHOT:
            long snpId = in.readLong();
            byte full = in.readByte();
            return new SnapshotRecord(snpId, full == 1);
        case EXCHANGE:
            int idx = in.readInt();
            short constId = in.readShort();
            long ts = in.readLong();
            return new ExchangeRecord(constId, ExchangeRecord.Type.values()[idx], ts);
        case TX_RECORD:
            return txRecordSerializer.read(in);
        case BASELINE_TOP_RECORD:
            return bltRecSerializer.read(in);
        default:
            return delegateSerializer.readRecord(type, in);
    }
}
Also used : FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer) ArrayList(java.util.ArrayList) CheckpointRecord(org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord) CacheState(org.apache.ignite.internal.pagemem.wal.record.CacheState) SnapshotRecord(org.apache.ignite.internal.pagemem.wal.record.SnapshotRecord) DataEntry(org.apache.ignite.internal.pagemem.wal.record.DataEntry) ExchangeRecord(org.apache.ignite.internal.pagemem.wal.record.ExchangeRecord) DataRecord(org.apache.ignite.internal.pagemem.wal.record.DataRecord) UUID(java.util.UUID)

Example 10 with FileWALPointer

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

the class RecordV2Serializer method readPositionAndCheckPoint.

/**
 * @param in Data input to read pointer from.
 * @param skipPositionCheck Flag for skipping position check.
 * @return Read file WAL pointer.
 * @throws IOException If failed to write.
 */
@SuppressWarnings("UnusedReturnValue")
private static FileWALPointer readPositionAndCheckPoint(DataInput in, WALPointer expPtr, boolean skipPositionCheck) throws IgniteCheckedException, IOException {
    long idx = in.readLong();
    int fileOff = in.readInt();
    int len = in.readInt();
    FileWALPointer p = (FileWALPointer) expPtr;
    if (!F.eq(idx, p.index()) || (!skipPositionCheck && !F.eq(fileOff, p.fileOffset())))
        throw new WalSegmentTailReachedException("WAL segment tail is reached. [ " + "Expected next state: {Index=" + p.index() + ",Offset=" + p.fileOffset() + "}, " + "Actual state : {Index=" + idx + ",Offset=" + fileOff + "} ]", null);
    return new FileWALPointer(idx, fileOff, len);
}
Also used : FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer) WalSegmentTailReachedException(org.apache.ignite.internal.processors.cache.persistence.wal.WalSegmentTailReachedException)

Aggregations

FileWALPointer (org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer)15 CheckpointRecord (org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 DataRecord (org.apache.ignite.internal.pagemem.wal.record.DataRecord)5 IOException (java.io.IOException)4 UUID (java.util.UUID)4 DataEntry (org.apache.ignite.internal.pagemem.wal.record.DataEntry)4 PageSnapshot (org.apache.ignite.internal.pagemem.wal.record.PageSnapshot)4 FileChannel (java.nio.channels.FileChannel)3 ArrayList (java.util.ArrayList)3 MetastoreDataRecord (org.apache.ignite.internal.pagemem.wal.record.MetastoreDataRecord)3 DataPageInsertFragmentRecord (org.apache.ignite.internal.pagemem.wal.record.delta.DataPageInsertFragmentRecord)3 DataPageInsertRecord (org.apache.ignite.internal.pagemem.wal.record.delta.DataPageInsertRecord)3 DataPageUpdateRecord (org.apache.ignite.internal.pagemem.wal.record.delta.DataPageUpdateRecord)3 MetaPageUpdatePartitionDataRecord (org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdatePartitionDataRecord)3 File (java.io.File)2 ByteBuffer (java.nio.ByteBuffer)2 ExchangeRecord (org.apache.ignite.internal.pagemem.wal.record.ExchangeRecord)2 LazyDataEntry (org.apache.ignite.internal.pagemem.wal.record.LazyDataEntry)2 MemoryRecoveryRecord (org.apache.ignite.internal.pagemem.wal.record.MemoryRecoveryRecord)2