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