Search in sources :

Example 11 with CacheDataRow

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

the class SchemaIndexCacheVisitorImpl method processPartition.

/**
     * Process partition.
     *
     * @param part Partition.
     * @param clo Index closure.
     * @throws IgniteCheckedException If failed.
     */
private void processPartition(GridDhtLocalPartition part, FilteringVisitorClosure clo) throws IgniteCheckedException {
    checkCancelled();
    boolean reserved = false;
    if (part != null && part.state() != EVICTED)
        reserved = (part.state() == OWNING || part.state() == RENTING) && part.reserve();
    if (!reserved)
        return;
    try {
        GridCursor<? extends CacheDataRow> cursor = part.dataStore().cursor();
        while (cursor.next()) {
            CacheDataRow row = cursor.get();
            KeyCacheObject key = row.key();
            processKey(key, row.link(), clo);
        }
    } finally {
        part.release();
    }
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.database.CacheDataRow) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 12 with CacheDataRow

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

the class H2PkHashIndex method find.

/** {@inheritDoc} */
@Override
public Cursor find(Session ses, final SearchRow lower, final SearchRow upper) {
    IndexingQueryFilter f = threadLocalFilter();
    IgniteBiPredicate<Object, Object> p = null;
    if (f != null) {
        String cacheName = getTable().cacheName();
        p = f.forCache(cacheName);
    }
    KeyCacheObject lowerObj = null;
    KeyCacheObject upperObj = null;
    if (lower != null)
        lowerObj = cctx.toCacheKeyObject(lower.getValue(0).getObject());
    if (upper != null)
        upperObj = cctx.toCacheKeyObject(upper.getValue(0).getObject());
    try {
        List<GridCursor<? extends CacheDataRow>> cursors = new ArrayList<>();
        for (IgniteCacheOffheapManager.CacheDataStore store : cctx.offheap().cacheDataStores()) cursors.add(store.cursor(lowerObj, upperObj));
        return new H2Cursor(new CompositeGridCursor<>(cursors.iterator()), p);
    } catch (IgniteCheckedException e) {
        throw DbException.convert(e);
    }
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.database.CacheDataRow) GridCursor(org.apache.ignite.internal.util.lang.GridCursor) IndexingQueryFilter(org.apache.ignite.spi.indexing.IndexingQueryFilter) ArrayList(java.util.ArrayList) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteCacheOffheapManager(org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 13 with CacheDataRow

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

the class IgniteH2Indexing method rebuildIndexesFromHash.

/** {@inheritDoc} */
@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
@Override
public void rebuildIndexesFromHash(GridCacheContext cctx, String schemaName, String typeName) throws IgniteCheckedException {
    H2TableDescriptor tbl = tableDescriptor(schemaName, typeName);
    if (tbl == null)
        return;
    assert tbl.table() != null;
    assert tbl.table().rebuildFromHashInProgress();
    H2PkHashIndex hashIdx = tbl.primaryKeyHashIndex();
    Cursor cursor = hashIdx.find((Session) null, null, null);
    while (cursor.next()) {
        CacheDataRow dataRow = (CacheDataRow) cursor.get();
        boolean done = false;
        while (!done) {
            GridCacheEntryEx entry = cctx.cache().entryEx(dataRow.key());
            try {
                synchronized (entry) {
                    // TODO : How to correctly get current value and link here?
                    GridH2Row row = tbl.table().rowDescriptor().createRow(entry.key(), entry.partition(), dataRow.value(), entry.version(), entry.expireTime());
                    row.link(dataRow.link());
                    List<Index> indexes = tbl.table().getAllIndexes();
                    for (int i = 2; i < indexes.size(); i++) {
                        Index idx = indexes.get(i);
                        if (idx instanceof H2TreeIndex)
                            ((H2TreeIndex) idx).put(row);
                    }
                    done = true;
                }
            } catch (GridCacheEntryRemovedException e) {
            // No-op
            }
        }
    }
    tbl.table().markRebuildFromHashInProgress(false);
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.database.CacheDataRow) H2TreeIndex(org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridH2Row(org.apache.ignite.internal.processors.query.h2.opt.GridH2Row) Index(org.h2.index.Index) H2TreeIndex(org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex) H2PkHashIndex(org.apache.ignite.internal.processors.query.h2.database.H2PkHashIndex) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) H2PkHashIndex(org.apache.ignite.internal.processors.query.h2.database.H2PkHashIndex) QueryCursor(org.apache.ignite.cache.query.QueryCursor) Cursor(org.h2.index.Cursor) FieldsQueryCursor(org.apache.ignite.cache.query.FieldsQueryCursor)

Example 14 with CacheDataRow

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

the class GridDhtLocalPartition method clearAll.

/**
     * Clears values for this partition.
     *
     * @throws NodeStoppingException If node stopping.
     */
public void clearAll() throws NodeStoppingException {
    GridCacheVersion clearVer = cctx.versions().next();
    boolean rec = cctx.events().isRecordable(EVT_CACHE_REBALANCE_OBJECT_UNLOADED);
    Iterator<GridCacheMapEntry> it = allEntries().iterator();
    GridCacheObsoleteEntryExtras extras = new GridCacheObsoleteEntryExtras(clearVer);
    while (it.hasNext()) {
        GridCacheMapEntry cached = null;
        cctx.shared().database().checkpointReadLock();
        try {
            cached = it.next();
            if (cached instanceof GridDhtCacheEntry && ((GridDhtCacheEntry) cached).clearInternal(clearVer, extras)) {
                removeEntry(cached);
                if (!cached.isInternal()) {
                    if (rec) {
                        cctx.events().addEvent(cached.partition(), cached.key(), cctx.localNodeId(), (IgniteUuid) null, null, EVT_CACHE_REBALANCE_OBJECT_UNLOADED, null, false, cached.rawGet(), cached.hasValue(), null, null, null, false);
                    }
                }
            }
        } catch (GridDhtInvalidPartitionException e) {
            assert isEmpty() && state() == EVICTED : "Invalid error [e=" + e + ", part=" + this + ']';
            // Partition is already concurrently cleared and evicted.
            break;
        } catch (NodeStoppingException e) {
            if (log.isDebugEnabled())
                log.debug("Failed to clear cache entry for evicted partition: " + cached.partition());
            rent.onDone(e);
            throw e;
        } catch (IgniteCheckedException e) {
            U.error(log, "Failed to clear cache entry for evicted partition: " + cached, e);
        } finally {
            cctx.shared().database().checkpointReadUnlock();
        }
    }
    if (!cctx.allowFastEviction()) {
        try {
            GridIterator<CacheDataRow> it0 = cctx.offheap().iterator(id);
            while (it0.hasNext()) {
                cctx.shared().database().checkpointReadLock();
                try {
                    CacheDataRow row = it0.next();
                    GridCacheMapEntry cached = putEntryIfObsoleteOrAbsent(cctx.affinity().affinityTopologyVersion(), row.key(), true, false);
                    if (cached instanceof GridDhtCacheEntry && ((GridDhtCacheEntry) cached).clearInternal(clearVer, extras)) {
                        if (rec) {
                            cctx.events().addEvent(cached.partition(), cached.key(), cctx.localNodeId(), (IgniteUuid) null, null, EVT_CACHE_REBALANCE_OBJECT_UNLOADED, null, false, cached.rawGet(), cached.hasValue(), null, null, null, false);
                        }
                    }
                } catch (GridDhtInvalidPartitionException e) {
                    assert isEmpty() && state() == EVICTED : "Invalid error [e=" + e + ", part=" + this + ']';
                    // Partition is already concurrently cleared and evicted.
                    break;
                } finally {
                    cctx.shared().database().checkpointReadUnlock();
                }
            }
        } catch (NodeStoppingException e) {
            if (log.isDebugEnabled())
                log.debug("Failed to get iterator for evicted partition: " + id);
            rent.onDone(e);
            throw e;
        } catch (IgniteCheckedException e) {
            U.error(log, "Failed to get iterator for evicted partition: " + id, e);
        }
    }
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.database.CacheDataRow) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) GridCacheObsoleteEntryExtras(org.apache.ignite.internal.processors.cache.extras.GridCacheObsoleteEntryExtras) GridCacheMapEntry(org.apache.ignite.internal.processors.cache.GridCacheMapEntry)

