johnyangk commented on a change in pull request #112: [NEMO-179] Delayed Task Cloning URL: https://github.com/apache/incubator-nemo/pull/112#discussion_r211816796
########## File path: runtime/master/src/main/java/edu/snu/nemo/runtime/master/BlockManagerMaster.java ########## @@ -302,21 +297,36 @@ private BlockMetadata getBlockMetaData(final String blockId) { } /** - * Deals with a request for the location of a block. - * * @param message the request message. * @param messageContext the message context which will be used for response. */ - void onRequestBlockLocation(final ControlMessage.Message message, - final MessageContext messageContext) { + private void registerLocationRequest(final ControlMessage.Message message, final MessageContext messageContext) { assert (message.getType() == ControlMessage.MessageType.RequestBlockLocation); final String blockIdWildcard = message.getRequestBlockLocationMsg().getBlockIdWildcard(); final long requestId = message.getId(); final Lock readLock = lock.readLock(); readLock.lock(); try { - final BlockRequestHandler locationFuture = getBlockLocationHandler(blockIdWildcard); - locationFuture.registerRequest(requestId, messageContext); + // (CASE 1) Check AVAILABLE blocks. + final List<BlockRequestHandler> availableBlocks = getBlockHandlers(blockIdWildcard, BlockState.State.AVAILABLE); + if (!availableBlocks.isEmpty()) { + // random pick + availableBlocks.get(random.nextInt(availableBlocks.size())).registerRequest(requestId, messageContext); + return; + } + + // (CASE 2) Check IN_PROGRESS blocks. + final List<BlockRequestHandler> progressBlocks = getBlockHandlers(blockIdWildcard, BlockState.State.IN_PROGRESS); + if (!progressBlocks.isEmpty()) { + // random pick Review comment: I prefer a random pick, as it is unknown which one of the IN_PROGRESS block attempts will complete first. It may be that the first attempt is a straggler, and the second attempt finishes faster. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services