Search in sources :

Example 1 with MapMergeTypes

use of com.hazelcast.spi.merge.SplitBrainMergeTypes.MapMergeTypes in project hazelcast by hazelcast.

the class DefaultRecordStore method merge.

@Override
public boolean merge(MapMergeTypes<Object, Object> mergingEntry, SplitBrainMergePolicy<Object, MapMergeTypes<Object, Object>, Object> mergePolicy, CallerProvenance provenance) {
    checkIfLoaded();
    long now = getNow();
    mergingEntry = (MapMergeTypes<Object, Object>) serializationService.getManagedContext().initialize(mergingEntry);
    mergePolicy = (SplitBrainMergePolicy<Object, MapMergeTypes<Object, Object>, Object>) serializationService.getManagedContext().initialize(mergePolicy);
    Data key = (Data) mergingEntry.getRawKey();
    Record record = getRecordOrNull(key, now, false);
    Object newValue;
    Object oldValue;
    if (record == null) {
        newValue = mergePolicy.merge(mergingEntry, null);
        if (newValue == null) {
            return false;
        }
        boolean persist = persistenceEnabledFor(provenance);
        putNewRecord(key, null, newValue, UNSET, UNSET, UNSET, now, null, ADDED, persist, false);
    } else {
        oldValue = record.getValue();
        ExpiryMetadata expiryMetadata = expirySystem.getExpiryMetadata(key);
        MapMergeTypes<Object, Object> existingEntry = createMergingEntry(serializationService, key, record, expiryMetadata);
        newValue = mergePolicy.merge(mergingEntry, existingEntry);
        // existing entry will be removed
        if (newValue == null) {
            if (persistenceEnabledFor(provenance)) {
                mapDataStore.remove(key, now, null);
            }
            onStore(record);
            mutationObserver.onRemoveRecord(key, record);
            removeKeyFromExpirySystem(key);
            storage.removeRecord(key, record);
            return true;
        }
        if (valueComparator.isEqual(newValue, oldValue, serializationService)) {
            mergeRecordExpiration(key, record, mergingEntry, now);
            return true;
        }
        boolean persist = persistenceEnabledFor(provenance);
        updateRecord(record, key, oldValue, newValue, UNSET, UNSET, UNSET, now, null, persist, true, false);
    }
    return newValue != null;
}
Also used : MapMergeTypes(com.hazelcast.spi.merge.SplitBrainMergeTypes.MapMergeTypes) EntryEventData(com.hazelcast.map.impl.event.EntryEventData) Data(com.hazelcast.internal.serialization.Data) Record(com.hazelcast.map.impl.record.Record) ExpiryMetadata(com.hazelcast.map.impl.recordstore.expiry.ExpiryMetadata)

Example 2 with MapMergeTypes

use of com.hazelcast.spi.merge.SplitBrainMergeTypes.MapMergeTypes in project hazelcast by hazelcast.

the class PutIfAbsentMergePolicyTest method merge_existingValuePresent.

@Test
public void merge_existingValuePresent() {
    MapMergeTypes existing = mergingValueWithGivenValue(EXISTING);
    MapMergeTypes merging = mergingValueWithGivenValue(MERGING);
    assertEquals(EXISTING, mergePolicy.merge(merging, existing));
}
Also used : MapMergeTypes(com.hazelcast.spi.merge.SplitBrainMergeTypes.MapMergeTypes) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with MapMergeTypes

use of com.hazelcast.spi.merge.SplitBrainMergeTypes.MapMergeTypes in project hazelcast by hazelcast.

the class PassThroughMergePolicyTest method merge_mergingNotNull.

@Test
public void merge_mergingNotNull() {
    MapMergeTypes existing = mergingValueWithGivenValue(EXISTING);
    MapMergeTypes merging = mergingValueWithGivenValue(MERGING);
    assertEquals(MERGING, mergePolicy.merge(merging, existing));
}
Also used : MapMergeTypes(com.hazelcast.spi.merge.SplitBrainMergeTypes.MapMergeTypes) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with MapMergeTypes

use of com.hazelcast.spi.merge.SplitBrainMergeTypes.MapMergeTypes in project hazelcast by hazelcast.

the class PassThroughMergePolicyTest method merge_mergingNull.

@Test
@SuppressWarnings("ConstantConditions")
public void merge_mergingNull() {
    MapMergeTypes existing = mergingValueWithGivenValue(EXISTING);
    MapMergeTypes merging = null;
    assertEquals(EXISTING, mergePolicy.merge(merging, existing));
}
Also used : MapMergeTypes(com.hazelcast.spi.merge.SplitBrainMergeTypes.MapMergeTypes) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with MapMergeTypes

use of com.hazelcast.spi.merge.SplitBrainMergeTypes.MapMergeTypes in project hazelcast by hazelcast.

the class DiscardMergePolicyTest method merge_existingValueAbsent.

@Test
@SuppressWarnings("ConstantConditions")
public void merge_existingValueAbsent() {
    MapMergeTypes existing = null;
    MapMergeTypes merging = mergingValueWithGivenValue(MERGING);
    assertNull(mergePolicy.merge(merging, existing));
}
Also used : MapMergeTypes(com.hazelcast.spi.merge.SplitBrainMergeTypes.MapMergeTypes) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

MapMergeTypes (com.hazelcast.spi.merge.SplitBrainMergeTypes.MapMergeTypes)14 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9 Test (org.junit.Test)9 Data (com.hazelcast.internal.serialization.Data)2 SerializationService (com.hazelcast.internal.serialization.SerializationService)2 MapOperation (com.hazelcast.map.impl.operation.MapOperation)2 MapOperationProvider (com.hazelcast.map.impl.operation.MapOperationProvider)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)1 MapService (com.hazelcast.map.impl.MapService)1 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)1 SimpleEntryView (com.hazelcast.map.impl.SimpleEntryView)1 EntryEventData (com.hazelcast.map.impl.event.EntryEventData)1 Record (com.hazelcast.map.impl.record.Record)1 ExpiryMetadata (com.hazelcast.map.impl.recordstore.expiry.ExpiryMetadata)1 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)1 OperationServiceImpl (com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)1 SplitBrainMergePolicy (com.hazelcast.spi.merge.SplitBrainMergePolicy)1 Accessors.getNodeEngineImpl (com.hazelcast.test.Accessors.getNodeEngineImpl)1