/** * @param c Cursor. * @return Number of elements. * @throws IgniteCheckedException If failed. */ private static int size(GridCursor<?> c) throws IgniteCheckedException { int cnt = 0; while(c.next()) cnt++; return cnt; }
/** {@inheritDoc} */ @Override public Row get() { try { return cursor.get(); } catch (IgniteCheckedException e) { throw DbException.convert(e); } }
/** * @throws IgniteCheckedException If failed. */ @Test public void testEmptyCursors() throws IgniteCheckedException { MAX_PER_PAGE = 5; TestTree tree = createTestTree(true); assertFalse(tree.find(null, null).next()); assertFalse(tree.find(0L, 1L).next()); tree.put(1L); tree.put(2L); tree.put(3L); assertEquals(3, size(tree.find(null, null))); assertFalse(tree.find(4L, null).next()); assertFalse(tree.find(null, 0L).next()); assertNoLocks(); }
/** {@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; }
assertFalse(tree.find(null, null).next()); assertEquals(0, tree.size()); assertEquals(0, tree.rootLevel());
/** {@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); } }
/** * 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 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); } }
/** * @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; }
/** {@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); } }
/** * @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 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); }