public boolean merge(Data dataKey, EntryView mergingEntry, MapMergePolicy mergePolicy) {
   checkIfLoaded();
   Record record = records.get(dataKey);
   Object newValue = null;
   if (record == null) {
     newValue = mergingEntry.getValue();
     newValue = writeMapStore(dataKey, newValue, null);
     record = mapService.createRecord(name, dataKey, newValue, DEFAULT_TTL);
     records.put(dataKey, record);
     updateSizeEstimator(calculateRecordSize(record));
   } else {
     Object oldValue = record.getValue();
     EntryView existingEntry =
         mapService.createSimpleEntryView(
             mapService.toObject(record.getKey()), mapService.toObject(record.getValue()), record);
     newValue = mergePolicy.merge(name, mergingEntry, existingEntry);
     if (newValue == null) { // existing entry will be removed
       removeIndex(dataKey);
       mapStoreDelete(record, dataKey);
       // reduce size.
       updateSizeEstimator(-calculateRecordSize(record));
       // remove from map & invalidate.
       deleteRecord(dataKey);
       return true;
     }
     // same with the existing entry so no need to mapstore etc operations.
     if (mapService.compare(name, newValue, oldValue)) {
       return true;
     }
     newValue = writeMapStore(dataKey, newValue, record);
     updateSizeEstimator(-calculateRecordSize(record));
     recordFactory.setValue(record, newValue);
     updateSizeEstimator(calculateRecordSize(record));
   }
   saveIndex(record);
   return newValue != null;
 }
 private void setRecordValue(Record record, Object value) {
   accessRecord(record);
   record.onUpdate();
   recordFactory.setValue(record, value);
 }