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);
}
});
}
}
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;
}
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);
}
}
}
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();
}
}
}
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;
}
Aggregations