/**
   * Entries for key.
   *
   * @param key Key.
   * @return Entries.
   * @throws IgniteCheckedException If failed.
   */
  private String entries(int key) throws IgniteCheckedException {
    if (partitioned()) {
      GridNearCacheAdapter<Integer, String> near1 = near(1);
      GridNearCacheAdapter<Integer, String> near2 = near(2);

      GridDhtCacheAdapter<Integer, String> dht1 = dht(1);
      GridDhtCacheAdapter<Integer, String> dht2 = dht(2);

      return "Entries [ne1="
          + near1.peekEx(key)
          + ", de1="
          + dht1.peekEx(key)
          + ", ne2="
          + near2.peekEx(key)
          + ", de2="
          + dht2.peekEx(key)
          + ']';
    }

    return "Entries [e1="
        + "("
        + key
        + ", "
        + ((IgniteKernal) ignite1).internalCache(null).get(key)
        + ")"
        + ", e2="
        + "("
        + key
        + ", "
        + ((IgniteKernal) ignite2).internalCache(null).get(key)
        + ")"
        + ']';
  }
Example #2
0
 /** {@inheritDoc} */
 @Override
 protected IgniteInternalFuture<Boolean> lockAllAsync(
     Collection<KeyCacheObject> keys,
     long timeout,
     @Nullable IgniteTxLocalEx tx,
     boolean isInvalidate,
     boolean isRead,
     boolean retval,
     @Nullable TransactionIsolation isolation,
     long accessTtl) {
   return dht.lockAllAsync(null, timeout);
 }
Example #3
0
 /** {@inheritDoc} */
 @SuppressWarnings("unchecked")
 @Override
 public IgniteInternalFuture<Boolean> removeAsync(K key, @Nullable CacheEntryPredicate... filter) {
   return dht.removeAsync(key, filter);
 }
Example #4
0
 /** {@inheritDoc} */
 @SuppressWarnings("unchecked")
 @Override
 public IgniteInternalFuture<GridCacheReturn> removexAsync(K key, V val) {
   return dht.removexAsync(key, val);
 }
Example #5
0
 /** {@inheritDoc} */
 @Override
 public IgniteInternalFuture<?> removeAllAsync(Collection<? extends K> keys) {
   return dht.removeAllAsync(keys);
 }
Example #6
0
 /** {@inheritDoc} */
 @Override
 public IgniteInternalFuture<?> removeAllConflictAsync(Map<KeyCacheObject, GridCacheVersion> drMap)
     throws IgniteCheckedException {
   return dht.removeAllConflictAsync(drMap);
 }
Example #7
0
 /** {@inheritDoc} */
 @Override
 public void putAll(Map<? extends K, ? extends V> m) throws IgniteCheckedException {
   dht.putAll(m);
 }
Example #8
0
 /** {@inheritDoc} */
 @Override
 public void removeAll() throws IgniteCheckedException {
   dht.removeAll();
 }
Example #9
0
 /** {@inheritDoc} */
 @Override
 public IgniteInternalFuture<?> localRemoveAll(CacheEntryPredicate filter) {
   return dht.localRemoveAll(filter);
 }
Example #10
0
 /** {@inheritDoc} */
 @Override
 public <T> IgniteInternalFuture<Map<K, EntryProcessorResult<T>>> invokeAllAsync(
     Map<? extends K, ? extends EntryProcessor<K, V, T>> map, Object... args) {
   return dht.invokeAllAsync(map, args);
 }
Example #11
0
 /** {@inheritDoc} */
 @Override
 public <T> IgniteInternalFuture<EntryProcessorResult<T>> invokeAsync(
     K key, EntryProcessor<K, V, T> entryProcessor, Object... args)
     throws EntryProcessorException {
   return dht.invokeAsync(key, entryProcessor, args);
 }
