/** {@inheritDoc} */ @Override public int partitions() { return delegate.partitions(); }
/** * @return Affinity partitions count. */ public int affinityPartitionsCount() { return ccfg.getAffinity().partitions(); }
/** {@inheritDoc} */ @Override public int partitions() { return grp.affinityFunction().partitions(); }
/** {@inheritDoc} */ @Override public int partitions() { return delegate.partitions(); }
/** {@inheritDoc} */ @Override public int partitions() { return cctx.group().affinityFunction().partitions(); }
/** * @param ctx Cache shared context. * @param grp Cache group. */ public GridDhtPartitionTopologyImpl( GridCacheSharedContext ctx, CacheGroupContext grp ) { assert ctx != null; assert grp != null; this.ctx = ctx; this.grp = grp; log = ctx.logger(getClass()); timeLog = ctx.logger(GridDhtPartitionsExchangeFuture.EXCHANGE_LOG); locParts = new AtomicReferenceArray<>(grp.affinityFunction().partitions()); cntrMap = new CachePartitionFullCountersMap(locParts.length()); }
/** * @param grpId Cache group ID. * @param discoCache Discovery data cache. * @return Topology. */ public GridDhtPartitionTopology clientTopology(int grpId, DiscoCache discoCache) { GridClientPartitionTopology top = clientTops.get(grpId); if (top != null) return top; CacheGroupDescriptor grpDesc = cctx.affinity().cacheGroups().get(grpId); assert grpDesc != null : grpId; CacheConfiguration<?, ?> ccfg = grpDesc.config(); AffinityFunction aff = ccfg.getAffinity(); Object affKey = cctx.kernalContext().affinity().similaryAffinityKey(aff, ccfg.getNodeFilter(), ccfg.getBackups(), aff.partitions()); GridClientPartitionTopology old = clientTops.putIfAbsent(grpId, top = new GridClientPartitionTopology(cctx, discoCache, grpId, aff.partitions(), affKey)); return old != null ? old : top; }
/** * Create data transfer object for affinity configuration properties. * * @param ccfg Cache configuration. */ public VisorCacheAffinityConfiguration(CacheConfiguration ccfg) { AffinityFunction aff = ccfg.getAffinity(); function = compactClass(aff); mapper = compactClass(ccfg.getAffinityMapper()); partitions = aff.partitions(); partitionedBackups = ccfg.getBackups(); Method mthd = findNonPublicMethod(aff.getClass(), "isExcludeNeighbors"); if (mthd != null) { try { exclNeighbors = (Boolean)mthd.invoke(aff); } catch (InvocationTargetException | IllegalAccessException ignored) { // No-op. } } }
/** * Prepare affinity identifier for cache. * * @param ccfg Cache configuration. * @return Affinity identifier. */ private static PartitionTableAffinityDescriptor affinityForCache(CacheConfiguration ccfg) { // Partition could be extracted only from PARTITIONED caches. if (ccfg.getCacheMode() != CacheMode.PARTITIONED) return null; PartitionAffinityFunctionType aff = ccfg.getAffinity().getClass().equals(RendezvousAffinityFunction.class) ? PartitionAffinityFunctionType.RENDEZVOUS : PartitionAffinityFunctionType.CUSTOM; boolean hasNodeFilter = ccfg.getNodeFilter() != null && !(ccfg.getNodeFilter() instanceof CacheConfiguration.IgniteAllNodesPredicate); return new PartitionTableAffinityDescriptor( aff, ccfg.getAffinity().partitions(), hasNodeFilter, ccfg.getDataRegionName() ); }
/** {@inheritDoc} */ @Override public int partitions() { ctx.gateway().readLock(); try { return cache().affinityFunction().partitions(); } catch (IgniteCheckedException e) { throw new IgniteException(e); } finally { ctx.gateway().readUnlock(); } }
/** {@inheritDoc} */ @Override protected void configure(IgniteConfiguration cfg) { super.configure(cfg); for (CacheConfiguration ccfg : cfg.getCacheConfiguration()) { AffinityFunction aff = ccfg.getAffinity(); int parts = aff != null ? aff.partitions() : RendezvousAffinityFunction.DFLT_PARTITION_COUNT; ccfg.setGroupName("testGroup-parts" + parts); } } }
/** * @param ignite Ignite. * @param cacheFilter cacheFilter. */ private void corruptingAndCheckDefaultCache(IgniteEx ignite, String cacheFilter) throws IOException { injectTestSystemOut(); GridCacheContext<Object, Object> cacheCtx = ignite.cachex(DEFAULT_CACHE_NAME).context(); corruptDataEntry(cacheCtx, 0, true, false); corruptDataEntry(cacheCtx, cacheCtx.config().getAffinity().partitions() / 2, false, true); assertEquals(EXIT_CODE_OK, execute("--cache", "idle_verify", "--dump", "--cache-filter", cacheFilter)); Matcher fileNameMatcher = dumpFileNameMatcher(); if (fileNameMatcher.find()) { String dumpWithConflicts = new String(Files.readAllBytes(Paths.get(fileNameMatcher.group(1)))); assertTrue(dumpWithConflicts.contains("found 2 conflict partitions: [counterConflicts=1, hashConflicts=1]")); } else fail("Should be found dump with conflicts"); }
/** * @throws Exception If failed. */ private void checkPartitionsWithAffinityBackupFilter() throws Exception { AffinityFunction aff = cacheConfiguration(grid(0).configuration(), DEFAULT_CACHE_NAME).getAffinity(); int partCnt = aff.partitions(); IgniteCache<Object, Object> cache = grid(0).cache(DEFAULT_CACHE_NAME); for (int i = 0; i < partCnt; i++) { Collection<ClusterNode> nodes = affinity(cache).mapKeyToPrimaryAndBackups(i); assertEquals(expectedNodesForEachPartition(), nodes.size()); Map<String, Integer> stat = getAttributeStatistic(nodes); assertEquals(stat.get(FIRST_NODE_GROUP), new Integer(expectedNodesForEachPartition() - 2 )); assertEquals(stat.get("B"), new Integer(1)); assertEquals(stat.get("C"), new Integer(1)); } } }
/** * 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()); }
/** * JUnit. * * @throws Exception If failed. */ @Test public void testPartitions() throws Exception { assertEquals(affinity().partitions(), grid(0).affinity(DEFAULT_CACHE_NAME).partitions()); }
/** * 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)); }
/** * Tests that both update counter and hash conflicts are detected. * * @throws Exception If failed. */ @Test public void testCacheIdleVerifyTwoConflictTypes() throws Exception { IgniteEx ignite = (IgniteEx)startGrids(2); ignite.cluster().active(true); createCacheAndPreload(ignite, 100); injectTestSystemOut(); assertEquals(EXIT_CODE_OK, execute("--cache", "idle_verify")); assertTrue(testOut.toString().contains("no conflicts have been found")); GridCacheContext<Object, Object> cacheCtx = ignite.cachex(DEFAULT_CACHE_NAME).context(); corruptDataEntry(cacheCtx, 1, true, false); corruptDataEntry(cacheCtx, 1 + cacheCtx.config().getAffinity().partitions() / 2, false, true); assertEquals(EXIT_CODE_OK, execute("--cache", "idle_verify")); assertTrue(testOut.toString().contains("found 2 conflict partitions")); }
/** * @param grpDesc Cache group descriptor. * @param ccfg Cache configuration. * @return Cache store holder. * @throws IgniteCheckedException If failed. */ private CacheStoreHolder initForCache(CacheGroupDescriptor grpDesc, CacheConfiguration ccfg) throws IgniteCheckedException { assert !grpDesc.sharedGroup() || ccfg.getGroupName() != null : ccfg.getName(); File cacheWorkDir = cacheWorkDir(ccfg); String dataRegionName = grpDesc.config().getDataRegionName(); DataRegionMetricsImpl regionMetrics = cctx.database().dataRegion(dataRegionName).memoryMetrics(); int grpId = CU.cacheId(grpDesc.cacheOrGroupName()); AllocatedPageTracker allocatedTracker = regionMetrics.getOrAllocateGroupPageAllocationTracker(grpId); return initDir( cacheWorkDir, grpDesc.groupId(), grpDesc.config().getAffinity().partitions(), allocatedTracker, ccfg.isEncryptionEnabled() ); }
/** * @throws Exception If failed. */ @SuppressWarnings("ConstantConditions") private void checkPartitions() throws Exception { AffinityFunction aff = cacheConfiguration(grid(0).configuration(), DEFAULT_CACHE_NAME).getAffinity(); int partCnt = aff.partitions(); IgniteCache<Object, Object> cache = grid(0).cache(DEFAULT_CACHE_NAME); for (int i = 0; i < partCnt; i++) { Collection<ClusterNode> nodes = affinity(cache).mapKeyToPrimaryAndBackups(i); assertEquals(2, nodes.size()); ClusterNode primary = F.first(nodes); ClusterNode backup = F.last(nodes); assertFalse(F.eq(primary.attribute(SPLIT_ATTRIBUTE_NAME), backup.attribute(SPLIT_ATTRIBUTE_NAME))); } }
/** * @throws Exception If failed. */ @Test public void testTestAffinity() throws Exception { try { affinityFunction = new TestAffinityFunction("Some value"); startGrids(3); for (int i = 0; i < 3; i++) { IgniteEx igniteEx = grid(i); IgniteAtomicLong atomic = igniteEx.atomicLong("test", 0, true); GridCacheContext cctx = GridTestUtils.getFieldValue(atomic, AtomicDataStructureProxy.class, "ctx"); TestAffinityFunction aff = (TestAffinityFunction) cctx.config().getAffinity(); assertNotNull(aff); assertEquals(aff.partitions(), affinityFunction.partitions()); assertEquals(aff.getCustomAttribute(), ((TestAffinityFunction)affinityFunction).getCustomAttribute()); } checkAtomics(); } finally { stopAllGrids(); } }