use of org.apache.ignite.internal.util.GridCloseableIteratorAdapter in project ignite by apache.
the class IgniteCacheOffheapManagerImpl method keysIterator.
/** {@inheritDoc} */
@Override
public GridCloseableIterator<KeyCacheObject> keysIterator(final int part) throws IgniteCheckedException {
CacheDataStore data = partitionData(part);
if (data == null)
return new GridEmptyCloseableIterator<>();
final GridCursor<? extends CacheDataRow> cur = data.cursor();
return new GridCloseableIteratorAdapter<KeyCacheObject>() {
/** */
private KeyCacheObject next;
@Override
protected KeyCacheObject onNext() {
KeyCacheObject res = next;
next = null;
return res;
}
@Override
protected boolean onHasNext() throws IgniteCheckedException {
if (next != null)
return true;
if (cur.next()) {
CacheDataRow row = cur.get();
next = row.key();
}
return next != null;
}
};
}
use of org.apache.ignite.internal.util.GridCloseableIteratorAdapter in project ignite by apache.
the class IgniteCacheOffheapManagerImpl method rowsIterator.
/**
* @param primary Primary entries flag.
* @param backups Backup entries flag.
* @param topVer Topology version.
* @return Iterator.
*/
private GridIterator<CacheDataRow> rowsIterator(boolean primary, boolean backups, AffinityTopologyVersion topVer) {
final Iterator<CacheDataStore> dataIt = cacheData(primary, backups, topVer);
return new GridCloseableIteratorAdapter<CacheDataRow>() {
/** */
private GridCursor<? extends CacheDataRow> cur;
/** */
private int curPart;
/** */
private CacheDataRow next;
@Override
protected CacheDataRow onNext() {
CacheDataRow res = next;
next = null;
return res;
}
@Override
protected boolean onHasNext() throws IgniteCheckedException {
if (next != null)
return true;
while (true) {
if (cur == null) {
if (dataIt.hasNext()) {
CacheDataStore ds = dataIt.next();
curPart = ds.partId();
cur = ds.cursor();
} else
break;
}
if (cur.next()) {
next = cur.get();
next.key().partition(curPart);
break;
} else
cur = null;
}
return next != null;
}
};
}
use of org.apache.ignite.internal.util.GridCloseableIteratorAdapter in project ignite by apache.
the class IgniteCacheOffheapManagerImpl method iterator.
/**
* @param cacheId Cache ID.
* @param dataIt Data store iterator.
* @param mvccSnapshot Mvcc snapshot.
* @param dataPageScanEnabled Flag to enable data page scan.
* @return Rows iterator
*/
private GridCloseableIterator<CacheDataRow> iterator(int cacheId, Iterator<CacheDataStore> dataIt, MvccSnapshot mvccSnapshot, Boolean dataPageScanEnabled) {
return new GridCloseableIteratorAdapter<CacheDataRow>() {
/**
*/
private GridCursor<? extends CacheDataRow> cur;
/**
*/
private int curPart;
/**
*/
private CacheDataRow next;
@Override
protected CacheDataRow onNext() {
CacheDataRow res = next;
next = null;
return res;
}
@Override
protected boolean onHasNext() throws IgniteCheckedException {
if (next != null)
return true;
while (true) {
try {
if (cur == null) {
if (dataIt.hasNext()) {
CacheDataStore ds = dataIt.next();
curPart = ds.partId();
// Data page scan is disabled by default for scan queries.
// TODO https://issues.apache.org/jira/browse/IGNITE-11998
CacheDataTree.setDataPageScanEnabled(false);
try {
if (mvccSnapshot == null)
cur = cacheId == CU.UNDEFINED_CACHE_ID ? ds.cursor() : ds.cursor(cacheId);
else {
cur = cacheId == CU.UNDEFINED_CACHE_ID ? ds.cursor(mvccSnapshot) : ds.cursor(cacheId, mvccSnapshot);
}
} finally {
CacheDataTree.setDataPageScanEnabled(false);
}
} else
break;
}
if (cur.next()) {
next = cur.get();
next.key().partition(curPart);
break;
} else
cur = null;
} catch (IgniteCheckedException ex) {
throw new IgniteCheckedException("Failed to get next data row due to underlying cursor " + "invalidation", ex);
}
}
return next != null;
}
};
}
use of org.apache.ignite.internal.util.GridCloseableIteratorAdapter in project ignite by apache.
the class GridUnsafeMap method iterator.
/**
* {@inheritDoc}
*/
@Override
public <T> GridCloseableIterator<T> iterator(final CX2<T2<Long, Integer>, T2<Long, Integer>, T> c) {
return new GridCloseableIteratorAdapter<T>() {
private GridCloseableIterator<T> curIt;
private int idx;
{
try {
advance();
} catch (IgniteCheckedException e) {
// Should never happen.
e.printStackTrace();
}
}
private void advance() throws IgniteCheckedException {
curIt = null;
while (idx < segs.length) {
curIt = segs[idx++].iterator(c);
if (curIt.hasNext())
return;
else
curIt.close();
}
curIt = null;
}
@Override
protected T onNext() throws IgniteCheckedException {
if (curIt == null)
throw new NoSuchElementException();
T t = curIt.next();
if (!curIt.hasNext()) {
curIt.close();
advance();
}
return t;
}
@Override
protected boolean onHasNext() {
return curIt != null;
}
@Override
protected void onRemove() {
throw new UnsupportedOperationException();
}
@Override
protected void onClose() throws IgniteCheckedException {
if (curIt != null)
curIt.close();
}
};
}
use of org.apache.ignite.internal.util.GridCloseableIteratorAdapter in project ignite by apache.
the class GridUnsafeMap method iterator.
/**
* {@inheritDoc}
*/
@Override
public GridCloseableIterator<IgniteBiTuple<byte[], byte[]>> iterator() {
return new GridCloseableIteratorAdapter<IgniteBiTuple<byte[], byte[]>>() {
private GridCloseableIterator<IgniteBiTuple<byte[], byte[]>> curIt;
private int idx;
{
try {
advance();
} catch (IgniteCheckedException e) {
// Should never happen.
e.printStackTrace();
}
}
private void advance() throws IgniteCheckedException {
curIt = null;
while (idx < segs.length) {
curIt = segs[idx++].iterator();
if (curIt.hasNext())
return;
else
curIt.close();
}
curIt = null;
}
@Override
protected IgniteBiTuple<byte[], byte[]> onNext() throws IgniteCheckedException {
if (curIt == null)
throw new NoSuchElementException();
IgniteBiTuple<byte[], byte[]> t = curIt.next();
if (!curIt.hasNext()) {
curIt.close();
advance();
}
return t;
}
@Override
protected boolean onHasNext() {
return curIt != null;
}
@Override
protected void onRemove() {
throw new UnsupportedOperationException();
}
@Override
protected void onClose() throws IgniteCheckedException {
if (curIt != null)
curIt.close();
}
};
}
Aggregations