/** @return Nodes to execute on. */
  private Collection<GridNode> nodes() {
    GridCacheMode cacheMode = cctx.config().getCacheMode();

    switch (cacheMode) {
      case LOCAL:
        if (prj != null)
          U.warn(
              log,
              "Ignoring query projection because it's executed over LOCAL cache "
                  + "(only local node will be queried): "
                  + this);

        return Collections.singletonList(cctx.localNode());

      case REPLICATED:
        if (prj != null) return nodes(cctx, prj);

        GridCacheDistributionMode mode = cctx.config().getDistributionMode();

        return mode == PARTITIONED_ONLY || mode == NEAR_PARTITIONED
            ? Collections.singletonList(cctx.localNode())
            : Collections.singletonList(F.rand(nodes(cctx, null)));

      case PARTITIONED:
        return nodes(cctx, prj);

      default:
        throw new IllegalStateException("Unknown cache distribution mode: " + cacheMode);
    }
  }
Ejemplo n.º 2
0
  /**
   * Creates node predicate that evaluates to {@code true} for all provided nodes. Implementation
   * will make a defensive copy.
   *
   * @param nodes Optional grid nodes. If none provided - predicate will always return {@code
   *     false}.
   */
  public GridNodePredicate(@Nullable GridNode... nodes) {
    if (F.isEmpty(nodes)) ids = Collections.emptySet();
    else if (nodes.length == 1) ids = Collections.singleton(nodes[0].id());
    else {
      ids = new HashSet<>(nodes.length);

      for (GridNode n : nodes) ids.add(n.id());
    }
  }
Ejemplo n.º 3
0
  /**
   * Creates node predicate that evaluates to {@code true} for all provided node IDs. Implementation
   * will make a defensive copy.
   *
   * @param ids Optional node IDs. If none provided - predicate will always return {@code false}.
   */
  public GridNodePredicate(@Nullable UUID... ids) {
    if (F.isEmpty(ids)) this.ids = Collections.emptySet();
    else if (ids.length == 1) this.ids = Collections.singleton(ids[0]);
    else {
      this.ids = new HashSet<>(ids.length);

      Collections.addAll(this.ids, ids);
    }
  }
  /**
   * Creates node shadow adapter.
   *
   * @param node Node.
   */
  GridDiscoveryNodeShadowAdapter(GridNode node) {
    assert node != null;

    created = U.currentTimeMillis();
    id = node.id();
    attrs = Collections.unmodifiableMap(node.attributes());
    addrs = Collections.unmodifiableCollection(node.addresses());
    hostNames = Collections.unmodifiableCollection(node.hostNames());
    order = node.order();
    lastMetrics = node.metrics();
    daemon = "true".equalsIgnoreCase(this.<String>attribute(ATTR_DAEMON));
  }
  /**
   * Test file creation.
   *
   * @throws Exception In case of exception.
   */
  public void testCreateFile() throws Exception {
    GridGgfsPath root = new GridGgfsPath("/");
    GridGgfsPath path = new GridGgfsPath("/asdf");

    long max = 100L * CFG_BLOCK_SIZE / WRITING_THREADS_CNT;

    for (long size = 0; size <= max; size = size * 15 / 10 + 1) {
      assertEquals(Collections.<GridGgfsPath>emptyList(), fs.listPaths(root));

      testCreateFile(path, size, new Random().nextInt());
    }
  }
Ejemplo n.º 6
0
  /**
   * Parses HTTP parameters in an appropriate format and return back map of values to predefined
   * list of names.
   *
   * @param req Request.
   * @return Map of parsed parameters.
   */
  @SuppressWarnings({"unchecked"})
  private Map<String, Object> parameters(ServletRequest req) {
    Map<String, String[]> params = req.getParameterMap();

    if (F.isEmpty(params)) return Collections.emptyMap();

    Map<String, Object> map = U.newHashMap(params.size());

    for (Map.Entry<String, String[]> entry : params.entrySet())
      map.put(entry.getKey(), parameter(entry.getValue()));

    return map;
  }
