/** * Create data transfer object. * * @param igfs Source IGFS. */ public VisorIgfs(IgniteFileSystem igfs) { assert igfs != null; name = igfs.name(); mode = igfs.configuration().getDefaultMode(); metrics = new VisorIgfsMetrics(igfs); secondaryFsConfigured = igfs.configuration().getSecondaryFileSystem() != null; }
/** * Get data cache for node. * * @param node Node. * @return Data cache. * @throws Exception If failed. */ private GridCacheAdapter dataCache(Ignite node) throws Exception { return ((IgniteKernal)node).internalCache(((IgniteKernal)node).igfsx(IGFS_NAME).configuration() .getDataCacheConfiguration().getName()); }
@Override public Object call() throws Exception { g.cache(((IgniteKernal)g).igfsx("igfs").configuration().getMetaCacheConfiguration().getName()); return null; } }, IllegalStateException.class, null);
@Override public Object call() throws Exception { g.cache(((IgniteKernal)g).igfsx("igfs").configuration().getDataCacheConfiguration().getName()); return null; } }, IllegalStateException.class, null);
@Override public boolean apply() { int metaSize = 0; for (Object metaId : grid(0).cachex(igfs.configuration().getMetaCacheConfiguration().getName()) .keySet()) { if (!IgfsUtils.isRootOrTrashId((IgniteUuid)metaId)) metaSize++; } return metaSize == 0; } }, 5000);
@Override public void apply() { for (int i = 0; i < NODE_CNT; i++) { IgniteEx g = grid(i); GridCacheAdapter<Object, Object> cache = ((IgniteKernal)g).internalCache( g.igfsx("igfs").configuration().getDataCacheConfiguration().getName()); assertTrue("Data cache is not empty [keys=" + cache.keySet() + ", node=" + g.localNode().id() + ']', cache.isEmpty()); } } });
/** * Determine primary and backup node IDs for the given block key. * * @param key Block key. * @return Collection of node IDs. */ private Collection<UUID> primaryOrBackups(IgfsBlockKey key) { IgniteEx grid = grid(0); Collection<UUID> ids = new HashSet<>(); for (ClusterNode node : grid.cluster().nodes()) { if (grid.affinity(grid.igfsx(IGFS_NAME).configuration().getDataCacheConfiguration().getName()) .isPrimaryOrBackup(node, key)) ids.add(node.id()); } return ids; }
/** * Get data cache for the given node ID. * * @param nodeId Node ID. * @return Data cache. */ private GridCacheAdapter<IgfsBlockKey, byte[]> cache(UUID nodeId) { IgniteEx g = (IgniteEx)G.ignite(nodeId); return (GridCacheAdapter<IgfsBlockKey, byte[]>)g.cachex(g.igfsx(IGFS_NAME).configuration() .getDataCacheConfiguration().getName()).<IgfsBlockKey, byte[]>cache(); }
/** * Gets the data cache instance for this IGFS instance. * * @param igfs The IGFS unstance. * @return The data cache. */ protected static GridCacheAdapter<IgfsBlockKey, byte[]> getDataCache(IgniteFileSystem igfs) { String dataCacheName = igfs.configuration().getDataCacheConfiguration().getName(); IgniteEx igniteEx = ((IgfsEx)igfs).context().kernalContext().grid(); return ((IgniteKernal)igniteEx).internalCache(dataCacheName); }
/** * Gets meta cache. * * @param igfs The IGFS instance. * @return The data cache. */ protected static GridCacheAdapter<IgniteUuid, IgfsEntryInfo> getMetaCache(IgniteFileSystem igfs) { String dataCacheName = igfs.configuration().getMetaCacheConfiguration().getName(); IgniteEx igniteEx = ((IgfsEx)igfs).context().kernalContext().grid(); return ((IgniteKernal)igniteEx).internalCache(dataCacheName); }
/** * @throws Exception If failed. */ @Test public void testCacheStart() throws Exception { Ignite g0 = G.start(config(true, 0)); String dataCacheName = ((IgniteEx)g0).igfsx("igfs").configuration().getDataCacheConfiguration().getName(); String metaCacheName = ((IgniteEx)g0).igfsx("igfs").configuration().getMetaCacheConfiguration().getName(); checkIgfsCaches(g0, dataCacheName, metaCacheName); Ignite g1 = G.start(config(false, 1)); checkIgfsCaches(g1, dataCacheName, metaCacheName); IgniteFileSystem igfs = g0.fileSystem("igfs"); igfs.mkdirs(new IgfsPath("/test")); try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(igfs.create( new IgfsPath("/test/test.file"), true)))) { for (int i = 0; i < 1000; i++) bw.write("test-" + i); } }
/** {@inheritDoc} */ @Override protected void afterTest() throws Exception { for (int i = 0; i < NODES_CNT; i++) { grid(i).cachex(grid(i).igfsx("igfs").configuration().getMetaCacheConfiguration().getName()).clear(); grid(i).cachex(grid(i).igfsx("igfs").configuration().getDataCacheConfiguration().getName()).clear(); } }
long start0 = U.currentTimeMillis(); FileSystemConfiguration igfsCfg = igfs.configuration();
/** @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)); }
/** * @throws Exception If failed. */ @Test public void testPreConfiguredCache() throws Exception { FileSystemConfiguration igfsCfg1 = new FileSystemConfiguration(g1IgfsCfg1); igfsCfg1.setName("igfs"); g1Cfg.setFileSystemConfiguration(igfsCfg1); CacheConfiguration ccfgData = dataCache(1024); ccfgData.setRebalanceTimeout(10001); CacheConfiguration ccfgMeta = metaCache(); ccfgMeta.setRebalanceTimeout(10002); igfsCfg1.setDataCacheConfiguration(ccfgData); igfsCfg1.setMetaCacheConfiguration(ccfgMeta); IgniteEx g = (IgniteEx)G.start(g1Cfg); assertEquals(10001, g.cachex(g.igfsx("igfs").configuration().getDataCacheConfiguration().getName()) .configuration().getRebalanceTimeout()); assertEquals(10002, g.cachex(g.igfsx("igfs").configuration().getMetaCacheConfiguration().getName()) .configuration().getRebalanceTimeout()); }
/** @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()); } }
grid(j).cachex(grid(j).igfsx("igfs").configuration().getDataCacheConfiguration().getName()), "ctx"); Collection<IgniteInternalTx> txs = ctx.tm().activeTransactions();
grid(j).cachex(grid(j).igfsx("igfs").configuration().getDataCacheConfiguration().getName()), "ctx"); Collection<IgniteInternalTx> txs = ctx.tm().activeTransactions();
IgfsPath path = new IgfsPath("/someFile"); String metaCacheName = grid(0).igfsx("igfs").configuration().getMetaCacheConfiguration().getName(); String dataCacheName = grid(0).igfsx("igfs").configuration().getDataCacheConfiguration().getName();