Esempio n. 1
0
 public void run() {
   SimpleEntryView entryView = (SimpleEntryView) mergingEntry;
   entryView.setKey(mapService.toObject(mergingEntry.getKey()));
   entryView.setValue(mapService.toObject(mergingEntry.getValue()));
   merged = recordStore.merge(dataKey, mergingEntry, mergePolicy);
   if (merged) {
     Record record = recordStore.getRecord(dataKey);
     if (record != null) dataValue = mapService.toData(record.getValue());
   }
 }
  protected void mergeRecordExpiration(Record record, EntryView mergingEntry) {
    final long ttlMillis = mergingEntry.getTtl();
    record.setTtl(ttlMillis);

    final long creationTime = mergingEntry.getCreationTime();
    record.setCreationTime(creationTime);

    final long lastAccessTime = mergingEntry.getLastAccessTime();
    record.setLastAccessTime(lastAccessTime);

    final long lastUpdateTime = mergingEntry.getLastUpdateTime();
    record.setLastUpdateTime(lastUpdateTime);

    final long maxIdleMillis = calculateMaxIdleMillis(mapContainer.getMapConfig());
    setExpirationTime(record, maxIdleMillis);

    markRecordStoreExpirable(record.getTtl());
  }
Esempio n. 3
0
 @Override
 public void onReplicationEvent(WanReplicationEvent replicationEvent) {
   Object eventObject = replicationEvent.getEventObject();
   if (eventObject instanceof MapReplicationUpdate) {
     MapReplicationUpdate replicationUpdate = (MapReplicationUpdate) eventObject;
     EntryView entryView = replicationUpdate.getEntryView();
     MapMergePolicy mergePolicy = replicationUpdate.getMergePolicy();
     String mapName = replicationUpdate.getMapName();
     MapContainer mapContainer = getMapContainer(mapName);
     MergeOperation operation =
         new MergeOperation(
             mapName,
             toData(entryView.getKey(), mapContainer.getPartitioningStrategy()),
             entryView,
             mergePolicy);
     try {
       int partitionId = nodeEngine.getPartitionService().getPartitionId(entryView.getKey());
       Future f =
           nodeEngine
               .getOperationService()
               .invokeOnPartition(SERVICE_NAME, operation, partitionId);
       f.get();
     } catch (Throwable t) {
       throw ExceptionUtil.rethrow(t);
     }
   } else if (eventObject instanceof MapReplicationRemove) {
     MapReplicationRemove replicationRemove = (MapReplicationRemove) eventObject;
     WanOriginatedDeleteOperation operation =
         new WanOriginatedDeleteOperation(
             replicationRemove.getMapName(), replicationRemove.getKey());
     try {
       int partitionId =
           nodeEngine.getPartitionService().getPartitionId(replicationRemove.getKey());
       Future f =
           nodeEngine
               .getOperationService()
               .invokeOnPartition(SERVICE_NAME, operation, partitionId);
       f.get();
     } catch (Throwable t) {
       throw ExceptionUtil.rethrow(t);
     }
   }
 }
Esempio n. 4
0
  @Override
  public boolean merge(Data key, EntryView mergingEntry, MapMergePolicy mergePolicy) {
    checkIfLoaded();
    final long now = getNow();

    Record record = getRecordOrNull(key, now, false);
    mergingEntry =
        EntryViews.convertToLazyEntryView(mergingEntry, serializationService, mergePolicy);
    Object newValue;
    if (record == null) {
      final Object notExistingKey = mapServiceContext.toObject(key);
      final EntryView nullEntryView = EntryViews.createNullEntryView(notExistingKey);
      newValue = mergePolicy.merge(name, mergingEntry, nullEntryView);
      if (newValue == null) {
        return false;
      }
      newValue = mapDataStore.add(key, newValue, now);
      record = createRecord(key, newValue, now);
      mergeRecordExpiration(record, mergingEntry);
      records.put(key, record);
      updateSizeEstimator(calculateRecordHeapCost(record));
    } else {
      Object oldValue = record.getValue();
      EntryView existingEntry =
          EntryViews.createLazyEntryView(
              record.getKey(), record.getValue(), record, serializationService, mergePolicy);
      newValue = mergePolicy.merge(name, mergingEntry, existingEntry);
      // existing entry will be removed
      if (newValue == null) {
        removeIndex(key);
        mapDataStore.remove(key, now);
        onStore(record);
        // reduce size.
        updateSizeEstimator(-calculateRecordHeapCost(record));
        // remove from map & invalidate.
        deleteRecord(key);
        return true;
      }
      if (newValue == mergingEntry.getValue()) {
        mergeRecordExpiration(record, mergingEntry);
      }
      // same with the existing entry so no need to map-store etc operations.
      if (mapServiceContext.compare(name, newValue, oldValue)) {
        return true;
      }
      newValue = mapDataStore.add(key, newValue, now);
      onStore(record);
      updateSizeEstimator(-calculateRecordHeapCost(record));
      recordFactory.setValue(record, newValue);
      updateSizeEstimator(calculateRecordHeapCost(record));
    }
    saveIndex(record);
    return newValue != null;
  }
Esempio n. 5
0
 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;
 }