Ejemplo n.º 7
0
 /** @return Near keys. */
 public List<byte[]> nearKeyBytes() {
   return nearKeyBytes != null ? nearKeyBytes : Collections.<byte[]>emptyList();
 }
 /**
  * Gets read-only view on internal {@code FIFO} queue in proper order.
  *
  * @return Read-only view ono internal {@code 'FIFO'} queue.
  */
 public Collection<GridCacheEntry<K, V>> queue() {
   return Collections.unmodifiableCollection(queue);
 }
Ejemplo n.º 9
0
 /** @return Collection of recovery writes. */
 public Collection<GridCacheTxEntry<K, V>> recoveryWrites() {
   return recoveryWrites == null
       ? Collections.<GridCacheTxEntry<K, V>>emptyList()
       : recoveryWrites;
 }
Ejemplo n.º 10
0
 /** @return Candidates map. */
 Map<K, Collection<GridCacheDgcLockCandidate>> candidatesMap() {
   return Collections.unmodifiableMap(map);
 }
Ejemplo n.º 11
0
 /** @return Node class loader participant map. */
 public Map<UUID, GridUuid> loaderParticipants() {
   return ldrParties != null ? Collections.unmodifiableMap(ldrParties) : null;
 }
Ejemplo n.º 12
0
 /**
  * Creates node predicate that evaluates to {@code true} for all provided node IDs. Implementation
  * will make a defensive copy.
  *
  * @param ids Optional node IDs. If none provided - predicate will always return {@code false}.
  */
 public GridNodePredicate(@Nullable Collection<UUID> ids) {
   this.ids =
       F.isEmpty(ids)
           ? Collections.<UUID>emptySet()
           : ids.size() == 1 ? Collections.singleton(F.first(ids)) : new HashSet<>(ids);
 }
  /** Initializes future. */
  public void prepare() {
    if (log.isDebugEnabled())
      log.debug("Checking if transaction was committed on remote nodes: " + tx);

    // Check local node first (local node can be a backup node for some part of this transaction).
    long originatingThreadId = tx.threadId();

    if (tx instanceof GridCacheTxRemoteEx)
      originatingThreadId = ((GridCacheTxRemoteEx) tx).remoteThreadId();

    GridCacheCommittedTxInfo<K, V> txInfo =
        cctx.tm().txCommitted(tx.nearXidVersion(), tx.eventNodeId(), originatingThreadId);

    if (txInfo != null) {
      onDone(txInfo);

      markInitialized();

      return;
    }

    Collection<GridNode> checkNodes = CU.remoteNodes(cctx, tx.topologyVersion());

    if (tx instanceof GridDhtTxRemote) {
      // If we got primary node failure and near node has not failed.
      if (tx.nodeId().equals(failedNodeId) && !tx.eventNodeId().equals(failedNodeId)) {
        nearCheck = true;

        GridNode nearNode = cctx.discovery().node(tx.eventNodeId());

        if (nearNode == null) {
          // Near node failed, separate check prepared future will take care of it.
          onDone(
              new GridTopologyException(
                  "Failed to check near transaction state (near node left grid): "
                      + tx.eventNodeId()));

          return;
        }

        checkNodes = Collections.singletonList(nearNode);
      }
    }

    for (GridNode rmtNode : checkNodes) {
      // Skip left nodes and local node.
      if (rmtNode.id().equals(failedNodeId)) continue;

      /*
       * Send message to all cache nodes in the topology.
       */

      MiniFuture fut = new MiniFuture(rmtNode.id());

      GridCachePessimisticCheckCommittedTxRequest<K, V> req =
          new GridCachePessimisticCheckCommittedTxRequest<>(
              tx, originatingThreadId, futureId(), fut.futureId());

      add(fut);

      try {
        cctx.io().send(rmtNode.id(), req);
      } catch (GridTopologyException ignored) {
        fut.onNodeLeft();
      } catch (GridException e) {
        fut.onError(e);

        break;
      }
    }

    markInitialized();
  }