Search in sources :

Example 21 with ReplicatedMapService

use of com.hazelcast.replicatedmap.impl.ReplicatedMapService in project hazelcast by hazelcast.

the class ReplicateUpdateToCallerOperation method run.

@Override
public void run() throws Exception {
    ILogger logger = getLogger();
    ReplicatedMapService service = getService();
    ReplicatedRecordStore store = service.getReplicatedRecordStore(name, true, getPartitionId());
    long currentVersion = store.getVersion();
    long updateVersion = response.getVersion();
    if (currentVersion >= updateVersion) {
        if (logger.isFineEnabled()) {
            logger.fine("Rejecting stale update received for replicated map: " + name + "  partitionId=" + getPartitionId() + " current version: " + currentVersion + " update version: " + updateVersion);
        }
        return;
    }
    Object key = store.marshall(dataKey);
    Object value = store.marshall(dataValue);
    if (isRemove) {
        store.removeWithVersion(key, updateVersion);
    } else {
        store.putWithVersion(key, value, ttl, TimeUnit.MILLISECONDS, true, updateVersion);
    }
    publishEvent();
}
Also used : ReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore) ReplicatedMapService(com.hazelcast.replicatedmap.impl.ReplicatedMapService) ILogger(com.hazelcast.logging.ILogger)

Example 22 with ReplicatedMapService

use of com.hazelcast.replicatedmap.impl.ReplicatedMapService 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 23 with ReplicatedMapService

use of com.hazelcast.replicatedmap.impl.ReplicatedMapService in project hazelcast by hazelcast.

the class ValuesOperation method run.

@Override
public void run() throws Exception {
    ReplicatedMapService service = getService();
    Collection<ReplicatedRecordStore> stores = service.getAllReplicatedRecordStores(name);
    Collection<ReplicatedRecord> values = new ArrayList<ReplicatedRecord>();
    for (ReplicatedRecordStore store : stores) {
        values.addAll(store.values(false));
    }
    Collection<Data> dataValues = new ArrayList<Data>(values.size());
    SerializationService serializationService = getNodeEngine().getSerializationService();
    for (ReplicatedRecord value : values) {
        dataValues.add(serializationService.toData(value.getValue()));
    }
    response = new ReplicatedMapValueCollection(dataValues);
}
Also used : ReplicatedRecord(com.hazelcast.replicatedmap.impl.record.ReplicatedRecord) ReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore) ReplicatedMapService(com.hazelcast.replicatedmap.impl.ReplicatedMapService) ArrayList(java.util.ArrayList) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) ReplicatedMapValueCollection(com.hazelcast.replicatedmap.impl.client.ReplicatedMapValueCollection)

Example 24 with ReplicatedMapService

use of com.hazelcast.replicatedmap.impl.ReplicatedMapService in project hazelcast by hazelcast.

the class CheckReplicaVersionOperation method run.

@Override
public void run() throws Exception {
    ILogger logger = getLogger();
    int partitionId = getPartitionId();
    ReplicatedMapService service = getService();
    PartitionContainer container = service.getPartitionContainer(getPartitionId());
    ConcurrentMap<String, ReplicatedRecordStore> stores = container.getStores();
    for (Map.Entry<String, Long> entry : versions.entrySet()) {
        String name = entry.getKey();
        Long version = entry.getValue();
        ReplicatedRecordStore store = stores.get(name);
        if (store == null) {
            if (logger.isFineEnabled()) {
                logger.fine("Missing store on the replica ! map: " + name + " owner version:" + version + " partitionId=" + partitionId);
            }
            requestDataFromOwner(name);
        } else if (store.isStale(version)) {
            if (logger.isFineEnabled()) {
                logger.fine("Stale replica! map: " + name + " owner version: " + version + " replica version: " + store.getVersion() + " partitionId=" + partitionId);
            }
            requestDataFromOwner(name);
        }
    }
}
Also used : PartitionContainer(com.hazelcast.replicatedmap.impl.PartitionContainer) ReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore) ReplicatedMapService(com.hazelcast.replicatedmap.impl.ReplicatedMapService) ILogger(com.hazelcast.logging.ILogger) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Example 25 with ReplicatedMapService

use of com.hazelcast.replicatedmap.impl.ReplicatedMapService in project hazelcast by hazelcast.

the class ClearOperation method run.

@Override
public void run() throws Exception {
    if (getNodeEngine().getConfig().isLiteMember()) {
        return;
    }
    ReplicatedMapService service = getService();
    ReplicatedRecordStore store = service.getReplicatedRecordStore(mapName, false, getPartitionId());
    if (store == null) {
        return;
    }
    response = store.size();
    if (replicateClear) {
        store.clear();
        replicateClearOperation(version);
    } else {
        store.clearWithVersion(version);
    }
}
Also used : ReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore) ReplicatedMapService(com.hazelcast.replicatedmap.impl.ReplicatedMapService)

Aggregations

ReplicatedMapService (com.hazelcast.replicatedmap.impl.ReplicatedMapService)32 ReplicatedRecordStore (com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore)17 ILogger (com.hazelcast.logging.ILogger)6 Data (com.hazelcast.nio.serialization.Data)6 ReplicatedMapEventPublishingService (com.hazelcast.replicatedmap.impl.ReplicatedMapEventPublishingService)6 HazelcastInstance (com.hazelcast.core.HazelcastInstance)5 Test (org.junit.Test)5 ReplicatedRecord (com.hazelcast.replicatedmap.impl.record.ReplicatedRecord)4 ParallelTest (com.hazelcast.test.annotation.ParallelTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Config (com.hazelcast.config.Config)3 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)3 SerializationService (com.hazelcast.spi.serialization.SerializationService)3 ArrayList (java.util.ArrayList)3 QueueService (com.hazelcast.collection.impl.queue.QueueService)2 DistributedExecutorService (com.hazelcast.executor.impl.DistributedExecutorService)2 MapService (com.hazelcast.map.impl.MapService)2 MultiMapService (com.hazelcast.multimap.impl.MultiMapService)2 Address (com.hazelcast.nio.Address)2 PartitionContainer (com.hazelcast.replicatedmap.impl.PartitionContainer)2