Example #12
0
 /** {@inheritDoc} */
 @Override
 public <T> EntryProcessorResult<T> invoke(
     K key, EntryProcessor<K, V, T> entryProcessor, Object... args) throws IgniteCheckedException {
   return dht.invoke(key, entryProcessor, args);
 }
Example #13
0
 /** {@inheritDoc} */
 @Override
 public <T> Map<K, EntryProcessorResult<T>> invokeAll(
     Set<? extends K> keys, EntryProcessor<K, V, T> entryProcessor, Object... args)
     throws IgniteCheckedException {
   return dht.invokeAll(keys, entryProcessor, args);
 }
Example #14
0
 /** {@inheritDoc} */
 @Override
 public IgniteInternalFuture<?> putAllConflictAsync(Map<KeyCacheObject, GridCacheDrInfo> drMap)
     throws IgniteCheckedException {
   return dht.putAllConflictAsync(drMap);
 }
Example #15
0
 /** {@inheritDoc} */
 @Override
 public void putAllConflict(Map<KeyCacheObject, GridCacheDrInfo> drMap)
     throws IgniteCheckedException {
   dht.putAllConflict(drMap);
 }
Example #16
0
 /** {@inheritDoc} */
 @Override
 public IgniteInternalFuture<?> putAllAsync(Map<? extends K, ? extends V> m) {
   return dht.putAllAsync(m);
 }
Example #17
0
 /** {@inheritDoc} */
 @Override
 public boolean remove(K key, V val) throws IgniteCheckedException {
   return dht.remove(key, val);
 }
Example #18
0
 /** {@inheritDoc} */
 @Override
 public <T> Map<K, EntryProcessorResult<T>> invokeAll(
     Map<? extends K, ? extends EntryProcessor<K, V, T>> map, Object... args)
     throws IgniteCheckedException {
   return dht.invokeAllAsync(map, args).get();
 }
Example #19
0
 /** {@inheritDoc} */
 @Override
 public IgniteInternalFuture<Boolean> removeAsync(K key, V val) {
   return dht.removeAsync(key, val);
 }
Example #20
0
 /** {@inheritDoc} */
 @Override
 public <T> IgniteInternalFuture<Map<K, EntryProcessorResult<T>>> invokeAllAsync(
     Set<? extends K> keys, EntryProcessor<K, V, T> entryProcessor, Object... args) {
   return dht.invokeAllAsync(keys, entryProcessor, args);
 }
Example #21
0
 /** {@inheritDoc} */
 @Override
 public IgniteInternalFuture<?> removeAllAsync() {
   return dht.removeAllAsync();
 }
Example #22
0
 /** {@inheritDoc} */
 @Override
 public void unlockAll(@Nullable Collection<? extends K> keys) throws IgniteCheckedException {
   dht.unlockAll(keys);
 }
Example #23
0
 /** {@inheritDoc} */
 @Override
 public void removeAllConflict(Map<KeyCacheObject, GridCacheVersion> drMap)
     throws IgniteCheckedException {
   dht.removeAllConflict(drMap);
 }
