/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Nullable @Override public T peek() throws IgniteException { try { while (true) { GridCacheQueueHeader hdr = (GridCacheQueueHeader)cache.get(queueKey); checkRemoved(hdr); if (hdr.empty()) return null; T val = (T)cache.get(itemKey(hdr.head())); if (val == null) // Header might have been polled. Retry. continue; return val; } } catch (IgniteCheckedException e) { throw U.convertException(e); } }
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public int size() { try { GridCacheQueueHeader hdr = (GridCacheQueueHeader)cache.get(queueKey); checkRemoved(hdr); return hdr.size(); } catch (IgniteCheckedException e) { throw U.convertException(e); } }
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public Iterator<T> iterator() { try { GridCacheQueueHeader hdr = (GridCacheQueueHeader)cache.get(queueKey); checkRemoved(hdr); return new QueueIterator(hdr); } catch (IgniteCheckedException e) { throw U.convertException(e); } }
@Nullable @Override public Object call() throws Exception { try { writeLatch.await(10, TimeUnit.SECONDS); Ignite g1 = startGrid(1); IgniteCache<Integer, Integer> cache = g1.cache(DEFAULT_CACHE_NAME); for (int j = 0; j < KEY_CNT; j++) { cache.put(j, j); if (j % FREQUENCY == 0) info("Stored value in cache: " + j); } done.set(true); for (int j = 0; j < KEY_CNT; j++) { Integer val = internalCache(cache).get(j); assert val != null; if (j % FREQUENCY == 0) info("Read entry: " + j + " -> " + val); assert val != null && val == j; } if (backups > 0) stopGrid(1); } finally { readLatch.countDown(); } return null; } },
/** {@inheritDoc} */ @Nullable @Override public V get(K key) throws IgniteCheckedException { A.notNull(key, "key"); boolean statsEnabled = ctx.statisticsEnabled(); long start = statsEnabled ? System.nanoTime() : 0L; boolean keepBinary = ctx.keepBinary(); if (keepBinary) key = (K)ctx.toCacheKeyObject(key); V val = get(key, !keepBinary, false); if (ctx.config().getInterceptor() != null) { key = keepBinary ? (K)ctx.unwrapBinaryIfNeeded(key, true, false) : key; val = (V)ctx.config().getInterceptor().onGet(key, val); } if (statsEnabled) metrics0().addGetTimeNanos(System.nanoTime() - start); return val; }
/** * @throws Exception If failed. */ private void testGet(boolean nullRead) throws Exception { try { final Ignite ignite = startGrid(); final GridCacheAdapter cache = ((IgniteKernal)grid()).internalCache(DEFAULT_CACHE_NAME); IgniteBiTuple<String, String> key = new IgniteBiTuple<>(); if (nullRead) { assertEquals(null, cache.get("key")); assertEquals(null, cache.get(key)); } else { assertEquals("key", cache.get("key")); assertEquals(key, cache.get(key)); } } finally { stopAllGrids(); } } }
/** {@inheritDoc} */ @Nullable @Override public CacheEntry<K, V> getEntry(K key) throws IgniteCheckedException { A.notNull(key, "key"); boolean statsEnabled = ctx.statisticsEnabled(); long start = statsEnabled ? System.nanoTime() : 0L; boolean keepBinary = ctx.keepBinary(); if (keepBinary) key = (K)ctx.toCacheKeyObject(key); EntryGetResult t = (EntryGetResult)get(key, !keepBinary, true); CacheEntry<K, V> val = t != null ? new CacheEntryImplEx<>( keepBinary ? (K)ctx.unwrapBinaryIfNeeded(key, true, false) : key, (V)t.value(), t.version()) : null; if (ctx.config().getInterceptor() != null) { key = keepBinary ? (K)ctx.unwrapBinaryIfNeeded(key, true, false) : key; V val0 = (V)ctx.config().getInterceptor().onGet(key, t != null ? val.getValue() : null); val = (val0 != null) ? new CacheEntryImplEx<>(key, val0, t != null ? t.version() : null) : null; } if (statsEnabled) metrics0().addGetTimeNanos(System.nanoTime() - start); return val; }
/** * @throws Exception If failed. */ @Test public void testCacheSets() throws Exception { // Make new atomic sequence in cache. IgniteAtomicSequence seq = grid().atomicSequence(UUID.randomUUID().toString(), 0, true); seq.incrementAndGet(); final String cacheName = DataStructuresProcessor.ATOMICS_CACHE_NAME + "@default-ds-group"; GridCacheAdapter cache = ((IgniteKernal)grid()).internalCache(cacheName); assertNotNull(cache); GridTestUtils.assertThrows(log, new Callable<Void>() { @Override public Void call() throws Exception { grid().cache(cacheName); return null; } }, IllegalStateException.class, null); for (String seqName : seqNames) assert null != cache.get(new GridCacheInternalKeyImpl(seqName, "default-ds-group")); }
/** * Entries for key. * * @param key Key. * @return Entries. * @throws IgniteCheckedException If failed. */ private String entries(int key) throws IgniteCheckedException { if (partitioned()) { GridNearCacheAdapter<Integer, String> near1 = near(1); GridNearCacheAdapter<Integer, String> near2 = near(2); GridDhtCacheAdapter<Integer, String> dht1 = dht(1); GridDhtCacheAdapter<Integer, String> dht2 = dht(2); return "Entries [ne1=" + near1.peekEx(key) + ", de1=" + dht1.peekEx(key) + ", ne2=" + near2.peekEx(key) + ", de2=" + dht2.peekEx(key) + ']'; } return "Entries [e1=" + "(" + key + ", " + ((IgniteKernal)ignite1).internalCache(DEFAULT_CACHE_NAME).get(key) + ")" + ", e2=" + "(" + key + ", " + ((IgniteKernal)ignite2).internalCache(DEFAULT_CACHE_NAME).get(key) + ")" + ']'; }
/** * Test Optimistic repeatable read write-through. * * @throws Exception If failed. */ @Test public void testOptimisticTxWriteThrough() throws Exception { IgniteCache<Object, Object> near = jcache(); GridCacheAdapter<Integer, String> dht = dht(); try (Transaction tx = grid().transactions().txStart(OPTIMISTIC, REPEATABLE_READ) ) { near.put(2, "2"); near.put(3, "3"); assert "2".equals(near.get(2)); assert "3".equals(near.get(3)); GridCacheEntryEx entry = dht.peekEx(2); assert entry == null || entry.rawGet() == null : "Invalid entry: " + entry; tx.commit(); } assert "2".equals(near.get(2)); assert "3".equals(near.get(3)); assert "2".equals(dht.get(2)); assert "3".equals(dht.get(3)); assertEquals(2, near.size()); assertEquals(2, near.size()); assertEquals(2, dht.size()); assertEquals(2, dht.size()); }
GridCacheAdapter<IgfsBlockKey, byte[]> dataCache = ((IgniteKernal)grid(0)).internalCache(dataCacheName); IgfsEntryInfo info = metaCache.get(fileId); assertNotNull(metaCache.get(info.id())); assertNotNull(dataCache.get(dataMgr.blockKey(i, info))); if (metaCache.get(info.id()) == null) break; assertNull(metaCache.get(info.id())); if (dataCache.get(dataMgr.blockKey(i, info)) != null) { doBreak = false; assertNull(dataCache.get(new IgfsBlockKey(info.id(), null, false, i)));
IgfsEntryInfo fileInfo = (IgfsEntryInfo)metaCache.get(fileImpl.fileId());
info("Entry in cache [key=" + key + ", val=" + metaCache.get(key) + ']');
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public Iterator<T> iterator() { try { GridCacheQueueHeader hdr = (GridCacheQueueHeader)cache.get(queueKey); checkRemoved(hdr); return new QueueIterator(hdr); } catch (IgniteCheckedException e) { throw U.convertException(e); } }
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public int size() { try { GridCacheQueueHeader hdr = (GridCacheQueueHeader)cache.get(queueKey); checkRemoved(hdr); return hdr.size(); } catch (IgniteCheckedException e) { throw U.convertException(e); } }
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Nullable @Override public T peek() throws IgniteException { try { while (true) { GridCacheQueueHeader hdr = (GridCacheQueueHeader)cache.get(queueKey); checkRemoved(hdr); if (hdr.empty()) return null; T val = (T)cache.get(itemKey(hdr.head())); if (val == null) // Header might have been polled. Retry. continue; return val; } } catch (IgniteCheckedException e) { throw U.convertException(e); } }
/** {@inheritDoc} */ @Nullable @Override public V get(K key) throws IgniteCheckedException { A.notNull(key, "key"); boolean statsEnabled = ctx.statisticsEnabled(); long start = statsEnabled ? System.nanoTime() : 0L; boolean keepBinary = ctx.keepBinary(); if (keepBinary) key = (K)ctx.toCacheKeyObject(key); V val = get(key, !keepBinary, false); if (ctx.config().getInterceptor() != null) { key = keepBinary ? (K)ctx.unwrapBinaryIfNeeded(key, true, false) : key; val = (V)ctx.config().getInterceptor().onGet(key, val); } if (statsEnabled) metrics0().addGetTimeNanos(System.nanoTime() - start); return val; }
/** {@inheritDoc} */ @Nullable @Override public CacheEntry<K, V> getEntry(K key) throws IgniteCheckedException { A.notNull(key, "key"); boolean statsEnabled = ctx.statisticsEnabled(); long start = statsEnabled ? System.nanoTime() : 0L; boolean keepBinary = ctx.keepBinary(); if (keepBinary) key = (K)ctx.toCacheKeyObject(key); EntryGetResult t = (EntryGetResult)get(key, !keepBinary, true); CacheEntry<K, V> val = t != null ? new CacheEntryImplEx<>( keepBinary ? (K)ctx.unwrapBinaryIfNeeded(key, true, false) : key, (V)t.value(), t.version()) : null; if (ctx.config().getInterceptor() != null) { key = keepBinary ? (K)ctx.unwrapBinaryIfNeeded(key, true, false) : key; V val0 = (V)ctx.config().getInterceptor().onGet(key, t != null ? val.getValue() : null); val = (val0 != null) ? new CacheEntryImplEx<>(key, val0, t != null ? t.version() : null) : null; } if (statsEnabled) metrics0().addGetTimeNanos(System.nanoTime() - start); return val; }