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));
}
}
}
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);
}
}
}
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);
}
}
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();
}
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;
}
Aggregations