/** {@inheritDoc} */ @Override public List<List<ClusterNode>> assignPartitions(AffinityFunctionContext affCtx) { return delegate.assignPartitions(affCtx); }
/** {@inheritDoc} */ @Override public List<List<ClusterNode>> assignPartitions(AffinityFunctionContext affCtx) { List<List<ClusterNode>> res0 = delegate.assignPartitions(affCtx); List<List<ClusterNode>> res = new ArrayList<>(res0.size()); for (int p = 0; p < res0.size(); p++) res.add(p, null); for (int p = 0; p < res0.size(); p++) res.set(partsAffMapping.get(p), res0.get(p)); return res; }
/** {@inheritDoc} */ @Override public void processOutStream(int type, BinaryRawWriterEx writer) throws IgniteCheckedException { if (type == OP_ASSIGN_PARTITIONS) { AffinityFunctionContext affCtx = currentAffCtx.get(); if (affCtx == null) throw new IgniteException("Thread-local AffinityFunctionContext is null. " + "This may indicate an unsupported call to the base AffinityFunction."); final List<List<ClusterNode>> partitions = baseFunc.assignPartitions(affCtx); PlatformAffinityUtils.writePartitionAssignment(partitions, writer, platformContext()); return; } super.processOutStream(type, writer); }
/** * @param aff Affinity function. * @param part Partition. * @param nodes Topology nodes. * @return Affinity nodes for partition. */ private Collection<ClusterNode> nodes(AffinityFunction aff, int part, Collection<ClusterNode> nodes) { List<List<ClusterNode>> assignment = aff.assignPartitions( new GridAffinityFunctionContextImpl(new ArrayList<>(nodes), null, null, new AffinityTopologyVersion(1), BACKUP_CNT)); return assignment.get(part); } }
info("======================================"); List<List<ClusterNode>> assignment = aff.assignPartitions( new GridAffinityFunctionContextImpl(nodes, prev, discoEvt, new AffinityTopologyVersion(i), backups));
/** * JUnit. * * @throws Exception If failed. */ @Test public void testMapPartitionsToNodeCollection() throws Exception { Collection<Integer> parts = new LinkedList<>(); for (int p = 0; p < affinity().partitions(); p++) parts.add(p); Map<Integer, ClusterNode> map = grid(0).affinity(DEFAULT_CACHE_NAME).mapPartitionsToNodes(parts); AffinityFunctionContext ctx = new GridAffinityFunctionContextImpl(new ArrayList<>(grid(0).cluster().nodes()), null, null, new AffinityTopologyVersion(1), 1); AffinityFunction aff = affinity(); List<List<ClusterNode>> assignment = aff.assignPartitions(ctx); for (Map.Entry<Integer, ClusterNode> e : map.entrySet()) assert F.eqNodes(F.first(nodes(assignment, aff, e.getKey())), e.getValue()); }
else if (hasBaseline && !changedBaseline) { if (baselineAssignment == null) baselineAssignment = aff.assignPartitions(new GridAffinityFunctionContextImpl( discoCache.state().baselineTopology().createBaselineView(sorted, nodeFilter), prevAssignment, events.lastEvent(), topVer, backups)); baselineAssignment = aff.assignPartitions(new GridAffinityFunctionContextImpl( discoCache.state().baselineTopology().createBaselineView(sorted, nodeFilter), prevAssignment, events.lastEvent(), topVer, backups)); assignment = aff.assignPartitions(new GridAffinityFunctionContextImpl(sorted, prevAssignment, events.lastEvent(), topVer, backups)); baselineAssignment = aff.assignPartitions(new GridAffinityFunctionContextImpl( discoCache.state().baselineTopology().createBaselineView(sorted, nodeFilter), prevAssignment, event, topVer, backups)); assignment = aff.assignPartitions(new GridAffinityFunctionContextImpl(sorted, prevAssignment, event, topVer, backups));
/** * JUnit. * * @throws Exception If failed. */ @Test public void testMapPartitionsToNode() throws Exception { Map<Integer, ClusterNode> map = grid(0).affinity(DEFAULT_CACHE_NAME).mapPartitionsToNodes(F.asList(0, 1, 5, 19, 12)); AffinityFunctionContext ctx = new GridAffinityFunctionContextImpl(new ArrayList<>(grid(0).cluster().nodes()), null, null, new AffinityTopologyVersion(1), 1); AffinityFunction aff = affinity(); List<List<ClusterNode>> assignment = aff.assignPartitions(ctx); for (Map.Entry<Integer, ClusterNode> e : map.entrySet()) assert F.eqNodes(F.first(nodes(assignment, aff, e.getKey())), e.getValue()); }
/** * JUnit. * * @throws Exception If failed. */ @Test public void testMapPartitionsToNodeArray() throws Exception { Map<Integer, ClusterNode> map = grid(0).affinity(DEFAULT_CACHE_NAME).mapPartitionsToNodes(F.asList(0, 1, 5, 19, 12)); AffinityFunctionContext ctx = new GridAffinityFunctionContextImpl(new ArrayList<>(grid(0).cluster().nodes()), null, null, new AffinityTopologyVersion(1), 1); AffinityFunction aff = affinity(); List<List<ClusterNode>> assignment = aff.assignPartitions(ctx); for (Map.Entry<Integer, ClusterNode> e : map.entrySet()) assert F.eqNodes(F.first(nodes(assignment, aff, e.getKey())), e.getValue()); }
List<List<ClusterNode>> assignments = aff.assignPartitions(ctx);
/** * JUnit. * * @throws Exception If failed. */ @Test public void testBackupPartitions() throws Exception { // Pick 2 nodes and create a projection over them. ClusterNode n0 = grid(0).localNode(); // Get backup partitions without explicitly specified levels. int[] parts = grid(0).affinity(DEFAULT_CACHE_NAME).backupPartitions(n0); assert !F.isEmpty(parts); AffinityFunctionContext ctx = new GridAffinityFunctionContextImpl(new ArrayList<>(grid(0).cluster().nodes()), null, null, new AffinityTopologyVersion(1), 1); List<List<ClusterNode>> assignment = affinity().assignPartitions(ctx); for (int p : parts) { Collection<ClusterNode> owners = new ArrayList<>(nodes(assignment, p)); assert !F.isEmpty(owners); // Remove primary. Iterator<ClusterNode> iter = owners.iterator(); iter.next(); iter.remove(); assert owners.contains(n0); } }
cctx.config().getBackups()); List<List<ClusterNode>> calcAff1_0 = func.assignPartitions(ctx); cctx.config().getBackups()); List<List<ClusterNode>> calcAff2_0 = func.assignPartitions(ctx);
/** * JUnit. * * @throws Exception If failed. */ @Test public void testMapPartitionToNode() throws Exception { int part = RND.nextInt(affinity().partitions()); AffinityFunctionContext ctx = new GridAffinityFunctionContextImpl(new ArrayList<>(grid(0).cluster().nodes()), null, null, new AffinityTopologyVersion(1), 1); AffinityFunction aff = affinity(); List<List<ClusterNode>> assignment = aff.assignPartitions(ctx); assertEquals(F.first(nodes(assignment, aff, part)), grid(0).affinity(DEFAULT_CACHE_NAME).mapPartitionToNode(part)); }
/** * @param cache Cache. * @param nodes Nodes. */ private List<List<ClusterNode>> calcAffinity(IgniteCache<?, ?> cache, List<ClusterNode> nodes) { IgniteCacheProxyImpl proxy = cache.unwrap(IgniteCacheProxyImpl.class); GridCacheContext<?, ?> cctx = proxy.context(); AffinityFunction func = cctx.config().getAffinity(); AffinityFunctionContext ctx = new GridAffinityFunctionContextImpl( nodes, null, null, AffinityTopologyVersion.NONE, cctx.config().getBackups()); return func.assignPartitions(ctx); }
/** * JUnit. * * @throws Exception If failed. */ @Test public void testAllPartitions() throws Exception { // Pick 2 nodes and create a projection over them. ClusterNode n0 = grid(0).localNode(); int[] parts = grid(0).affinity(DEFAULT_CACHE_NAME).allPartitions(n0); assert !F.isEmpty(parts); AffinityFunctionContext ctx = new GridAffinityFunctionContextImpl(new ArrayList<>(grid(0).cluster().nodes()), null, null, new AffinityTopologyVersion(1), 1); List<List<ClusterNode>> assignment = affinity().assignPartitions(ctx); for (int p : parts) { Collection<ClusterNode> owners = nodes(assignment, p); assert !F.isEmpty(owners); assert owners.contains(n0); } }
List<List<ClusterNode>> newAff = affFunc.assignPartitions(ctx);
new GridAffinityFunctionContextImpl(nodes, prev, discoEvt, new AffinityTopologyVersion(i), backups); List<List<ClusterNode>> assignment = aff.assignPartitions(ctx); List<List<ClusterNode>> assignment = aff.assignPartitions( new GridAffinityFunctionContextImpl(nodes, prev, discoEvt, new AffinityTopologyVersion(i), backups));
assert baseFunc != null; return baseFunc.assignPartitions(affCtx);
/** * JUnit. * * @throws Exception If failed. */ @Test public void testPrimaryPartitions() throws Exception { // Pick 2 nodes and create a projection over them. ClusterNode n0 = grid(0).localNode(); int[] parts = grid(0).affinity(DEFAULT_CACHE_NAME).primaryPartitions(n0); info("Primary partitions count: " + parts.length); assert parts.length > 1 : "Invalid partitions: " + Arrays.toString(parts); for (int part : parts) assert part >= 0; assert !F.isEmpty(parts); AffinityFunctionContext ctx = new GridAffinityFunctionContextImpl(new ArrayList<>(grid(0).cluster().nodes()), null, null, new AffinityTopologyVersion(1), 1); List<List<ClusterNode>> assignment = affinity().assignPartitions(ctx); for (int p : parts) { Collection<ClusterNode> owners = nodes(assignment, p); assert !F.isEmpty(owners); ClusterNode primary = F.first(owners); assert F.eqNodes(n0, primary); } }
/** * JUnit. * * @throws Exception If failed. */ @Test public void testPrimaryPartitionsOneNode() throws Exception { AffinityFunctionContext ctx = new GridAffinityFunctionContextImpl(new ArrayList<>(grid(0).cluster().nodes()), null, null, new AffinityTopologyVersion(1), 1); List<List<ClusterNode>> assignment = affinity().assignPartitions(ctx); for (ClusterNode node : grid(0).cluster().nodes()) { int[] parts = grid(0).affinity(DEFAULT_CACHE_NAME).primaryPartitions(node); assert !F.isEmpty(parts); for (int p : parts) { Collection<ClusterNode> owners = nodes(assignment, p); assert !F.isEmpty(owners); ClusterNode primary = F.first(owners); assert F.eqNodes(node, primary); } } }