Search in sources :

Example 1 with AbstractReplicatedRecordStore

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

the class ReplicationOperation method fillRecordStoreWithRecords.

private void fillRecordStoreWithRecords(ReplicatedMapService service) {
    for (Map.Entry<String, Set<RecordMigrationInfo>> dataEntry : data.entrySet()) {
        Set<RecordMigrationInfo> recordSet = dataEntry.getValue();
        String name = dataEntry.getKey();
        AbstractReplicatedRecordStore store = (AbstractReplicatedRecordStore) service.getReplicatedRecordStore(name, true, getPartitionId());
        long version = versions.get(name);
        store.putRecords(recordSet, version);
        store.setLoaded(true);
    }
}
Also used : Set(java.util.Set) SetUtil.createHashSet(com.hazelcast.internal.util.SetUtil.createHashSet) AbstractReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.AbstractReplicatedRecordStore) RecordMigrationInfo(com.hazelcast.replicatedmap.impl.record.RecordMigrationInfo) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap) Map(java.util.Map)

Example 2 with AbstractReplicatedRecordStore

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

the class PartitionContainer method buildConstructorFunction.

private ConstructorFunction<String, ReplicatedRecordStore> buildConstructorFunction() {
    return new ConstructorFunction<String, ReplicatedRecordStore>() {

        @Override
        public ReplicatedRecordStore createNew(String name) {
            ReplicatedMapConfig replicatedMapConfig = service.getReplicatedMapConfig(name);
            InMemoryFormat inMemoryFormat = replicatedMapConfig.getInMemoryFormat();
            AbstractReplicatedRecordStore replicatedRecordStorage = null;
            switch(inMemoryFormat) {
                case OBJECT:
                    replicatedRecordStorage = new ObjectReplicatedRecordStorage(name, service, partitionId);
                    break;
                case BINARY:
                    replicatedRecordStorage = new DataReplicatedRecordStore(name, service, partitionId);
                    break;
                case NATIVE:
                    throw new IllegalStateException("Native memory not yet supported for replicated map");
                default:
                    throw new IllegalStateException("Unhandled in memory format:" + inMemoryFormat);
            }
            return replicatedRecordStorage;
        }
    };
}
Also used : AbstractReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.AbstractReplicatedRecordStore) ReplicatedMapConfig(com.hazelcast.config.ReplicatedMapConfig) ObjectReplicatedRecordStorage(com.hazelcast.replicatedmap.impl.record.ObjectReplicatedRecordStorage) ConstructorFunction(com.hazelcast.util.ConstructorFunction) InMemoryFormat(com.hazelcast.config.InMemoryFormat) DataReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.DataReplicatedRecordStore)

Example 3 with AbstractReplicatedRecordStore

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

the class ReplicatedMapEventPublishingService method dispatchEvent.

