use of org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException 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;
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.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());
}
}
}
use of org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException in project ignite by apache.
the class GridNearTxRemote method addEntry.
/**
* @param entry Entry to enlist.
* @throws IgniteCheckedException If failed.
* @return {@code True} if entry was enlisted.
*/
private boolean addEntry(IgniteTxEntry entry) throws IgniteCheckedException {
checkInternal(entry.txKey());
GridCacheContext cacheCtx = entry.context();
if (!cacheCtx.isNear())
cacheCtx = cacheCtx.dht().near().context();
GridNearCacheEntry cached = cacheCtx.near().peekExx(entry.key());
if (cached == null) {
evicted.add(entry.txKey());
return false;
} else {
try {
cached.unswap();
CacheObject val = cached.peek(null);
if (val == null && cached.evictInternal(xidVer, null, false)) {
evicted.add(entry.txKey());
return false;
} else {
// Initialize cache entry.
entry.cached(cached);
txState.addWriteEntry(entry.txKey(), entry);
addExplicit(entry);
return true;
}
} catch (GridCacheEntryRemovedException ignore) {
evicted.add(entry.txKey());
if (log.isDebugEnabled())
log.debug("Got removed entry when adding to remote transaction (will ignore): " + cached);
return false;
}
}
}
use of org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException in project ignite by apache.
the class GridNearOptimisticSerializableTxPrepareFuture method map.
/**
* @param entry Transaction entry.
* @param topVer Topology version.
* @param curMapping Current mapping.
* @param txMapping Mapping.
* @param remap Remap flag.
* @param topLocked Topology locked flag.
*/
private void map(IgniteTxEntry entry, AffinityTopologyVersion topVer, Map<UUID, GridDistributedTxMapping> curMapping, GridDhtTxMapping txMapping, boolean remap, boolean topLocked) {
GridCacheContext cacheCtx = entry.context();
List<ClusterNode> nodes = cacheCtx.isLocal() ? cacheCtx.affinity().nodesByKey(entry.key(), topVer) : cacheCtx.topology().nodes(cacheCtx.affinity().partition(entry.key()), topVer);
if (F.isEmpty(nodes)) {
onDone(new ClusterTopologyServerNotFoundException("Failed to map keys to nodes " + "(partition is not mapped to any node) [key=" + entry.key() + ", partition=" + cacheCtx.affinity().partition(entry.key()) + ", topVer=" + topVer + ']'));
return;
}
txMapping.addMapping(nodes);
ClusterNode primary = F.first(nodes);
assert primary != null;
if (log.isDebugEnabled()) {
log.debug("Mapped key to primary node [key=" + entry.key() + ", part=" + cacheCtx.affinity().partition(entry.key()) + ", primary=" + U.toShortString(primary) + ", topVer=" + topVer + ']');
}
// Must re-initialize cached entry while holding topology lock.
if (cacheCtx.isNear())
entry.cached(cacheCtx.nearTx().entryExx(entry.key(), topVer));
else if (!cacheCtx.isLocal())
entry.cached(cacheCtx.colocated().entryExx(entry.key(), topVer, true));
else
entry.cached(cacheCtx.local().entryEx(entry.key(), topVer));
if (!remap && (cacheCtx.isNear() || cacheCtx.isLocal())) {
if (entry.explicitVersion() == null) {
if (keyLockFut == null) {
keyLockFut = new KeyLockFuture();
add(keyLockFut);
}
keyLockFut.addLockKey(entry.txKey());
}
}
GridDistributedTxMapping cur = curMapping.get(primary.id());
if (cur == null) {
cur = new GridDistributedTxMapping(primary);
curMapping.put(primary.id(), cur);
cur.clientFirst(!topLocked && cctx.kernalContext().clientNode());
cur.last(true);
}
if (primary.isLocal()) {
if (cacheCtx.isNear())
tx.nearLocallyMapped(true);
else if (cacheCtx.isColocated())
tx.colocatedLocallyMapped(true);
}
cur.add(entry);
if (entry.explicitVersion() != null) {
tx.markExplicit(primary.id());
cur.markExplicitLock();
}
entry.nodeId(primary.id());
if (cacheCtx.isNear()) {
while (true) {
try {
GridNearCacheEntry cached = (GridNearCacheEntry) entry.cached();
cached.dhtNodeId(tx.xidVersion(), primary.id());
break;
} catch (GridCacheEntryRemovedException ignore) {
entry.cached(cacheCtx.near().entryEx(entry.key(), topVer));
}
}
}
}
use of org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException in project ignite by apache.
the class IgniteCacheExpiryPolicyAbstractTest method checkTtl.
/**
* @param key Key.
* @param ttl TTL.
* @param wait If {@code true} waits for ttl update.
* @throws Exception If failed.
*/
private void checkTtl(Object key, final long ttl, boolean wait) throws Exception {
boolean found = false;
for (int i = 0; i < gridCount(); i++) {
IgniteKernal grid = (IgniteKernal) grid(i);
GridCacheAdapter<Object, Object> cache = grid.context().cache().internalCache(DEFAULT_CACHE_NAME);
if (cache.context().isNear())
cache = cache.context().near().dht();
while (true) {
try {
GridCacheEntryEx e = cache.entryEx(key);
if (e != null && e.deleted()) {
assertEquals(0, e.ttl());
assertFalse("Invalid entry [e=" + e + ", node=" + i + ']', cache.affinity().isPrimaryOrBackup(grid.localNode(), key));
continue;
}
if (e == null)
assertTrue("Not found " + key, !cache.affinity().isPrimaryOrBackup(grid.localNode(), key));
else {
e.unswap();
found = true;
if (ttl > 0)
assertTrue(e.expireTime() > 0);
else
assertEquals(0, e.expireTime());
}
break;
} catch (GridCacheEntryRemovedException ignore) {
// Retry.
} catch (GridDhtInvalidPartitionException ignore) {
// No need to check.
break;
}
}
}
assertTrue(found);
}
Aggregations