Search in sources :

Example 31 with CacheObject

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

the class GridDhtCacheAdapter method loadEntry.

/**
 * @param key Key.
 * @param val Value.
 * @param ver Cache version.
 * @param p Optional predicate.
 * @param topVer Topology version.
 * @param replicate Replication flag.
 * @param plc Expiry policy.
 */
private void loadEntry(KeyCacheObject key, Object val, GridCacheVersion ver, @Nullable IgniteBiPredicate<K, V> p, AffinityTopologyVersion topVer, boolean replicate, @Nullable ExpiryPolicy plc) {
    if (p != null && !p.apply(key.<K>value(ctx.cacheObjectContext(), false), (V) val))
        return;
    try {
        GridDhtLocalPartition part = ctx.group().topology().localPartition(ctx.affinity().partition(key), AffinityTopologyVersion.NONE, true);
        // Reserve to make sure that partition does not get unloaded.
        if (part.reserve()) {
            GridCacheEntryEx entry = null;
            ctx.shared().database().checkpointReadLock();
            try {
                long ttl = CU.ttlForLoad(plc);
                if (ttl == CU.TTL_ZERO)
                    return;
                CacheObject cacheVal = ctx.toCacheObject(val);
                entry = entryEx(key);
                entry.initialValue(cacheVal, ver, ttl, CU.EXPIRE_TIME_CALCULATE, false, topVer, replicate ? DR_LOAD : DR_NONE, false);
            } catch (IgniteCheckedException e) {
                throw new IgniteException("Failed to put cache value: " + entry, e);
            } catch (GridCacheEntryRemovedException ignore) {
                if (log.isDebugEnabled())
                    log.debug("Got removed entry during loadCache (will ignore): " + entry);
            } finally {
                if (entry != null)
                    entry.context().evicts().touch(entry, topVer);
                part.release();
                ctx.shared().database().checkpointReadUnlock();
            }
        } else if (log.isDebugEnabled())
            log.debug("Will node load entry into cache (partition is invalid): " + part);
    } catch (GridDhtInvalidPartitionException e) {
        if (log.isDebugEnabled())
            log.debug(S.toString("Ignoring entry for partition that does not belong", "key", key, true, "val", val, true, "err", e, false));
    }
}
Also used : GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 32 with CacheObject

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

the class GridDhtTransactionalCacheAdapter method createLockReply.

/**
 * @param nearNode Near node.
 * @param entries Entries.
 * @param req Lock request.
 * @param tx Transaction.
 * @param mappedVer Mapped version.
 * @param err Error.
 * @return Response.
 */
private GridNearLockResponse createLockReply(ClusterNode nearNode, List<GridCacheEntryEx> entries, GridNearLockRequest req, @Nullable GridDhtTxLocalAdapter tx, GridCacheVersion mappedVer, Throwable err) {
    assert mappedVer != null;
    assert tx == null || tx.xidVersion().equals(mappedVer);
    try {
        // Send reply back to originating near node.
        GridNearLockResponse res = new GridNearLockResponse(ctx.cacheId(), req.version(), req.futureId(), req.miniId(), tx != null && tx.onePhaseCommit(), entries.size(), err, null, ctx.deploymentEnabled());
        if (err == null) {
            res.pending(localDhtPendingVersions(entries, mappedVer));
            // We have to add completed versions for cases when nearLocal and remote transactions
            // execute concurrently.
            IgnitePair<Collection<GridCacheVersion>> versPair = ctx.tm().versions(req.version());
            res.completedVersions(versPair.get1(), versPair.get2());
            int i = 0;
            for (ListIterator<GridCacheEntryEx> it = entries.listIterator(); it.hasNext(); ) {
                GridCacheEntryEx e = it.next();
                assert e != null;
                while (true) {
                    try {
                        // Don't return anything for invalid partitions.
                        if (tx == null || !tx.isRollbackOnly()) {
                            GridCacheVersion dhtVer = req.dhtVersion(i);
                            GridCacheVersion ver = e.version();
                            boolean ret = req.returnValue(i) || dhtVer == null || !dhtVer.equals(ver);
                            CacheObject val = null;
                            if (ret)
                                val = e.innerGet(null, tx, /*read-through*/
                                false, /*update-metrics*/
                                true, /*event notification*/
                                req.returnValue(i), CU.subjectId(tx, ctx.shared()), null, tx != null ? tx.resolveTaskName() : null, null, req.keepBinary());
                            assert e.lockedBy(mappedVer) || (ctx.mvcc().isRemoved(e.context(), mappedVer) && req.timeout() > 0) : "Entry does not own lock for tx [locNodeId=" + ctx.localNodeId() + ", entry=" + e + ", mappedVer=" + mappedVer + ", ver=" + ver + ", tx=" + tx + ", req=" + req + ", err=" + err + ']';
                            boolean filterPassed = false;
                            if (tx != null && tx.onePhaseCommit()) {
                                IgniteTxEntry writeEntry = tx.entry(ctx.txKey(e.key()));
                                assert writeEntry != null : "Missing tx entry for locked cache entry: " + e;
                                filterPassed = writeEntry.filtersPassed();
                            }
                            if (ret && val == null)
                                val = e.valueBytes(null);
                            // We include values into response since they are required for local
                            // calls and won't be serialized. We are also including DHT version.
                            res.addValueBytes(ret ? val : null, filterPassed, ver, mappedVer);
                        } else {
                            // We include values into response since they are required for local
                            // calls and won't be serialized. We are also including DHT version.
                            res.addValueBytes(null, false, e.version(), mappedVer);
                        }
                        break;
                    } catch (GridCacheEntryRemovedException ignore) {
                        if (log.isDebugEnabled())
                            log.debug("Got removed entry when sending reply to DHT lock request " + "(will retry): " + e);
                        e = entryExx(e.key());
                        it.set(e);
                    }
                }
                i++;
            }
        }
        return res;
    } catch (IgniteCheckedException e) {
        U.error(log, "Failed to get value for lock reply message for node [node=" + U.toShortString(nearNode) + ", req=" + req + ']', e);
        return new GridNearLockResponse(ctx.cacheId(), req.version(), req.futureId(), req.miniId(), false, entries.size(), e, null, ctx.deploymentEnabled());
    }
}
Also used : IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Collection(java.util.Collection) GridNearLockResponse(org.apache.ignite.internal.processors.cache.distributed.near.GridNearLockResponse) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 33 with CacheObject

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

