use of org.apache.ignite.internal.processors.cache.distributed.GridDistributedTxMapping 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(), 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.distributed.GridDistributedTxMapping in project ignite by apache.
the class GridNearTxLocal method addSingleEntryMapping.
/**
* @param map Mapping.
* @param entry Entry.
*/
void addSingleEntryMapping(GridDistributedTxMapping map, IgniteTxEntry entry) {
ClusterNode n = map.primary();
GridDistributedTxMapping m = new GridDistributedTxMapping(n);
mappings.put(m);
if (map.explicitLock())
m.markExplicitLock();
m.add(entry);
}
use of org.apache.ignite.internal.processors.cache.distributed.GridDistributedTxMapping in project ignite by apache.
the class GridNearTxLocal method markExplicit.
/**
* @param nodeId Node ID to mark with explicit lock.
* @return {@code True} if mapping was found.
*/
public boolean markExplicit(UUID nodeId) {
explicitLock = true;
GridDistributedTxMapping m = mappings.get(nodeId);
if (m != null) {
m.markExplicitLock();
return true;
}
return false;
}
use of org.apache.ignite.internal.processors.cache.distributed.GridDistributedTxMapping in project ignite by apache.
the class GridNearTxLocal method addKeyMapping.
/**
* Adds key mapping to dht mapping.
*
* @param key Key to add.
* @param node Node this key mapped to.
*/
public void addKeyMapping(IgniteTxKey key, ClusterNode node) {
GridDistributedTxMapping m = mappings.get(node.id());
if (m == null)
mappings.put(m = new GridDistributedTxMapping(node));
IgniteTxEntry txEntry = entry(key);
assert txEntry != null;
txEntry.nodeId(node.id());
m.add(txEntry);
if (log.isDebugEnabled())
log.debug("Added mappings to transaction [locId=" + cctx.localNodeId() + ", key=" + key + ", node=" + node + ", tx=" + this + ']');
}
use of org.apache.ignite.internal.processors.cache.distributed.GridDistributedTxMapping in project ignite by apache.
the class GridNearPessimisticTxPrepareFuture method preparePessimistic.
/**
*
*/
private void preparePessimistic() {
Map<UUID, GridDistributedTxMapping> mappings = new HashMap<>();
AffinityTopologyVersion topVer = tx.topologyVersion();
GridDhtTxMapping txMapping = new GridDhtTxMapping();
boolean hasNearCache = false;
for (IgniteTxEntry txEntry : tx.allEntries()) {
txEntry.clearEntryReadVersion();
GridCacheContext cacheCtx = txEntry.context();
if (cacheCtx.isNear())
hasNearCache = true;
List<ClusterNode> nodes;
if (!cacheCtx.isLocal()) {
GridDhtPartitionTopology top = cacheCtx.topology();
nodes = top.nodes(cacheCtx.affinity().partition(txEntry.key()), topVer);
} else
nodes = cacheCtx.affinity().nodesByKey(txEntry.key(), topVer);
assert !nodes.isEmpty();
ClusterNode primary = nodes.get(0);
GridDistributedTxMapping nodeMapping = mappings.get(primary.id());
if (nodeMapping == null)
mappings.put(primary.id(), nodeMapping = new GridDistributedTxMapping(primary));
txEntry.nodeId(primary.id());
nodeMapping.add(txEntry);
txMapping.addMapping(nodes);
}
tx.transactionNodes(txMapping.transactionNodes());
if (!hasNearCache)
checkOnePhase(txMapping);
long timeout = tx.remainingTime();
if (timeout == -1) {
onDone(new IgniteTxTimeoutCheckedException("Transaction timed out and was rolled back: " + tx));
return;
}
int miniId = 0;
Map<UUID, Collection<UUID>> txNodes = txMapping.transactionNodes();
for (final GridDistributedTxMapping m : mappings.values()) {
final ClusterNode primary = m.primary();
if (primary.isLocal()) {
if (m.hasNearCacheEntries() && m.hasColocatedCacheEntries()) {
GridNearTxPrepareRequest nearReq = createRequest(txMapping.transactionNodes(), m, timeout, m.nearEntriesReads(), m.nearEntriesWrites());
prepareLocal(nearReq, m, ++miniId, true);
GridNearTxPrepareRequest colocatedReq = createRequest(txNodes, m, timeout, m.colocatedEntriesReads(), m.colocatedEntriesWrites());
prepareLocal(colocatedReq, m, ++miniId, false);
} else {
GridNearTxPrepareRequest req = createRequest(txNodes, m, timeout, m.reads(), m.writes());
prepareLocal(req, m, ++miniId, m.hasNearCacheEntries());
}
} else {
GridNearTxPrepareRequest req = createRequest(txNodes, m, timeout, m.reads(), m.writes());
final MiniFuture fut = new MiniFuture(m, ++miniId);
req.miniId(fut.futureId());
add(fut);
try {
cctx.io().send(primary, req, tx.ioPolicy());
if (msgLog.isDebugEnabled()) {
msgLog.debug("Near pessimistic prepare, sent request [txId=" + tx.nearXidVersion() + ", node=" + primary.id() + ']');
}
} catch (ClusterTopologyCheckedException e) {
e.retryReadyFuture(cctx.nextAffinityReadyFuture(topVer));
fut.onNodeLeft(e);
} catch (IgniteCheckedException e) {
if (msgLog.isDebugEnabled()) {
msgLog.debug("Near pessimistic prepare, failed send request [txId=" + tx.nearXidVersion() + ", node=" + primary.id() + ", err=" + e + ']');
}
fut.onError(e);
break;
}
}
}
markInitialized();
}
Aggregations