Search in sources :

Example 51 with CacheDataRow

use of org.apache.ignite.internal.processors.cache.persistence.CacheDataRow in project ignite by apache.

the class IgniteCacheOffheapManagerImpl method mvccRead.

/**
 * {@inheritDoc}
 */
@Nullable
@Override
public CacheDataRow mvccRead(GridCacheContext cctx, KeyCacheObject key, MvccSnapshot mvccSnapshot) throws IgniteCheckedException {
    assert mvccSnapshot != null;
    CacheDataStore dataStore = dataStore(cctx, key);
    CacheDataRow row = dataStore != null ? dataStore.mvccFind(cctx, key, mvccSnapshot) : null;
    assert row == null || row.value() != null : row;
    return row;
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) Nullable(org.jetbrains.annotations.Nullable)

Example 52 with CacheDataRow

use of org.apache.ignite.internal.processors.cache.persistence.CacheDataRow in project ignite by apache.

the class IgniteCacheOffheapManagerImpl method rebalanceIterator.

/**
 * {@inheritDoc}
 */
@Override
public IgniteRebalanceIterator rebalanceIterator(IgniteDhtDemandedPartitionsMap parts, AffinityTopologyVersion topVer) throws IgniteCheckedException {
    TreeMap<Integer, GridCloseableIterator<CacheDataRow>> iterators = new TreeMap<>();
    Set<Integer> missing = new HashSet<>();
    for (Integer p : parts.fullSet()) {
        GridCloseableIterator<CacheDataRow> partIter = reservedIterator(p, topVer);
        if (partIter == null) {
            missing.add(p);
            continue;
        }
        iterators.put(p, partIter);
    }
    IgniteHistoricalIterator historicalIterator = historicalIterator(parts.historicalMap(), missing);
    IgniteRebalanceIterator iter = new IgniteRebalanceIteratorImpl(iterators, historicalIterator);
    for (Integer p : missing) iter.setPartitionMissing(p);
    return iter;
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) GridCloseableIterator(org.apache.ignite.internal.util.lang.GridCloseableIterator) IgniteHistoricalIterator(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.IgniteHistoricalIterator) IgniteRebalanceIteratorImpl(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.IgniteRebalanceIteratorImpl) TreeMap(java.util.TreeMap) HashSet(java.util.HashSet)

Example 53 with CacheDataRow

use of org.apache.ignite.internal.processors.cache.persistence.CacheDataRow in project ignite by apache.

the class IgniteCacheOffheapManagerImpl method cacheKeysIterator.

/**
 * {@inheritDoc}
 */
@Override
public GridCloseableIterator<KeyCacheObject> cacheKeysIterator(int cacheId, int part) throws IgniteCheckedException {
    CacheDataStore data = dataStore(part, true);
    if (data == null)
        return new GridEmptyCloseableIterator<>();
    GridCursor<? extends CacheDataRow> cur = data.cursor(cacheId, null, null, CacheDataRowAdapter.RowData.KEY_ONLY);
    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.persistence.CacheDataRow) GridCloseableIteratorAdapter(org.apache.ignite.internal.util.GridCloseableIteratorAdapter)

Example 54 with CacheDataRow

use of org.apache.ignite.internal.processors.cache.persistence.CacheDataRow in project ignite by apache.

the class IgniteCacheOffheapManagerImpl method cacheEntriesIterator.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public <K, V> GridCloseableIterator<Cache.Entry<K, V>> cacheEntriesIterator(GridCacheContext cctx, boolean primary, boolean backup, AffinityTopologyVersion topVer, boolean keepBinary, @Nullable MvccSnapshot mvccSnapshot, Boolean dataPageScanEnabled) {
    Iterator<CacheDataRow> it = cacheIterator(cctx.cacheId(), primary, backup, topVer, mvccSnapshot, dataPageScanEnabled);
    return new GridCloseableIteratorAdapter<Cache.Entry<K, V>>() {

        /**
         */
        private CacheEntryImplEx next;

        @Override
        protected Cache.Entry<K, V> onNext() {
            CacheEntryImplEx ret = next;
            next = null;
            return ret;
        }

        @Override
        protected boolean onHasNext() {
            if (next != null)
                return true;
            CacheDataRow nextRow = null;
            if (it.hasNext())
                nextRow = it.next();
            if (nextRow != null) {
                KeyCacheObject key = nextRow.key();
                CacheObject val = nextRow.value();
                Object key0 = cctx.unwrapBinaryIfNeeded(key, keepBinary, false, null);
                Object val0 = cctx.unwrapBinaryIfNeeded(val, keepBinary, false, null);
                next = new CacheEntryImplEx(key0, val0, nextRow.version());
                return true;
            }
            return false;
        }
    };
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) GridCloseableIteratorAdapter(org.apache.ignite.internal.util.GridCloseableIteratorAdapter) MVCC_OP_COUNTER_MASK(org.apache.ignite.internal.processors.cache.mvcc.MvccUtils.MVCC_OP_COUNTER_MASK) Cache(javax.cache.Cache)

Example 55 with CacheDataRow

use of org.apache.ignite.internal.processors.cache.persistence.CacheDataRow in project ignite by apache.

the class IgniteCacheOffheapManagerImpl method evictionSafeIterator.

/**
 * @param cacheId Cache ID.
 * @param dataIt Data store iterator.
 * @return Rows iterator
 */
private GridCloseableIterator<CacheDataRow> evictionSafeIterator(int cacheId, Iterator<CacheDataStore> dataIt) {
    return new GridCloseableIteratorAdapter<CacheDataRow>() {

        /**
         */
        private GridCursor<? extends CacheDataRow> cur;

        /**
         */
        private GridDhtLocalPartition 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();
                        if (!reservePartition(ds.partId()))
                            continue;
                        cur = cacheId == CU.UNDEFINED_CACHE_ID ? ds.cursor() : ds.cursor(cacheId);
                    } else
                        break;
                }
                if (cur.next()) {
                    next = cur.get();
                    next.key().partition(curPart.id());
                    break;
                } else {
                    cur = null;
                    releaseCurrentPartition();
                }
            }
            return next != null;
        }

        /**
         */
        private void releaseCurrentPartition() {
            GridDhtLocalPartition p = curPart;
            assert p != null;
            curPart = null;
            p.release();
        }

        /**
         * @param partId Partition number.
         * @return {@code True} if partition was reserved.
         */
        private boolean reservePartition(int partId) {
            GridDhtLocalPartition p = grp.topology().localPartition(partId);
            if (p != null && p.reserve()) {
                curPart = p;
                return true;
            }
            return false;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        protected void onClose() throws IgniteCheckedException {
            if (curPart != null)
                releaseCurrentPartition();
        }
    };
}
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) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)

Aggregations

CacheDataRow (org.apache.ignite.internal.processors.cache.persistence.CacheDataRow)78 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)35 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)20 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)16 ArrayList (java.util.ArrayList)14 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)14 IgniteException (org.apache.ignite.IgniteException)14 Nullable (org.jetbrains.annotations.Nullable)12 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)11 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)11 GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)11 HashMap (java.util.HashMap)10 IgniteEx (org.apache.ignite.internal.IgniteEx)10 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)10 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)10 HashSet (java.util.HashSet)9 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)9 EntryGetResult (org.apache.ignite.internal.processors.cache.EntryGetResult)8 GridCursor (org.apache.ignite.internal.util.lang.GridCursor)8 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)7