public Runnable prepareMergeRunnable() { Map<MapContainer, Collection<Record>> recordMap = new HashMap<MapContainer, Collection<Record>>(mapContainers.size()); InternalPartitionService partitionService = nodeEngine.getPartitionService(); int partitionCount = partitionService.getPartitionCount(); Address thisAddress = nodeEngine.getClusterService().getThisAddress(); for (MapContainer mapContainer : mapContainers.values()) { for (int i = 0; i < partitionCount; i++) { RecordStore recordStore = getPartitionContainer(i).getRecordStore(mapContainer.getName()); // add your owned entries to the map so they will be merged if (thisAddress.equals(partitionService.getPartitionOwner(i))) { Collection<Record> records = recordMap.get(mapContainer); if (records == null) { records = new ArrayList<Record>(); recordMap.put(mapContainer, records); } records.addAll(recordStore.getReadonlyRecordMap().values()); } // clear all records either owned or backup recordStore.reset(); } } return new Merger(recordMap); }
@Override public boolean open(NodeEngine nodeEngine) { NodeEngineImpl nei = (NodeEngineImpl) nodeEngine; InternalPartitionService ps = nei.getPartitionService(); MapService mapService = nei.getService(MapService.SERVICE_NAME); ss = nei.getSerializationService(); Address partitionOwner = ps.getPartitionOwner(partitionId); if (partitionOwner == null) { return false; } RecordStore recordStore = mapService.getMapServiceContext().getRecordStore(partitionId, mapName); iterator = recordStore.entrySetData().iterator(); return true; }
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; }