/** * Iterates over cache. * * @param cache Projection. * @param c Visitor closure. */ private void iterate(IgniteCache<Integer, Integer> cache, IgniteInClosure<Cache.Entry<Integer, Integer>> c) { for (Cache.Entry<Integer, Integer> entry : cache.localEntries()) c.apply(entry); }
@Override public List<Person> applyx(CountDownLatch startLatch, CountDownLatch endLatch2) throws IgniteCheckedException { Iterator<Cache.Entry<Integer, Person>> it = cache().localEntries(CachePeekMode.PRIMARY).iterator(); List<Cache.Entry<Integer, Person>> pres = new ArrayList<>(); for (int i = 0; i < 10; i++) pres.add(it.next()); if (startLatch != null) startLatch.countDown(); while (it.hasNext()) pres.add(it.next()); if (endLatch2 != null) U.await(endLatch2); return entriesToPersons(pres); } };
/** {@inheritDoc} */ @Override public Iterable<Entry<K, V>> call() throws Exception { Collection<Entry<K, V>> res = new ArrayList<>(); for (Entry<K, V> e : cache().localEntries(peekModes)) res.add(new CacheEntryImpl<>(e.getKey(), e.getValue())); return res; } }
checkLocalEntries(cache0.localEntries(), nearKeys, primaryKeys, backupKeys); checkLocalEntries(cache0.localEntries(ALL), nearKeys, primaryKeys, backupKeys); checkLocalEntries(cache0.localEntries(NEAR), nearKeys); checkLocalEntries(cache0.localEntries(PRIMARY, BACKUP, NEAR), nearKeys, primaryKeys, backupKeys); checkLocalEntries(cache0.localEntries(NEAR, PRIMARY), nearKeys, primaryKeys); checkLocalEntries(cache0.localEntries(NEAR, BACKUP), nearKeys, backupKeys); checkLocalEntries(cache0.localEntries(), primaryKeys, backupKeys); checkLocalEntries(cache0.localEntries(ALL), primaryKeys, backupKeys); checkLocalEntries(cache0.localEntries(NEAR)); checkLocalEntries(cache0.localEntries(NEAR, PRIMARY), primaryKeys); checkLocalEntries(cache0.localEntries(NEAR, BACKUP), backupKeys); checkLocalEntries(cache0.localEntries(PRIMARY, BACKUP, NEAR), primaryKeys, backupKeys); checkLocalEntries(cache0.localEntries(PRIMARY), primaryKeys); checkLocalEntries(cache0.localEntries(BACKUP), backupKeys); checkLocalEntries(cache0.localEntries(PRIMARY, BACKUP), primaryKeys, backupKeys);
/** * Removes old cache entries locally. * * @param ignite Ignite. * @param dataCacheName Cache name. * @param currentVersions Current versions. */ private static void removeOldEntries(final Ignite ignite, final String dataCacheName, final Map<String, EntryProcessorResult<Long>> currentVersions) { IgniteCache<PlatformDotNetEntityFrameworkCacheKey, PlatformDotNetEntityFrameworkCacheEntry> cache = ignite.cache(dataCacheName); Set<PlatformDotNetEntityFrameworkCacheKey> keysToRemove = new TreeSet<>(); ClusterNode localNode = ignite.cluster().localNode(); for (Cache.Entry<PlatformDotNetEntityFrameworkCacheKey, PlatformDotNetEntityFrameworkCacheEntry> cacheEntry : cache.localEntries(CachePeekMode.ALL)) { // Check if we are on a primary node for the key, since we use CachePeekMode.ALL // and we don't want to process backup entries. if (!ignite.affinity(dataCacheName).isPrimary(localNode, cacheEntry.getKey())) continue; long[] versions = cacheEntry.getKey().versions(); String[] entitySets = cacheEntry.getValue().entitySets(); for (int i = 0; i < entitySets.length; i++) { EntryProcessorResult<Long> curVer = currentVersions.get(entitySets[i]); if (curVer != null && versions[i] < curVer.get()) keysToRemove.add(cacheEntry.getKey()); } } cache.removeAll(keysToRemove); }
/** * Verifies that local <code>select count(*)</code> query returns a correct result. * * @throws Exception If failed. */ public void checkLocalSizeQueryWithSegmentedIndex() throws Exception { for (int i = 0; i < nodesCount(); i++) { final Ignite node = ignite(i); IgniteCache<Integer, Person> c1 = node.cache(PERSON_CAHE_NAME); IgniteCache<Integer, Organization> c2 = node.cache(ORG_CACHE_NAME); Set<Integer> locOrgIds = new HashSet<>(); for (Cache.Entry<Integer, Organization> e : c2.localEntries()) locOrgIds.add(e.getKey()); int expPersons = 0; for (Cache.Entry<Integer, Person> e : c1.localEntries()) { final Integer orgId = e.getValue().orgId; if (locOrgIds.contains(orgId)) expPersons++; } String select0 = "select count(*) from \"pers\".Person p, \"org\".Organization o where p.orgId = o._key"; List<List<?>> res = c1.query(new SqlFieldsQuery(select0).setLocal(true)).getAll(); assertEquals((long) expPersons, res.get(0).get(0)); } }
/** * Test local query. * * @throws Exception If failed. */ public void checkLocalQueryWithSegmentedIndex() throws Exception { for (int i = 0; i < nodesCount(); i++) { final Ignite node = ignite(i); IgniteCache<Integer, Person> c1 = node.cache(PERSON_CAHE_NAME); IgniteCache<Integer, Organization> c2 = node.cache(ORG_CACHE_NAME); Set<Integer> locOrgIds = new HashSet<>(); for (Cache.Entry<Integer, Organization> e : c2.localEntries()) locOrgIds.add(e.getKey()); long expPersons = 0; for (Cache.Entry<Integer, Person> e : c1.localEntries()) { final Integer orgId = e.getValue().orgId; if (locOrgIds.contains(orgId)) expPersons++; } String select0 = "select o.name n1, p.name n2 from \"pers\".Person p, \"org\".Organization o where p.orgId = o._key"; List<List<?>> res = c1.query(new SqlFieldsQuery(select0).setLocal(true)).getAll(); assertEquals(expPersons, res.size()); } }
/** * @throws Exception If failed. */ @Test public void testLocalPeek() throws Exception { IgniteCache<Integer, String> cache = grid(0).cache(DEFAULT_CACHE_NAME); Iterable<Cache.Entry<Integer, String>> entries = cache.localEntries(); for (Cache.Entry<Integer, String> entry : entries) checkVersionedEntry(entry.unwrap(CacheEntry.class)); }
/** * Execute given query locally and check results. * @param cache Cache to run query on. * @param fldsQry Query. */ private void doTestLocalQuery(IgniteCache<?, ?> cache, SqlFieldsQuery fldsQry) throws InterruptedException { awaitPartitionMapExchange(true, true, null); int exp = 0; for(Cache.Entry e: intCache.localEntries(CachePeekMode.PRIMARY)){ if(e.getValue() instanceof Integer) exp++; } QueryCursor<List<?>> qry = cache.query(fldsQry.setLocal(true)); assertEquals(exp, qry.getAll().size()); } }
/** * @param total Expected total entries. * @param cntrs Expected per-node entries count. */ private void checkLocalEntries(int total, Map<UUID, Integer> cntrs) { Set<DbKey> allKeys = new HashSet<>(); for (int i = 0; i < gridCount(); i++) { Ignite ignite0 = grid(i); IgniteCache<DbKey, DbValue> cache0 = ignite0.cache("non-primitive"); int cnt = 0; for (Cache.Entry<DbKey, DbValue> e : cache0.localEntries()) { cnt++; allKeys.add(e.getKey()); assertEquals(e.getKey().val, e.getValue().iVal); } assertEquals(cntrs.get(ignite0.cluster().localNode().id()), (Integer)cnt); } assertEquals(total, allKeys.size()); }
/** * @param idx Node index. * @param cacheName Cache name. * @param data Expected data. * @throws Exception If failed. */ private void checkLocalData(int idx, String cacheName, Integer[] data) throws Exception { Ignite ignite = ignite(idx); ClusterNode node = ignite.cluster().localNode(); IgniteCache cache = ignite.<Integer, Integer>cache(cacheName); Affinity aff = affinity(cache); Set<Integer> locKeys = new TreeSet<>(); for (int key = 0; key < data.length; key++) { if(aff.isPrimaryOrBackup(node, key)) locKeys.add(key); } Iterable<Cache.Entry<Integer, Integer>> locEntries = cache.localEntries(CachePeekMode.OFFHEAP); for (Cache.Entry<Integer, Integer> entry : locEntries) { assertTrue(locKeys.remove(entry.getKey())); assertEquals(data[entry.getKey()], entry.getValue()); } assertTrue(locKeys.isEmpty()); }
@Override public boolean applyx() throws IgniteCheckedException { jcache(fi).removeAll(); if (jcache(fi).size(CachePeekMode.ALL) > 0) { for (Cache.Entry<String, ?> k : jcache(fi).localEntries()) jcache(fi).remove(k.getKey()); } return jcache(fi).localSize(CachePeekMode.ALL) == 0; } },
IgniteCache<Object, Object> cache = grid(i).cache(DEFAULT_CACHE_NAME); for (Cache.Entry<Object, Object> entry : cache.localEntries(new CachePeekMode[] {CachePeekMode.ALL})) cache.remove(entry.getKey());
/** * @throws Exception If failed. */ @Test public void testLocalEntries() throws Exception { IgniteCache<Integer, BinaryObject> cache = grid(0).cache(DEFAULT_CACHE_NAME).withKeepBinary(); final int ENTRY_CNT = 10; for (int i = 0; i < ENTRY_CNT; i++) cache.put(i, userObject("user-" + i)); assertEquals(ENTRY_CNT, cache.localSize(CachePeekMode.ALL)); for (int i = 0; i < gridCount(); i++) jcache(i).withKeepBinary().localEntries(); cache.removeAll(); }
cur = new VisorNearCacheCursor<>(c.localEntries(CachePeekMode.NEAR).iterator()); else { ScanQuery<Object, Object> qry = new ScanQuery<>(filter);
/** * @throws Exception If failed. */ @Test public void testOffHeapIterator() throws Exception { try { startGrids(1); grid(0); IgniteCache<Integer, Integer> cache = grid(0).cache(DEFAULT_CACHE_NAME); for (int i = 0; i < 100; i++) { info("Putting: " + i); cache.put(i, i); } int i = 0; for (Cache.Entry<Integer, Integer> e : cache.localEntries(CachePeekMode.OFFHEAP)) { Integer key = e.getKey(); info("Key: " + key); i++; cache.remove(e.getKey()); assertNull(cache.get(key)); } assertEquals(100, i); assert cache.localSize() == 0; } finally { stopAllGrids(); } }
/** {@inheritDoc} */ @Override protected void afterTest() throws Exception { grid(0).cache(DEFAULT_CACHE_NAME).removeAll(); for (int i = 0; i < GRID_CNT; i++) { Ignite g = grid(i); IgniteCache<String, int[]> c = g.cache(DEFAULT_CACHE_NAME); GridCacheAdapter<Object, Object> cache = ((IgniteEx)g).context().cache().internalCache(DEFAULT_CACHE_NAME); info("Node: " + g.cluster().localNode().id()); info("Entries: " + cache.entries()); if (cache.context().isNear()) info("DHT entries: " + cache.context().near().dht().entries()); assertEquals("Cache is not empty, node [entries=" + c.localEntries() + ", igniteInstanceName=" + g.name() + ']', 0, c.localSize()); } }
/** {@inheritDoc} */ @Override protected void afterTest() throws Exception { super.afterTest(); // Clean up all caches. for (int i = 0; i < GRID_CNT; i++) { for(String cacheName : grid(i).cacheNames()) { IgniteCache<Object, Object> c = grid(i).cache(cacheName); c.removeAll(); // Fix for tests where mapping was removed at primary node // but was not removed at others. // removeAll() removes mapping only when it presents at a primary node. // To remove all mappings used force remove by key. if (c.size() > 0) { for (Cache.Entry<Object, Object> e : c.localEntries()) c.remove(e.getKey()); } } } U.sleep(5000); for (int i = 0; i < GRID_CNT; i++) { for(String cacheName : grid(i).cacheNames()) { IgniteCache<Object, Object> c = grid(i).cache(cacheName); assertEquals(0, c.size(CachePeekMode.OFFHEAP)); assertEquals(0, c.size(CachePeekMode.PRIMARY)); assertEquals(0, c.size()); } } }
/** * Starts caches dynamically. * * @throws Exception If failed. */ private void startCachesDinamically() throws Exception { for (int i = 0; i < gridCount(); i++) { info("Starting cache dinamically on grid: " + i); IgniteEx grid = grid(i); if (i != CLIENT_NODE_IDX && i != CLIENT_NEAR_ONLY_IDX) { CacheConfiguration cc = cacheConfiguration(); cc.setName(cacheName()); grid.getOrCreateCache(cc); } if (testsCfg.withClients() && i == CLIENT_NEAR_ONLY_IDX && grid(i).configuration().isClientMode()) grid(CLIENT_NEAR_ONLY_IDX).createNearCache(cacheName(), new NearCacheConfiguration()); } awaitPartitionMapExchange(); for (int i = 0; i < gridCount(); i++) assertNotNull(jcache(i)); for (int i = 0; i < gridCount(); i++) assertEquals("Cache is not empty [idx=" + i + ", entrySet=" + jcache(i).localEntries() + ']', 0, jcache(i).localSize(CachePeekMode.ALL)); }
for (Cache.Entry<Integer, String> e : this.<Integer, String>jcache(0).localEntries()) { assert aff.isPrimary(locNode, e.getKey()) || aff.isBackup(locNode, e.getKey());