Example 15 with CacheDataRow

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

the class GridPartitionedSingleGetFuture method localGet.

/**
     * @param topVer Topology version.
     * @param part Partition.
     * @return {@code True} if future completed.
     */
private boolean localGet(AffinityTopologyVersion topVer, int part) {
    assert cctx.affinityNode() : this;
    GridDhtCacheAdapter colocated = cctx.dht();
    boolean readNoEntry = cctx.readNoEntry(expiryPlc, false);
    boolean evt = !skipVals;
    while (true) {
        try {
            CacheObject v = null;
            GridCacheVersion ver = null;
            boolean skipEntry = readNoEntry;
            if (readNoEntry) {
                CacheDataRow row = cctx.offheap().read(key);
                if (row != null) {
                    long expireTime = row.expireTime();
                    if (expireTime == 0 || expireTime > U.currentTimeMillis()) {
                        v = row.value();
                        if (needVer)
                            ver = row.version();
                        if (evt) {
                            cctx.events().readEvent(key, null, row.value(), subjId, taskName, !deserializeBinary);
                        }
                    } else
                        skipEntry = false;
                }
            }
            if (!skipEntry) {
                GridCacheEntryEx entry = colocated.entryEx(key);
                // If our DHT cache do has value, then we peek it.
                if (entry != null) {
                    boolean isNew = entry.isNewLocked();
                    if (needVer) {
                        EntryGetResult res = entry.innerGetVersioned(null, null, /*update-metrics*/
                        false, /*event*/
                        evt, subjId, null, taskName, expiryPlc, true, null);
                        if (res != null) {
                            v = res.value();
                            ver = res.version();
                        }
                    } else {
                        v = entry.innerGet(null, null, /*read-through*/
                        false, /*update-metrics*/
                        false, /*event*/
                        evt, subjId, null, taskName, expiryPlc, true);
                    }
                    colocated.context().evicts().touch(entry, topVer);
                    // Entry was not in memory or in swap, so we remove it from cache.
                    if (v == null) {
                        if (isNew && entry.markObsoleteIfEmpty(ver))
                            colocated.removeEntry(entry);
                    }
                }
            }
            if (v != null) {
                if (!skipVals && cctx.config().isStatisticsEnabled())
                    cctx.cache().metrics0().onRead(true);
                if (!skipVals)
                    setResult(v, ver);
                else
                    setSkipValueResult(true, ver);
                return true;
            }
            boolean topStable = cctx.isReplicated() || topVer.equals(cctx.topology().topologyVersion());
            // Entry not found, complete future with null result if topology did not change and there is no store.
            if (!cctx.readThroughConfigured() && (topStable || partitionOwned(part))) {
                if (!skipVals && cctx.config().isStatisticsEnabled())
                    colocated.metrics0().onRead(false);
                if (skipVals)
                    setSkipValueResult(false, null);
                else
                    setResult(null, null);
                return true;
            }
            return false;
        } catch (GridCacheEntryRemovedException ignored) {
        // No-op, will retry.
        } catch (GridDhtInvalidPartitionException ignored) {
            return false;
        } catch (IgniteCheckedException e) {
            onDone(e);
            return true;
        }
    }
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.database.CacheDataRow) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) EntryGetResult(org.apache.ignite.internal.processors.cache.EntryGetResult) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Aggregations

CacheDataRow (org.apache.ignite.internal.processors.cache.database.CacheDataRow)24 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)13 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)9 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)7 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)6 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)6 UUID (java.util.UUID)5 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)5 EntryGetResult (org.apache.ignite.internal.processors.cache.EntryGetResult)5 GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition)5 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)4 GridDhtInvalidPartitionException (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException)4 GridCloseableIteratorAdapter (org.apache.ignite.internal.util.GridCloseableIteratorAdapter)4 IgniteException (org.apache.ignite.IgniteException)3 IgniteCacheExpiryPolicy (org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy)3 GridFinishedFuture (org.apache.ignite.internal.util.future.GridFinishedFuture)3 NoSuchElementException (java.util.NoSuchElementException)2 EntryProcessor (javax.cache.processor.EntryProcessor)2 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 StorageException (org.apache.ignite.internal.pagemem.wal.StorageException)2