/** * Dynamically starts cache. * * @param ccfg Cache configuration. * @param cacheName Cache name. * @param nearCfg Near cache configuration. * @param failIfExists Fail if exists flag. * @param failIfNotStarted If {@code true} fails if cache is not started. * @param checkThreadTx If {@code true} checks that current thread does not have active transactions. * @return Future that will be completed when cache is deployed. */ public IgniteInternalFuture<Boolean> dynamicStartCache( @Nullable CacheConfiguration ccfg, String cacheName, @Nullable NearCacheConfiguration nearCfg, boolean failIfExists, boolean failIfNotStarted, boolean checkThreadTx ) { return dynamicStartCache(ccfg, cacheName, nearCfg, CacheType.USER, false, failIfExists, failIfNotStarted, checkThreadTx); }
kernal.context().cache().dynamicStartCache(ccfg, ccfg.getName(), null, true, false, true).get();
/** * Dynamically starts cache using template configuration. * * @param cacheName Cache name. * @return Future that will be completed when cache is deployed. */ public IgniteInternalFuture<?> createFromTemplate(String cacheName) { try { CacheConfiguration cfg = getOrCreateConfigFromTemplate(cacheName); return dynamicStartCache(cfg, cacheName, null, true, true, true); } catch (IgniteCheckedException e) { throw U.convertException(e); } }
/** * Dynamically starts cache as a result of SQL {@code CREATE TABLE} command. * * @param ccfg Cache configuration. */ public IgniteInternalFuture<Boolean> dynamicStartSqlCache( CacheConfiguration ccfg ) { A.notNull(ccfg, "ccfg"); return dynamicStartCache(ccfg, ccfg.getName(), ccfg.getNearConfiguration(), CacheType.USER, true, false, true, true); }
@Override public Object call() throws Exception { CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME); ccfg.setName(DYNAMIC_CACHE_NAME); IgniteEx kernal = grid(ThreadLocalRandom.current().nextInt(nodeCount())); futs.add(kernal.context().cache().dynamicStartCache(ccfg, ccfg.getName(), null, true, true, true)); return null; } }, threadNum, "cache-starter");
/** * @param cacheName Cache name. * @param failIfNotStarted If {@code true} throws {@link IllegalArgumentException} if cache is not started, * otherwise returns {@code null} in this case. * @param checkThreadTx If {@code true} checks that current thread does not have active transactions. * @return Cache instance for given name. * @throws IgniteCheckedException If failed. */ @Nullable public <K, V> IgniteCacheProxy<K, V> publicJCache(String cacheName, boolean failIfNotStarted, boolean checkThreadTx) throws IgniteCheckedException { assert cacheName != null; if (log.isDebugEnabled()) log.debug("Getting public cache for name: " + cacheName); DynamicCacheDescriptor desc = cacheDescriptor(cacheName); if (desc != null && !desc.cacheType().userCache()) throw new IllegalStateException("Failed to get cache because it is a system cache: " + cacheName); IgniteCacheProxyImpl<?, ?> proxy = jcacheProxy(cacheName, true); // Try to start cache, there is no guarantee that cache will be instantiated. if (proxy == null) { dynamicStartCache(null, cacheName, null, false, failIfNotStarted, checkThreadTx).get(); proxy = jcacheProxy(cacheName, true); } return proxy != null ? (IgniteCacheProxy<K, V>)proxy.gatewayWrapper() : null; }
/** * @param name Cache name. * @return Cache instance for given name. * @throws IgniteCheckedException If failed. */ public <K, V> IgniteInternalCache<K, V> getOrStartCache( String name, CacheConfiguration ccfg ) throws IgniteCheckedException { assert name != null; if (log.isDebugEnabled()) log.debug("Getting cache for name: " + name); IgniteCacheProxy<?, ?> cache = jcacheProxy(name, true); if (cache == null) { dynamicStartCache(ccfg, name, null, false, ccfg == null, true).get(); cache = jcacheProxy(name, true); } return cache == null ? null : (IgniteInternalCache<K, V>)cache.internalProxy(); }
dynamicStartCache(null, ccfg.getName(), null, false, true, true).get();
@Override public Object call() throws Exception { CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME); ccfg.setName(DYNAMIC_CACHE_NAME); futs.add(kernal.context().cache().dynamicStartCache(ccfg, ccfg.getName(), null, true, true, true)); return null; } }, threadNum, "cache-starter");
ctx.cache().dynamicStartCache(cacheConfiguration(cfg, cacheName, grpName), cacheName, null,
/** * Check that given table has not started cache and start it for such case. * * @param tbl Table to check on not started cache. * @return {@code true} in case not started and has been started. */ @SuppressWarnings({"ConstantConditions", "UnusedReturnValue"}) public static boolean checkAndStartNotStartedCache(GridKernalContext ctx, GridH2Table tbl) { if (tbl != null && tbl.isCacheLazy()) { String cacheName = tbl.cacheInfo().config().getName(); try { Boolean res = ctx.cache().dynamicStartCache(null, cacheName, null, false, true, true).get(); return U.firstNotNull(res, Boolean.FALSE); } catch (IgniteCheckedException ex) { throw U.convertException(ex); } } return false; }
/** * Dynamically starts cache using template configuration. * * @param cacheName Cache name. * @param templateName Cache template name. * @param cfgOverride Cache config properties to override. * @param checkThreadTx If {@code true} checks that current thread does not have active transactions. * @return Future that will be completed when cache is deployed. */ public IgniteInternalFuture<?> getOrCreateFromTemplate(String cacheName, String templateName, CacheConfigurationOverride cfgOverride, boolean checkThreadTx) { assert cacheName != null; try { if (publicJCache(cacheName, false, checkThreadTx) != null) // Cache with given name already started. return new GridFinishedFuture<>(); CacheConfiguration ccfg = F.isEmpty(templateName) ? getOrCreateConfigFromTemplate(cacheName) : getOrCreateConfigFromTemplate(templateName); ccfg.setName(cacheName); if (cfgOverride != null) cfgOverride.apply(ccfg); return dynamicStartCache(ccfg, cacheName, null, false, true, checkThreadTx); } catch (IgniteCheckedException e) { return new GridFinishedFuture<>(e); } }
ctx.cache().dynamicStartCache(null, cacheName, nearCfg, ctx.cache().dynamicStartCache(null, cacheName, nearCfg,
/** {@inheritDoc} */ @Override public <K, V> IgniteCache<K, V> createNearCache(String cacheName, NearCacheConfiguration<K, V> nearCfg) { CU.validateNewCacheName(cacheName); A.notNull(nearCfg, "nearCfg"); guard(); try { checkClusterState(); ctx.cache().dynamicStartCache(null, cacheName, nearCfg, true, true, true).get(); IgniteCacheProxy<K, V> cache = ctx.cache().publicJCache(cacheName); checkNearCacheStarted(cache); return cache; } catch (IgniteCheckedException e) { throw CU.convertToCacheException(e); } finally { unguard(); } }
@Override public void run() { try { ignite.context().cache().dynamicStartCache( new CacheConfiguration().setName(cacheName), cacheName, null, false, false, false ).get(); assertNotNull(ignite.context().cache().cache(cacheName)); } catch (IgniteCheckedException ex) { throw new IgniteException(ex); } } }, 10, "cache-start");
/** {@inheritDoc} */ @Override public <K, V> IgniteCache<K, V> createCache(CacheConfiguration<K, V> cacheCfg) { A.notNull(cacheCfg, "cacheCfg"); CU.validateNewCacheName(cacheCfg.getName()); guard(); try { checkClusterState(); ctx.cache().dynamicStartCache(cacheCfg, cacheCfg.getName(), null, true, true, true).get(); return ctx.cache().publicJCache(cacheCfg.getName()); } catch (IgniteCheckedException e) { throw CU.convertToCacheException(e); } finally { unguard(); } }
return null; ctx.cache().dynamicStartCache(cacheConfiguration(cfg, cacheName, grpName), cacheName, null,
ctx.cache().dynamicStartCache(cacheCfg, cacheCfg.getName(), nearCfg, ctx.cache().dynamicStartCache(cacheCfg, cacheCfg.getName(), nearCfg,
/** {@inheritDoc} */ @Override public <K, V> IgniteCache<K, V> createCache( CacheConfiguration<K, V> cacheCfg, NearCacheConfiguration<K, V> nearCfg ) { A.notNull(cacheCfg, "cacheCfg"); CU.validateNewCacheName(cacheCfg.getName()); A.notNull(nearCfg, "nearCfg"); guard(); try { checkClusterState(); ctx.cache().dynamicStartCache(cacheCfg, cacheCfg.getName(), nearCfg, true, true, true).get(); return ctx.cache().publicJCache(cacheCfg.getName()); } catch (IgniteCheckedException e) { throw CU.convertToCacheException(e); } finally { unguard(); } }
res = sql ? ctx.cache().dynamicStartSqlCache(cacheCfg).get() : ctx.cache().dynamicStartCache(cacheCfg, cacheName, null,