org.apache.ignite.Ignite.affinity()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(5.9k)|赞(0)|评价(0)|浏览(230)

本文整理了Java中org.apache.ignite.Ignite.affinity()方法的一些代码示例,展示了Ignite.affinity()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ignite.affinity()方法的具体详情如下:
包路径:org.apache.ignite.Ignite
类名称:Ignite
方法名:affinity

Ignite.affinity介绍

[英]Gets affinity service to provide information about data partitioning and distribution.
[中]获取关联服务以提供有关数据分区和分发的信息。

代码示例

代码示例来源:origin: apache/ignite

/**
   * @return Affinity.
   */
  protected Affinity<K> affinity() {
    return ignite.affinity(cacheName);
  }
}

代码示例来源:origin: apache/ignite

/**
 * @param ignite Grid.
 * @return Affinity.
 */
static Affinity<Object> affinity(Ignite ignite) {
  return ignite.affinity(DEFAULT_CACHE_NAME);
}

代码示例来源:origin: apache/ignite

/**
 * @param g Grid.
 * @return Affinity.
 */
private Affinity<Object> affinity(Ignite g) {
  return g.affinity(DEFAULT_CACHE_NAME);
}

代码示例来源:origin: apache/ignite

/**
 * @param ignite Grid.
 * @return Affinity.
 */
static Affinity<Object> affinity(Ignite ignite) {
  return ignite.affinity(DEFAULT_CACHE_NAME);
}

代码示例来源:origin: apache/ignite

/**
 * @param entries Entries.
 * @param g Grid.
 * @return Affinity nodes.
 */
private Set<UUID> affinityNodes(Iterable<Cache.Entry<Integer, Integer>> entries, Ignite g) {
  Set<UUID> nodes = new HashSet<>();
  for (Cache.Entry<Integer, Integer> entry : entries)
    nodes.add(g.affinity(DEFAULT_CACHE_NAME).mapKeyToPrimaryAndBackups(entry.getKey()).iterator().next().id());
  return nodes;
}

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
  @Override public boolean apply(CacheEvent evt) {
    Affinity<Object> affinity = ignite.affinity(cacheName);
    if (affinity.isPrimary(ignite.cluster().localNode(), evt.key())) {
      // Process this event. Ignored on backups.
      if (filter != null && filter.apply(evt))
        return false;
      return true;
    }
    return false;
  }
}

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
  @Override public boolean apply(CacheEvent evt) {
    Affinity<Object> affinity = ignite.affinity(cacheName);

    // Process this event. Ignored on backups.
    return affinity.isPrimary(ignite.cluster().localNode(), evt.key()) &&
        (filter == null || filter.apply(evt));
  }
}

代码示例来源:origin: apache/ignite

/**
 * @param cacheName Cache name.
 */
private int mapped(String cacheName) {
  int mapped = 0;
  ClusterGroup srvs = ignite.cluster().forServers();
  Collection<ClusterNode> nodes = srvs.forDataNodes(cacheName).nodes();
  for (ClusterNode node : nodes)
    mapped += ignite.affinity(cacheName).primaryPartitions(node).length;
  return mapped;
}

代码示例来源:origin: apache/ignite

/** Constructor */
AffinityKeyGenerator(Ignite node, String cacheName) {
  this.affinity = node.affinity(cacheName);
  this.node = node.cluster().localNode();
}

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
@Override protected Object executeJob(int gridSize, String arg) {
  A.notNull(arg, "task argument");
  String[] split = arg.split(":", 2);
  A.ensure(split.length == 2, "Task argument should have format 'cacheName:affinityKey'.");
  String cacheName = split[0];
  String affKey = split[1];
  if ("null".equals(cacheName))
    cacheName = null;
  ClusterNode node = ignite.affinity(cacheName).mapKeyToNode(affKey);
  return node.id().toString();
}

代码示例来源:origin: apache/ignite

