/** * @return Configured affinity function. */ public AffinityFunction affinityFunction() { return ccfg.getAffinity(); }
/** {@inheritDoc} */ @Override public void start0() throws IgniteCheckedException { affFunction = cctx.config().getAffinity(); affMapper = cctx.config().getAffinityMapper(); aff = cctx.group().affinity(); }
/** * @return Affinity partitions count. */ public int affinityPartitionsCount() { return ccfg.getAffinity().partitions(); }
/** * 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. } } }
/** * Find .NET affinity functions in configuration. * * @param cfg Configuration. * @return affinity functions. */ private static List<PlatformDotNetAffinityFunction> affinityFunctions(IgniteConfiguration cfg) { List<PlatformDotNetAffinityFunction> res = new ArrayList<>(); CacheConfiguration[] cacheCfg = cfg.getCacheConfiguration(); if (cacheCfg != null) { for (CacheConfiguration ccfg : cacheCfg) { if (ccfg.getAffinity() instanceof PlatformDotNetAffinityFunction) res.add((PlatformDotNetAffinityFunction)ccfg.getAffinity()); } } return res; } }
/** * @param cfg Configuration. * @param objs Extra components. * @throws IgniteCheckedException If failed to inject. */ private void prepare(CacheConfiguration cfg, Collection<Object> objs) throws IgniteCheckedException { prepare(cfg, cfg.getAffinity(), false); prepare(cfg, cfg.getAffinityMapper(), false); prepare(cfg, cfg.getEvictionFilter(), false); prepare(cfg, cfg.getInterceptor(), false); for (Object obj : objs) prepare(cfg, obj, false); }
/** * @return Affinity class name. */ public String cacheAffinityClassName() { return className(ccfg.getAffinity()); }
/** {@inheritDoc} */ @Override public GridTuple3<GridAffinityMessage, GridAffinityMessage, GridAffinityAssignment> call() throws Exception { assert ignite != null; assert log != null; IgniteKernal kernal = ((IgniteKernal) ignite); GridCacheContext<Object, Object> cctx = kernal.internalCache(cacheName).context(); assert cctx != null; GridKernalContext ctx = kernal.context(); cctx.affinity().affinityReadyFuture(topVer).get(); AffinityAssignment assign0 = cctx.affinity().assignment(topVer); //using legacy GridAffinityAssignment for compatibility. return F.t( affinityMessage(ctx, cctx.config().getAffinity()), affinityMessage(ctx, cctx.config().getAffinityMapper()), new GridAffinityAssignment(topVer, assign0.assignment(), assign0.idealAssignment()) ); }
/** * @return Affinity include neighbors. */ public boolean affinityIncludeNeighbors() { AffinityFunction aff = ccfg.getAffinity(); return aff instanceof RendezvousAffinityFunction && !((RendezvousAffinityFunction)aff).isExcludeNeighbors(); }
/** * @param cctx Cache context. */ private void cleanup(GridCacheContext cctx) { CacheConfiguration cfg = cctx.config(); cleanup(cfg, cfg.getAffinity(), false); cleanup(cfg, cfg.getAffinityMapper(), false); cleanup(cfg, cfg.getEvictionFilter(), false); cleanup(cfg, cfg.getInterceptor(), false); cleanup(cfg, cctx.store().configuredStore(), false); if (!CU.isUtilityCache(cfg.getName()) && !CU.isSystemCache(cfg.getName())) { unregisterMbean(cctx.cache().localMxBean(), cfg.getName(), false); unregisterMbean(cctx.cache().clusterMxBean(), cfg.getName(), false); } cctx.cleanup(); }
/** * @return Configured user objects which should be initialized/stopped on group start/stop. */ Collection<?> configuredUserObjects() { return Arrays.asList(ccfg.getAffinity(), ccfg.getNodeFilter(), ccfg.getTopologyValidator()); }
/** * @return Affinity. */ private AffinityFunction affinity() { return ((IgniteKernal)grid(0)).internalCache(DEFAULT_CACHE_NAME).configuration().getAffinity(); }
@Test public void testWronglySetAffinityFunctionForLocalCache() { Ignite node = ignite(NODE_CNT - 1); CacheConfiguration ccf = node.cache(CACHE1).getConfiguration(CacheConfiguration.class); assertEquals("org.apache.ignite.internal.processors.cache.GridCacheProcessor$LocalAffinityFunction", ccf.getAffinity().getClass().getName()); }
/** {@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)); } } }
/** * @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); }
/** * 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 c Cache projection. * @param key Key. * @param attempt Attempt. */ private void printFailureDetails(IgniteCache<Integer, String> c, int key, int attempt) { error("*** Failure details ***"); error("Key: " + key); error("Partition: " + c.getConfiguration(CacheConfiguration.class).getAffinity().partition(key)); error("Attempt: " + attempt); error("Node: " + c.unwrap(Ignite.class).cluster().localNode().id()); } }
/** * @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))); } }