Search in sources :

Example 6 with RecordMigrationInfo

use of com.hazelcast.replicatedmap.impl.record.RecordMigrationInfo in project hazelcast by hazelcast.

the class ReplicationOperation method fetchReplicatedMapRecords.

private void fetchReplicatedMapRecords(PartitionContainer container) {
    int storeCount = container.getStores().size();
    data = new HashMap<String, Set<RecordMigrationInfo>>(storeCount);
    versions = new HashMap<String, Long>(storeCount);
    for (Map.Entry<String, ReplicatedRecordStore> entry : container.getStores().entrySet()) {
        String name = entry.getKey();
        ReplicatedRecordStore store = entry.getValue();
        Set<RecordMigrationInfo> recordSet = new HashSet<RecordMigrationInfo>(store.size());
        Iterator<ReplicatedRecord> iterator = store.recordIterator();
        while (iterator.hasNext()) {
            ReplicatedRecord record = iterator.next();
            Data dataKey = serializationService.toData(record.getKeyInternal());
            Data dataValue = serializationService.toData(record.getValueInternal());
            RecordMigrationInfo migrationInfo = new RecordMigrationInfo();
            migrationInfo.setKey(dataKey);
            migrationInfo.setValue(dataValue);
            migrationInfo.setTtl(record.getTtlMillis());
            migrationInfo.setHits(record.getHits());
            migrationInfo.setCreationTime(record.getCreationTime());
            migrationInfo.setLastAccessTime(record.getLastAccessTime());
            migrationInfo.setLastUpdateTime(record.getUpdateTime());
            recordSet.add(migrationInfo);
        }
        data.put(name, recordSet);
        versions.put(name, store.getVersion());
    }
}
Also used : ReplicatedRecord(com.hazelcast.replicatedmap.impl.record.ReplicatedRecord) Set(java.util.Set) HashSet(java.util.HashSet) Data(com.hazelcast.nio.serialization.Data) RecordMigrationInfo(com.hazelcast.replicatedmap.impl.record.RecordMigrationInfo) AbstractReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.AbstractReplicatedRecordStore) ReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 7 with RecordMigrationInfo

use of com.hazelcast.replicatedmap.impl.record.RecordMigrationInfo in project hazelcast by hazelcast.

the class RequestMapDataOperation method getRecordSet.

private Set<RecordMigrationInfo> getRecordSet(ReplicatedRecordStore store) {
    Set<RecordMigrationInfo> recordSet = new HashSet<RecordMigrationInfo>(store.size());
    Iterator<ReplicatedRecord> iterator = store.recordIterator();
    while (iterator.hasNext()) {
        ReplicatedRecord record = iterator.next();
        SerializationService serializationService = getNodeEngine().getSerializationService();
        Data dataKey = serializationService.toData(record.getKeyInternal());
        Data dataValue = serializationService.toData(record.getValueInternal());
        recordSet.add(new RecordMigrationInfo(dataKey, dataValue, record.getTtlMillis()));
    }
    return recordSet;
}
Also used : ReplicatedRecord(com.hazelcast.replicatedmap.impl.record.ReplicatedRecord) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) RecordMigrationInfo(com.hazelcast.replicatedmap.impl.record.RecordMigrationInfo) HashSet(java.util.HashSet)

Example 8 with RecordMigrationInfo

use of com.hazelcast.replicatedmap.impl.record.RecordMigrationInfo in project hazelcast by hazelcast.

the class SyncReplicatedMapDataOperation method writeInternal.

@Override
protected void writeInternal(ObjectDataOutput out) throws IOException {
    out.writeUTF(name);
    out.writeLong(version);
    out.writeInt(recordSet.size());
    for (RecordMigrationInfo record : recordSet) {
        record.writeData(out);
    }
}
Also used : RecordMigrationInfo(com.hazelcast.replicatedmap.impl.record.RecordMigrationInfo)

Example 9 with RecordMigrationInfo

use of com.hazelcast.replicatedmap.impl.record.RecordMigrationInfo in project hazelcast by hazelcast.

the class SyncReplicatedMapDataOperation method run.

