Search in sources :

Example 1 with SplitBrainMergePolicy

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);
}
Also used : SplitBrainMergePolicy(com.hazelcast.spi.merge.SplitBrainMergePolicy) WanMapAddOrUpdateEvent(com.hazelcast.map.impl.wan.WanMapAddOrUpdateEvent) MapContainer(com.hazelcast.map.impl.MapContainer)

Example 2 with SplitBrainMergePolicy

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);
}
Also used : SplitBrainMergePolicy(com.hazelcast.spi.merge.SplitBrainMergePolicy)

Example 3 with SplitBrainMergePolicy

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);
    }
}
Also used : SplitBrainMergePolicy(com.hazelcast.spi.merge.SplitBrainMergePolicy) SplitBrainMergeTypes(com.hazelcast.spi.merge.SplitBrainMergeTypes)

Example 4 with SplitBrainMergePolicy

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();
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) SplitBrainMergePolicy(com.hazelcast.spi.merge.SplitBrainMergePolicy) HazelcastInstance(com.hazelcast.core.HazelcastInstance) PutIfAbsentMergePolicy(com.hazelcast.spi.merge.PutIfAbsentMergePolicy) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) SimpleEntryView(com.hazelcast.map.impl.SimpleEntryView) Data(com.hazelcast.internal.serialization.Data) SplitBrainMergePolicyProvider(com.hazelcast.spi.merge.SplitBrainMergePolicyProvider) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with SplitBrainMergePolicy

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);
    }
}
Also used : SplitBrainMergePolicy(com.hazelcast.spi.merge.SplitBrainMergePolicy) SerializationService(com.hazelcast.internal.serialization.SerializationService) Future(java.util.concurrent.Future) MapMergeTypes(com.hazelcast.spi.merge.SplitBrainMergeTypes.MapMergeTypes) MapOperationProvider(com.hazelcast.map.impl.operation.MapOperationProvider) MapOperation(com.hazelcast.map.impl.operation.MapOperation)

Aggregations

SplitBrainMergePolicy (com.hazelcast.spi.merge.SplitBrainMergePolicy)9 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 Data (com.hazelcast.internal.serialization.Data)4 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)4 SimpleEntryView (com.hazelcast.map.impl.SimpleEntryView)4 RecordStore (com.hazelcast.map.impl.recordstore.RecordStore)4 SplitBrainMergePolicyProvider (com.hazelcast.spi.merge.SplitBrainMergePolicyProvider)4 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Test (org.junit.Test)4 NodeEngine (com.hazelcast.spi.impl.NodeEngine)3 PutIfAbsentMergePolicy (com.hazelcast.spi.merge.PutIfAbsentMergePolicy)2 MergePolicyConfig (com.hazelcast.config.MergePolicyConfig)1 SerializationService (com.hazelcast.internal.serialization.SerializationService)1 MapContainer (com.hazelcast.map.impl.MapContainer)1 MapService (com.hazelcast.map.impl.MapService)1 MapOperation (com.hazelcast.map.impl.operation.MapOperation)1 MapOperationProvider (com.hazelcast.map.impl.operation.MapOperationProvider)1 WanMapAddOrUpdateEvent (com.hazelcast.map.impl.wan.WanMapAddOrUpdateEvent)1 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)1