/** * Initialize internal cache names */ private void initializeInternalCacheNames() { FileSystemConfiguration[] igfsCfgs = ctx.grid().configuration().getFileSystemConfiguration(); if (igfsCfgs != null) { for (FileSystemConfiguration igfsCfg : igfsCfgs) { internalCaches.add(igfsCfg.getMetaCacheConfiguration().getName()); internalCaches.add(igfsCfg.getDataCacheConfiguration().getName()); } } if (IgniteComponentType.HADOOP.inClassPath()) internalCaches.add(CU.SYS_CACHE_HADOOP_MR); }
/** * 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().getDataCacheConfiguration().getName()); return null; } }, IllegalStateException.class, null);
/** * @throws Exception If failed. */ @Test public void testLocalIfQueryIndexingEnabledForDataCache() throws Exception { g1IgfsCfg1.setDataCacheConfiguration(dataCache(1024)); g1IgfsCfg1.getDataCacheConfiguration().setIndexedTypes(Integer.class, String.class); checkGridStartFails(g1Cfg, "IGFS data cache cannot start with enabled query indexing", true); }
@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; }
/** * 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); }
/** * 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(); }
/** {@inheritDoc} */ @Override protected void start0() throws IgniteCheckedException { dataCacheStartLatch = new CountDownLatch(1); String igfsName = igfsCtx.configuration().getName(); topic = F.isEmpty(igfsName) ? TOPIC_IGFS : TOPIC_IGFS.topic(igfsName); igfsCtx.kernalContext().io().addMessageListener(topic, new GridMessageListener() { @Override public void onMessage(UUID nodeId, Object msg, byte plc) { if (msg instanceof IgfsBlocksMessage) processBlocksMessage(nodeId, (IgfsBlocksMessage)msg); else if (msg instanceof IgfsAckMessage) processAckMessage(nodeId, (IgfsAckMessage)msg); } }); igfsCtx.kernalContext().event().addLocalEventListener(new GridLocalEventListener() { @Override public void onEvent(Event evt) { assert evt.type() == EVT_NODE_FAILED || evt.type() == EVT_NODE_LEFT; DiscoveryEvent discoEvt = (DiscoveryEvent)evt; if (igfsCtx.igfsNode(discoEvt.eventNode())) { for (WriteCompletionFuture future : pendingWrites.values()) { future.onError(discoEvt.eventNode().id(), new ClusterTopologyCheckedException("Node left grid before write completed: " + evt.node().id())); } } } }, EVT_NODE_LEFT, EVT_NODE_FAILED); delWorker = new AsyncDeleteWorker(igfsCtx.kernalContext().igniteInstanceName(), "igfs-" + igfsName + "-delete-worker", log); dataCacheName = igfsCtx.configuration().getDataCacheConfiguration().getName(); }
if (isProxyCache(ignite, igfsCfg.getDataCacheConfiguration().getName()) || isProxyCache(ignite, igfsCfg.getMetaCacheConfiguration().getName())) continue;
/** * @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); } }
/** * @throws Exception If failed. */ @Test public void testLocalIfAffinityMapperIsWrongClass() throws Exception { for (FileSystemConfiguration igfsCfg : g1Cfg.getFileSystemConfiguration()) { igfsCfg.setDataCacheConfiguration(dataCache(1024)); igfsCfg.setMetaCacheConfiguration(metaCache()); igfsCfg.getMetaCacheConfiguration().setAffinityMapper(new GridCacheDefaultAffinityKeyMapper()); igfsCfg.getDataCacheConfiguration().setAffinityMapper(new GridCacheDefaultAffinityKeyMapper()); } checkGridStartFails(g1Cfg, "Invalid IGFS data cache configuration (key affinity mapper class should be", true); }
@Override public void apply(IgniteConfiguration cfg) { String memPlcName = "igfsDataMemPlc"; cfg.setDataStorageConfiguration(new DataStorageConfiguration().setDataRegionConfigurations( new DataRegionConfiguration().setMaxSize(maxSize).setInitialSize(maxSize).setName(memPlcName))); FileSystemConfiguration igfsCfg = cfg.getFileSystemConfiguration()[0]; igfsCfg.getDataCacheConfiguration().setDataRegionName(memPlcName); cfg.setCacheConfiguration(new CacheConfiguration().setName("QQQ").setDataRegionName(memPlcName)); } };
/** @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)); }
/** {@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(); } }
/** @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()); } }
bufSize = cfg.getBufferSize(); colocateMeta = cfg.isColocateMetadata(); dataCacheCfg = cfg.getDataCacheConfiguration(); dfltMode = cfg.getDefaultMode(); fragmentizerConcurrentFiles = cfg.getFragmentizerConcurrentFiles();
/** * Create data transfer object for IGFS configuration properties. * @param igfs IGFS configuration. */ public VisorIgfsConfiguration(FileSystemConfiguration igfs) { name = igfs.getName(); metaCacheName = igfs.getMetaCacheConfiguration().getName(); dataCacheName = igfs.getDataCacheConfiguration().getName(); blockSize = igfs.getBlockSize(); prefetchBlocks = igfs.getPrefetchBlocks(); streamBufSize = igfs.getBufferSize(); perNodeBatchSize = igfs.getPerNodeBatchSize(); perNodeParallelBatchCnt = igfs.getPerNodeParallelBatchCount(); dfltMode = igfs.getDefaultMode(); pathModes = igfs.getPathModes(); maxTaskRangeLen = igfs.getMaximumTaskRangeLength(); fragmentizerConcurrentFiles = igfs.getFragmentizerConcurrentFiles(); fragmentizerEnabled = igfs.isFragmentizerEnabled(); fragmentizerThrottlingBlockLen = igfs.getFragmentizerThrottlingBlockLength(); fragmentizerThrottlingDelay = igfs.getFragmentizerThrottlingDelay(); IgfsIpcEndpointConfiguration endpointCfg = igfs.getIpcEndpointConfiguration(); ipcEndpointCfg = endpointCfg != null ? endpointCfg.toString() : null; ipcEndpointEnabled = igfs.isIpcEndpointEnabled(); mgmtPort = igfs.getManagementPort(); seqReadsBeforePrefetch = igfs.getSequentialReadsBeforePrefetch(); colocateMeta = igfs.isColocateMetadata(); relaxedConsistency = igfs.isRelaxedConsistency(); updateFileLenOnFlush = igfs.isUpdateFileLengthOnFlush(); }
/** * 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 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()); }