use of org.apache.ignite.internal.processors.cache.distributed.GridDistributedTxMapping in project ignite by apache.
the class GridNearTxLocal method addEntryMapping.
/**
* @param maps Mappings.
*/
void addEntryMapping(@Nullable Collection<GridDistributedTxMapping> maps) {
if (!F.isEmpty(maps)) {
for (GridDistributedTxMapping map : maps) {
ClusterNode primary = map.primary();
GridDistributedTxMapping m = mappings.get(primary.id());
if (m == null) {
mappings.put(m = new GridDistributedTxMapping(primary));
if (map.explicitLock())
m.markExplicitLock();
}
for (IgniteTxEntry entry : map.entries()) m.add(entry);
}
if (log.isDebugEnabled())
log.debug("Added mappings to transaction [locId=" + cctx.localNodeId() + ", mappings=" + maps + ", tx=" + this + ']');
}
}
use of org.apache.ignite.internal.processors.cache.distributed.GridDistributedTxMapping in project ignite by apache.
the class GridNearTxFinishFuture method finishOnePhase.
/**
* @param commit Commit flag.
*/
private void finishOnePhase(boolean commit) {
assert Thread.holdsLock(this);
if (finishOnePhaseCalled)
return;
finishOnePhaseCalled = true;
GridDistributedTxMapping locMapping = mappings.localMapping();
if (locMapping != null) {
// No need to send messages as transaction was already committed on remote node.
// Finish local mapping only as we need send commit message to backups.
IgniteInternalFuture<IgniteInternalTx> fut = cctx.tm().txHandler().finishColocatedLocal(commit, tx);
// Add new future.
if (fut != null)
add(fut);
}
}
use of org.apache.ignite.internal.processors.cache.distributed.GridDistributedTxMapping in project ignite by apache.
the class GridNearTxPrepareFutureAdapter method onPrepareResponse.
/**
* @param m Mapping.
* @param res Response.
* @param updateMapping Update mapping flag.
*/
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
final void onPrepareResponse(GridDistributedTxMapping m, GridNearTxPrepareResponse res, boolean updateMapping) {
if (res == null)
return;
assert res.error() == null : res;
UUID nodeId = m.primary().id();
for (Map.Entry<IgniteTxKey, CacheVersionedValue> entry : res.ownedValues().entrySet()) {
IgniteTxEntry txEntry = tx.entry(entry.getKey());
assert txEntry != null;
GridCacheContext cacheCtx = txEntry.context();
while (true) {
try {
if (cacheCtx.isNear()) {
GridNearCacheEntry nearEntry = (GridNearCacheEntry) txEntry.cached();
CacheVersionedValue tup = entry.getValue();
nearEntry.resetFromPrimary(tup.value(), tx.xidVersion(), tup.version(), nodeId, tx.topologyVersion());
} else if (txEntry.cached().detached()) {
GridDhtDetachedCacheEntry detachedEntry = (GridDhtDetachedCacheEntry) txEntry.cached();
CacheVersionedValue tup = entry.getValue();
detachedEntry.resetFromPrimary(tup.value(), tx.xidVersion());
}
break;
} catch (GridCacheEntryRemovedException ignored) {
// Retry.
txEntry.cached(cacheCtx.cache().entryEx(txEntry.key(), tx.topologyVersion()));
}
}
}
tx.implicitSingleResult(res.returnValue());
for (IgniteTxKey key : res.filterFailedKeys()) {
IgniteTxEntry txEntry = tx.entry(key);
assert txEntry != null : "Missing tx entry for write key: " + key;
txEntry.op(NOOP);
assert txEntry.context() != null;
ExpiryPolicy expiry = txEntry.context().expiryForTxEntry(txEntry);
if (expiry != null)
txEntry.ttl(CU.toTtl(expiry.getExpiryForAccess()));
}
if (!m.empty()) {
// This step is very important as near and DHT versions grow separately.
cctx.versions().onReceived(nodeId, res.dhtVersion());
if (updateMapping && m.hasNearCacheEntries()) {
GridCacheVersion writeVer = res.writeVersion();
if (writeVer == null)
writeVer = res.dhtVersion();
// Register DHT version.
m.dhtVersion(res.dhtVersion(), writeVer);
GridDistributedTxMapping map = tx.mappings().get(nodeId);
if (map != null)
map.dhtVersion(res.dhtVersion(), writeVer);
tx.readyNearLocks(m, res.pending(), res.committedVersions(), res.rolledbackVersions());
}
}
}
Aggregations