Ejemplo n.º 1
0
 public static int getEvictableSize(
     int currentPartitionSize, MapConfig mapConfig, MapService mapService) {
   int evictableSize;
   final MaxSizeConfig.MaxSizePolicy maxSizePolicy =
       mapConfig.getMaxSizeConfig().getMaxSizePolicy();
   final int evictionPercentage = mapConfig.getEvictionPercentage();
   switch (maxSizePolicy) {
     case PER_PARTITION:
       int maxSize = mapConfig.getMaxSizeConfig().getSize();
       int targetSizePerPartition =
           Double.valueOf(
                   maxSize
                       * ((ONE_HUNDRED_PERCENT - evictionPercentage) / (1D * ONE_HUNDRED_PERCENT)))
               .intValue();
       int diffFromTargetSize = currentPartitionSize - targetSizePerPartition;
       int prunedSize = currentPartitionSize * evictionPercentage / ONE_HUNDRED_PERCENT + 1;
       evictableSize = Math.max(diffFromTargetSize, prunedSize);
       break;
     case PER_NODE:
       maxSize = mapConfig.getMaxSizeConfig().getSize();
       int memberCount = mapService.getNodeEngine().getClusterService().getMembers().size();
       int maxPartitionSize =
           (maxSize
               * memberCount
               / mapService.getNodeEngine().getPartitionService().getPartitionCount());
       targetSizePerPartition =
           Double.valueOf(
                   maxPartitionSize
                       * ((ONE_HUNDRED_PERCENT - evictionPercentage) / (1D * ONE_HUNDRED_PERCENT)))
               .intValue();
       diffFromTargetSize = currentPartitionSize - targetSizePerPartition;
       prunedSize = currentPartitionSize * evictionPercentage / ONE_HUNDRED_PERCENT + 1;
       evictableSize = Math.max(diffFromTargetSize, prunedSize);
       break;
     case USED_HEAP_PERCENTAGE:
     case USED_HEAP_SIZE:
       evictableSize = currentPartitionSize * evictionPercentage / ONE_HUNDRED_PERCENT;
       break;
     default:
       throw new IllegalArgumentException(
           "Max size policy is not defined [" + maxSizePolicy + "]");
   }
   return evictableSize;
 }
Ejemplo n.º 2
0
 public static void fireEvent(Data key, Object value, String mapName, MapService mapService) {
   final NodeEngine nodeEngine = mapService.getNodeEngine();
   mapService.publishEvent(
       nodeEngine.getThisAddress(),
       mapName,
       EntryEventType.EVICTED,
       key,
       mapService.toData(value),
       null);
 }
Ejemplo n.º 3
0
 private Operation createExpirationOperation(int expirationPercentage, int partitionId) {
   final MapService mapService = this.mapService;
   final ClearExpiredOperation clearExpiredOperation =
       new ClearExpiredOperation(expirationPercentage);
   clearExpiredOperation
       .setNodeEngine(mapService.getNodeEngine())
       .setCallerUuid(mapService.getNodeEngine().getLocalMember().getUuid())
       .setPartitionId(partitionId)
       .setValidateTarget(false)
       .setService(mapService);
   return clearExpiredOperation;
 }
Ejemplo n.º 4
0
 private static long getUsedHeapSize(final MapContainer mapContainer) {
   long heapCost = 0L;
   final MapService mapService = mapContainer.getMapService();
   final String mapName = mapContainer.getName();
   final NodeEngine nodeEngine = mapService.getNodeEngine();
   final Address thisAddress = nodeEngine.getThisAddress();
   for (int i = 0; i < nodeEngine.getPartitionService().getPartitionCount(); i++) {
     if (nodeEngine.getPartitionService().getPartition(i).isOwnerOrBackup(thisAddress)) {
       final PartitionContainer container = mapService.getPartitionContainer(i);
       if (container == null) {
         return -1L;
       }
       heapCost += container.getRecordStore(mapName).getHeapCost();
     }
   }
   heapCost += mapContainer.getNearCacheSizeEstimator().getSize();
   return heapCost;
 }
Ejemplo n.º 5
0
 public void clearPartition() {
   final LockService lockService =
       mapService.getNodeEngine().getSharedService(LockService.SERVICE_NAME);
   if (lockService != null) {
     lockService.clearLockStore(
         partitionId, new DefaultObjectNamespace(MapService.SERVICE_NAME, name));
   }
   final IndexService indexService = mapContainer.getIndexService();
   if (indexService.hasIndex()) {
     for (Data key : records.keySet()) {
       indexService.removeEntryIndex(key);
     }
   }
   cancelAssociatedSchedulers(records.keySet());
   clearRecordsMap(Collections.<Data, Record>emptyMap());
   resetSizeEstimator();
   resetAccessSequenceNumber();
 }
