use of org.apache.ignite.internal.processors.cache.GridCacheEntryEx in project ignite by apache.
the class IgniteTxLocalAdapter method postLockWrite.
/**
* Post lock processing for put or remove.
*
* @param cacheCtx Context.
* @param keys Keys.
* @param ret Return value.
* @param rmv {@code True} if remove.
* @param retval Flag to return value or not.
* @param read {@code True} if read.
* @param accessTtl TTL for read operation.
* @param filter Filter to check entries.
* @throws IgniteCheckedException If error.
* @param computeInvoke If {@code true} computes return value for invoke operation.
*/
@SuppressWarnings("unchecked")
protected final void postLockWrite(GridCacheContext cacheCtx, Iterable<KeyCacheObject> keys, GridCacheReturn ret, boolean rmv, boolean retval, boolean read, long accessTtl, CacheEntryPredicate[] filter, boolean computeInvoke) throws IgniteCheckedException {
for (KeyCacheObject k : keys) {
IgniteTxEntry txEntry = entry(cacheCtx.txKey(k));
if (txEntry == null)
throw new IgniteCheckedException("Transaction entry is null (most likely collection of keys passed into cache " + "operation was changed before operation completed) [missingKey=" + k + ", tx=" + this + ']');
while (true) {
GridCacheEntryEx cached = txEntry.cached();
try {
assert cached.detached() || cached.lockedByThread(threadId) || isRollbackOnly() : "Transaction lock is not acquired [entry=" + cached + ", tx=" + this + ", nodeId=" + cctx.localNodeId() + ", threadId=" + threadId + ']';
if (log.isDebugEnabled())
log.debug("Post lock write entry: " + cached);
CacheObject v = txEntry.previousValue();
boolean hasPrevVal = txEntry.hasPreviousValue();
if (onePhaseCommit())
filter = txEntry.filters();
// If we have user-passed filter, we must read value into entry for peek().
if (!F.isEmptyOrNulls(filter) && !F.isAlwaysTrue(filter))
retval = true;
boolean invoke = txEntry.op() == TRANSFORM;
if (retval || invoke) {
if (!cacheCtx.isNear()) {
if (!hasPrevVal) {
// For non-local cache should read from store after lock on primary.
boolean readThrough = cacheCtx.isLocal() && (invoke || cacheCtx.loadPreviousValue()) && !txEntry.skipStore();
v = cached.innerGet(null, this, readThrough, /*metrics*/
!invoke, /*event*/
!invoke && !dht(), CU.subjectId(this, cctx), null, resolveTaskName(), null, txEntry.keepBinary());
}
} else {
if (!hasPrevVal)
v = cached.rawGet();
}
if (txEntry.op() == TRANSFORM) {
if (computeInvoke) {
GridCacheVersion ver;
try {
ver = cached.version();
} catch (GridCacheEntryRemovedException e) {
assert optimistic() : txEntry;
if (log.isDebugEnabled())
log.debug("Failed to get entry version: [msg=" + e.getMessage() + ']');
ver = null;
}
addInvokeResult(txEntry, v, ret, ver);
}
} else
ret.value(cacheCtx, v, txEntry.keepBinary());
}
boolean pass = F.isEmpty(filter) || cacheCtx.isAll(cached, filter);
// For remove operation we return true only if we are removing s/t,
// i.e. cached value is not null.
ret.success(pass && (!retval ? !rmv || cached.hasValue() || v != null : !rmv || v != null));
if (onePhaseCommit())
txEntry.filtersPassed(pass);
boolean updateTtl = read;
if (pass) {
txEntry.markValid();
if (log.isDebugEnabled())
log.debug("Filter passed in post lock for key: " + k);
} else {
// Revert operation to previous. (if no - NOOP, so entry will be unlocked).
txEntry.setAndMarkValid(txEntry.previousOperation(), cacheCtx.toCacheObject(ret.value()));
txEntry.filters(CU.empty0());
txEntry.filtersSet(false);
updateTtl = !cacheCtx.putIfAbsentFilter(filter);
}
if (updateTtl) {
if (!read) {
ExpiryPolicy expiryPlc = cacheCtx.expiryForTxEntry(txEntry);
if (expiryPlc != null)
txEntry.ttl(CU.toTtl(expiryPlc.getExpiryForAccess()));
} else
txEntry.ttl(accessTtl);
}
// While.
break;
}// If entry cached within transaction got removed before lock.
catch (GridCacheEntryRemovedException ignore) {
if (log.isDebugEnabled())
log.debug("Got removed entry in putAllAsync method (will retry): " + cached);
txEntry.cached(entryEx(cached.context(), txEntry.txKey(), topologyVersion()));
}
}
}
}
use of org.apache.ignite.internal.processors.cache.GridCacheEntryEx in project ignite by apache.
the class IgniteTxManager method unlockMultiple.
/**
* @param tx Owning transaction.
* @param entries Entries to unlock.
*/
private void unlockMultiple(IgniteInternalTx tx, Iterable<IgniteTxEntry> entries) {
for (IgniteTxEntry txEntry : entries) {
GridCacheContext cacheCtx = txEntry.context();
while (true) {
try {
GridCacheEntryEx entry = txEntry.cached();
assert entry != null;
if (entry.detached())
break;
entry.txUnlock(tx);
break;
} catch (GridCacheEntryRemovedException ignored) {
if (log.isDebugEnabled())
log.debug("Got removed entry in TM unlockMultiple(..) method (will retry): " + txEntry);
// Renew cache entry.
txEntry.cached(cacheCtx.cache().entryEx(txEntry.key(), tx.topologyVersion()));
}
}
}
}
use of org.apache.ignite.internal.processors.cache.GridCacheEntryEx in project ignite by apache.
the class IgniteTxRemoteStateImpl method invalidPartition.
/** {@inheritDoc} */
@Override
public void invalidPartition(int part) {
if (writeMap != null) {
for (Iterator<IgniteTxEntry> it = writeMap.values().iterator(); it.hasNext(); ) {
IgniteTxEntry e = it.next();
GridCacheContext cacheCtx = e.context();
GridCacheEntryEx cached = e.cached();
if (cached != null) {
if (cached.partition() == part)
it.remove();
} else if (cacheCtx.affinity().partition(e.key()) == part)
it.remove();
}
}
}
use of org.apache.ignite.internal.processors.cache.GridCacheEntryEx in project ignite by apache.
the class IgniteTxManager method lockMultiple.
/**
* @param tx Transaction.
* @param entries Entries to lock.
* @return {@code True} if all keys were locked.
* @throws IgniteCheckedException If lock has been cancelled.
*/
private boolean lockMultiple(IgniteInternalTx tx, Iterable<IgniteTxEntry> entries) throws IgniteCheckedException {
assert tx.optimistic() || !tx.local();
long remainingTime = tx.remainingTime();
// For serializable transactions, failure to acquire lock means
// that there is a serializable conflict. For all other isolation levels,
// we wait for the lock.
long timeout = remainingTime < 0 ? 0 : remainingTime;
GridCacheVersion serOrder = (tx.serializable() && tx.optimistic()) ? tx.nearXidVersion() : null;
for (IgniteTxEntry txEntry1 : entries) {
// Check if this entry was prepared before.
if (!txEntry1.markPrepared() || txEntry1.explicitVersion() != null)
continue;
GridCacheContext cacheCtx = txEntry1.context();
while (true) {
try {
GridCacheEntryEx entry1 = txEntry1.cached();
assert entry1 != null : txEntry1;
assert !entry1.detached() : "Expected non-detached entry for near transaction " + "[locNodeId=" + cctx.localNodeId() + ", entry=" + entry1 + ']';
GridCacheVersion serReadVer = txEntry1.entryReadVersion();
assert serReadVer == null || (tx.optimistic() && tx.serializable()) : txEntry1;
boolean read = serOrder != null && txEntry1.op() == READ;
entry1.unswap();
if (!entry1.tmLock(tx, timeout, serOrder, serReadVer, read)) {
// Unlock locks locked so far.
for (IgniteTxEntry txEntry2 : entries) {
if (txEntry2 == txEntry1)
break;
txEntry2.cached().txUnlock(tx);
}
return false;
}
break;
} catch (GridCacheEntryRemovedException ignored) {
if (log.isDebugEnabled())
log.debug("Got removed entry in TM lockMultiple(..) method (will retry): " + txEntry1);
try {
// Renew cache entry.
txEntry1.cached(cacheCtx.cache().entryEx(txEntry1.key(), tx.topologyVersion()));
} catch (GridDhtInvalidPartitionException e) {
assert tx.dht() : "Received invalid partition for non DHT transaction [tx=" + tx + ", invalidPart=" + e.partition() + ']';
// If partition is invalid, we ignore this entry.
tx.addInvalidPartition(cacheCtx, e.partition());
break;
}
} catch (GridDistributedLockCancelledException ignore) {
tx.setRollbackOnly();
throw new IgniteCheckedException("Entry lock has been cancelled for transaction: " + tx);
}
}
}
return true;
}
use of org.apache.ignite.internal.processors.cache.GridCacheEntryEx in project ignite by apache.
the class IgniteTxHandler method invalidateNearEntry.
/**
* @param cacheCtx Context.
* @param key Key
* @param ver Version.
* @throws IgniteCheckedException If invalidate failed.
*/
private void invalidateNearEntry(GridCacheContext cacheCtx, KeyCacheObject key, GridCacheVersion ver) throws IgniteCheckedException {
GridNearCacheAdapter near = cacheCtx.isNear() ? cacheCtx.near() : cacheCtx.dht().near();
GridCacheEntryEx nearEntry = near.peekEx(key);
if (nearEntry != null)
nearEntry.invalidate(null, ver);
}
Aggregations