/** * Gets cache mode. * * @param cacheName Cache name to check. * @return Cache mode. */ public CacheMode cacheMode(String cacheName) { assert cacheName != null; DynamicCacheDescriptor desc = cacheDescriptor(cacheName); return desc != null ? desc.cacheConfiguration().getCacheMode() : null; }
/** */ private Set<Integer> getGroupIds() { Set<Integer> grpIds = new HashSet<>(); if (arg.getCaches() != null && !arg.getCaches().isEmpty()) { Set<String> missingCaches = new HashSet<>(); for (String cacheName : arg.getCaches()) { DynamicCacheDescriptor desc = ignite.context().cache().cacheDescriptor(cacheName); if (desc == null || !isCacheMatchFilter(cacheName)) { missingCaches.add(cacheName); continue; } grpIds.add(desc.groupId()); } handlingMissedCaches(missingCaches); } else if (onlySpecificCaches()) { for (DynamicCacheDescriptor desc : ignite.context().cache().cacheDescriptors().values()) { if (desc.cacheConfiguration().getCacheMode() != LOCAL && isCacheMatchFilter(desc.cacheName())) grpIds.add(desc.groupId()); } } else grpIds = getCacheGroupIds(); return grpIds; }
/** * @param name Cache name. * @return {@code True} if specified cache is system, {@code false} otherwise. */ public boolean systemCache(String name) { assert name != null; DynamicCacheDescriptor desc = cacheDescriptor(name); return desc != null && !desc.cacheType().userCache(); }
/** * Returns cache object context if created or creates new and caches it until cache started. * * @param cacheId Cache id. */ @Nullable public CacheObjectContext cacheObjectContext(int cacheId) throws IgniteCheckedException { GridCacheContext<K, V> ctx = ctxMap.get(cacheId); if (ctx != null) return ctx.cacheObjectContext(); DynamicCacheDescriptor desc = cache().cacheDescriptor(cacheId); return desc != null ? desc.cacheObjectContext(kernalContext().cacheObjects()) : null; }
/** * Gets the cache descriptor. * * @param ctx Context. * @param cacheId Cache id. * @return Cache descriptor. */ public static DynamicCacheDescriptor cacheDescriptor(ClientConnectionContext ctx, int cacheId) { DynamicCacheDescriptor desc = ctx.kernalContext().cache().cacheDescriptor(cacheId); if (desc == null) throw new IgniteClientException(ClientStatus.CACHE_DOES_NOT_EXIST, "Cache does not exist [cacheId= " + cacheId + "]", null); return desc; }
/** * Get configuration for the given cache. * * @param name Cache name. * @return Cache configuration. */ public CacheConfiguration cacheConfiguration(String name) { assert name != null; DynamicCacheDescriptor desc = cacheDescriptor(name); if (desc == null) { if (cachesInfo.isRestarting(name)) { IgniteCacheProxyImpl<?, ?> proxy = jCacheProxies.get(name); assert proxy != null: name; proxy.internalProxy(); //should throw exception // we have procceed, try again return cacheConfiguration(name); } throw new IllegalStateException("Cache doesn't exist: " + name); } else return desc.cacheConfiguration(); }
/** * @param msg Message. * @return Cache or group descriptor. */ private Object descriptorForMessage(GridCacheMessage msg) { if (msg instanceof GridCacheIdMessage) return cctx.cache().cacheDescriptor(((GridCacheIdMessage)msg).cacheId()); else if (msg instanceof GridCacheGroupIdMessage) return cctx.cache().cacheGroupDescriptors().get(((GridCacheGroupIdMessage)msg).groupId()); return null; }
/** * @param cacheName Cache name. */ public boolean walEnabled(String cacheName) { DynamicCacheDescriptor desc = ctx.cache().cacheDescriptor(cacheName); if (desc == null) throw new IgniteException("Cache not found: " + cacheName); return desc.groupDescriptor().walEnabled(); }
/** * @param name Cache name. * @param <K> type of keys. * @param <V> type of values. * @return Cache instance for given name. */ public <K, V> IgniteInternalCache<K, V> publicCache(String name) { assert name != null; if (log.isDebugEnabled()) log.debug("Getting public cache for name: " + name); DynamicCacheDescriptor desc = cacheDescriptor(name); if (desc == null) throw new IllegalArgumentException("Cache is not started: " + name); if (!desc.cacheType().userCache()) throw new IllegalStateException("Failed to get cache because it is a system cache: " + name); IgniteCacheProxy<K, V> jcache = (IgniteCacheProxy<K, V>)jcacheProxy(name, true); if (jcache == null) throw new IllegalArgumentException("Cache is not started: " + name); return jcache.internalProxy(); }
/** * @param buf Buffer to write to. * @param entry Data entry. * @throws IgniteCheckedException If failed. */ void putEncryptedDataEntry(ByteBuffer buf, DataEntry entry) throws IgniteCheckedException { DynamicCacheDescriptor desc = cctx.cache().cacheDescriptor(entry.cacheId()); if (desc != null && needEncryption(desc.groupId())) { int clSz = entrySize(entry); ByteBuffer clData = ByteBuffer.allocate(clSz); putPlainDataEntry(clData, entry); clData.rewind(); buf.put(ENCRYPTED); writeEncryptedData(desc.groupId(), null, clData, buf); } else { buf.put(PLAIN); putPlainDataEntry(buf, entry); } }
/** * Check security access for caches. * * @param cacheIds Cache IDs. */ private void checkSecurity(Collection<Integer> cacheIds) { if (F.isEmpty(cacheIds)) return; for (Integer cacheId : cacheIds) { DynamicCacheDescriptor desc = ctx.cache().cacheDescriptor(cacheId); if (desc != null) ctx.security().authorize(desc.cacheName(), SecurityPermission.CACHE_READ, null); } }
/** */ private int colsCnt(IgniteEx node, String cacheName) { DynamicCacheDescriptor desc = node.context().cache().cacheDescriptor(cacheName); int cnt = 0; if (desc != null) { QuerySchema schema = desc.schema(); if (schema != null) { for (QueryEntity entity : schema.entities()) cnt += entity.getFields().size(); } } return cnt; }
/** */ private int indexCnt(IgniteEx node, String cacheName) { DynamicCacheDescriptor desc = node.context().cache().cacheDescriptor(cacheName); int cnt = 0; if (desc != null) { QuerySchema schema = desc.schema(); if (schema != null) { for (QueryEntity entity : schema.entities()) cnt += entity.getIndexes().size(); } } return cnt; }
/** {@inheritDoc} */ @Override protected void afterTest() throws Exception { stmt.close(); conn.close(); // Destroy all SQL caches after test. for (String cacheName : grid(0).cacheNames()) { DynamicCacheDescriptor cacheDesc = grid(0).context().cache().cacheDescriptor(cacheName); if (cacheDesc != null && cacheDesc.sql()) grid(0).destroyCache0(cacheName, true); } super.afterTest(); }
/** * Ensures that cache has been started and is ready to store streamed data. */ private void ensureCacheStarted() { DynamicCacheDescriptor desc = ctx.cache().cacheDescriptor(cacheName); assert desc != null; if (desc.startTopologyVersion() == null) return; IgniteInternalFuture<?> affReadyFut = ctx.cache().context().exchange() .affinityReadyFuture(desc.startTopologyVersion()); if (affReadyFut != null) { try { affReadyFut.get(); } catch (IgniteCheckedException ex) { throw new IgniteException(ex); } } }
/** {@inheritDoc} */ @Override protected void afterTest() throws Exception { conn.close(); // Destroy all SQL caches after test. for (String cacheName : grid(0).cacheNames()) { DynamicCacheDescriptor cacheDesc = grid(0).context().cache().cacheDescriptor(cacheName); if (cacheDesc != null && cacheDesc.sql()) grid(0).destroyCache0(cacheName, true); } super.afterTest(); }
/** * @param cacheName Cache name. */ private boolean isCacheMatchFilter(String cacheName) { if (arg instanceof VisorIdleVerifyDumpTaskArg) { DataStorageConfiguration dsCfg = ignite.context().config().getDataStorageConfiguration(); DynamicCacheDescriptor desc = ignite.context().cache().cacheDescriptor(cacheName); CacheConfiguration cc = desc.cacheConfiguration(); VisorIdleVerifyDumpTaskArg vdta = (VisorIdleVerifyDumpTaskArg)arg; switch (vdta.getCacheFilterEnum()) { case SYSTEM: return !desc.cacheType().userCache(); case NOT_PERSISTENT: return desc.cacheType().userCache() && !GridCacheUtils.isPersistentCache(cc, dsCfg); case PERSISTENT: return desc.cacheType().userCache() && GridCacheUtils.isPersistentCache(cc, dsCfg); case ALL: break; default: assert false : "Illegal cache filter: " + vdta.getCacheFilterEnum(); } } return true; }
/** * Tests that ignite can start when caches' configurations with same name in different groups stored. * * @throws Exception If fails. */ @Test public void testStartDuplicatedCacheConfigurations() throws Exception { IgniteEx ig0 = (IgniteEx)startGrids(NODES); ig0.cluster().active(true); startCaches(ig0); DynamicCacheDescriptor desc = ig0.context().cache().cacheDescriptor(cacheName(3)); storeInvalidCacheData(desc); stopAllGrids(); startGrids(NODES); desc = ig0.context().cache().cacheDescriptor(cacheName(3)); assertEquals("expected that group of " + cacheName(3) + " is " + EVEN_GROUP_NAME, EVEN_GROUP_NAME, desc.groupDescriptor().groupName()); }
/** */ private void checkNodeState(IgniteEx node, String schemaName, String tableName, String fieldName) { String cacheName = F.eq(schemaName, QueryUtils.DFLT_SCHEMA) ? QueryUtils.createTableCacheName(schemaName, tableName) : schemaName; DynamicCacheDescriptor desc = node.context().cache().cacheDescriptor(cacheName); assertNotNull("Cache descriptor not found", desc); QuerySchema schema = desc.schema(); assertNotNull(schema); QueryEntity entity = null; for (QueryEntity e : schema.entities()) { if (F.eq(tableName, e.getTableName())) { entity = e; break; } } assertNotNull(entity); assertNotNull(entity.getNotNullFields()); assertTrue(entity.getNotNullFields().contains(fieldName)); }
/** * Check that exception contains proper filename when trying to read corrupted cache configuration file. * * @throws Exception If failed. */ @Test public void testCorruptedCacheConfigurationsValidation() throws Exception { IgniteEx ig0 = (IgniteEx)startGrids(NODES); ig0.cluster().active(true); startCaches(ig0); DynamicCacheDescriptor desc = ig0.context().cache().cacheDescriptor(cacheName(2)); corruptCacheData(desc); stopAllGrids(); GridTestUtils.assertThrowsAnyCause(log, () -> startGrids(NODES), IgniteCheckedException.class, desc.cacheName() + CACHE_DATA_FILENAME); }