Search in sources :

Example 41 with ExpiryPolicy

use of javax.cache.expiry.ExpiryPolicy in project ignite by apache.

the class GridCacheAdapter method localLoad.

/**
 * @param keys Keys to load.
 * @param plc Optional expiry policy.
 * @throws IgniteCheckedException If failed.
 */
public void localLoad(Collection<? extends K> keys, @Nullable ExpiryPolicy plc, final boolean keepBinary) throws IgniteCheckedException {
    final boolean replicate = ctx.isDrEnabled();
    final AffinityTopologyVersion topVer = ctx.affinity().affinityTopologyVersion();
    final ExpiryPolicy plc0 = plc != null ? plc : ctx.expiry();
    Collection<KeyCacheObject> keys0 = ctx.cacheKeysView(keys);
    if (ctx.store().isLocal()) {
        DataStreamerImpl ldr = ctx.kernalContext().dataStream().dataStreamer(ctx.name());
        try {
            ldr.skipStore(true);
            ldr.keepBinary(keepBinary);
            ldr.receiver(new IgniteDrDataStreamerCacheUpdater());
            LocalStoreLoadClosure c = new LocalStoreLoadClosure(null, ldr, plc0);
            ctx.store().localStoreLoadAll(null, keys0, c);
            c.onDone();
        } finally {
            ldr.closeEx(false);
        }
    } else {
        // Version for all loaded entries.
        final GridCacheVersion ver0 = ctx.versions().nextForLoad();
        ctx.store().loadAll(null, keys0, new CI2<KeyCacheObject, Object>() {

            @Override
            public void apply(KeyCacheObject key, Object val) {
                long ttl = CU.ttlForLoad(plc0);
                if (ttl == CU.TTL_ZERO)
                    return;
                loadEntry(key, val, ver0, null, topVer, replicate, ttl);
            }
        });
    }
}
Also used : IgniteDrDataStreamerCacheUpdater(org.apache.ignite.internal.processors.dr.IgniteDrDataStreamerCacheUpdater) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) IgniteExternalizableExpiryPolicy(org.apache.ignite.internal.processors.cache.distributed.IgniteExternalizableExpiryPolicy) DataStreamerImpl(org.apache.ignite.internal.processors.datastreamer.DataStreamerImpl)

Example 42 with ExpiryPolicy

use of javax.cache.expiry.ExpiryPolicy in project ignite by apache.

the class GridCacheAdapter method globalLoadCacheAsync.

/**
 * @param p Predicate.
 * @param args Arguments.
 * @return Load cache future.
 * @throws IgniteCheckedException If failed.
 */
IgniteInternalFuture<?> globalLoadCacheAsync(@Nullable IgniteBiPredicate<K, V> p, @Nullable Object... args) throws IgniteCheckedException {
    ctx.kernalContext().task().setThreadContext(TC_NO_FAILOVER, true);
    CacheOperationContext opCtx = ctx.operationContextPerCall();
    ExpiryPolicy plc = opCtx != null ? opCtx.expiry() : null;
    Collection<ClusterNode> nodes = ctx.kernalContext().grid().cluster().forDataNodes(ctx.name()).nodes();
    assert !F.isEmpty(nodes) : "There are not datanodes fo cache: " + ctx.name();
    final boolean keepBinary = opCtx != null && opCtx.isKeepBinary();
    ComputeTaskInternalFuture fut = ctx.kernalContext().closure().callAsync(BROADCAST, Collections.singletonList(new LoadCacheJobV2<>(ctx.name(), ctx.affinity().affinityTopologyVersion(), p, args, plc, keepBinary)), nodes);
    return fut;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) ComputeTaskInternalFuture(org.apache.ignite.internal.ComputeTaskInternalFuture) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) IgniteExternalizableExpiryPolicy(org.apache.ignite.internal.processors.cache.distributed.IgniteExternalizableExpiryPolicy)

Example 43 with ExpiryPolicy

use of javax.cache.expiry.ExpiryPolicy in project ignite by apache.

the class GridDhtTxPrepareFuture method map.

/**
 * @param entry Transaction entry.
 */
