use of org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtDetachedCacheEntry in project ignite by apache.
the class GridNearTxPrepareFutureAdapter method onPrepareResponse.
/**
* @param m Mapping.
* @param res Response.
* @param updateMapping Update mapping flag.
*/
final void onPrepareResponse(GridDistributedTxMapping m, GridNearTxPrepareResponse res, boolean updateMapping) {
if (res == null)
return;
assert res.error() == null : res;
if (tx.onePhaseCommit() && !res.onePhaseCommit())
tx.onePhaseCommit(false);
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.queryUpdate() || !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