/** * Remove learning environment from local cache by Dataset ID. * * @param ignite Ingnite instance. * @param datasetId Dataset ID. */ public static void removeLearningEnv(Ignite ignite, UUID datasetId) { ignite.cluster().nodeLocalMap().remove(String.format(ENVIRONMENT_STORAGE_KEY_TEMPLATE, datasetId)); }
/** * Remove data from local cache by Dataset ID. * * @param ignite Ignite instance. * @param datasetId Dataset ID. */ public static void removeData(Ignite ignite, UUID datasetId) { ignite.cluster().nodeLocalMap().remove(String.format(DATA_STORAGE_KEY_TEMPLATE, datasetId)); }
/** * Concurrently increments numeric cache value. * * @param key Key for the value to be incremented. */ private <T> void concurrentIncrement(T key) { ConcurrentMap<T, Integer> nodeLoc = ignite.cluster().nodeLocalMap(); Integer cntr = nodeLoc.get(key); if (cntr == null) cntr = nodeLoc.putIfAbsent(key, 1); if (cntr != null) { while (!nodeLoc.replace(key, cntr, cntr + 1)) { cntr = nodeLoc.get(key); assert cntr != null; } } } }
/** * Returns task metadata storage that is kept by every node in the cluster. * * @return Task metadata storage that is kept by every node in the cluster. */ ConcurrentHashMap<UUID, Future<?>> getMetadataStorage() { Ignite ignite = Ignition.localIgnite(); ConcurrentMap<String, ConcurrentHashMap<UUID, Future<?>>> nodeLocMap = ignite.cluster().nodeLocalMap(); return nodeLocMap.computeIfAbsent(LONG_RUNNING_PROCESS_STORAGE_NAME, k -> new ConcurrentHashMap<>()); } }
/** * Gets learning environment for given partition. If learning environment is not found in local node map, * it will be created with specified {@link LearningEnvironmentBuilder}. * * @param ignite Ignite instance. * @param datasetId Dataset id. * @param part Partition index. * @param envBuilder {@link LearningEnvironmentBuilder}. * @return Learning environment for given partition. */ public static LearningEnvironment getLearningEnvironment(Ignite ignite, UUID datasetId, int part, LearningEnvironmentBuilder envBuilder) { @SuppressWarnings("unchecked") ConcurrentMap<Integer, LearningEnvironment> envStorage = (ConcurrentMap<Integer, LearningEnvironment>)ignite .cluster() .nodeLocalMap() .computeIfAbsent(String.format(ENVIRONMENT_STORAGE_KEY_TEMPLATE, datasetId), key -> new ConcurrentHashMap<>()); return envStorage.computeIfAbsent(part, envBuilder::buildForWorker); }
/** * @param futId Cursor ID. * @param c Cursor. * @return {@code true} If succeeded. */ private boolean remove(UUID futId, Cursor c) { if (ignite.cluster().<UUID,Cursor>nodeLocalMap().remove(futId, c)) { c.cursor.close(); return true; } return false; }
@Override public void applyx() { for (;;) { Cursor c = ignite.cluster().<UUID,Cursor>nodeLocalMap().get(id); if (c == null) break; // If the cursor was accessed since last scheduling then reschedule. long untouchedTime = U.currentTimeMillis() - c.lastAccessTime; if (untouchedTime < RMV_DELAY) { scheduleRemoval(id, RMV_DELAY - untouchedTime); break; } else if (remove(id, c)) break; } } }, delay, TimeUnit.MILLISECONDS);
/** {@inheritDoc} */ @Override public void onLifecycleEvent(LifecycleEventType evt) { evtQueue.add(evt); // check nodeLocalMap is not locked ConcurrentMap map = ignite.cluster().nodeLocalMap(); assertNotNull(map); } }
/** {@inheritDoc} */ @Override public boolean apply(UUID nodeId, Object msg) { ignite.log().info("Received message [nodeId=" + nodeId + ", locNodeId=" + ignite.cluster().localNode().id() + ", msg=" + msg + ']'); ConcurrentMap<String, AtomicInteger> map = ignite.cluster().nodeLocalMap(); AtomicInteger cnt = map.get("msgCnt"); if (cnt == null) { AtomicInteger old = map.putIfAbsent("msgCnt", cnt = new AtomicInteger(0)); if (old != null) cnt = old; } cnt.incrementAndGet(); return true; } }
/** * @param expCnt Expected messages count. * @return If check passed. */ private boolean checkDeployedListeners(int expCnt) { for (Ignite g : G.allGrids()) { AtomicInteger cnt = g.cluster().<String, AtomicInteger>nodeLocalMap().get("msgCnt"); if (cnt == null || cnt.get() != expCnt) return false; } return true; }
assert evtTypes != null && evtTypes.length > 0; ConcurrentMap<String, Long> nl = ignite.cluster().nodeLocalMap();
/** * Test node-local values operations. * * @throws Exception If test failed. */ @Test public void testNodeLocal() throws Exception { Ignite g = G.ignite(getTestIgniteInstanceName()); String keyStr = "key"; int keyNum = 1; Date keyDate = new Date(); GridTuple3 key = F.t(keyNum, keyStr, keyDate); ConcurrentMap<Object, Object> nl = g.cluster().nodeLocalMap(); nl.put(keyStr, "Hello world!"); nl.put(key, 12); assert nl.containsKey(keyStr); assert nl.containsKey(key); assert !nl.containsKey(keyNum); assert !nl.containsKey(F.t(keyNum, keyStr)); assert "Hello world!".equals(nl.get(keyStr)); assert (Integer)nl.get(key) == 12; }
/** * Test that node local map is cleared via {@link IgniteMXBean#clearNodeLocalMap()}. * * @throws Exception if test failed. */ @Test public void testClearNodeLocalMap() throws Exception { final String key = "key"; final String value = "value"; Ignite grid = G.ignite(getTestIgniteInstanceName()); ConcurrentMap<Object, Object> nodeLocalMap = grid.cluster().nodeLocalMap(); nodeLocalMap.put(key, value); assert !nodeLocalMap.isEmpty() : "Empty node local map"; assert nodeLocalMap.containsKey(key); IgniteMXBean igniteMXBean = (IgniteMXBean)grid; igniteMXBean.clearNodeLocalMap(); assert nodeLocalMap.isEmpty() : "Not empty node local map"; } }
ConcurrentMap<UUID,Cursor> m = ignite.cluster().nodeLocalMap();
/** {@inheritDoc} */ @Override public Object execute() { ConcurrentMap<String, T2<AtomicLong, AtomicLong>> nodeLoc = ignite.cluster().nodeLocalMap(); T2<AtomicLong, AtomicLong> cntrs = nodeLoc.get("cntrs"); if (cntrs == null) { T2<AtomicLong, AtomicLong> other = nodeLoc.putIfAbsent("cntrs", cntrs = new T2<>(new AtomicLong(), new AtomicLong(System.currentTimeMillis()))); if (other != null) cntrs = other; } long cnt = cntrs.get1().incrementAndGet(); doWork(); GridNearCacheAdapter near = (GridNearCacheAdapter)((IgniteKernal) ignite).internalCache(DEFAULT_CACHE_NAME); GridDhtCacheAdapter dht = near.dht(); long start = cntrs.get2().get(); long now = System.currentTimeMillis(); long dur = now - start; if (dur > 20000 && cntrs.get2().compareAndSet(start, System.currentTimeMillis())) { cntrs.get1().set(0); X.println("Stats [tx/sec=" + (cnt / (dur / 1000)) + ", nearSize=" + near.size() + ", dhtSize=" + dht.size() + ']'); } return null; }
/** * @return Result. */ @SuppressWarnings("ConstantConditions") @Override public Object execute() { ConcurrentMap<String, T2<AtomicLong, AtomicLong>> nodeLoc = ignite.cluster().nodeLocalMap(); T2<AtomicLong, AtomicLong> cntrs = nodeLoc.get("cntrs"); if (cntrs == null) { T2<AtomicLong, AtomicLong> other = nodeLoc.putIfAbsent("cntrs", cntrs = new T2<>(new AtomicLong(), new AtomicLong(System.currentTimeMillis()))); if (other != null) cntrs = other; } long cnt = cntrs.get1().incrementAndGet(); GridNearCacheAdapter near = (GridNearCacheAdapter)((IgniteKernal) ignite).internalCache(cacheName); GridDhtCacheAdapter dht = near.dht(); doWork(); long start = cntrs.get2().get(); long now = System.currentTimeMillis(); long dur = now - start; if (dur > 20000 && cntrs.get2().compareAndSet(start, System.currentTimeMillis())) { cntrs.get1().set(0); long txPerSec = cnt / (dur / 1000); X.println("Stats [tx/sec=" + txPerSec + ", nearSize=" + near.size() + ", dhtSize=" + dht.size() + ']'); return new T3<>(txPerSec, near.size(), dht.size()); } return null; }
.nodeLocalMap() .computeIfAbsent(String.format(DATA_STORAGE_KEY_TEMPLATE, datasetId), key -> new PartitionDataStorage());
cluster.nodeLocalMap().put("locMapKey", 10); assertEquals(10, cluster.nodeLocalMap().get("locMapKey"));
/** * @param futId Cursor ID. * @param c Cursor. * @return {@code true} If succeeded. */ private boolean remove(UUID futId, Cursor c) { if (ignite.cluster().<UUID,Cursor>nodeLocalMap().remove(futId, c)) { c.cursor.close(); return true; } return false; }
@Override public void applyx() { for (;;) { Cursor c = ignite.cluster().<UUID,Cursor>nodeLocalMap().get(id); if (c == null) break; // If the cursor was accessed since last scheduling then reschedule. long untouchedTime = U.currentTimeMillis() - c.lastAccessTime; if (untouchedTime < RMV_DELAY) { scheduleRemoval(id, RMV_DELAY - untouchedTime); break; } else if (remove(id, c)) break; } } }, delay, TimeUnit.MILLISECONDS);