private void map(IgniteTxEntry entry) {
    if (entry.cached().isLocal())
        return;
    GridDhtCacheEntry cached = (GridDhtCacheEntry) entry.cached();
    GridCacheContext cacheCtx = entry.context();
    GridDhtCacheAdapter<?, ?> dht = cacheCtx.isNear() ? cacheCtx.near().dht() : cacheCtx.dht();
    ExpiryPolicy expiry = cacheCtx.expiryForTxEntry(entry);
    if (expiry != null && (entry.op() == READ || entry.op() == NOOP)) {
        entry.op(NOOP);
        entry.ttl(CU.toTtl(expiry.getExpiryForAccess()));
    }
    while (true) {
        try {
            List<ClusterNode> dhtNodes = dht.topology().nodes(cached.partition(), tx.topologyVersion());
            assert !dhtNodes.isEmpty() && dhtNodes.get(0).id().equals(cctx.localNodeId()) : "localNode = " + cctx.localNodeId() + ", dhtNodes = " + dhtNodes;
            if (log.isDebugEnabled())
                log.debug("Mapping entry to DHT nodes [nodes=" + U.toShortString(dhtNodes) + ", entry=" + entry + ']');
            for (int i = 1; i < dhtNodes.size(); i++) {
                ClusterNode node = dhtNodes.get(i);
                addMapping(entry, node, dhtMap);
            }
            Collection<UUID> readers = cached.readers();
            if (!F.isEmpty(readers)) {
                for (UUID readerId : readers) {
                    if (readerId.equals(tx.nearNodeId()))
                        continue;
                    ClusterNode readerNode = cctx.discovery().node(readerId);
                    if (readerNode == null || canSkipNearReader(dht, readerNode, dhtNodes))
                        continue;
                    if (log.isDebugEnabled())
                        log.debug("Mapping entry to near node [node=" + readerNode + ", entry=" + entry + ']');
                    addMapping(entry, readerNode, nearMap);
                }
            } else if (log.isDebugEnabled())
                log.debug("Entry has no near readers: " + entry);
            break;
        } catch (GridCacheEntryRemovedException ignore) {
            cached = dht.entryExx(entry.key(), tx.topologyVersion());
            entry.cached(cached);
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) UUID(java.util.UUID)

Example 44 with ExpiryPolicy

use of javax.cache.expiry.ExpiryPolicy in project ignite by apache.

the class GridDhtTxPrepareFuture method onEntriesLocked.

/**
 */
private void onEntriesLocked() {
    ret = new GridCacheReturn(null, tx.localResult(), true, null, true);
    for (IgniteTxEntry writeEntry : req.writes()) {
        IgniteTxEntry txEntry = tx.entry(writeEntry.txKey());
        assert txEntry != null : writeEntry;
        GridCacheContext cacheCtx = txEntry.context();
        GridCacheEntryEx cached = txEntry.cached();
        ExpiryPolicy expiry = cacheCtx.expiryForTxEntry(txEntry);
        cctx.database().checkpointReadLock();
        try {
            if ((txEntry.op() == CREATE || txEntry.op() == UPDATE) && txEntry.conflictExpireTime() == CU.EXPIRE_TIME_CALCULATE) {
                if (expiry != null) {
                    cached.unswap(true);
                    Duration duration = cached.hasValue() ? expiry.getExpiryForUpdate() : expiry.getExpiryForCreation();
                    txEntry.ttl(CU.toTtl(duration));
                }
            }
            boolean hasFilters = !F.isEmptyOrNulls(txEntry.filters()) && !F.isAlwaysTrue(txEntry.filters());
            CacheObject val;
            CacheObject oldVal = null;
            boolean readOld = hasFilters || retVal || txEntry.op() == DELETE || txEntry.op() == TRANSFORM || tx.nearOnOriginatingNode() || tx.hasInterceptor();
            if (readOld) {
                boolean readThrough = !txEntry.skipStore() && (txEntry.op() == TRANSFORM || ((retVal || hasFilters) && cacheCtx.config().isLoadPreviousValue()));
                boolean evt = retVal || txEntry.op() == TRANSFORM;
                EntryProcessor entryProc = null;
                if (evt && txEntry.op() == TRANSFORM)
                    entryProc = F.first(txEntry.entryProcessors()).get1();
                final boolean keepBinary = txEntry.keepBinary();
                val = oldVal = cached.innerGet(null, tx, readThrough, /*metrics*/
                retVal, /*event*/
                evt, tx.subjectId(), entryProc, tx.resolveTaskName(), null, keepBinary);
                if (retVal || txEntry.op() == TRANSFORM) {
                    if (!F.isEmpty(txEntry.entryProcessors())) {
                        invoke = true;
                        if (txEntry.hasValue())
                            val = txEntry.value();
                        KeyCacheObject key = txEntry.key();
                        Object procRes = null;
                        Exception err = null;
                        boolean modified = false;
                        txEntry.oldValueOnPrimary(val != null);
                        for (T2<EntryProcessor<Object, Object, Object>, Object[]> t : txEntry.entryProcessors()) {
                            CacheInvokeEntry<Object, Object> invokeEntry = new CacheInvokeEntry<>(key, val, txEntry.cached().version(), keepBinary, txEntry.cached());
                            try {
                                EntryProcessor<Object, Object, Object> processor = t.get1();
                                procRes = processor.process(invokeEntry, t.get2());
                                val = cacheCtx.toCacheObject(invokeEntry.getValue(true));
                                if (// no validation for remove case
                                val != null)
                                    cacheCtx.validateKeyAndValue(key, val);
                            } catch (Exception e) {
                                err = e;
                                break;
                            }
                            modified |= invokeEntry.modified();
                        }
                        if (modified)
                            val = cacheCtx.toCacheObject(cacheCtx.unwrapTemporary(val));
                        GridCacheOperation op = modified ? (val == null ? DELETE : UPDATE) : NOOP;
                        if (op == NOOP) {
                            if (expiry != null) {
                                long ttl = CU.toTtl(expiry.getExpiryForAccess());
                                txEntry.ttl(ttl);
                                if (ttl == CU.TTL_ZERO)
                                    op = DELETE;
                            }
                        }
                        txEntry.entryProcessorCalculatedValue(new T2<>(op, op == NOOP ? null : val));
                        if (retVal) {
                            if (err != null || procRes != null)
                                ret.addEntryProcessResult(txEntry.context(), key, null, procRes, err, keepBinary);
                            else
                                ret.invokeResult(true);
                        }
                    } else if (retVal)
                        ret.value(cacheCtx, val, keepBinary);
                }
                if (hasFilters && !cacheCtx.isAll(cached, txEntry.filters())) {
                    if (expiry != null)
                        txEntry.ttl(CU.toTtl(expiry.getExpiryForAccess()));
                    txEntry.op(GridCacheOperation.NOOP);
                    if (filterFailedKeys == null)
                        filterFailedKeys = new ArrayList<>();
                    filterFailedKeys.add(cached.txKey());
                    ret.success(false);
                } else
                    ret.success(txEntry.op() != DELETE || cached.hasValue());
            }
            // Send old value in case if rebalancing is not finished.
            final boolean sndOldVal = !cacheCtx.isLocal() && !cacheCtx.topology().rebalanceFinished(tx.topologyVersion());
            if (sndOldVal) {
                if (oldVal == null && !readOld) {
                    oldVal = cached.innerGet(null, tx, /*readThrough*/
                    false, /*metrics*/
                    false, /*event*/
                    false, /*subjectId*/
                    tx.subjectId(), /*transformClo*/
                    null, /*taskName*/
                    null, /*expiryPlc*/
                    null, /*keepBinary*/
                    true);
                }
                if (oldVal != null)
                    oldVal.prepareMarshal(cacheCtx.cacheObjectContext());
                txEntry.oldValue(oldVal);
            }
        } catch (IgniteCheckedException e) {
            U.error(log, "Failed to get result value for cache entry: " + cached, e);
        } catch (GridCacheEntryRemovedException e) {
            assert false : "Got entry removed exception while holding transactional lock on entry [e=" + e + ", cached=" + cached + ']';
        } finally {
            cctx.database().checkpointReadUnlock();
        }
    }
}
Also used : IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) GridCacheReturn(org.apache.ignite.internal.processors.cache.GridCacheReturn) ArrayList(java.util.ArrayList) Duration(javax.cache.expiry.Duration) IgniteTxTimeoutCheckedException(org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) IgniteTxHeuristicCheckedException(org.apache.ignite.internal.transactions.IgniteTxHeuristicCheckedException) IgniteFutureCancelledException(org.apache.ignite.lang.IgniteFutureCancelledException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) IgniteTxOptimisticCheckedException(org.apache.ignite.internal.transactions.IgniteTxOptimisticCheckedException) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) EntryProcessor(javax.cache.processor.EntryProcessor) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheInvokeEntry(org.apache.ignite.internal.processors.cache.CacheInvokeEntry) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) GridCacheOperation(org.apache.ignite.internal.processors.cache.GridCacheOperation) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 45 with ExpiryPolicy

