/** * Resolve affinity nodes for specified part of file. * * @param info File info to resolve affinity nodes for. * @param start Start position in the file. * @param len File part length to get affinity for. * @return Affinity blocks locations. * @throws IgniteCheckedException If failed. */ public Collection<IgfsBlockLocation> affinity(IgfsEntryInfo info, long start, long len) throws IgniteCheckedException { return affinity(info, start, len, 0); }
@Override public Object call() throws Exception { mgr.affinity(info, start, len); return null; } }, IgfsException.class, msg);
/** @throws Exception If failed. */ @Test public void testAffinityFileMap() throws Exception { int blockSize = BLOCK_SIZE; long t = System.currentTimeMillis(); IgfsEntryInfo info = IgfsUtils.createFile(IgniteUuid.randomUuid(), blockSize, 1024 * 1024, null, null, false, null, t, t); IgniteUuid affKey = IgniteUuid.randomUuid(); IgfsFileMap map = new IgfsFileMap(); map.addRange(new IgfsFileAffinityRange(3 * BLOCK_SIZE, 5 * BLOCK_SIZE - 1, affKey)); map.addRange(new IgfsFileAffinityRange(13 * BLOCK_SIZE, 17 * BLOCK_SIZE - 1, affKey)); info = info.fileMap(map); Collection<IgfsBlockLocation> affinity = mgr.affinity(info, 0, info.length()); checkAffinity(blockSize, info, affinity); // Check from middle of range. affinity = mgr.affinity(info, 3 * BLOCK_SIZE + BLOCK_SIZE / 2, info.length()); checkAffinity(blockSize, info, affinity); // Check from middle of last range. affinity = mgr.affinity(info, 14 * BLOCK_SIZE, info.length()); checkAffinity(blockSize, info, affinity); // Check inside one range. affinity = mgr.affinity(info, 14 * BLOCK_SIZE, 2 * BLOCK_SIZE); checkAffinity(blockSize, info, affinity); // Check outside last range. affinity = mgr.affinity(info, 18 * BLOCK_SIZE, info.length()); checkAffinity(blockSize, info, affinity); }
@Override public Collection<IgfsBlockLocation> call() throws Exception { if (log.isDebugEnabled()) log.debug("Get affinity for file block [path=" + path + ", start=" + start + ", len=" + len + ']'); IgfsMode mode = resolveMode(path); if (mode == PROXY) return secondaryFs.affinity(path, start, len, maxLen); // Check memory first. IgfsEntryInfo info = meta.infoForPath(path); if (info == null && mode != PRIMARY) { assert IgfsUtils.isDualMode(mode); assert secondaryFs != null; // Synchronize info = meta.synchronizeFileDual(secondaryFs, path); } if (info == null) throw new IgfsPathNotFoundException("File not found: " + path); if (!info.isFile()) throw new IgfsPathIsDirectoryException("Failed to get affinity for path because it is not " + "a file: " + path); return data.affinity(info, start, len, maxLen); } });
/** @throws Exception If failed. */ @Test public void testAffinity2() throws Exception { int blockSize = BLOCK_SIZE; long t = System.currentTimeMillis(); IgfsEntryInfo info = IgfsUtils.createFile(IgniteUuid.randomUuid(), blockSize, 1024 * 1024, null, null, false, null, t, t); Collection<IgfsBlockLocation> affinity = mgr.affinity(info, 0, info.length()); for (IgfsBlockLocation loc : affinity) { info("Going to check IGFS block location: " + loc); int block = (int)(loc.start() / blockSize); int endPos; do { IgfsBlockKey key = new IgfsBlockKey(info.id(), null, false, block); ClusterNode affNode = grid(0).affinity(grid(0).igfsx("igfs").configuration() .getDataCacheConfiguration().getName()).mapKeyToNode(key); assertTrue("Failed to find node in affinity [dataMgr=" + loc.nodeIds() + ", nodeId=" + affNode.id() + ", block=" + block + ']', loc.nodeIds().contains(affNode.id())); endPos = (block + 1) * blockSize; block++; } while (endPos < loc.start() + loc.length()); } }
/** * Resolve affinity nodes for specified part of file. * * @param info File info to resolve affinity nodes for. * @param start Start position in the file. * @param len File part length to get affinity for. * @return Affinity blocks locations. * @throws IgniteCheckedException If failed. */ public Collection<IgfsBlockLocation> affinity(IgfsEntryInfo info, long start, long len) throws IgniteCheckedException { return affinity(info, start, len, 0); }
@Override public Collection<IgfsBlockLocation> call() throws Exception { if (log.isDebugEnabled()) log.debug("Get affinity for file block [path=" + path + ", start=" + start + ", len=" + len + ']'); IgfsMode mode = resolveMode(path); if (mode == PROXY) return secondaryFs.affinity(path, start, len, maxLen); // Check memory first. IgfsEntryInfo info = meta.infoForPath(path); if (info == null && mode != PRIMARY) { assert IgfsUtils.isDualMode(mode); assert secondaryFs != null; // Synchronize info = meta.synchronizeFileDual(secondaryFs, path); } if (info == null) throw new IgfsPathNotFoundException("File not found: " + path); if (!info.isFile()) throw new IgfsPathIsDirectoryException("Failed to get affinity for path because it is not " + "a file: " + path); return data.affinity(info, start, len, maxLen); } });