@Override protected boolean onHasNext() throws IgniteCheckedException { if (next != null) return true; if (cur.next()) next = cur.get(); return next != null; }
/** {@inheritDoc} */ @Override public Row get() { try { return cursor.get(); } catch (IgniteCheckedException e) { throw DbException.convert(e); } }
/** {@inheritDoc} */ @Override public Row get() { try { return desc.createRow(curr.get()); } catch (IgniteCheckedException e) { throw DbException.convert(e); } }
/** * Read all items from metastore. */ public Collection<IgniteBiTuple<String, byte[]>> readAll() throws IgniteCheckedException { ArrayList<IgniteBiTuple<String, byte[]>> res = new ArrayList<>(); GridCursor<MetastorageDataRow> cur = tree.find(null, null); while (cur.next()) { MetastorageDataRow row = cur.get(); res.add(new IgniteBiTuple<>(row.key(), row.value())); } return res; }
/** {@inheritDoc} */ @Override public boolean next() { try { while (cursor.next()) { GridH2Row row = cursor.get(); if (row.expireTime() > 0 && row.expireTime() <= time) continue; return true; } return false; } catch (IgniteCheckedException e) { throw DbException.convert(e); } }
/** * @param cursor cursor to check. * @param iterator iterator with expected result. * @throws IgniteCheckedException If failed */ private void checkCursor(GridCursor<Long> cursor, Iterator<Long> iterator) throws IgniteCheckedException { while (cursor.next()) { assertTrue(iterator.hasNext()); assertEquals(iterator.next(), cursor.get()); } assertFalse(iterator.hasNext()); }
/** {@inheritDoc} */ @Override public boolean next() { try { CacheDataRowStore.setSkipVersion(true); GridQueryTypeDescriptor type = desc.type(); for (;;) { if (curr != null) { while (curr.next()) { // Need to filter rows by value type because in a single cache // we can have multiple indexed types. if (type.matchType(curr.get().value())) return true; } } if (!iter.hasNext()) return false; curr = iter.next(); } } catch (IgniteCheckedException e) { throw DbException.convert(e); } finally { CacheDataRowStore.setSkipVersion(false); } }
/** * Copying all data from the 'meta' to temporary storage. * * @return Target temporary storage */ private TmpStorage copyDataToTmpStorage() throws IgniteCheckedException { TmpStorage tmpStorage = new TmpStorage(TEMPORARY_METASTORAGE_IN_MEMORY_SIZE, log); GridCursor<MetastorageDataRow> cur = tree.find(null, null); while (cur.next()) { MetastorageDataRow row = cur.get(); tmpStorage.add(row.key(), row.value()); } return tmpStorage; }
/** * @param cache Cache. * @param key Key. * @return Collection of versioned rows. * @throws IgniteCheckedException if failed. */ private List<CacheDataRow> allKeyVersions(IgniteCache cache, Object key) throws IgniteCheckedException { IgniteCacheProxy cache0 = (IgniteCacheProxy)cache; GridCacheContext cctx = cache0.context(); KeyCacheObject key0 = cctx.toCacheKeyObject(key); GridCursor<CacheDataRow> cur = cctx.offheap().mvccAllVersionsCursor(cctx, key0, null); List<CacheDataRow> rows = new ArrayList<>(); while (cur.next()) { CacheDataRow row = cur.get(); rows.add(row); } return rows; }
/** * Retrieves all versions of all keys from cache. * * @param cache Cache. * @return {@link Map} of keys to its versions. * @throws IgniteCheckedException If failed. */ private Map<KeyCacheObject, List<CacheDataRow>> allVersions(IgniteCache cache) throws IgniteCheckedException { IgniteCacheProxy cache0 = (IgniteCacheProxy)cache; GridCacheContext cctx = cache0.context(); assert cctx.mvccEnabled(); Map<KeyCacheObject, List<CacheDataRow>> vers = new HashMap<>(); for (Object e : cache) { IgniteBiTuple entry = (IgniteBiTuple)e; KeyCacheObject key = cctx.toCacheKeyObject(entry.getKey()); GridCursor<CacheDataRow> cur = cctx.offheap().mvccAllVersionsCursor(cctx, key, null); List<CacheDataRow> rows = new ArrayList<>(); while (cur.next()) { CacheDataRow row = cur.get(); rows.add(row); } vers.put(key, rows); } return vers; }
/** * @param tree Tree. * @param map Map. * @throws IgniteCheckedException If failed. */ private void assertEqualContents(IgniteTree<Long, Long> tree, Map<Long,Long> map) throws IgniteCheckedException { GridCursor<Long> cursor = tree.find(null, null); while (cursor.next()) { Long x = cursor.get(); assert x != null; assertEquals(map.get(x), x); assertNoLocks(); } assertEquals(map.size(), tree.size()); assertNoLocks(); }
/** {@inheritDoc} */ @Override public List<IgniteBiTuple<Object, MvccVersion>> mvccFindAllVersions( GridCacheContext cctx, KeyCacheObject key) throws IgniteCheckedException { assert grp.mvccEnabled(); // Note: this method is intended for testing only. key.valueBytes(cctx.cacheObjectContext()); int cacheId = grp.sharedGroup() ? cctx.cacheId() : CU.UNDEFINED_CACHE_ID; GridCursor<CacheDataRow> cur = dataTree.find( new MvccMaxSearchRow(cacheId, key), new MvccMinSearchRow(cacheId, key) ); List<IgniteBiTuple<Object, MvccVersion>> res = new ArrayList<>(); long crd = MVCC_CRD_COUNTER_NA; long cntr = MVCC_COUNTER_NA; int opCntr = MVCC_OP_COUNTER_NA; while (cur.next()) { CacheDataRow row = cur.get(); if (compareNewVersion(row, crd, cntr, opCntr) != 0) // deleted row res.add(F.t(null, row.newMvccVersion())); res.add(F.t(row.value(), row.mvccVersion())); crd = row.mvccCoordinatorVersion(); cntr = row.mvccCounter(); opCntr = row.mvccOperationCounter(); } return res; }
/** {@inheritDoc} */ @Override public void clear(int cacheId) throws IgniteCheckedException { assert cacheId != CU.UNDEFINED_CACHE_ID; if (cacheSize(cacheId) == 0) return; Exception ex = null; GridCursor<? extends CacheDataRow> cur = cursor(cacheId, null, null, CacheDataRowAdapter.RowData.KEY_ONLY); while (cur.next()) { CacheDataRow row = cur.get(); assert row.link() != 0 : row; try { boolean res = dataTree.removex(row); assert res : row; rowStore.removeRow(row.link(), grp.statisticsHolderData()); decrementSize(cacheId); } catch (IgniteCheckedException e) { U.error(log, "Fail remove row [link=" + row.link() + "]"); if (ex == null) ex = e; else ex.addSuppressed(e); } } if (ex != null) throw new IgniteCheckedException("Fail destroy store", ex); }
/** {@inheritDoc} */ @Override public void clear(int cacheId) throws IgniteCheckedException { CacheDataStore delegate0 = init0(true); if (delegate0 == null) return; ctx.database().checkpointReadLock(); try { // Clear persistent pendingTree if (pendingTree != null) { PendingRow row = new PendingRow(cacheId); GridCursor<PendingRow> cursor = pendingTree.find(row, row, PendingEntriesTree.WITHOUT_KEY); while (cursor.next()) { PendingRow row0 = cursor.get(); assert row0.link != 0 : row; boolean res = pendingTree.removex(row0); assert res; } } delegate0.clear(cacheId); } finally { ctx.database().checkpointReadUnlock(); } }
/** * @param cacheId Cache ID. */ private void removeCacheData(int cacheId) { assert grp.affinityNode(); try { if (grp.sharedGroup()) { assert cacheId != CU.UNDEFINED_CACHE_ID; for (CacheDataStore store : cacheDataStores()) store.clear(cacheId); // Clear non-persistent pending tree if needed. if (pendingEntries != null) { PendingRow row = new PendingRow(cacheId); GridCursor<PendingRow> cursor = pendingEntries.find(row, row, PendingEntriesTree.WITHOUT_KEY); while (cursor.next()) { boolean res = pendingEntries.removex(cursor.get()); assert res; } } } } catch (IgniteCheckedException e) { throw new IgniteException(e.getMessage(), e); } }
/** */ private void checkAllVersionsHints(IgniteCache cache) throws IgniteCheckedException { IgniteCacheProxy cache0 = (IgniteCacheProxy)cache; GridCacheContext cctx = cache0.context(); assert cctx.mvccEnabled(); for (Object e : cache) { IgniteBiTuple entry = (IgniteBiTuple)e; KeyCacheObject key = cctx.toCacheKeyObject(entry.getKey()); GridCursor<CacheDataRow> cur = cctx.offheap().mvccAllVersionsCursor(cctx, key, CacheDataRowAdapter.RowData.LINK_WITH_HEADER); while (cur.next()) { CacheDataRow row = cur.get(); assertTrue(row.mvccTxState() != 0); } } }
CacheDataRow row = cur.get();
/** * @param ignite Ignite. * @param orgId Organization id. * @return Count of found Person object with specified orgId * @throws Exception If failed. */ private static int getPersonsCountFromPartitionMap(final IgniteEx ignite, int orgId) throws Exception { int part = ignite.affinity(Organization.class.getSimpleName()).partition(orgId); GridCacheAdapter<?, ?> cacheAdapterPers = ignite.context().cache() .internalCache(Person.class.getSimpleName()); GridDhtLocalPartition pPers = cacheAdapterPers.context().topology() .localPartition(part, AffinityTopologyVersion.NONE, false); int cnt = 0; GridCursor<? extends CacheDataRow> c = pPers.dataStore().cursor(); CacheObjectContext ctx = cacheAdapterPers.context().cacheObjectContext(); while (c.next()) { CacheDataRow e = c.get(); Person.Key k = e.key().value(ctx, false); Person p = e.value().value(ctx, false); if (p != null && p.getOrgId() == orgId && k.orgId == orgId) ++cnt; } return cnt; }
/** * @param ignite Ignite. * @param orgId Organization id. * @return Count of found Person object with specified orgId * @throws Exception If failed. */ private static int getOrganizationCountFromPartitionMap(final IgniteEx ignite, int orgId) throws Exception { int part = ignite.affinity(Organization.class.getSimpleName()).partition(orgId); GridCacheAdapter<?, ?> cacheAdapterOrg = ignite.context().cache() .internalCache(Organization.class.getSimpleName()); GridDhtLocalPartition pOrgs = cacheAdapterOrg.context().topology() .localPartition(part, AffinityTopologyVersion.NONE, false); int cnt = 0; GridCursor<? extends CacheDataRow> c = pOrgs.dataStore().cursor(); CacheObjectContext ctx = cacheAdapterOrg.context().cacheObjectContext(); while (c.next()) { CacheDataRow e = c.get(); Integer k = e.key().value(ctx, false); Organization org = e.value().value(ctx, false); if (org != null && org.getId() == orgId) ++cnt; } return cnt; }
/** * Check versions presence in index tree. * * @param srv Node. * @param afterRebuild Whether index rebuild has occurred. * @throws IgniteCheckedException if failed. */ @SuppressWarnings({"ConstantConditions", "unchecked"}) protected void checkDataState(IgniteEx srv, boolean afterRebuild) throws IgniteCheckedException { IgniteInternalCache icache = srv.cachex(CACHE_NAME); IgniteCache cache = srv.cache(CACHE_NAME); assertNotNull(icache); for (IgniteCacheOffheapManager.CacheDataStore store : icache.context().offheap().cacheDataStores()) { GridCursor<? extends CacheDataRow> cur = store.cursor(); while (cur.next()) { CacheDataRow row = cur.get(); int key = row.key().value(icache.context().cacheObjectContext(), false); if (!afterRebuild || key <= AMOUNT / 2) assertEquals(key, cache.get(key)); else assertEquals(-1, cache.get(key)); } } }