Search in sources :

Example 1 with GridCloseableIteratorAdapter

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;
        }
    };
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.database.CacheDataRow) GridCloseableIteratorAdapter(org.apache.ignite.internal.util.GridCloseableIteratorAdapter)

Example 2 with GridCloseableIteratorAdapter

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;
        }
    };
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.database.CacheDataRow) GridCursor(org.apache.ignite.internal.util.lang.GridCursor) GridCloseableIteratorAdapter(org.apache.ignite.internal.util.GridCloseableIteratorAdapter)

Example 3 with GridCloseableIteratorAdapter

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;
        }
    };
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) GridCursor(org.apache.ignite.internal.util.lang.GridCursor) GridCloseableIteratorAdapter(org.apache.ignite.internal.util.GridCloseableIteratorAdapter) IgniteCheckedException(org.apache.ignite.IgniteCheckedException)

Example 4 with GridCloseableIteratorAdapter

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();
        }
    };
}
Also used : GridCloseableIteratorAdapter(org.apache.ignite.internal.util.GridCloseableIteratorAdapter) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCloseableIterator(org.apache.ignite.internal.util.lang.GridCloseableIterator) NoSuchElementException(java.util.NoSuchElementException)

Example 5 with GridCloseableIteratorAdapter

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();
        }
    };
}
Also used : GridCloseableIteratorAdapter(org.apache.ignite.internal.util.GridCloseableIteratorAdapter) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCloseableIterator(org.apache.ignite.internal.util.lang.GridCloseableIterator) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

GridCloseableIteratorAdapter (org.apache.ignite.internal.util.GridCloseableIteratorAdapter)16 CacheDataRow (org.apache.ignite.internal.processors.cache.persistence.CacheDataRow)8 GridCursor (org.apache.ignite.internal.util.lang.GridCursor)5 NoSuchElementException (java.util.NoSuchElementException)4 CacheDataRow (org.apache.ignite.internal.processors.cache.database.CacheDataRow)4 GridCloseableIterator (org.apache.ignite.internal.util.lang.GridCloseableIterator)4 Cache (javax.cache.Cache)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)2 IgniteUuid (org.apache.ignite.lang.IgniteUuid)2 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1