Search in sources :

Example 1 with UUIDSerializationUtil.writeUUID

use of com.hazelcast.internal.util.UUIDSerializationUtil.writeUUID in project hazelcast by hazelcast.

the class MapChunk method writeWriteBehindState.

private void writeWriteBehindState(ObjectDataOutput out, RecordStore recordStore) throws IOException {
    MapContainer mapContainer = recordStore.getMapContainer();
    MapConfig mapConfig = mapContainer.getMapConfig();
    if (mapConfig.getTotalBackupCount() < getReplicaIndex() || !mapContainer.getMapStoreContext().isWriteBehindMapStoreEnabled()) {
        // we don't have hasWriteBehindState
        out.writeBoolean(false);
        return;
    }
    // we have hasWriteBehindState
    out.writeBoolean(true);
    MapServiceContext mapServiceContext = recordStore.getMapContainer().getMapServiceContext();
    WriteBehindStore mapDataStore = (WriteBehindStore) recordStore.getMapDataStore();
    // write delayed entries
    List<DelayedEntry> delayedEntries = mapDataStore.getWriteBehindQueue().asList();
    out.writeInt(delayedEntries.size());
    for (DelayedEntry e : delayedEntries) {
        Data key = mapServiceContext.toData(e.getKey());
        Data value = mapServiceContext.toData(e.getValue());
        long expirationTime = e.getExpirationTime();
        IOUtil.writeData(out, key);
        IOUtil.writeData(out, value);
        out.writeLong(expirationTime);
        out.writeLong(e.getStoreTime());
        out.writeInt(e.getPartitionId());
        out.writeLong(e.getSequence());
        UUIDSerializationUtil.writeUUID(out, e.getTxnId());
    }
    // write sequences
    Deque<WriteBehindStore.Sequence> sequences = new ArrayDeque<>(mapDataStore.getFlushSequences());
    out.writeInt(sequences.size());
    for (WriteBehindStore.Sequence sequence : sequences) {
        out.writeLong(sequence.getSequence());
        out.writeBoolean(sequence.isFullFlush());
    }
    // write txn reservations
    Map<UUID, Long> reservationsByTxnId = mapDataStore.getTxnReservedCapacityCounter().getReservedCapacityCountPerTxnId();
    out.writeInt(reservationsByTxnId.size());
    for (Map.Entry<UUID, Long> counterByTxnId : reservationsByTxnId.entrySet()) {
        writeUUID(out, counterByTxnId.getKey());
        out.writeLong(counterByTxnId.getValue());
    }
}
Also used : Data(com.hazelcast.internal.serialization.Data) DelayedEntry(com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntry) DelayedEntries.newAddedDelayedEntry(com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntries.newAddedDelayedEntry) MapContainer(com.hazelcast.map.impl.MapContainer) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) WriteBehindStore(com.hazelcast.map.impl.mapstore.writebehind.WriteBehindStore) ArrayDeque(java.util.ArrayDeque) MapConfig(com.hazelcast.config.MapConfig) UUIDSerializationUtil.readUUID(com.hazelcast.internal.util.UUIDSerializationUtil.readUUID) UUID(java.util.UUID) UUIDSerializationUtil.writeUUID(com.hazelcast.internal.util.UUIDSerializationUtil.writeUUID) Map(java.util.Map) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap)

Example 2 with UUIDSerializationUtil.writeUUID

use of com.hazelcast.internal.util.UUIDSerializationUtil.writeUUID in project hazelcast by hazelcast.

the class WriteBehindStateHolder method writeData.

@Override
public void writeData(ObjectDataOutput out) throws IOException {
    MapService mapService = mapReplicationOperation.getService();
    MapServiceContext mapServiceContext = mapService.getMapServiceContext();
    out.writeInt(delayedEntries.size());
    for (Map.Entry<String, List<DelayedEntry>> entry : delayedEntries.entrySet()) {
        out.writeString(entry.getKey());
        List<DelayedEntry> delayedEntryList = entry.getValue();
        out.writeInt(delayedEntryList.size());
        for (DelayedEntry e : delayedEntryList) {
            Data key = mapServiceContext.toData(e.getKey());
            Data value = mapServiceContext.toData(e.getValue());
            long expirationTime = e.getExpirationTime();
            IOUtil.writeData(out, key);
            IOUtil.writeData(out, value);
            out.writeLong(expirationTime);
            out.writeLong(e.getStoreTime());
            out.writeInt(e.getPartitionId());
            out.writeLong(e.getSequence());
            UUIDSerializationUtil.writeUUID(out, e.getTxnId());
        }
    }
    out.writeInt(flushSequences.size());
    for (Map.Entry<String, Queue<WriteBehindStore.Sequence>> entry : flushSequences.entrySet()) {
        out.writeString(entry.getKey());
        Queue<WriteBehindStore.Sequence> queue = entry.getValue();
        out.writeInt(queue.size());
        for (WriteBehindStore.Sequence sequence : queue) {
            out.writeLong(sequence.getSequence());
            out.writeBoolean(sequence.isFullFlush());
        }
    }
    out.writeInt(reservationsByTxnIdPerMap.size());
    for (Map.Entry<String, Map<UUID, Long>> entry : reservationsByTxnIdPerMap.entrySet()) {
        out.writeString(entry.getKey());
        Map<UUID, Long> reservationsByTxnId = entry.getValue();
        out.writeInt(reservationsByTxnId.size());
        for (Map.Entry<UUID, Long> counterByTxnId : reservationsByTxnId.entrySet()) {
            writeUUID(out, counterByTxnId.getKey());
            out.writeLong(counterByTxnId.getValue());
        }
    }
}
Also used : Data(com.hazelcast.internal.serialization.Data) DelayedEntry(com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntry) DelayedEntries.newAddedDelayedEntry(com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntries.newAddedDelayedEntry) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) WriteBehindStore(com.hazelcast.map.impl.mapstore.writebehind.WriteBehindStore) ArrayList(java.util.ArrayList) List(java.util.List) MapService(com.hazelcast.map.impl.MapService) UUIDSerializationUtil.readUUID(com.hazelcast.internal.util.UUIDSerializationUtil.readUUID) UUIDSerializationUtil.writeUUID(com.hazelcast.internal.util.UUIDSerializationUtil.writeUUID) UUID(java.util.UUID) HashMap(java.util.HashMap) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap) Map(java.util.Map) WriteBehindQueue(com.hazelcast.map.impl.mapstore.writebehind.WriteBehindQueue) Queue(java.util.Queue)

Aggregations

Data (com.hazelcast.internal.serialization.Data)2 MapUtil.createHashMap (com.hazelcast.internal.util.MapUtil.createHashMap)2 UUIDSerializationUtil.readUUID (com.hazelcast.internal.util.UUIDSerializationUtil.readUUID)2 UUIDSerializationUtil.writeUUID (com.hazelcast.internal.util.UUIDSerializationUtil.writeUUID)2 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)2 WriteBehindStore (com.hazelcast.map.impl.mapstore.writebehind.WriteBehindStore)2 DelayedEntries.newAddedDelayedEntry (com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntries.newAddedDelayedEntry)2 DelayedEntry (com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntry)2 Map (java.util.Map)2 UUID (java.util.UUID)2 MapConfig (com.hazelcast.config.MapConfig)1 MapContainer (com.hazelcast.map.impl.MapContainer)1 MapService (com.hazelcast.map.impl.MapService)1 WriteBehindQueue (com.hazelcast.map.impl.mapstore.writebehind.WriteBehindQueue)1 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Queue (java.util.Queue)1