use of org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry in project ignite by apache.
the class GridNearOptimisticTxPrepareFuture method prepare.
/**
* @param writes Write entries.
* @param topLocked {@code True} if thread already acquired lock preventing topology change.
* @param remap Remap flag.
*/
private void prepare(Iterable<IgniteTxEntry> writes, boolean topLocked, boolean remap) {
AffinityTopologyVersion topVer = tx.topologyVersion();
assert topVer.topologyVersion() > 0;
txMapping = new GridDhtTxMapping();
Map<Object, GridDistributedTxMapping> map = new HashMap<>();
// Assign keys to primary nodes.
GridDistributedTxMapping cur = null;
Queue<GridDistributedTxMapping> mappings = new ArrayDeque<>();
boolean hasNearCache = false;
for (IgniteTxEntry write : writes) {
write.clearEntryReadVersion();
GridDistributedTxMapping updated = map(write, topVer, cur, topLocked, remap);
if (updated == null)
// an exception occurred while transaction mapping, stop further processing
break;
if (write.context().isNear())
hasNearCache = true;
if (cur != updated) {
mappings.offer(updated);
updated.last(true);
ClusterNode primary = updated.primary();
assert !primary.isLocal() || !cctx.kernalContext().clientNode() || write.context().isLocal();
// Minor optimization to not create MappingKey: on client node can not have mapping for local node.
Object key = cctx.kernalContext().clientNode() ? primary.id() : new MappingKey(primary.id(), primary.isLocal() && updated.hasNearCacheEntries());
GridDistributedTxMapping prev = map.put(key, updated);
if (prev != null)
prev.last(false);
if (updated.primary().isLocal()) {
if (write.context().isNear())
tx.nearLocallyMapped(true);
else if (write.context().isColocated())
tx.colocatedLocallyMapped(true);
}
cur = updated;
}
}
if (isDone()) {
if (log.isDebugEnabled())
log.debug("Abandoning (re)map because future is done: " + this);
return;
}
if (keyLockFut != null)
keyLockFut.onAllKeysAdded();
tx.addEntryMapping(mappings);
cctx.mvcc().recheckPendingLocks();
tx.transactionNodes(txMapping.transactionNodes());
if (!hasNearCache)
checkOnePhase(txMapping);
proceedPrepare(mappings);
}
Aggregations