Ejemplo n.º 6
0
 private static boolean isEvictablePerPartition(final MapContainer mapContainer) {
   final MapService mapService = mapContainer.getMapService();
   final MaxSizeConfig maxSizeConfig = mapContainer.getMapConfig().getMaxSizeConfig();
   final int maxSize = getApproximateMaxSize(maxSizeConfig.getSize());
   final String mapName = mapContainer.getName();
   final NodeEngine nodeEngine = mapService.getNodeEngine();
   final InternalPartitionService partitionService = nodeEngine.getPartitionService();
   for (int i = 0; i < partitionService.getPartitionCount(); i++) {
     final Address owner = partitionService.getPartitionOwner(i);
     if (nodeEngine.getThisAddress().equals(owner)) {
       final PartitionContainer container = mapService.getPartitionContainer(i);
       if (container == null) {
         return false;
       }
       final int size = container.getRecordStore(mapName).size();
       if (size >= maxSize) {
         return true;
       }
     }
   }
   return false;
 }
Ejemplo n.º 7
0
    public void run() {
      final long now = Clock.currentTimeMillis();
      final MapService mapService = ExpirationManager.this.mapService;
      final NodeEngine nodeEngine = mapService.getNodeEngine();
      final int partitionCount = nodeEngine.getPartitionService().getPartitionCount();
      List<PartitionContainer> partitionContainers = Collections.emptyList();
      boolean createLazy = true;
      int currentlyRunningCleanupOperationsCount = 0;
      for (int partitionId = 0; partitionId < partitionCount; partitionId++) {
        InternalPartition partition = nodeEngine.getPartitionService().getPartition(partitionId);
        if (partition.isOwnerOrBackup(nodeEngine.getThisAddress())) {
          final PartitionContainer partitionContainer =
              mapService.getPartitionContainer(partitionId);
          if (isContainerEmpty(partitionContainer)) {
            continue;
          }
          if (hasRunningCleanup(partitionContainer)) {
            currentlyRunningCleanupOperationsCount++;
            continue;
          }
          if (currentlyRunningCleanupOperationsCount > getMaxCleanupOperationCountInOneRound()
              || notInProcessableTimeWindow(partitionContainer, now)
              || notAnyExpirableRecord(partitionContainer)) {
            continue;
          }

          if (createLazy) {
            partitionContainers = new ArrayList<PartitionContainer>();
            createLazy = false;
          }
          partitionContainers.add(partitionContainer);
        }
      }
      if (partitionContainers.isEmpty()) {
        return;
      }
      Collections.sort(partitionContainers, partitionContainerComparator);
      sendCleanupOperations(partitionContainers);
    }
Ejemplo n.º 8
0
 public void start() {
   mapService
       .getNodeEngine()
       .getExecutionService()
       .scheduleAtFixedRate(new ClearExpiredRecordsTask(), INITIAL_DELAY, PERIOD, UNIT);
 }
Ejemplo n.º 9
0
 public DefaultRecordStore(String name, MapService mapService, int partitionId) {
   this.name = name;
   this.partitionId = partitionId;
   this.mapService = mapService;
   this.mapContainer = mapService.getMapContainer(name);
   this.logger = mapService.getNodeEngine().getLogger(this.getName());
   recordFactory = mapContainer.getRecordFactory();
   NodeEngine nodeEngine = mapService.getNodeEngine();
   final LockService lockService = nodeEngine.getSharedService(LockService.SERVICE_NAME);
   this.lockStore =
       lockService == null
           ? null
           : lockService.createLockStore(
               partitionId, new DefaultObjectNamespace(MapService.SERVICE_NAME, name));
   this.sizeEstimator = SizeEstimators.createMapSizeEstimator();
   final int mapLoadChunkSize = nodeEngine.getGroupProperties().MAP_LOAD_CHUNK_SIZE.getInteger();
   final Queue<Map> chunks = new LinkedList<Map>();
   if (nodeEngine
       .getThisAddress()
       .equals(nodeEngine.getPartitionService().getPartitionOwner(partitionId))) {
     if (mapContainer.getStore() != null && !loaded.get()) {
       Map<Data, Object> loadedKeys = mapContainer.getInitialKeys();
       if (loadedKeys != null && !loadedKeys.isEmpty()) {
         Map<Data, Object> partitionKeys = new HashMap<Data, Object>();
         Iterator<Map.Entry<Data, Object>> iterator = loadedKeys.entrySet().iterator();
         while (iterator.hasNext()) {
           final Map.Entry<Data, Object> entry = iterator.next();
           final Data data = entry.getKey();
           if (partitionId == nodeEngine.getPartitionService().getPartitionId(data)) {
             partitionKeys.put(data, entry.getValue());
             // split into chunks
             if (partitionKeys.size() >= mapLoadChunkSize) {
               chunks.add(partitionKeys);
               partitionKeys = new HashMap<Data, Object>();
             }
             iterator.remove();
           }
         }
         if (!partitionKeys.isEmpty()) {
           chunks.add(partitionKeys);
         }
         if (!chunks.isEmpty()) {
           try {
             Map<Data, Object> chunkedKeys;
             final AtomicInteger checkIfMapLoaded = new AtomicInteger(chunks.size());
             while ((chunkedKeys = chunks.poll()) != null) {
               nodeEngine
                   .getExecutionService()
                   .submit("hz:map-load", new MapLoadAllTask(chunkedKeys, checkIfMapLoaded));
             }
           } catch (Throwable t) {
             throw ExceptionUtil.rethrow(t);
           }
         } else {
           loaded.set(true);
         }
       } else {
         loaded.set(true);
       }
     }
   } else {
     loaded.set(true);
   }
 }