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;
}
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;
}
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);
}
}
Aggregations