Beispiel #1
0
  /**
   * @param mapping Mapping to order.
   * @param committedVers Committed versions.
   * @param rolledbackVers Rolled back versions.
   */
  void orderCompleted(
      GridDistributedTxMapping<K, V> mapping,
      Collection<GridCacheVersion> committedVers,
      Collection<GridCacheVersion> rolledbackVers) {
    for (GridCacheTxEntry<K, V> txEntry : F.concat(false, mapping.reads(), mapping.writes())) {
      while (true) {
        GridDistributedCacheEntry<K, V> entry = (GridDistributedCacheEntry<K, V>) txEntry.cached();

        try {
          // Handle explicit locks.
          GridCacheVersion base =
              txEntry.explicitVersion() != null ? txEntry.explicitVersion() : xidVer;

          entry.doneRemote(xidVer, base, committedVers, rolledbackVers);

          if (ec()) entry.recheck();

          break;
        } catch (GridCacheEntryRemovedException ignored) {
          assert entry.obsoleteVersion() != null;

          if (log.isDebugEnabled())
            log.debug(
                "Replacing obsolete entry in remote transaction [entry="
                    + entry
                    + ", tx="
                    + this
                    + ']');

          // Replace the entry.
          txEntry.cached(cctx.cache().entryEx(txEntry.key()), entry.keyBytes());
        }
      }
    }
  }
Beispiel #2
0
  /** @param keyMap Key map to register. */
  void addKeyMapping(Map<GridRichNode, Collection<K>> keyMap) {
    for (Map.Entry<GridRichNode, Collection<K>> mapping : keyMap.entrySet()) {
      GridRichNode n = mapping.getKey();

      for (K key : mapping.getValue()) {
        GridCacheTxEntry<K, V> txEntry = txMap.get(key);

        assert txEntry != null;

        GridDistributedTxMapping<K, V> m = mappings.get(n.id());

        if (m == null) mappings.put(n.id(), m = new GridDistributedTxMapping<K, V>(n));

        txEntry.nodeId(n.id());

        m.add(txEntry);
      }
    }

    if (log.isDebugEnabled())
      log.debug(
          "Added mappings to transaction [locId="
              + cctx.nodeId()
              + ", mappings="
              + keyMap
              + ", tx="
              + this
              + ']');
  }
Beispiel #3
0
  /**
   * @param nodeId Node ID.
   * @param dhtVer DHT version.
   */
  void addDhtVersion(UUID nodeId, GridCacheVersion dhtVer) {
    // This step is very important as near and DHT versions grow separately.
    cctx.versions().onReceived(nodeId, dhtVer);

    GridDistributedTxMapping<K, V> m = mappings.get(nodeId);

    if (m != null) m.dhtVersion(dhtVer);
  }
  /**
   * @param entry Transaction entry.
   * @param nodes Nodes.
   */
  private void map(GridCacheTxEntry<K, V> entry, Collection<GridRichNode> nodes) {
    GridRichNode primary = CU.primary0(cctx.affinity(entry.key(), nodes));

    GridDistributedTxMapping<K, V> t = mappings.get(primary.id());

    if (t == null) mappings.put(primary.id(), t = new GridDistributedTxMapping<K, V>(primary));

    t.add(entry);
  }
Beispiel #5
0
  /**
   * @param nodeId Node ID to mark with explicit lock.
   * @return {@code True} if mapping was found.
   */
  boolean markExplicit(UUID nodeId) {
    GridDistributedTxMapping<K, V> m = mappings.get(nodeId);

    if (m != null) {
      m.markExplicitLock();

      return true;
    }

    return false;
  }
Beispiel #6
0
  /**
   * @param nodeId Node ID.
   * @param key Key.
   */
  public void removeMapping(UUID nodeId, K key) {
    GridDistributedTxMapping<K, V> m = mappings.get(nodeId);

    if (m != null) {
      GridCacheTxEntry<K, V> txEntry = txMap.get(key);

      if (txEntry != null) m.removeEntry(txEntry);

      if (m.empty()) mappings.remove(nodeId);
    }
  }
  /** @param m Mapping. */
  @SuppressWarnings({"unchecked"})
  private void finish(GridDistributedTxMapping<K, V> m) {
    GridRichNode n = m.node();

    assert !m.empty();

    GridNearTxFinishRequest req =
        new GridNearTxFinishRequest<K, V>(
            futId,
            tx.xidVersion(),
            tx.commitVersion(),
            tx.threadId(),
            commit,
            tx.isInvalidate(),
            m.explicitLock(),
            tx.topologyVersion(),
            null,
            null,
            null,
            commit && tx.pessimistic() ? m.writes() : null,
            tx.syncCommit() && commit || tx.syncRollback() && !commit);

    // If this is the primary node for the keys.
    if (n.isLocal()) {
      req.miniId(GridUuid.randomUuid());

      if (CU.DHT_ENABLED) {
        GridFuture<GridCacheTx> fut =
            commit ? dht().commitTx(n.id(), req) : dht().rollbackTx(n.id(), req);

        // Add new future.
        add(fut);
      } else
        // Add done future for testing.
        add(new GridFinishedFuture<GridCacheTx>(ctx));
    } else {
      MiniFuture fut = new MiniFuture(m);

      req.miniId(fut.futureId());

      add(fut); // Append new future.

      try {
        cctx.io().send(n, req);

        // If we don't wait for result, then mark future as done.
        if (!isSync() && !m.explicitLock()) fut.onDone();
      } catch (GridTopologyException e) {
        // Remove previous mapping.
        mappings.remove(m.node().id());

        fut.onResult(e);
      } catch (GridException e) {
        // Fail the whole thing.
        fut.onResult(e);
      }
    }
  }
 /** @return Node ID. */
 public GridRichNode node() {
   return m.node();
 }