use of javax.cache.expiry.ExpiryPolicy in project ignite by apache.

the class GridLocalAtomicCache method expiryPerCall.

/**
 * @return Expiry policy.
 */
@Nullable
private ExpiryPolicy expiryPerCall() {
    CacheOperationContext opCtx = ctx.operationContextPerCall();
    ExpiryPolicy expiry = opCtx != null ? opCtx.expiry() : null;
    if (expiry == null)
        expiry = ctx.expiry();
    return expiry;
}
Also used : CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext) IgniteCacheExpiryPolicy(org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ExpiryPolicy (javax.cache.expiry.ExpiryPolicy)54 Duration (javax.cache.expiry.Duration)23 TouchedExpiryPolicy (javax.cache.expiry.TouchedExpiryPolicy)15 IgniteCacheExpiryPolicy (org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy)13 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)12 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)11 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)11 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)10 CacheOperationContext (org.apache.ignite.internal.processors.cache.CacheOperationContext)9 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)9 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)9 CacheOperationProvider (com.hazelcast.cache.impl.CacheOperationProvider)7 UUID (java.util.UUID)7 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)7 Transaction (org.apache.ignite.transactions.Transaction)7 Map (java.util.Map)5 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)5 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)5 IgniteTxTimeoutCheckedException (org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException)5