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