@Override
public void run() throws Exception {
    ILogger logger = getLogger();
    if (logger.isFineEnabled()) {
        logger.fine("Syncing " + recordSet.size() + " records and version: " + version + " for map: " + name + " partitionId=" + getPartitionId() + " from: " + getCallerAddress() + " to: " + getNodeEngine().getThisAddress());
    }
    ReplicatedMapService service = getService();
    AbstractReplicatedRecordStore store = (AbstractReplicatedRecordStore) service.getReplicatedRecordStore(name, true, getPartitionId());
    InternalReplicatedMapStorage<K, V> newStorage = new InternalReplicatedMapStorage<K, V>();
    for (RecordMigrationInfo record : recordSet) {
        K key = (K) store.marshall(record.getKey());
        V value = (V) store.marshall(record.getValue());
        ReplicatedRecord<K, V> replicatedRecord = buildReplicatedRecord(key, value, record.getTtl());
        ReplicatedRecord oldRecord = store.getReplicatedRecord(key);
        if (oldRecord != null) {
            replicatedRecord.setHits(oldRecord.getHits());
        }
        newStorage.put(key, replicatedRecord);
        if (record.getTtl() > 0) {
            store.scheduleTtlEntry(record.getTtl(), key, value);
        }
    }
    newStorage.syncVersion(version);
    AtomicReference<InternalReplicatedMapStorage<K, V>> storageRef = store.getStorageRef();
    storageRef.set(newStorage);
    store.setLoaded(true);
}
Also used : ReplicatedRecord(com.hazelcast.replicatedmap.impl.record.ReplicatedRecord) AbstractReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.AbstractReplicatedRecordStore) ReplicatedMapService(com.hazelcast.replicatedmap.impl.ReplicatedMapService) ILogger(com.hazelcast.logging.ILogger) InternalReplicatedMapStorage(com.hazelcast.replicatedmap.impl.record.InternalReplicatedMapStorage) RecordMigrationInfo(com.hazelcast.replicatedmap.impl.record.RecordMigrationInfo)

Example 10 with RecordMigrationInfo

use of com.hazelcast.replicatedmap.impl.record.RecordMigrationInfo in project hazelcast by hazelcast.

the class SyncReplicatedMapDataOperation method readInternal.

@Override
protected void readInternal(ObjectDataInput in) throws IOException {
    name = in.readUTF();
    version = in.readLong();
    int size = in.readInt();
    recordSet = new HashSet<RecordMigrationInfo>(size);
    for (int j = 0; j < size; j++) {
        RecordMigrationInfo record = new RecordMigrationInfo();
        record.readData(in);
        recordSet.add(record);
    }
}
Also used : RecordMigrationInfo(com.hazelcast.replicatedmap.impl.record.RecordMigrationInfo)

Aggregations

RecordMigrationInfo (com.hazelcast.replicatedmap.impl.record.RecordMigrationInfo)10 HashSet (java.util.HashSet)5 Set (java.util.Set)4 AbstractReplicatedRecordStore (com.hazelcast.replicatedmap.impl.record.AbstractReplicatedRecordStore)3 ReplicatedRecord (com.hazelcast.replicatedmap.impl.record.ReplicatedRecord)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ILogger (com.hazelcast.logging.ILogger)2 Data (com.hazelcast.nio.serialization.Data)2 ReplicatedMapService (com.hazelcast.replicatedmap.impl.ReplicatedMapService)2 ReplicatedRecordStore (com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore)2 ArrayDataSerializableFactory (com.hazelcast.internal.serialization.impl.ArrayDataSerializableFactory)1 Address (com.hazelcast.nio.Address)1 IdentifiedDataSerializable (com.hazelcast.nio.serialization.IdentifiedDataSerializable)1 PartitionContainer (com.hazelcast.replicatedmap.impl.PartitionContainer)1 InternalReplicatedMapStorage (com.hazelcast.replicatedmap.impl.record.InternalReplicatedMapStorage)1 ReplicatedMapEntryView (com.hazelcast.replicatedmap.impl.record.ReplicatedMapEntryView)1 OperationService (com.hazelcast.spi.OperationService)1 SerializationService (com.hazelcast.spi.serialization.SerializationService)1 ConstructorFunction (com.hazelcast.util.ConstructorFunction)1