/** * Use local LRU to evict data, and get <code> requestBytes </code> available space. * * @param requestBytes The data requested. * @return <code> true </code> if the space is granted, <code> false </code> if not. */ private boolean memoryEvictionLRU(long requestBytes) { Set<Integer> pinList; try { pinList = mMasterClient.worker_getPinIdList(); } catch (TException e) { LOG.error(e.getMessage()); pinList = new HashSet<Integer>(); } synchronized (mLatestBlockAccessTimeMs) { synchronized (mUsersPerLockedBlock) { while (mWorkerSpaceCounter.getAvailableBytes() < requestBytes) { long blockId = -1; long latestTimeMs = Long.MAX_VALUE; for (Entry<Long, Long> entry : mLatestBlockAccessTimeMs.entrySet()) { if (entry.getValue() < latestTimeMs && !pinList.contains(BlockInfo.computeInodeId(entry.getKey()))) { if (!mUsersPerLockedBlock.containsKey(entry.getKey())) { blockId = entry.getKey(); latestTimeMs = entry.getValue(); } } } if (blockId != -1) { freeBlock(blockId); } else { return false; } } } } return true; }