Search in sources :

Example 6 with CacheState

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

the class RecordDataV1Serializer method cacheStatesSize.

/**
 * @param states Partition states.
 * @return Size required to write partition states.
 */
private int cacheStatesSize(Map<Integer, CacheState> states) {
    // Need 4 bytes for the number of caches.
    int size = 2;
    for (Map.Entry<Integer, CacheState> entry : states.entrySet()) {
        // Cache ID.
        size += 4;
        // Need 2 bytes for the number of partitions.
        size += 2;
        CacheState state = entry.getValue();
        // 2 bytes partition ID, size and counter per partition.
        size += 18 * state.size();
    }
    return size;
}
Also used : CacheState(org.apache.ignite.internal.pagemem.wal.record.CacheState) Map(java.util.Map) HashMap(java.util.HashMap)

Example 7 with CacheState

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

the class RecordDataV2Serializer method readPartitionStates.

/**
 * @param buf Buffer to read from.
 * @return Read map.
 */
private Map<Integer, CacheState> readPartitionStates(DataInput buf) throws IOException {
    int caches = buf.readShort() & 0xFFFF;
    if (caches == 0)
        return Collections.emptyMap();
    Map<Integer, CacheState> states = new HashMap<>(caches, 1.0f);
    for (int i = 0; i < caches; i++) {
        int cacheId = buf.readInt();
        int parts = buf.readShort() & 0xFFFF;
        CacheState state = new CacheState(parts);
        for (int p = 0; p < parts; p++) {
            int partId = buf.readShort() & 0xFFFF;
            long size = buf.readLong();
            long partCntr = buf.readLong();
            byte partState = buf.readByte();
            state.addPartitionState(partId, size, partCntr, partState);
        }
        states.put(cacheId, state);
    }
    return states;
}
Also used : HashMap(java.util.HashMap) CacheState(org.apache.ignite.internal.pagemem.wal.record.CacheState)

Example 8 with CacheState

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

CacheState (org.apache.ignite.internal.pagemem.wal.record.CacheState)8 HashMap (java.util.HashMap)6 Map (java.util.Map)4 ArrayList (java.util.ArrayList)2 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 EOFException (java.io.EOFException)1 FullPageId (org.apache.ignite.internal.pagemem.FullPageId)1 ExchangeRecord (org.apache.ignite.internal.pagemem.wal.record.ExchangeRecord)1 LazyDataEntry (org.apache.ignite.internal.pagemem.wal.record.LazyDataEntry)1 MemoryRecoveryRecord (org.apache.ignite.internal.pagemem.wal.record.MemoryRecoveryRecord)1 MetastoreDataRecord (org.apache.ignite.internal.pagemem.wal.record.MetastoreDataRecord)1 PageSnapshot (org.apache.ignite.internal.pagemem.wal.record.PageSnapshot)1 SnapshotRecord (org.apache.ignite.internal.pagemem.wal.record.SnapshotRecord)1 WALRecord (org.apache.ignite.internal.pagemem.wal.record.WALRecord)1 DataPageInsertFragmentRecord (org.apache.ignite.internal.pagemem.wal.record.delta.DataPageInsertFragmentRecord)1 DataPageInsertRecord (org.apache.ignite.internal.pagemem.wal.record.delta.DataPageInsertRecord)1 DataPageRemoveRecord (org.apache.ignite.internal.pagemem.wal.record.delta.DataPageRemoveRecord)1