/** * @param start Start. * @param len Length. * @param block Block. */ public IgfsBlockLocationImpl(long start, long len, IgfsBlockLocation block) { assert start >= 0; assert len > 0; this.start = start; this.len = len; nodeIds = block.nodeIds(); names = block.names(); hosts = block.hosts(); }
/** * @param location HDFS block location. * @param len New length. */ public IgfsBlockLocationImpl(IgfsBlockLocation location, long len) { assert location != null; start = location.start(); this.len = len; nodeIds = location.nodeIds(); names = location.names(); hosts = location.hosts(); }
/** @throws Exception If failed. */ @Test public void testZeroReplicationFactor() throws Exception { // This test doesn't make sense for any mode except of PRIMARY. if (mode == PRIMARY) { Path igfsHome = new Path(PRIMARY_URI); Path file = new Path(igfsHome, "someFile"); try (FSDataOutputStream out = fs.create(file, (short)0)) { out.write(new byte[1024 * 1024]); } IgniteFileSystem igfs = grid(0).fileSystem("igfs"); IgfsPath filePath = new IgfsPath("/someFile"); IgfsFile fileInfo = igfs.info(filePath); awaitPartitionMapExchange(); Collection<IgfsBlockLocation> locations = igfs.affinity(filePath, 0, fileInfo.length()); assertEquals(1, locations.size()); IgfsBlockLocation location = F.first(locations); assertEquals(1, location.nodeIds().size()); } }
/** @throws Exception If failed. */ @Test public void testZeroReplicationFactor() throws Exception { // This test doesn't make sense for any mode except of PRIMARY. if (mode == PRIMARY) { Path igfsHome = new Path(primaryFsUri); Path file = new Path(igfsHome, "someFile"); try (FSDataOutputStream out = fs.create(file, EnumSet.noneOf(CreateFlag.class), Options.CreateOpts.perms(FsPermission.getDefault()), Options.CreateOpts.repFac((short)1))) { out.write(new byte[1024 * 1024]); } IgniteFileSystem igfs = grid(0).fileSystem("igfs"); IgfsPath filePath = new IgfsPath("/someFile"); IgfsFile fileInfo = igfs.info(filePath); Collection<IgfsBlockLocation> locations = igfs.affinity(filePath, 0, fileInfo.length()); assertEquals(1, locations.size()); IgfsBlockLocation location = F.first(locations); assertEquals(1, location.nodeIds().size()); } }
ClusterNode node = null; for (UUID nodeId : loc.nodeIds()) { node = nodes.get(nodeId);
if (last != null && equal(last.nodeIds(), F.viewReadOnly(affNodes, F.node2id()))) {
", affNodes=" + F.nodeIds(affNodes) + ']'); if (last != null && equal(last.nodeIds(), F.viewReadOnly(affNodes, F.node2id()))) {
/** @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()); } }
/** * Checks affinity validity. * * @param blockSize Block size. * @param info File info. * @param affinity Affinity block locations to check. */ private void checkAffinity(int blockSize, IgfsEntryInfo info, Iterable<IgfsBlockLocation> affinity) { 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(), info.fileMap().affinityKey(block * blockSize, false), 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()); } }
/** @throws Exception If failed. */ @Test public void testCreateFileColocated() throws Exception { IgfsPath path = new IgfsPath("/colocated"); UUID uuid = UUID.randomUUID(); IgniteUuid affKey; long idx = 0; while (true) { affKey = new IgniteUuid(uuid, idx); if (grid(0).affinity(grid(0).igfsx("igfs").configuration().getDataCacheConfiguration() .getName()).mapKeyToNode(affKey).id().equals(grid(0).localNode().id())) break; idx++; } try (IgfsOutputStream out = fs.create(path, 1024, true, affKey, 0, 1024, null)) { // Write 5M, should be enough to test distribution. for (int i = 0; i < 15; i++) out.write(new byte[1024 * 1024]); } IgfsFile info = fs.info(path); Collection<IgfsBlockLocation> affNodes = fs.affinity(path, 0, info.length()); assertEquals(1, affNodes.size()); Collection<UUID> nodeIds = F.first(affNodes).nodeIds(); assertEquals(1, nodeIds.size()); assertEquals(grid(0).localNode().id(), F.first(nodeIds)); }
/** * @param start Start. * @param len Length. * @param block Block. */ public IgfsBlockLocationImpl(long start, long len, IgfsBlockLocation block) { assert start >= 0; assert len > 0; this.start = start; this.len = len; nodeIds = block.nodeIds(); names = block.names(); hosts = block.hosts(); }
/** * @param location HDFS block location. * @param len New length. */ public IgfsBlockLocationImpl(IgfsBlockLocation location, long len) { assert location != null; start = location.start(); this.len = len; nodeIds = location.nodeIds(); names = location.names(); hosts = location.hosts(); }
ClusterNode node = null; for (UUID nodeId : loc.nodeIds()) { node = nodes.get(nodeId);
if (last != null && equal(last.nodeIds(), F.viewReadOnly(affNodes, F.node2id()))) {
", affNodes=" + F.nodeIds(affNodes) + ']'); if (last != null && equal(last.nodeIds(), F.viewReadOnly(affNodes, F.node2id()))) {