/** * @return Affinity key backups. */ public int affinityKeyBackups() { return ccfg.getBackups(); }
/** {@inheritDoc} */ @Override public int getBackups() { return ctx.config().getBackups(); }
/** * This method checks if we should skip mapping of an entry update to the near reader. We can skip the update * if the reader is a primary or a backup. If the reader is a partition owner, but not a primary or a backup, * we cannot skip the reader update and must attempt to update a near entry anyway. * * @param dhtCache DHT cache to check mapping. * @param readerNode Reader node. * @param dhtNodes Current DHT nodes (primary + backups first and other DHT nodes afterwards). * @return {@code true} if reader is either a primary or a backup. */ private boolean canSkipNearReader(GridDhtCacheAdapter<?, ?> dhtCache, ClusterNode readerNode, List<ClusterNode> dhtNodes) { int limit = Math.min(dhtCache.configuration().getBackups() + 1, dhtNodes.size()); for (int i = 0; i < limit; i++) { if (dhtNodes.get(i).id().equals(readerNode.id())) return true; } return false; }
/** * Checks if cache configurations are alike for warmup. * * @param ccfg0 First configuration. * @param ccfg1 Second configuration. * @return {@code True} if configurations match. */ private boolean matches(CacheConfiguration ccfg0, CacheConfiguration ccfg1) { return F.eq(ccfg0.getCacheMode(), ccfg1.getCacheMode()) && F.eq(ccfg0.getBackups(), ccfg1.getBackups()) && F.eq(ccfg0.getAtomicityMode(), ccfg1.getAtomicityMode()); }
/** {@inheritDoc} */ @Override protected boolean updateNearCache(GridCacheContext cacheCtx, KeyCacheObject key, AffinityTopologyVersion topVer) { if (!cacheCtx.isDht() || !isNearEnabled(cacheCtx) || cctx.localNodeId().equals(nearNodeId)) return false; if (cacheCtx.config().getBackups() == 0) return true; // Check if we are on the backup node. return !cacheCtx.affinity().backupsByKey(key, topVer).contains(cctx.localNode()); }
/** * @param cache Cache. * @return Test keys. * @throws Exception If failed. */ private List<Integer> testKeys(IgniteCache<Integer, Integer> cache) throws Exception { CacheConfiguration ccfg = cache.getConfiguration(CacheConfiguration.class); List<Integer> keys = new ArrayList<>(); if (ccfg.getCacheMode() == PARTITIONED) keys.add(nearKey(cache)); keys.add(primaryKey(cache)); if (ccfg.getBackups() != 0) keys.add(backupKey(cache)); return keys; }
/** {@inheritDoc} */ @Override protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception { CacheConfiguration ccfg = super.cacheConfiguration(igniteInstanceName); assertEquals(1, ccfg.getBackups()); ccfg.setBackups(2); return ccfg; } }
/** {@inheritDoc} */ @Nullable @Override public IndexingQueryCacheFilter forCache(String cacheName) { final GridCacheAdapter<Object, Object> cache = ctx.cache().internalCache(cacheName); // REPLICATED -> nothing to filter (explicit partitions are not supported). if (cache.context().isReplicated()) return null; // No backups and explicit partitions -> nothing to filter. if (cache.configuration().getBackups() == 0 && parts == null) return null; return new IndexingQueryCacheFilter(cache.context().affinity(), parts, topVer, ctx.discovery().localNode()); } }
/** * @param cache Cache. * @param vers Current versions. */ @SuppressWarnings("unchecked") private void checkVersionIncrease(IgniteCache<Object, Object> cache, Map<Integer, Comparable> vers) { for (Integer k : vers.keySet()) { cache.put(k, k); Comparable curVer = vers.get(k); CacheEntry entry = cache.getEntry(k); if (entry != null) { Comparable newVer = entry.version(); assertTrue(newVer.compareTo(curVer) > 0); vers.put(k, newVer); } else { CacheConfiguration ccfg = cache.getConfiguration(CacheConfiguration.class); assertEquals(0, ccfg.getBackups()); } } }
/** * @param ccfg Cache configuration. */ private void logCacheInfo(CacheConfiguration<?, ?> ccfg) { log.info("Test cache [mode=" + ccfg.getCacheMode() + ", sync=" + ccfg.getWriteSynchronizationMode() + ", backups=" + ccfg.getBackups() + ", near=" + (ccfg.getNearConfiguration() != null) + ']'); }
/** * @param cache Cache. * @return Test keys. * @throws Exception If failed. */ private List<Integer> testKeys(IgniteCache<Integer, Integer> cache) throws Exception { CacheConfiguration ccfg = cache.getConfiguration(CacheConfiguration.class); List<Integer> keys = new ArrayList<>(); if (!cache.unwrap(Ignite.class).configuration().isClientMode()) { if (ccfg.getCacheMode() == PARTITIONED) keys.add(nearKey(cache)); keys.add(primaryKey(cache)); if (ccfg.getBackups() != 0) keys.add(backupKey(cache)); } else keys.add(nearKey(cache)); return keys; }
/** * @param cache Cache. * @return Test keys. * @throws Exception If failed. */ private List<Integer> testKeys(IgniteCache<Integer, Integer> cache) throws Exception { CacheConfiguration ccfg = cache.getConfiguration(CacheConfiguration.class); List<Integer> keys = new ArrayList<>(); if (!cache.unwrap(Ignite.class).configuration().isClientMode()) { if (ccfg.getCacheMode() == PARTITIONED && serversNumber() > 1) keys.add(nearKey(cache)); keys.add(primaryKey(cache)); if (ccfg.getBackups() != 0 && serversNumber() > 1) keys.add(backupKey(cache)); } else keys.add(nearKey(cache)); return keys; }
/** * @param ignite Ignite. * @param name Cache name. * @param expBackups Expected number of backups. */ private void checkCreate(final Ignite ignite, final String name, int expBackups) { IgniteCache cache = ignite.createCache(name); assertNotNull(cache); CacheConfiguration cfg = (CacheConfiguration)cache.getConfiguration(CacheConfiguration.class); assertEquals(name, cfg.getName()); assertEquals(expBackups, cfg.getBackups()); }
/** * @param ignite Ignite. * @param name Cache name. * @param expBackups Expected number of backups. */ private void checkGetOrCreate(Ignite ignite, String name, int expBackups) { IgniteCache cache = ignite.getOrCreateCache(name); assertNotNull(cache); CacheConfiguration cfg = (CacheConfiguration)cache.getConfiguration(CacheConfiguration.class); assertEquals(name, cfg.getName()); assertEquals(expBackups, cfg.getBackups()); }
/** * @param ccfg Cache configuration. */ private void logCacheInfo(CacheConfiguration<?, ?> ccfg) { log.info("Test cache [mode=" + ccfg.getCacheMode() + ", sync=" + ccfg.getWriteSynchronizationMode() + ", backups=" + ccfg.getBackups() + ", near=" + (ccfg.getNearConfiguration() != null) + ", store=" + ccfg.isWriteThrough() + ", evictPlc=" + (ccfg.getEvictionPolicy() != null) + ']'); }
/** * @param ccfg Cache configuration. */ private void logCacheInfo(CacheConfiguration<?, ?> ccfg) { log.info("Test cache [mode=" + ccfg.getCacheMode() + ", sync=" + ccfg.getWriteSynchronizationMode() + ", backups=" + ccfg.getBackups() + ", near=" + (ccfg.getNearConfiguration() != null) + ", store=" + ccfg.isWriteThrough() + ", evictPlc=" + (ccfg.getEvictionPolicy() != null) + ']'); }
/** * @param ignite Ignite. * @param name Cache name. * @param expBackups Expected number of backups. */ private void checkGetOrCreate(Ignite ignite, String name, int expBackups) { IgniteCache cache = ignite.getOrCreateCache(name); assertNotNull(cache); CacheConfiguration cfg = (CacheConfiguration)cache.getConfiguration(CacheConfiguration.class); assertEquals(name, cfg.getName()); assertEquals(expBackups, cfg.getBackups()); } }
/** * Test backups propagation. * * @throws Exception If failed. */ @SuppressWarnings("unchecked") @Test public void testBackups() throws Exception { String cacheName = "BackupTestCache"; execute("CREATE TABLE \"BackupTest\" (id BIGINT PRIMARY KEY, name VARCHAR) WITH \"template=" + CACHE_NAME_BACKUPS + ", cache_name=" + cacheName + "\""); CacheConfiguration ccfg = grid(0).cache(cacheName).getConfiguration(CacheConfiguration.class); assertEquals(DFLT_BACKUPS, ccfg.getBackups()); execute("DROP TABLE PUBLIC.\"BackupTest\""); execute("CREATE TABLE \"BackupTest\" (id BIGINT PRIMARY KEY, name VARCHAR) WITH \"template=" + CACHE_NAME_BACKUPS + ", cache_name=" + cacheName + ", backups=1\""); ccfg = grid(0).cache(cacheName).getConfiguration(CacheConfiguration.class); assertEquals(1, ccfg.getBackups()); }
/** * @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); }
/** * @throws Exception If failed. */ private void checkNoPrimaryReadPreloadFinished(List<CacheConfiguration<Object, Object>> cacheCfgs) throws Exception { for (CacheConfiguration<Object, Object> ccfg : cacheCfgs) { boolean near = (ccfg.getNearConfiguration() != null); log.info("Test cache [mode=" + ccfg.getCacheMode() + ", atomicity=" + ccfg.getAtomicityMode() + ", backups=" + ccfg.getBackups() + ", near=" + near + "]"); ignite(0).createCache(ccfg); awaitPartitionMapExchange(); try { checkLocalRead(NODES, ccfg); } finally { ignite(0).destroyCache(ccfg.getName()); } } }