/** {@inheritDoc} */ @Override public boolean mvccEnabled() { for (IgniteTxEntry e : writeMap.values()) { if (e.context().mvccEnabled()) return true; } return false; } }
/** {@inheritDoc} */ @Override public boolean mvccEnabled() { return entry != null && entry.context().mvccEnabled(); } }
/** * @param entry Adds entry. */ public void add(IgniteTxEntry entry) { if (entries.add(entry) && entry.context().isNear()) nearEntries++; }
@Override public boolean apply(IgniteTxEntry e) { return e.context().isNear(); }
@Override public boolean apply(IgniteTxEntry e) { return e.op() != READ && e.context().isNear(); }
@Override public boolean apply(IgniteTxEntry e) { return e.op() != READ && !e.context().isNear(); }
@Override public boolean apply(IgniteTxEntry e) { return e.op() == READ && e.context().isNear(); }
@Override public boolean apply(IgniteTxEntry e) { return e.op() == READ && !e.context().isNear(); }
/** {@inheritDoc} */ @Override public Collection<CacheStoreManager> stores(GridCacheSharedContext cctx) { if (entry == null) return null; CacheStoreManager store = entry.context().store(); if (store.configured() && store.isLocal()) { // Only local stores take part at tx on backup node. return Collections.singleton(store); } return null; }
/** {@inheritDoc} */ @Override public void invalidPartition(int part) { if (writeMap != null) { for (Iterator<IgniteTxEntry> it = writeMap.values().iterator(); it.hasNext(); ) { IgniteTxEntry e = it.next(); GridCacheContext cacheCtx = e.context(); GridCacheEntryEx cached = e.cached(); if (cached != null) { if (cached.partition() == part) it.remove(); } else if (cacheCtx.affinity().partition(e.key()) == part) it.remove(); } } }
/** {@inheritDoc} */ @Override public void invalidPartition(int part) { if (entry != null && entry.context().affinity().partition(entry.key()) == part) entry = null; }
/** {@inheritDoc} */ @Override public Collection<CacheStoreManager> stores(GridCacheSharedContext cctx) { int locStoreCnt = cctx.getLocalStoreCount(); if (locStoreCnt > 0 && !writeMap.isEmpty()) { Collection<CacheStoreManager> stores = null; for (IgniteTxEntry e : writeMap.values()) { if (e.skipStore()) continue; CacheStoreManager store = e.context().store(); if (store.configured() && store.isLocal()) { if (stores == null) stores = new ArrayList<>(locStoreCnt); stores.add(store); if (stores.size() == locStoreCnt) break; } } return stores; } return null; }
/** * Clones entries so that tx entries with initialized near entries are not passed to DHT transaction. * Used only when local part of prepare is invoked. * * @param c Collection of entries to clone. * @return Cloned collection. */ private Collection<IgniteTxEntry> cloneEntries(Collection<IgniteTxEntry> c) { if (F.isEmpty(c)) return c; Collection<IgniteTxEntry> cp = new ArrayList<>(c.size()); for (IgniteTxEntry e : c) { GridCacheContext cacheCtx = e.context(); // Clone only if it is a near cache. if (cacheCtx.isNear()) cp.add(e.cleanCopy(cacheCtx.nearTx().dht().context())); else cp.add(e); } return cp; }
/** * @param cctx Context. * @param tx Transaction. */ protected GridNearOptimisticTxPrepareFutureAdapter(GridCacheSharedContext cctx, GridNearTxLocal tx) { super(cctx, tx); assert tx.optimistic() : tx; if (tx.timeout() > 0) { // Init keyLockFut to make sure it is created when {@link #onNearTxLocalTimeout} is called. for (IgniteTxEntry e : tx.writeEntries()) { if (e.context().isNear() || e.context().isLocal()) { keyLockFut = new KeyLockFuture(); break; } } if (tx.serializable() && keyLockFut == null) { for (IgniteTxEntry e : tx.readEntries()) { if (e.context().isNear() || e.context().isLocal()) { keyLockFut = new KeyLockFuture(); break; } } } if (keyLockFut != null) add((IgniteInternalFuture)keyLockFut); } }
/** * @param ctx Context. * @param transferExpiry {@code True} if expire policy should be marshalled. * @throws IgniteCheckedException If failed. */ public void marshal(GridCacheSharedContext<?, ?> ctx, boolean transferExpiry) throws IgniteCheckedException { if (filters != null) { for (CacheEntryPredicate p : filters) { if (p != null) p.prepareMarshal(this.ctx); } } // Do not serialize filters if they are null. if (transformClosBytes == null && entryProcessorsCol != null) transformClosBytes = CU.marshal(this.ctx, entryProcessorsCol); if (transferExpiry) transferExpiryPlc = expiryPlc != null && expiryPlc != this.ctx.expiry(); key.prepareMarshal(context().cacheObjectContext()); val.marshal(context()); if (transferExpiryPlc) { if (expiryPlcBytes == null) expiryPlcBytes = CU.marshal(this.ctx, new IgniteExternalizableExpiryPolicy(expiryPlc)); } else expiryPlcBytes = null; }
/** {@inheritDoc} */ @Override public void touch(IgniteTxEntry txEntry, boolean loc) { assert txEntry.context() == cctx : "Entry from another cache context passed to eviction manager: [" + "entry=" + txEntry + ", cctx=" + cctx + ", entryCtx=" + txEntry.context() + "]"; if (!plcEnabled) return; if (!loc) { if (cctx.isNear()) return; } GridCacheEntryEx e = txEntry.cached(); if (e.detached() || e.isInternal()) return; try { if (e.markObsoleteIfEmpty(null) || e.obsolete()) e.context().cache().removeEntry(e); } catch (IgniteCheckedException ex) { U.error(log, "Failed to evict entry from cache: " + e, ex); } notifyPolicy(e); }
/** * @param tx Transaction. * @param txEntry Entry to unlock. */ private void txUnlock(IgniteInternalTx tx, IgniteTxEntry txEntry) { while (true) { try { GridCacheEntryEx entry = txEntry.cached(); assert entry != null; if (entry.detached()) break; entry.txUnlock(tx); break; } catch (GridCacheEntryRemovedException ignored) { if (log.isDebugEnabled()) log.debug("Got removed entry in TM txUnlock(..) method (will retry): " + txEntry); txEntry.cached(txEntry.context().cache().entryEx(txEntry.key(), tx.topologyVersion())); } } }
/** * @param entry Write entry. * @param ldr Class loader. * @throws IgniteCheckedException If failed. */ public void addWrite(IgniteTxEntry entry, ClassLoader ldr) throws IgniteCheckedException { entry.unmarshal(cctx, false, ldr); GridCacheContext cacheCtx = entry.context(); try { GridDhtCacheEntry cached = cacheCtx.dht().entryExx(entry.key(), topologyVersion()); checkInternal(entry.txKey()); // Initialize cache entry. entry.cached(cached); txState.addWriteEntry(entry.txKey(), entry); addExplicit(entry); } catch (GridDhtInvalidPartitionException e) { addInvalidPartition(cacheCtx, e.partition()); } }
/** * @param e Transaction entry. * @param primaryOnly Flag to include backups into check or not. * @return {@code True} if entry is locally mapped as a primary or back up node. */ protected boolean isNearLocallyMapped(IgniteTxEntry e, boolean primaryOnly) { GridCacheContext cacheCtx = e.context(); if (!cacheCtx.isNear()) return false; // Try to take either entry-recorded primary node ID, // or transaction node ID from near-local transactions. UUID nodeId = e.nodeId() == null ? local() ? this.nodeId : null : e.nodeId(); if (nodeId != null && nodeId.equals(cctx.localNodeId())) return true; GridCacheEntryEx cached = e.cached(); int part = cached != null ? cached.partition() : cacheCtx.affinity().partition(e.key()); List<ClusterNode> affNodes = cacheCtx.affinity().nodesByPartition(part, topologyVersion()); e.locallyMapped(F.contains(affNodes, cctx.localNode())); if (primaryOnly) { ClusterNode primary = F.first(affNodes); if (primary == null && !cacheCtx.affinityNode()) return false; assert primary != null : "Primary node is null for affinity nodes: " + affNodes; return primary.isLocal(); } else return e.locallyMapped(); }
/** * @param tx Transaction. */ private void removeObsolete(IgniteInternalTx tx) { Collection<IgniteTxEntry> entries = tx.local() ? tx.allEntries() : tx.writeEntries(); for (IgniteTxEntry entry : entries) { GridCacheEntryEx cached = entry.cached(); GridCacheContext cacheCtx = entry.context(); if (cached == null) cached = cacheCtx.cache().peekEx(entry.key()); if (cached.detached()) continue; try { if (cached.obsolete() || cached.markObsoleteIfEmpty(tx.xidVersion())) cacheCtx.cache().removeEntry(cached); if (!tx.near() && isNearEnabled(cacheCtx)) { GridNearCacheAdapter near = cacheCtx.isNear() ? cacheCtx.near() : cacheCtx.dht().near(); GridNearCacheEntry e = near.peekExx(entry.key()); if (e != null && e.markObsoleteIfEmpty(null)) near.removeEntry(e); } } catch (IgniteCheckedException e) { U.error(log, "Failed to remove obsolete entry from cache: " + cached, e); } } }