use of org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry in project ignite by apache.
the class GridDhtTxLocalAdapter method mapExplicitLocks.
/**
* Map explicit locks.
*/
protected void mapExplicitLocks() {
if (!mapped) {
// Explicit locks may participate in implicit transactions only.
if (!implicit()) {
mapped = true;
return;
}
Map<ClusterNode, List<GridDhtCacheEntry>> dhtEntryMap = null;
Map<ClusterNode, List<GridDhtCacheEntry>> nearEntryMap = null;
for (IgniteTxEntry e : allEntries()) {
assert e.cached() != null;
GridCacheContext cacheCtx = e.cached().context();
if (cacheCtx.isNear())
continue;
if (e.cached().obsolete()) {
GridCacheEntryEx cached = cacheCtx.cache().entryEx(e.key(), topologyVersion());
e.cached(cached);
}
if (e.cached().detached() || e.cached().isLocal())
continue;
while (true) {
try {
// Map explicit locks.
if (e.explicitVersion() != null && !e.explicitVersion().equals(xidVer)) {
if (dhtEntryMap == null)
dhtEntryMap = new GridLeanMap<>();
if (nearEntryMap == null)
nearEntryMap = new GridLeanMap<>();
cacheCtx.dhtMap((GridDhtCacheEntry) e.cached(), e.explicitVersion(), log, dhtEntryMap, nearEntryMap);
}
break;
} catch (GridCacheEntryRemovedException ignore) {
GridCacheEntryEx cached = cacheCtx.cache().entryEx(e.key(), topologyVersion());
e.cached(cached);
}
}
}
if (!F.isEmpty(dhtEntryMap))
addDhtNodeEntryMapping(dhtEntryMap);
if (!F.isEmpty(nearEntryMap))
addNearNodeEntryMapping(nearEntryMap);
mapped = true;
}
}
use of org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry in project ignite by apache.
the class GridDhtTxLocalAdapter method removeMapping.
/**
* @param nodeId Node ID.
* @param entry Entry to remove.
* @param map Map to remove from.
* @return {@code True} if was removed.
*/
private boolean removeMapping(UUID nodeId, @Nullable GridCacheEntryEx entry, Map<UUID, GridDistributedTxMapping> map) {
if (entry != null) {
if (log.isDebugEnabled())
log.debug("Removing mapping for entry [nodeId=" + nodeId + ", entry=" + entry + ']');
IgniteTxEntry txEntry = entry(entry.txKey());
if (txEntry == null)
return false;
GridDistributedTxMapping m = map.get(nodeId);
boolean ret = m != null && m.removeEntry(txEntry);
if (m != null && m.empty())
map.remove(nodeId);
return ret;
} else
return map.remove(nodeId) != null;
}
use of org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry in project ignite by apache.
the class GridNearOptimisticSerializableTxPrepareFuture method onOwnerChanged.
/**
* {@inheritDoc}
*/
@Override
public boolean onOwnerChanged(GridCacheEntryEx entry, GridCacheMvccCandidate owner) {
if (log.isDebugEnabled())
log.debug("Transaction future received owner changed callback: " + entry);
if ((entry.context().isNear() || entry.context().isLocal()) && owner != null) {
IgniteTxEntry txEntry = tx.entry(entry.txKey());
if (txEntry != null) {
if (entry.context().isLocal()) {
GridCacheVersion serReadVer = txEntry.entryReadVersion();
if (serReadVer != null) {
GridCacheContext ctx = entry.context();
while (true) {
try {
if (!entry.checkSerializableReadVersion(serReadVer)) {
Object key = entry.key().value(ctx.cacheObjectContext(), false);
IgniteTxOptimisticCheckedException err0 = new IgniteTxOptimisticCheckedException(S.toString("Failed to prepare transaction, read/write conflict", "key", key, true, "cache", ctx.name(), false));
ERR_UPD.compareAndSet(this, null, err0);
}
break;
} catch (GridCacheEntryRemovedException ignored) {
entry = ctx.cache().entryEx(entry.key(), tx.topologyVersion());
txEntry.cached(entry);
}
}
}
}
if (keyLockFut != null)
keyLockFut.onKeyLocked(entry.txKey());
return true;
}
}
return false;
}
use of org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry in project ignite by apache.
the class GridNearOptimisticSerializableTxPrepareFuture method createRequest.
/**
* @param txNodes Tx nodes.
* @param fut Future.
* @param timeout Timeout.
* @param reads Read entries.
* @param writes Write entries.
* @return Request.
*/
private GridNearTxPrepareRequest createRequest(Map<UUID, Collection<UUID>> txNodes, MiniFuture fut, long timeout, Collection<IgniteTxEntry> reads, Collection<IgniteTxEntry> writes) {
GridDistributedTxMapping m = fut.mapping();
GridNearTxPrepareRequest req = new GridNearTxPrepareRequest(futId, tx.topologyVersion(), tx, timeout, reads, writes, m.hasNearCacheEntries(), txNodes, m.last(), tx.onePhaseCommit(), tx.needReturnValue() && tx.implicit(), tx.implicitSingle(), m.explicitLock(), tx.subjectId(), tx.taskNameHash(), m.clientFirst(), txNodes.size() == 1, tx.activeCachesDeploymentEnabled());
for (IgniteTxEntry txEntry : writes) {
if (txEntry.op() == TRANSFORM)
req.addDhtVersion(txEntry.txKey(), null);
}
req.miniId(fut.futureId());
return req;
}
use of org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry in project ignite by apache.
the class GridNearOptimisticTxPrepareFuture method requestedKeys.
/**
* @return Keys for which {@code MiniFuture} isn't completed.
*/
@SuppressWarnings("ForLoopReplaceableByForEach")
public Set<IgniteTxKey> requestedKeys() {
synchronized (this) {
int size = futuresCountNoLock();
for (int i = 0; i < size; i++) {
IgniteInternalFuture<GridNearTxPrepareResponse> fut = future(i);
if (isMini(fut) && !fut.isDone()) {
MiniFuture miniFut = (MiniFuture) fut;
Collection<IgniteTxEntry> entries = miniFut.mapping().entries();
Set<IgniteTxKey> keys = U.newHashSet(entries.size());
for (IgniteTxEntry entry : entries) keys.add(entry.txKey());
return keys;
}
}
}
return null;
}
Aggregations