Search in sources :

Example 21 with ReplicatedRecordStore

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

the class ReplicatedMapReorderedReplicationTest method testNonConvergingReplicatedMaps.

@Test
public void testNonConvergingReplicatedMaps() throws Exception {
    final int nodeCount = 4;
    final int keyCount = 10000;
    final int threadCount = 2;
    updateFactory();
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
    final Config config = new Config();
    final HazelcastInstance[] instances = factory.newInstances(config, nodeCount);
    warmUpPartitions(instances);
    final int partitionId = randomPartitionOwnedBy(instances[0]).getPartitionId();
    final String mapName = randomMapName();
    final NodeEngineImpl nodeEngine = getNodeEngineImpl(instances[0]);
    final Thread[] threads = new Thread[threadCount];
    for (int i = 0; i < threadCount; i++) {
        final int startIndex = i;
        threads[i] = new Thread(new Runnable() {

            @Override
            public void run() {
                for (int j = startIndex; j < keyCount; j += threadCount) {
                    put(nodeEngine, mapName, partitionId, j, j);
                }
            }
        });
    }
    for (Thread thread : threads) {
        thread.start();
    }
    for (Thread thread : threads) {
        thread.join();
    }
    final ReplicatedRecordStore[] stores = new ReplicatedRecordStore[nodeCount];
    for (int i = 0; i < nodeCount; i++) {
        ReplicatedMapService service = getNodeEngineImpl(instances[i]).getService(ReplicatedMapService.SERVICE_NAME);
        service.triggerAntiEntropy();
        stores[i] = service.getReplicatedRecordStore(mapName, false, partitionId);
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            long version = stores[0].getVersion();
            for (ReplicatedRecordStore store : stores) {
                assertEquals(version, store.getVersion());
                assertFalse(store.isStale(version));
            }
        }
    });
    for (int i = 0; i < keyCount; i++) {
        for (ReplicatedRecordStore store : stores) {
            assertTrue(store.containsKey(i));
        }
    }
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) Config(com.hazelcast.config.Config) ReplicatedMapService(com.hazelcast.replicatedmap.impl.ReplicatedMapService) RetryableHazelcastException(com.hazelcast.spi.exception.RetryableHazelcastException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 22 with ReplicatedRecordStore

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

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

the class ClearOperation method run.

@Override
public void run() throws Exception {
    if (getNodeEngine().getLocalMember().isLiteMember()) {
        return;
    }
    ReplicatedMapService service = getService();
    ReplicatedRecordStore store = service.getReplicatedRecordStore(mapName, false, getPartitionId());
    if (store == null) {
        return;
    }
    response = store.getStorage().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)

Example 24 with ReplicatedRecordStore

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

the class ReplicateUpdateOperation method run.

@Override
public void run() throws Exception {
    ReplicatedMapService service = getService();
    ReplicatedRecordStore store = service.getReplicatedRecordStore(name, true, getPartitionId());
    long currentVersion = store.getVersion();
    long updateVersion = response.getVersion();
    if (currentVersion >= updateVersion) {
        ILogger logger = getLogger();
        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, false, updateVersion);
    }
    publishEvent();
}
Also used : ReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore) ReplicatedMapService(com.hazelcast.replicatedmap.impl.ReplicatedMapService) ILogger(com.hazelcast.logging.ILogger)

Example 25 with ReplicatedRecordStore

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

the class ReplicatedMapProxy method values.

@Nonnull
@Override
public Collection<V> values(@Nullable Comparator<V> comparator) {
    ensureNoSplitBrain(READ);
    Collection<ReplicatedRecordStore> stores = service.getAllReplicatedRecordStores(getName());
    List<V> values = new ArrayList<>();
    for (ReplicatedRecordStore store : stores) {
        values.addAll(store.values(comparator));
    }
    values.sort(comparator);
    return values;
}
Also used : ReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore) ArrayList(java.util.ArrayList) Nonnull(javax.annotation.Nonnull)

Aggregations

ReplicatedRecordStore (com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore)38 ReplicatedMapService (com.hazelcast.replicatedmap.impl.ReplicatedMapService)19 ReplicatedRecord (com.hazelcast.replicatedmap.impl.record.ReplicatedRecord)7 ArrayList (java.util.ArrayList)7 Data (com.hazelcast.internal.serialization.Data)5 ILogger (com.hazelcast.logging.ILogger)4 Nonnull (javax.annotation.Nonnull)4 Address (com.hazelcast.cluster.Address)3 SerializationService (com.hazelcast.internal.serialization.SerializationService)3 ReplicatedMapProxy (com.hazelcast.replicatedmap.impl.ReplicatedMapProxy)3 Map (java.util.Map)3 ReplicatedMapConfig (com.hazelcast.config.ReplicatedMapConfig)2 LocalReplicatedMapStatsImpl (com.hazelcast.internal.monitor.impl.LocalReplicatedMapStatsImpl)2 DataCollection (com.hazelcast.map.impl.DataCollection)2 PartitionContainer (com.hazelcast.replicatedmap.impl.PartitionContainer)2 AbstractBaseReplicatedRecordStore (com.hazelcast.replicatedmap.impl.record.AbstractBaseReplicatedRecordStore)2 AbstractReplicatedRecordStore (com.hazelcast.replicatedmap.impl.record.AbstractReplicatedRecordStore)2 RecordMigrationInfo (com.hazelcast.replicatedmap.impl.record.RecordMigrationInfo)2 BitSet (java.util.BitSet)2 Member (com.hazelcast.cluster.Member)1