/** {@inheritDoc} */ @SuppressWarnings("BusyWait") @Override public Boolean reduce(List<GridComputeJobResult> results) throws GridException { assert taskSes != null; assert results != null; assert params != null; assert !params.isEmpty(); assert results.size() == params.size(); Map<String, Integer> receivedParams = new HashMap<>(); boolean allAttrReceived = false; int cnt = 0; while (!allAttrReceived && cnt++ < 3) { allAttrReceived = true; for (Map.Entry<String, Integer> entry : params.entrySet()) { assert taskSes.getAttribute(entry.getKey()) != null; Integer newVal = (Integer) taskSes.getAttribute(entry.getKey()); assert newVal != null; receivedParams.put(entry.getKey(), newVal); if (newVal != entry.getValue() + 1) allAttrReceived = false; } if (!allAttrReceived) { try { Thread.sleep(100); } catch (InterruptedException e) { throw new GridException("Thread interrupted.", e); } } } if (log.isDebugEnabled()) { for (Map.Entry<String, Integer> entry : receivedParams.entrySet()) { log.debug( "Received session attr value [name=" + entry.getKey() + ", val=" + entry.getValue() + ", expected=" + (params.get(entry.getKey()) + 1) + ']'); } } return allAttrReceived; }
/** {@inheritDoc} */ @Nullable @Override public final Map<? extends GridComputeJob, GridNode> map( List<GridNode> subgrid, @Nullable GridGgfsTaskArgs<T> args) throws GridException { assert grid != null; assert args != null; GridGgfs ggfs = grid.ggfs(args.ggfsName()); GridGgfsProcessorAdapter ggfsProc = ((GridKernal) grid).context().ggfs(); Map<GridComputeJob, GridNode> splitMap = new HashMap<>(); Map<UUID, GridNode> nodes = mapSubgrid(subgrid); for (GridGgfsPath path : args.paths()) { GridGgfsFile file = ggfs.info(path); if (file == null) { if (args.skipNonExistentFiles()) continue; else throw new GridException("Failed to process GGFS file because it doesn't exist: " + path); } Collection<GridGgfsBlockLocation> aff = ggfs.affinity(path, 0, file.length(), args.maxRangeLength()); long totalLen = 0; for (GridGgfsBlockLocation loc : aff) { GridNode node = null; for (UUID nodeId : loc.nodeIds()) { node = nodes.get(nodeId); if (node != null) break; } if (node == null) throw new GridException( "Failed to find any of block affinity nodes in subgrid [loc=" + loc + ", subgrid=" + subgrid + ']'); GridGgfsJob job = createJob(path, new GridGgfsFileRange(file.path(), loc.start(), loc.length()), args); if (job != null) { GridComputeJob jobImpl = ggfsProc.createJob( job, ggfs.name(), file.path(), loc.start(), loc.length(), args.recordResolver()); splitMap.put(jobImpl, node); } totalLen += loc.length(); } assert totalLen == file.length(); } return splitMap; }