@Override public boolean apply() {
    // Partition count which must be transferred to 2'nd node.
    int parts = ignite2.affinity(DEFAULT_CACHE_NAME).allPartitions(ignite2.cluster().localNode()).length;
    return evtCnt.get() >= parts;
  }
}, 5000);

代码示例来源:origin: apache/ignite

@Override public boolean apply() {
    // Partition count which must be transferred to 2'nd node.
    int parts = ignite2.affinity(DEFAULT_CACHE_NAME).allPartitions(ignite2.cluster().localNode()).length;
    return evtCnt.get() >= parts;
  }
}, 5000);

代码示例来源:origin: apache/ignite

/** */
private static int keyInSamePartition(Ignite ignite, String cacheName, int key) {
  Affinity<Object> affinity = ignite.affinity(cacheName);
  return IntStream.iterate(key + 1, i -> i + 1)
    .filter(i -> affinity.partition(i) == affinity.partition(key))
    .findFirst().getAsInt();
}

代码示例来源:origin: apache/ignite

/** */
  private static int keyInDifferentPartition(Ignite ignite, String cacheName, int key) {
    Affinity<Object> affinity = ignite.affinity(cacheName);

    return IntStream.iterate(key + 1, i -> i + 1)
      .filter(i -> affinity.partition(i) != affinity.partition(key))
      .findFirst().getAsInt();
  }
}

代码示例来源:origin: apache/ignite

@Override public boolean apply(final Ignite ignite) {
    Collection<ClusterNode> srvs = ignite.cluster().forServers().nodes();
    if (srvs.size() < serverCount())
      return false;
    for (ClusterNode node : srvs) {
      int[] primaries = ignite.affinity(CACHE_NAME).primaryPartitions(node);
      if (primaries == null || primaries.length == 0)
        return false;
    }
    return true;
  }
};

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
  @Override public void applyx() throws IgniteCheckedException {
    assert ignite.cluster().localNode().id().equals(ignite.affinity(DEFAULT_CACHE_NAME).mapKeyToNode(affKey).id());
    assert ignite.cluster().localNode().id().equals(ignite.affinity(DEFAULT_CACHE_NAME).mapKeyToNode(key).id());
  }
}

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
  @Override public Object call() throws IgniteCheckedException {
    assert ignite.cluster().localNode().id().equals(ignite.affinity(DEFAULT_CACHE_NAME).mapKeyToNode(affKey).id());
    assert ignite.cluster().localNode().id().equals(ignite.affinity(DEFAULT_CACHE_NAME).mapKeyToNode(key).id());
    return null;
  }
}

代码示例来源:origin: apache/ignite

/** @throws Exception If failed. */
@Test
public void testAffinity() throws Exception {
  waitTopologyUpdate();
  Ignite g0 = grid(0);
  Ignite g1 = grid(1);
  for (int i = 0; i < 100; i++)
    assertEquals(g0.affinity(DEFAULT_CACHE_NAME).mapKeyToNode(i).id(), g1.affinity(DEFAULT_CACHE_NAME).mapKeyToNode(i).id());
}

代码示例来源:origin: apache/ignite

@Override public IgniteFuture<?> applyx(ClusterGroup prj) {
    Affinity<Object> aff = prj.ignite().affinity(DEFAULT_CACHE_NAME);
    ClusterNode node = F.first(prj.nodes());
    return compute(prj).affinityRunAsync(DEFAULT_CACHE_NAME, keyForNode(aff, node), new TestRunnable());
  }
});

代码示例来源:origin: apache/ignite

@Override public IgniteFuture<?> applyx(ClusterGroup prj) {
    Affinity<Object> aff = prj.ignite().affinity(DEFAULT_CACHE_NAME);
    ClusterNode node = F.first(prj.nodes());
    return compute(prj).affinityCallAsync(DEFAULT_CACHE_NAME, keyForNode(aff, node), new TestCallable());
  }
});

相关文章