/** * @param queueLimit Maximum size of unacknowledged messages queue. * @param node Node. * @param log Logger. */ public GridNioRecoveryDescriptor(int queueLimit, GridNode node, GridLogger log) { assert !node.isLocal() : node; assert queueLimit > 0; msgFuts = new ArrayDeque<>(queueLimit); this.queueLimit = queueLimit; this.node = node; this.log = log; }
/** * @param prj Grid nodes projection. * @return Whether given projection contains any local node. */ private boolean hasLocalNode(GridProjection prj) { for (GridNode n : prj.nodes()) { if (n.isLocal()) return true; } return false; }
/** * @param prj Grid nodes projection. * @return Whether given projection contains any local node. */ private boolean hasLocalNode(GridProjection prj) { for (GridNode n : prj.nodes()) { if (n.isLocal()) return true; } return false; }
@Override public List<List<GridNode>> assignPartitions(GridCacheAffinityFunctionContext affCtx) { GridNode locNode = null; for (GridNode n : affCtx.currentTopologySnapshot()) { if (n.isLocal()) { locNode = n; break; } } if (locNode == null) throw new GridRuntimeException("Local node is not included into affinity nodes for 'LOCAL' cache"); List<List<GridNode>> res = new ArrayList<>(partitions()); for (int part = 0; part < partitions(); part++) res.add(Collections.singletonList(locNode)); return Collections.unmodifiableList(res); }
/** * Generates next affinity key for local node based on current topology. If previous affinity key maps * on local node, return previous affinity key to prevent unnecessary file map growth. * * @param prevAffKey Affinity key of previous block. * @return Affinity key. */ public GridUuid nextAffinityKey(@Nullable GridUuid prevAffKey) { // Do not generate affinity key for non-affinity nodes. if (!isAffinityNode(dataCache.configuration())) return null; UUID nodeId = ggfsCtx.kernalContext().localNodeId(); if (prevAffKey != null && dataCache.affinity().mapKeyToNode(prevAffKey).isLocal()) return prevAffKey; while (true) { GridUuid key = new GridUuid(nodeId, affKeyGen.getAndIncrement()); if (dataCache.affinity().mapKeyToNode(key).isLocal()) return key; } }
/** * Generates next affinity key for local node based on current topology. If previous affinity key maps * on local node, return previous affinity key to prevent unnecessary file map growth. * * @param prevAffKey Affinity key of previous block. * @return Affinity key. */ public GridUuid nextAffinityKey(@Nullable GridUuid prevAffKey) { // Do not generate affinity key for non-affinity nodes. if (!isAffinityNode(dataCache.configuration())) return null; UUID nodeId = ggfsCtx.kernalContext().localNodeId(); if (prevAffKey != null && dataCache.affinity().mapKeyToNode(prevAffKey).isLocal()) return prevAffKey; while (true) { GridUuid key = new GridUuid(nodeId, affKeyGen.getAndIncrement()); if (dataCache.affinity().mapKeyToNode(key).isLocal()) return key; } }
if (oldest.isLocal()) onDeployment(dep, topVer);
if (!node.isLocal()) { final GridGgfsBlocksMessage msg = new GridGgfsBlocksMessage(fileId, batchId, blocks);
if (!node.isLocal()) { final GridGgfsBlocksMessage msg = new GridGgfsBlocksMessage(fileId, batchId, blocks);
/** * @param mapping Mappings. * @param key Key to map. * @param topVer Topology version. * @return Near lock mapping. * @throws GridException If mapping for key failed. */ private GridNearLockMapping<K, V> map(K key, @Nullable GridNearLockMapping<K, V> mapping, long topVer) throws GridException { assert mapping == null || mapping.node() != null; GridNode primary = cctx.affinity().primary(key, topVer); if (primary == null) throw new GridTopologyException("Failed to lock keys (all data nodes left grid)."); if (cctx.discovery().node(primary.id()) == null) // If primary node left the grid before lock acquisition, fail the whole future. throw newTopologyException(null, primary.id()); if (inTx() && tx.groupLock() && !primary.isLocal()) throw new GridException("Failed to start group lock transaction (local node is not primary for " + " key) [key=" + key + ", primaryNodeId=" + primary.id() + ']'); if (mapping == null || !primary.id().equals(mapping.node().id())) mapping = new GridNearLockMapping<>(primary, key); else mapping.addKey(key); return mapping; }
/** * @param mapping Mappings. * @param key Key to map. * @param topVer Topology version. * @return Near lock mapping. * @throws GridException If mapping failed. */ private GridNearLockMapping<K, V> map(K key, @Nullable GridNearLockMapping<K, V> mapping, long topVer) throws GridException { assert mapping == null || mapping.node() != null; GridNode primary = cctx.affinity().primary(key, topVer); if (primary == null) throw new GridTopologyException("Failed to lock keys (all data nodes left grid)."); if (cctx.discovery().node(primary.id()) == null) // If primary node left the grid before lock acquisition, fail the whole future. throw newTopologyException(null, primary.id()); if (inTx() && tx.groupLock() && !primary.isLocal()) throw new GridException("Failed to start group lock transaction (local node is not primary for " + " key) [key=" + key + ", primaryNodeId=" + primary.id() + ']'); if (mapping == null || !primary.id().equals(mapping.node().id())) mapping = new GridNearLockMapping<>(primary, key); else mapping.addKey(key); return mapping; }
if (m.node().isLocal()) { GridFuture<GridCacheTx> fut = cctx.colocated().finishLocal(commit, m.explicitLock(), tx);
/** * @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(GridCacheTxEntry<K, V> e, boolean primaryOnly) { if (!near()) 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.nodeId())) return true; GridCacheEntryEx<K, V> cached = e.cached(); int part = cached != null ? cached.partition() : cctx.affinity().partition(e.key()); List<GridNode> affNodes = cctx.affinity().nodes(part, topologyVersion()); e.locallyMapped(F.contains(affNodes, cctx.localNode())); if (primaryOnly) { GridNode primary = F.first(affNodes); if (primary == null && !isAffinityNode(cctx.config())) return false; assert primary != null : "Primary node is null for affinity nodes: " + affNodes; return primary.isLocal(); } else return e.locallyMapped(); }
/** * @param entry Transaction entry. * @param topVer Topology version. * @param cur Current mapping. * @throws GridException If transaction is group-lock and local node is not primary for key. * @return Mapping. */ private GridDistributedTxMapping<K, V> map(GridCacheTxEntry<K, V> entry, long topVer, GridDistributedTxMapping<K, V> cur) throws GridException { List<GridNode> nodes = cctx.affinity().nodes(entry.key(), topVer); txMapping.addMapping(nodes); GridNode primary = F.first(nodes); assert primary != null; if (log.isDebugEnabled()) log.debug("Mapped key to primary node [key=" + entry.key() + ", part=" + cctx.affinity().partition(entry.key()) + ", primary=" + U.toShortString(primary) + ", topVer=" + topVer + ']'); if (tx.groupLock() && !primary.isLocal()) throw new GridException("Failed to prepare group lock transaction (local node is not primary for " + " key) [key=" + entry.key() + ", primaryNodeId=" + primary.id() + ']'); // Must re-initialize cached entry while holding topology lock. entry.cached(cctx.colocated().entryExx(entry.key(), topVer, true), entry.keyBytes()); if (cur == null || !cur.node().id().equals(primary.id())) cur = new GridDistributedTxMapping<>(primary); cur.add(entry); entry.nodeId(primary.id()); return cur; }
if (oldest.isLocal()) { final Collection<GridServiceDeployment> retries = new ConcurrentLinkedQueue<>();
req.filter(filter, cctx); if (node.isLocal()) lockLocally(mappedKeys, req.topologyVersion(), mappings); else {
if (tx.groupLock() && !primary.isLocal()) throw new GridException("Failed to prepare group lock transaction (local node is not primary for " + " key)[key=" + entry.key() + ", primaryNodeId=" + primary.id() + ']');
if (n.isLocal()) { GridFuture<GridCacheTx> fut = cctx.colocated().finishLocal(commit, m.explicitLock(), tx);
if (n.isLocal()) { req.miniId(GridUuid.randomUuid());