use of com.hazelcast.spi.merge.SplitBrainMergePolicy in project hazelcast by hazelcast.
the class MapEventPublisherImpl method publishWanUpdate.
@Override
public void publishWanUpdate(@Nonnull String mapName, @Nonnull WanMapEntryView<Object, Object> entryView, boolean hasLoadProvenance) {
if (!isOwnedPartition(entryView.getDataKey())) {
return;
}
MapContainer mapContainer = mapServiceContext.getMapContainer(mapName);
SplitBrainMergePolicy wanMergePolicy = mapContainer.getWanMergePolicy();
WanMapAddOrUpdateEvent event = new WanMapAddOrUpdateEvent(mapName, wanMergePolicy, entryView);
publishWanEvent(mapName, event);
}
use of com.hazelcast.spi.merge.SplitBrainMergePolicy in project hazelcast by hazelcast.
the class MergePolicyValidator method checkMergeTypeProviderHasRequiredTypes.
/**
* Checks if the provided {@code mergeTypes} satisfy the requirements of a
* given merge policy.
*
* @param mergeTypes the provided merge types
* @param mergePolicyProvider the {@link SplitBrainMergePolicyProvider} to resolve merge policy classes
* @param mergePolicyClassName the merge policy class name
* @throws InvalidConfigurationException if the given merge policy is no {@link SplitBrainMergePolicy}
*/
static void checkMergeTypeProviderHasRequiredTypes(Class<? extends MergingValue> mergeTypes, SplitBrainMergePolicyProvider mergePolicyProvider, String mergePolicyClassName) {
if (mergePolicyProvider == null) {
return;
}
SplitBrainMergePolicy mergePolicy = getMergePolicyInstance(mergePolicyProvider, mergePolicyClassName);
checkSplitBrainMergePolicy(mergeTypes, mergePolicy);
}
use of com.hazelcast.spi.merge.SplitBrainMergePolicy in project hazelcast by hazelcast.
the class MergePolicyValidator method checkMapMergePolicy.
/**
* Checks the merge policy configuration
* aligns with {@link MapConfig}.
*
* @param mapConfig the {@link MapConfig}
* @param mergePolicyClassName class name of merge policy
* @param mergePolicyProvider the {@link
* SplitBrainMergePolicyProvider} to resolve merge policy classes
*/
public static void checkMapMergePolicy(MapConfig mapConfig, String mergePolicyClassName, SplitBrainMergePolicyProvider mergePolicyProvider) {
SplitBrainMergePolicy mergePolicyInstance = mergePolicyProvider.getMergePolicy(mergePolicyClassName);
List<Class> requiredMergeTypes = checkSplitBrainMergePolicy(SplitBrainMergeTypes.MapMergeTypes.class, mergePolicyInstance);
if (!mapConfig.isPerEntryStatsEnabled() && requiredMergeTypes != null) {
checkMapMergePolicyWhenStatisticsAreDisabled(mergePolicyClassName, requiredMergeTypes);
}
}
use of com.hazelcast.spi.merge.SplitBrainMergePolicy in project hazelcast by hazelcast.
the class MapMergePolicyQuickTest method testPutIfAbsentMapMergePolicy.
@Test
public void testPutIfAbsentMapMergePolicy() {
HazelcastInstance instance = createHazelcastInstance(getConfig());
String name = randomString();
IMap<String, String> map = instance.getMap(name);
MapServiceContext mapServiceContext = getMapServiceContext(instance);
Data dataKey = mapServiceContext.toData("key");
Data dataValue = mapServiceContext.toData("value1");
Data dataValue2 = mapServiceContext.toData("value2");
RecordStore recordStore = mapServiceContext.getRecordStore(getPartitionId(instance, "key"), name);
recordStore.beforeOperation();
NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
SplitBrainMergePolicyProvider mergePolicyProvider = nodeEngine.getSplitBrainMergePolicyProvider();
SplitBrainMergePolicy mergePolicy = mergePolicyProvider.getMergePolicy(PutIfAbsentMergePolicy.class.getName());
SimpleEntryView<Data, Data> initialEntry = new SimpleEntryView<>(dataKey, dataValue);
recordStore.merge(createMergingEntry(nodeEngine.getSerializationService(), initialEntry), mergePolicy, CallerProvenance.NOT_WAN);
SimpleEntryView<Data, Data> mergingEntry = new SimpleEntryView<>(dataKey, dataValue2);
recordStore.merge(createMergingEntry(nodeEngine.getSerializationService(), mergingEntry), mergePolicy, CallerProvenance.NOT_WAN);
assertEquals("value1", map.get("key"));
recordStore.afterOperation();
}
use of com.hazelcast.spi.merge.SplitBrainMergePolicy in project hazelcast by hazelcast.
the class WanMapSupportingService method handleAddOrUpdate.
private void handleAddOrUpdate(WanMapAddOrUpdateEvent replicationUpdate) {
SplitBrainMergePolicy mergePolicy = replicationUpdate.getMergePolicy();
String mapName = replicationUpdate.getObjectName();
MapOperationProvider operationProvider = mapServiceContext.getMapOperationProvider(mapName);
SerializationService serializationService = nodeEngine.getSerializationService();
MapMergeTypes<Object, Object> mergingEntry = createMergingEntry(serializationService, replicationUpdate.getEntryView());
// noinspection unchecked
MapOperation operation = operationProvider.createMergeOperation(mapName, mergingEntry, (SplitBrainMergePolicy<Object, MapMergeTypes<Object, Object>, Object>) mergePolicy, true);
try {
int partitionId = nodeEngine.getPartitionService().getPartitionId(replicationUpdate.getEntryView().getKey());
Future future = nodeEngine.getOperationService().invokeOnPartition(SERVICE_NAME, operation, partitionId);
future.get();
wanEventTypeCounters.incrementUpdate(mapName);
} catch (Throwable t) {
throw rethrow(t);
}
}
Aggregations