/** * @param desc Cache configuration for start. * @param reqNearCfg Near cache configuration for start. * @param exchTopVer Exchange topology version in which starting happened. * @param disabledAfterStart Disable started cache after start or not. */ public StartCacheInfo(DynamicCacheDescriptor desc, NearCacheConfiguration reqNearCfg, AffinityTopologyVersion exchTopVer, boolean disabledAfterStart) { this(desc.cacheConfiguration(), desc, reqNearCfg, exchTopVer, disabledAfterStart); }
@Override public String apply(DynamicCacheDescriptor desc) { return desc.cacheConfiguration().getName(); } });
@Override public String apply(DynamicCacheDescriptor desc) { return desc.cacheConfiguration().getName(); } },
@Override public String apply(DynamicCacheDescriptor desc) { return desc.cacheConfiguration().getName(); } },
/** * @return Collection of persistent cache descriptors. */ public Collection<DynamicCacheDescriptor> persistentCaches() { return cachesInfo.registeredCaches().values() .stream() .filter(desc -> isPersistentCache(desc.cacheConfiguration(), ctx.config().getDataStorageConfiguration())) .collect(Collectors.toList()); }
/** * 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; }
/** * @param cacheId Cache ID. * @return Cache descriptor. */ @Nullable public DynamicCacheDescriptor cacheDescriptor(int cacheId) { for (DynamicCacheDescriptor cacheDesc : cacheDescriptors().values()) { CacheConfiguration ccfg = cacheDesc.cacheConfiguration(); assert ccfg != null : cacheDesc; if (CU.cacheId(ccfg.getName()) == cacheId) return cacheDesc; } return null; }
/** {@inheritDoc} */ @Override public void afterBinaryMemoryRestore(IgniteCacheDatabaseSharedManager mgr, GridCacheDatabaseSharedManager.RestoreBinaryState restoreState) throws IgniteCheckedException { boolean hasMvccCaches = ctx.cache().persistentCaches().stream() .anyMatch(c -> c.cacheConfiguration().getAtomicityMode() == TRANSACTIONAL_SNAPSHOT); if (hasMvccCaches) { txLog = new TxLog(ctx, mgr); mvccEnabled = true; } }
/** {@inheritDoc} */ @Override public Map<String, CacheConfiguration<?, ?>> startedCaches() { Map<Integer, DynamicCacheDescriptor> cachesMap = ctx.affinity().caches(); Map<String, CacheConfiguration<?, ?>> res = U.newHashMap(cachesMap.size()); for (DynamicCacheDescriptor desc : cachesMap.values()) { if (desc.cacheType().userCache()) res.put(desc.cacheName(), desc.cacheConfiguration()); } return res; }
/** * Save dynamic cache descriptor on disk. * * @param desc Cache to save. */ private void saveCacheConfiguration(DynamicCacheDescriptor desc) { try { ctx.cache().saveCacheConfiguration(desc); } catch (IgniteCheckedException e) { log.error("Error while saving cache configuration to disk, cfg = " + desc.cacheConfiguration(), e); } }
/** * 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(); }
/** * Registers caches and groups. * Persists caches configurations on disk if needed. * * @param groupDescriptors Cache group descriptors. * @param cacheDescriptors Cache descriptors. * @return Future that will be completed when all unregistered cache configurations will be persisted. */ private IgniteInternalFuture<?> registerAllCachesAndGroups( Collection<CacheGroupDescriptor> groupDescriptors, Collection<DynamicCacheDescriptor> cacheDescriptors ) { waitLastRegistration(); for (CacheGroupDescriptor grpDesc : groupDescriptors) registerGroup(grpDesc); for (DynamicCacheDescriptor cacheDesc : cacheDescriptors) registerCache(cacheDesc); List<DynamicCacheDescriptor> cachesToPersist = cacheDescriptors.stream() .filter(cacheDesc -> shouldPersist(cacheDesc.cacheConfiguration())) .collect(Collectors.toList()); if (cachesToPersist.isEmpty()) return cachesConfPersistFuture = new GridFinishedFuture<>(); return cachesConfPersistFuture = persistCacheConfigurations(cachesToPersist); }
/** * Constructor of not started cache context. * * @param cacheDesc Cache descriptor. */ public GridCacheContextInfo(DynamicCacheDescriptor cacheDesc) { config = cacheDesc.cacheConfiguration(); dynamicDeploymentId = cacheDesc.deploymentId(); groupId = cacheDesc.groupId(); cacheId = CU.cacheId(config.getName()); clientCache = true; }
/** * Remove all persistent files for all registered caches. */ public void cleanupCachesDirectories() throws IgniteCheckedException { if (sharedCtx.pageStore() == null || sharedCtx.kernalContext().clientNode()) return; for (DynamicCacheDescriptor desc : cacheDescriptors().values()) { if (isPersistentCache(desc.cacheConfiguration(), sharedCtx.gridConfig().getDataStorageConfiguration())) sharedCtx.pageStore().cleanupPersistentSpace(desc.cacheConfiguration()); } }
/** * @param node Node to check. * @return Public cache names accessible on the given node. */ public Map<String, CacheConfiguration> nodePublicCaches(ClusterNode node) { Map<String, CacheConfiguration> caches = U.newHashMap(registeredCaches.size()); for (DynamicCacheDescriptor cacheDesc : ctx.cache().cacheDescriptors().values()) { if (!cacheDesc.cacheType().userCache()) continue; CachePredicate p = registeredCaches.get(cacheDesc.cacheName()); if (p != null && p.cacheNode(node)) caches.put(cacheDesc.cacheName(), cacheDesc.cacheConfiguration()); } return caches; }
/** * Called when cache was restored during recovery and node has joined to topology. * * @param topVer Cache topology join version. * @param clusterWideDesc Cluster-wide cache descriptor received during exchange. */ public void finishRecovery(AffinityTopologyVersion topVer, DynamicCacheDescriptor clusterWideDesc) { assert recoveryMode : this; recoveryMode = false; locStartTopVer = topVer; locMacs = localNode().attribute(ATTR_MACS); assert locMacs != null; this.statisticsEnabled = clusterWideDesc.cacheConfiguration().isStatisticsEnabled(); this.dynamicDeploymentId = clusterWideDesc.deploymentId(); }
/** {@inheritDoc} */ @Override public List<List<ClusterNode>> cachePartitionOwners(String cacheName) { if (cacheName == null) throw new NullPointerException("Null cache name."); DynamicCacheDescriptor cacheDesc = ctx.affinity().caches().get(CU.cacheId(cacheName)); if (cacheDesc == null) throw new IllegalArgumentException("Invalid cache name: " + cacheName); if (cacheDesc.cacheConfiguration().getCacheMode() == CacheMode.LOCAL) return Collections.emptyList(); CacheGroupContext grp = ctx.cache().cacheGroup(cacheDesc.groupId()); GridDhtPartitionTopology top; if (grp == null) { top = ctx.exchange().clientTopologyIfExists(cacheDesc.groupId()); assert top != null : cacheName; } else top = grp.topology(); return top.allOwners(); }
/** * Form a {@link StoredCacheData} with all data to correctly restore cache params when its configuration is read * from page store. Essentially, this method takes from {@link DynamicCacheDescriptor} all that's needed to start * cache correctly, leaving out everything else. */ public StoredCacheData toStoredData() { assert schema != null; StoredCacheData res = new StoredCacheData(cacheConfiguration()); res.queryEntities(schema().entities()); res.sql(sql()); return res; }
/** * Save cache configuration to persistent store if necessary. * * @param desc Cache descriptor. */ public void saveCacheConfiguration(DynamicCacheDescriptor desc) throws IgniteCheckedException { assert desc != null; if (sharedCtx.pageStore() != null && !sharedCtx.kernalContext().clientNode() && isPersistentCache(desc.cacheConfiguration(), sharedCtx.gridConfig().getDataStorageConfiguration())) sharedCtx.pageStore().storeCacheData(desc.toStoredData(), true); }
/** * Finishes recovery for given cache context. * * @param cacheStartVer Cache join to topology version. * @param cacheContext Cache context. * @throws IgniteCheckedException If failed. */ private void finishRecovery( AffinityTopologyVersion cacheStartVer, GridCacheContext<?, ?> cacheContext ) throws IgniteCheckedException { CacheGroupContext groupContext = cacheContext.group(); // Take cluster-wide cache descriptor and try to update local cache and cache group parameters. DynamicCacheDescriptor updatedDescriptor = cacheDescriptor(cacheContext.cacheId()); groupContext.finishRecovery( cacheStartVer, updatedDescriptor.receivedFrom(), isLocalAffinity(updatedDescriptor.cacheConfiguration()) ); cacheContext.finishRecovery(cacheStartVer, updatedDescriptor); if (cacheContext.config().getAtomicityMode() == TRANSACTIONAL_SNAPSHOT) sharedCtx.coordinators().ensureStarted(); onKernalStart(cacheContext.cache()); if (log.isInfoEnabled()) log.info("Finished recovery for cache [cache=" + cacheContext.name() + ", grp=" + groupContext.cacheOrGroupName() + ", startVer=" + cacheStartVer + "]"); }