Example #24
0
  /**
   * @param ignite Grid.
   * @param cacheName Cache name.
   * @param sample Sample size.
   * @return Data transfer object for given cache.
   * @throws IgniteCheckedException If failed to create data transfer object.
   */
  public VisorCache from(IgniteEx ignite, String cacheName, int sample)
      throws IgniteCheckedException {
    assert ignite != null;

    GridCacheAdapter ca = ignite.context().cache().internalCache(cacheName);

    // Cache was not started.
    if (ca == null || !ca.context().started()) return null;

    name = cacheName;

    try {
      swapSize = ca.swapSize();
      swapKeys = ca.swapKeys();
    } catch (IgniteCheckedException ignored) {
      swapSize = -1;
      swapKeys = -1;
    }

    primaryPartitions = Collections.emptyList();
    backupPartitions = Collections.emptyList();

    CacheConfiguration cfg = ca.configuration();

    mode = cfg.getCacheMode();

    boolean partitioned =
        (mode == CacheMode.PARTITIONED || mode == CacheMode.REPLICATED)
            && ca.context().affinityNode();

    if (partitioned) {
      GridDhtCacheAdapter dca = null;

      if (ca instanceof GridNearCacheAdapter) dca = ((GridNearCacheAdapter) ca).dht();
      else if (ca instanceof GridDhtCacheAdapter) dca = (GridDhtCacheAdapter) ca;

      if (dca != null) {
        GridDhtPartitionTopology top = dca.topology();

        if (cfg.getCacheMode() != CacheMode.LOCAL && cfg.getBackups() > 0) {
          GridDhtPartitionMap2 map2 = top.localPartitionMap();

          partitionsMap = new GridDhtPartitionMap(map2.nodeId(), map2.updateSequence(), map2.map());
        }

        List<GridDhtLocalPartition> parts = top.localPartitions();

        primaryPartitions = new ArrayList<>(parts.size());
        backupPartitions = new ArrayList<>(parts.size());

        for (GridDhtLocalPartition part : parts) {
          int p = part.id();

          int sz = part.size();

          // Pass -1 as topology version in order not to wait for topology version.
          if (part.primary(AffinityTopologyVersion.NONE))
            primaryPartitions.add(new IgnitePair<>(p, sz));
          else if (part.state() == GridDhtPartitionState.OWNING
              && part.backup(AffinityTopologyVersion.NONE))
            backupPartitions.add(new IgnitePair<>(p, sz));
        }
      } else {
        // Old way of collecting partitions info.
        ClusterNode node = ignite.cluster().localNode();

        int[] pp = ca.affinity().primaryPartitions(node);

        primaryPartitions = new ArrayList<>(pp.length);

        for (int p : pp) {
          Set set = ca.entrySet(p);

          primaryPartitions.add(new IgnitePair<>(p, set != null ? set.size() : 0));
        }

        int[] bp = ca.affinity().backupPartitions(node);

        backupPartitions = new ArrayList<>(bp.length);

        for (int p : bp) {
          Set set = ca.entrySet(p);

          backupPartitions.add(new IgnitePair<>(p, set != null ? set.size() : 0));
        }
      }
    }

    size = ca.size();
    nearSize = ca.nearSize();

    dynamicDeploymentId = ca.context().dynamicDeploymentId();
    dhtSize = size - nearSize;
    primarySize = ca.primarySize();
    offHeapAllocatedSize = ca.offHeapAllocatedSize();
    offHeapEntriesCnt = ca.offHeapEntriesCount();
    partitions = ca.affinity().partitions();
    metrics = VisorCacheMetrics.from(ignite, cacheName);

    estimateMemorySize(ignite, ca, sample);

    return this;
  }
Example #25
0
 /** {@inheritDoc} */
 @Override
 public V getAndRemove(K key) throws IgniteCheckedException {
   return dht.getAndRemove(key);
 }
Example #26
0
 /** {@inheritDoc} */
 @SuppressWarnings("unchecked")
 @Override
 public IgniteInternalFuture<GridCacheReturn> replacexAsync(K key, V oldVal, V newVal) {
   return dht.replacexAsync(key, oldVal, newVal);
 }
Example #27
0
 /** {@inheritDoc} */
 @SuppressWarnings("unchecked")
 @Override
 public IgniteInternalFuture<V> getAndRemoveAsync(K key) {
   return dht.getAndRemoveAsync(key);
 }