@Override
public void dispatchEvent(Object event, Object listener) {
    if ((event instanceof EntryEventData)) {
        EntryEventData entryEventData = (EntryEventData) event;
        Member member = getMember(entryEventData);
        EntryEvent entryEvent = createDataAwareEntryEvent(entryEventData, member);
        EntryListener entryListener = (EntryListener) listener;
        switch(entryEvent.getEventType()) {
            case ADDED:
                entryListener.entryAdded(entryEvent);
                break;
            case EVICTED:
                entryListener.entryEvicted(entryEvent);
                break;
            case UPDATED:
                entryListener.entryUpdated(entryEvent);
                break;
            case REMOVED:
                entryListener.entryRemoved(entryEvent);
                break;
            default:
                throw new IllegalArgumentException("event type " + entryEvent.getEventType() + " not supported");
        }
        String mapName = ((EntryEventData) event).getMapName();
        Boolean statisticsEnabled = statisticsMap.get(mapName);
        if (statisticsEnabled == null) {
            ReplicatedMapConfig mapConfig = config.findReplicatedMapConfig(mapName);
            statisticsEnabled = mapConfig.isStatisticsEnabled();
            statisticsMap.put(mapName, statisticsEnabled);
        }
        if (statisticsEnabled) {
            int partitionId = nodeEngine.getPartitionService().getPartitionId(entryEventData.getDataKey());
            ReplicatedRecordStore recordStore = replicatedMapService.getPartitionContainer(partitionId).getRecordStore(mapName);
            if (recordStore instanceof AbstractReplicatedRecordStore) {
                LocalReplicatedMapStatsImpl stats = ((AbstractReplicatedRecordStore) recordStore).getStats();
                stats.incrementReceivedEvents();
            }
        }
    } else if (event instanceof MapEventData) {
        MapEventData mapEventData = (MapEventData) event;
        Member member = getMember(mapEventData);
        MapEvent mapEvent = new MapEvent(mapEventData.getMapName(), member, mapEventData.getEventType(), mapEventData.getNumberOfEntries());
        EntryListener entryListener = (EntryListener) listener;
        EntryEventType type = EntryEventType.getByType(mapEventData.getEventType());
        if (type == EntryEventType.CLEAR_ALL) {
            entryListener.mapCleared(mapEvent);
        } else {
            throw new IllegalArgumentException("Unsupported EntryEventType: " + type);
        }
    }
}
Also used : AbstractReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.AbstractReplicatedRecordStore) MapEvent(com.hazelcast.map.MapEvent) MapEventData(com.hazelcast.map.impl.event.MapEventData) EntryListener(com.hazelcast.core.EntryListener) EntryEventType(com.hazelcast.core.EntryEventType) LocalReplicatedMapStatsImpl(com.hazelcast.internal.monitor.impl.LocalReplicatedMapStatsImpl) AbstractReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.AbstractReplicatedRecordStore) ReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore) DataAwareEntryEvent(com.hazelcast.map.impl.DataAwareEntryEvent) EntryEvent(com.hazelcast.core.EntryEvent) ReplicatedMapConfig(com.hazelcast.config.ReplicatedMapConfig) EntryEventData(com.hazelcast.map.impl.event.EntryEventData) Member(com.hazelcast.cluster.Member)

Example 4 with AbstractReplicatedRecordStore

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

the class SyncReplicatedMapDataOperation method run.

@Override
@SuppressWarnings("unchecked")
public void run() throws Exception {
    ILogger logger = getLogger();
    if (logger.isFineEnabled()) {
        logger.fine("Syncing " + recordSet.size() + " records (version " + version + ") for replicated 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<>();
    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)

Aggregations

AbstractReplicatedRecordStore (com.hazelcast.replicatedmap.impl.record.AbstractReplicatedRecordStore)4 ReplicatedMapConfig (com.hazelcast.config.ReplicatedMapConfig)2 RecordMigrationInfo (com.hazelcast.replicatedmap.impl.record.RecordMigrationInfo)2 Member (com.hazelcast.cluster.Member)1 InMemoryFormat (com.hazelcast.config.InMemoryFormat)1 EntryEvent (com.hazelcast.core.EntryEvent)1 EntryEventType (com.hazelcast.core.EntryEventType)1 EntryListener (com.hazelcast.core.EntryListener)1 LocalReplicatedMapStatsImpl (com.hazelcast.internal.monitor.impl.LocalReplicatedMapStatsImpl)1 MapUtil.createHashMap (com.hazelcast.internal.util.MapUtil.createHashMap)1 SetUtil.createHashSet (com.hazelcast.internal.util.SetUtil.createHashSet)1 ILogger (com.hazelcast.logging.ILogger)1 MapEvent (com.hazelcast.map.MapEvent)1 DataAwareEntryEvent (com.hazelcast.map.impl.DataAwareEntryEvent)1 EntryEventData (com.hazelcast.map.impl.event.EntryEventData)1 MapEventData (com.hazelcast.map.impl.event.MapEventData)1 ReplicatedMapService (com.hazelcast.replicatedmap.impl.ReplicatedMapService)1 DataReplicatedRecordStore (com.hazelcast.replicatedmap.impl.record.DataReplicatedRecordStore)1 InternalReplicatedMapStorage (com.hazelcast.replicatedmap.impl.record.InternalReplicatedMapStorage)1 ObjectReplicatedRecordStorage (com.hazelcast.replicatedmap.impl.record.ObjectReplicatedRecordStorage)1