Search in sources :

Example 1 with SnapshotRecord

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

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

Aggregations

UUID (java.util.UUID)2 CheckpointRecord (org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord)2 DataEntry (org.apache.ignite.internal.pagemem.wal.record.DataEntry)2 DataRecord (org.apache.ignite.internal.pagemem.wal.record.DataRecord)2 ExchangeRecord (org.apache.ignite.internal.pagemem.wal.record.ExchangeRecord)2 SnapshotRecord (org.apache.ignite.internal.pagemem.wal.record.SnapshotRecord)2 FileWALPointer (org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer)2 ArrayList (java.util.ArrayList)1 CacheState (org.apache.ignite.internal.pagemem.wal.record.CacheState)1 HeaderRecord (org.apache.ignite.internal.processors.cache.persistence.wal.record.HeaderRecord)1