the class GridDhtGetSingleFuture method toEntryInfo.

/**
 * @param map Map to convert.
 * @return List of infos.
 */
private GridCacheEntryInfo toEntryInfo(Map<KeyCacheObject, EntryGetResult> map) {
    if (map.isEmpty())
        return null;
    EntryGetResult val = map.get(key);
    assert val != null;
    GridCacheEntryInfo info = new GridCacheEntryInfo();
    info.cacheId(cctx.cacheId());
    info.key(key);
    info.value(skipVals ? null : (CacheObject) val.value());
    info.version(val.version());
    info.expireTime(val.expireTime());
    info.ttl(val.ttl());
    return info;
}
Also used : GridCacheEntryInfo(org.apache.ignite.internal.processors.cache.GridCacheEntryInfo) EntryGetResult(org.apache.ignite.internal.processors.cache.EntryGetResult) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 34 with CacheObject

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

the class GridDhtLockFuture method loadMissingFromStore.

/**
 */
private void loadMissingFromStore() {
    if (!skipStore && (read || cctx.loadPreviousValue()) && cctx.readThrough() && (needReturnVal || read)) {
        final Map<KeyCacheObject, GridDhtCacheEntry> loadMap = new LinkedHashMap<>();
        final GridCacheVersion ver = version();
        for (GridDhtCacheEntry entry : entries) {
            try {
                entry.unswap(false);
                if (!entry.hasValue())
                    loadMap.put(entry.key(), entry);
            } catch (GridCacheEntryRemovedException e) {
                assert false : "Should not get removed exception while holding lock on entry " + "[entry=" + entry + ", e=" + e + ']';
            } catch (IgniteCheckedException e) {
                onDone(e);
                return;
            }
        }
        try {
            cctx.store().loadAll(null, loadMap.keySet(), new CI2<KeyCacheObject, Object>() {

                @Override
                public void apply(KeyCacheObject key, Object val) {
                    // No value loaded from store.
                    if (val == null)
                        return;
                    GridDhtCacheEntry entry0 = loadMap.get(key);
                    try {
                        CacheObject val0 = cctx.toCacheObject(val);
                        long ttl = createTtl;
                        long expireTime;
                        if (ttl == CU.TTL_ZERO)
                            expireTime = CU.expireTimeInPast();
                        else {
                            if (ttl == CU.TTL_NOT_CHANGED)
                                ttl = CU.TTL_ETERNAL;
                            expireTime = CU.toExpireTime(ttl);
                        }
                        entry0.initialValue(val0, ver, ttl, expireTime, false, topVer, GridDrType.DR_LOAD, true);
                    } catch (GridCacheEntryRemovedException e) {
                        assert false : "Should not get removed exception while holding lock on entry " + "[entry=" + entry0 + ", e=" + e + ']';
                    } catch (IgniteCheckedException e) {
                        onDone(e);
                    }
                }
            });
        } catch (IgniteCheckedException e) {
            onDone(e);
        }
    }
}
Also used : GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) LinkedHashMap(java.util.LinkedHashMap)

Example 35 with CacheObject

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

the class UserCacheObjectImpl method prepareForCache.

/**
 * {@inheritDoc}
 */
@Override
public CacheObject prepareForCache(CacheObjectContext ctx) {
    try {
        IgniteCacheObjectProcessor proc = ctx.kernalContext().cacheObjects();
        if (valBytes == null)
            valBytes = proc.marshal(ctx, val);
        if (ctx.storeValue()) {
            boolean p2pEnabled = ctx.kernalContext().config().isPeerClassLoadingEnabled();
            ClassLoader ldr = p2pEnabled ? IgniteUtils.detectClass(this.val).getClassLoader() : val.getClass().getClassLoader();
            Object val = this.val != null && proc.immutable(this.val) ? this.val : proc.unmarshal(ctx, valBytes, ldr);
            return new CacheObjectImpl(val, valBytes);
        }
        return new CacheObjectImpl(null, valBytes);
    } catch (IgniteCheckedException e) {
        throw new IgniteException("Failed to marshal object: " + val, e);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) CacheObjectImpl(org.apache.ignite.internal.processors.cache.CacheObjectImpl)

Aggregations

CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)96 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)86 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)46 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)44 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)38 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)26 CacheLockCandidates (org.apache.ignite.internal.processors.cache.CacheLockCandidates)17 GridCacheMvcc (org.apache.ignite.internal.processors.cache.GridCacheMvcc)17 ArrayList (java.util.ArrayList)15 EntryGetResult (org.apache.ignite.internal.processors.cache.EntryGetResult)15 GridCacheOperation (org.apache.ignite.internal.processors.cache.GridCacheOperation)15 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)13 Nullable (org.jetbrains.annotations.Nullable)13 UUID (java.util.UUID)11 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)11 GridCacheMvccCandidate (org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate)11 GridTimeoutObject (org.apache.ignite.internal.processors.timeout.GridTimeoutObject)11 IgniteException (org.apache.ignite.IgniteException)10 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)10 LinkedHashMap (java.util.LinkedHashMap)9