Example #28
0
 /** {@inheritDoc} */
 @Override
 public void removeAll(Collection<? extends K> keys) throws IgniteCheckedException {
   dht.removeAll(keys);
 }
  /** @throws InterruptedException If interrupted. */
  @SuppressWarnings("BusyWait")
  protected void awaitPartitionMapExchange() throws InterruptedException {
    for (Ignite g : G.allGrids()) {
      IgniteKernal g0 = (IgniteKernal) g;

      for (IgniteCacheProxy<?, ?> c : g0.context().cache().jcaches()) {
        CacheConfiguration cfg = c.context().config();

        if (cfg.getCacheMode() == PARTITIONED
            && cfg.getRebalanceMode() != NONE
            && g.cluster().nodes().size() > 1) {
          AffinityFunction aff = cfg.getAffinity();

          GridDhtCacheAdapter<?, ?> dht = dht(c);

          GridDhtPartitionTopology top = dht.topology();

          for (int p = 0; p < aff.partitions(); p++) {
            long start = 0;

            for (int i = 0; ; i++) {
              boolean match = false;

              AffinityTopologyVersion readyVer =
                  dht.context().shared().exchange().readyAffinityVersion();

              if (readyVer.topologyVersion() > 0 && c.context().started()) {
                // Must map on updated version of topology.
                Collection<ClusterNode> affNodes =
                    g0.affinity(cfg.getName()).mapPartitionToPrimaryAndBackups(p);

                int exp = affNodes.size();

                GridDhtTopologyFuture topFut = top.topologyVersionFuture();

                Collection<ClusterNode> owners =
                    (topFut != null && topFut.isDone())
                        ? top.nodes(p, AffinityTopologyVersion.NONE)
                        : Collections.<ClusterNode>emptyList();

                int actual = owners.size();

                if (affNodes.size() != owners.size() || !affNodes.containsAll(owners)) {
                  LT.warn(
                      log(),
                      null,
                      "Waiting for topology map update ["
                          + "grid="
                          + g.name()
                          + ", cache="
                          + cfg.getName()
                          + ", cacheId="
                          + dht.context().cacheId()
                          + ", topVer="
                          + top.topologyVersion()
                          + ", topFut="
                          + topFut
                          + ", p="
                          + p
                          + ", affNodesCnt="
                          + exp
                          + ", ownersCnt="
                          + actual
                          + ", affNodes="
                          + affNodes
                          + ", owners="
                          + owners
                          + ", locNode="
                          + g.cluster().localNode()
                          + ']');
                } else match = true;
              } else {
                LT.warn(
                    log(),
                    null,
                    "Waiting for topology map update ["
                        + "grid="
                        + g.name()
                        + ", cache="
                        + cfg.getName()
                        + ", cacheId="
                        + dht.context().cacheId()
                        + ", topVer="
                        + top.topologyVersion()
                        + ", started="
                        + dht.context().started()
                        + ", p="
                        + p
                        + ", readVer="
                        + readyVer
                        + ", locNode="
                        + g.cluster().localNode()
                        + ']');
              }

              if (!match) {
                if (i == 0) start = System.currentTimeMillis();

                if (System.currentTimeMillis() - start > 30_000)
                  throw new IgniteException(
                      "Timeout of waiting for topology map update ["
                          + "grid="
                          + g.name()
                          + ", cache="
                          + cfg.getName()
                          + ", cacheId="
                          + dht.context().cacheId()
                          + ", topVer="
                          + top.topologyVersion()
                          + ", p="
                          + p
                          + ", readVer="
                          + readyVer
                          + ", locNode="
                          + g.cluster().localNode()
                          + ']');

                Thread.sleep(200); // Busy wait.

                continue;
              }

              if (i > 0)
                log()
                    .warning(
                        "Finished waiting for topology map update [grid="
                            + g.name()
                            + ", p="
                            + p
                            + ", duration="
                            + (System.currentTimeMillis() - start)
                            + "ms]");

              break;
            }
          }
        }
      }
    }
  }
Example #30
0
 /** {@inheritDoc} */
 @Override
 public GridCacheReturn replacex(K key, V oldVal, V newVal) throws IgniteCheckedException {
   return dht.replacex(key, oldVal, newVal);
 }