/** * Collects non local cache group descriptors. * * @return Collection of non local cache group descriptors. */ private List<CacheGroupDescriptor> nonLocalCacheGroupDescriptors() { return cctx.affinity().cacheGroups().values().stream() .filter(grpDesc -> grpDesc.config().getCacheMode() != CacheMode.LOCAL) .collect(Collectors.toList()); }
/** * Starts statically configured caches received from remote nodes during exchange. * * @param nodeId Joining node ID. * @param exchTopVer Current exchange version. * @return Started caches descriptors. * @throws IgniteCheckedException If failed. */ public Collection<DynamicCacheDescriptor> startReceivedCaches(UUID nodeId, AffinityTopologyVersion exchTopVer) throws IgniteCheckedException { List<DynamicCacheDescriptor> receivedCaches = cachesInfo.cachesReceivedFromJoin(nodeId); List<StartCacheInfo> startCacheInfos = receivedCaches.stream() .filter(desc -> isLocalAffinity(desc.groupDescriptor().config())) .map(desc -> new StartCacheInfo(desc, null, exchTopVer, false)) .collect(Collectors.toList()); prepareStartCaches(startCacheInfos); return receivedCaches; }
/** * @param c Cache closure. */ private void forAllRegisteredCacheGroups(IgniteInClosureX<CacheGroupDescriptor> c) { Collection<CacheGroupDescriptor> affinityCaches = cachesRegistry.allGroups().values().stream() .filter(desc -> desc.config().getCacheMode() != LOCAL) .collect(Collectors.toList()); try { U.doInParallel(cctx.kernalContext().getSystemExecutorService(), affinityCaches, t -> { c.applyx(t); return null; }); } catch (IgniteCheckedException e) { throw new IgniteException("Failed to execute affinity operation on cache groups", e); } }
/** * @param knownKeys Saved keys set. * @return New keys for local cache groups. */ @Nullable private HashMap<Integer, byte[]> newEncryptionKeys(Set<Integer> knownKeys) { Map<Integer, CacheGroupDescriptor> grpDescs = ctx.cache().cacheGroupDescriptors(); HashMap<Integer, byte[]> newKeys = null; for (CacheGroupDescriptor grpDesc : grpDescs.values()) { if (knownKeys.contains(grpDesc.groupId()) || !grpDesc.config().isEncryptionEnabled()) continue; if (newKeys == null) newKeys = new HashMap<>(); newKeys.put(grpDesc.groupId(), getSpi().encryptKey(getSpi().create())); } return newKeys; }
/** * @param ccfg Cache configuration to start. * @throws IgniteCheckedException If failed. */ void validateStartCacheConfiguration(CacheConfiguration ccfg) throws IgniteCheckedException { if (ccfg.getGroupName() != null) { CacheGroupDescriptor grpDesc = cacheGroupByName(ccfg.getGroupName()); if (grpDesc != null) { assert ccfg.getGroupName().equals(grpDesc.groupName()); validateCacheGroupConfiguration(grpDesc.config(), ccfg); } } }
/** * Check for affinity node and customize near configuration if needed. * * @param desc Cache descriptor. * @param reqNearCfg Near configuration if specified for client cache start request. * @param ccfg Cache configuration to use. * @return {@code true} if it is affinity node for cache. */ private boolean checkForAffinityNode( DynamicCacheDescriptor desc, @Nullable NearCacheConfiguration reqNearCfg, CacheConfiguration ccfg ) { if (ccfg.getCacheMode() == LOCAL) { ccfg.setNearConfiguration(null); return true; } if (isLocalAffinity(desc.groupDescriptor().config())) return true; ccfg.setNearConfiguration(reqNearCfg); return false; }
/** * Return cache store holedr. * * @param grpId Cache group ID. * @return Cache store holder. */ private CacheStoreHolder getHolder(int grpId) throws IgniteCheckedException { try { return idxCacheStores.computeIfAbsent(grpId, (key) -> { CacheGroupDescriptor gDesc = cctx.cache().cacheGroupDescriptors().get(grpId); CacheStoreHolder holder0 = null; if (gDesc != null) { if (CU.isPersistentCache(gDesc.config(), cctx.gridConfig().getDataStorageConfiguration())) { try { holder0 = initForCache(gDesc, gDesc.config()); } catch (IgniteCheckedException e) { throw new IgniteException(e); } } } return holder0; }); } catch (IgniteException ex) { if (X.hasCause(ex, IgniteCheckedException.class)) throw ex.getCause(IgniteCheckedException.class); else throw ex; } }
/** * @param grpId Cache group ID. * @param discoCache Discovery data cache. * @return Topology. */ public GridDhtPartitionTopology clientTopology(int grpId, DiscoCache discoCache) { GridClientPartitionTopology top = clientTops.get(grpId); if (top != null) return top; CacheGroupDescriptor grpDesc = cctx.affinity().cacheGroups().get(grpId); assert grpDesc != null : grpId; CacheConfiguration<?, ?> ccfg = grpDesc.config(); AffinityFunction aff = ccfg.getAffinity(); Object affKey = cctx.kernalContext().affinity().similaryAffinityKey(aff, ccfg.getNodeFilter(), ccfg.getBackups(), aff.partitions()); GridClientPartitionTopology old = clientTops.putIfAbsent(grpId, top = new GridClientPartitionTopology(cctx, discoCache, grpId, aff.partitions(), affKey)); return old != null ? old : top; }
/** * Method to merge this CacheGroup descriptor with another one. * * @param otherDesc CacheGroup descriptor that must be merged with this one. */ void mergeWith(CacheGroupDescriptor otherDesc) { assert otherDesc != null && otherDesc.config() != null : otherDesc; CacheConfiguration otherCfg = otherDesc.config(); cacheCfg.setRebalanceDelay(otherCfg.getRebalanceDelay()); cacheCfg.setRebalanceBatchesPrefetchCount(otherCfg.getRebalanceBatchesPrefetchCount()); cacheCfg.setRebalanceBatchSize(otherCfg.getRebalanceBatchSize()); cacheCfg.setRebalanceOrder(otherCfg.getRebalanceOrder()); cacheCfg.setRebalanceThrottle(otherCfg.getRebalanceThrottle()); cacheCfg.setRebalanceTimeout(otherCfg.getRebalanceTimeout()); }
/** {@inheritDoc} */ @Override public void cleanupRestoredCaches() { if (dataRegionMap.isEmpty()) return; for (CacheGroupDescriptor grpDesc : cctx.cache().cacheGroupDescriptors().values()) { String regionName = grpDesc.config().getDataRegionName(); DataRegion region = regionName != null ? dataRegionMap.get(regionName) : dfltDataRegion; if (region == null) continue; if (log.isInfoEnabled()) log.info("Page memory " + region.config().getName() + " for " + grpDesc + " has invalidated."); int partitions = grpDesc.config().getAffinity().partitions(); if (region.pageMemory() instanceof PageMemoryEx) { PageMemoryEx memEx = (PageMemoryEx)region.pageMemory(); for (int partId = 0; partId < partitions; partId++) memEx.invalidate(grpDesc.groupId(), partId); memEx.invalidate(grpDesc.groupId(), PageIdAllocator.INDEX_PARTITION); } } storeMgr.cleanupPageStoreIfMatch( new Predicate<Integer>() { @Override public boolean test(Integer grpId) { return MetaStorage.METASTORAGE_CACHE_ID != grpId; } }, true); }
/** {@inheritDoc} */ @Override public void beforeCacheGroupStart(CacheGroupDescriptor grpDesc) { if (grpDesc.persistenceEnabled()) { boolean localEnabled = cctx.database().walEnabled(grpDesc.groupId(), true); boolean globalEnabled = cctx.database().walEnabled(grpDesc.groupId(), false); if (!localEnabled || !globalEnabled) { File dir = cacheWorkDir(grpDesc.config()); assert dir.exists(); boolean res = IgniteUtils.delete(dir); assert res; if (!globalEnabled) grpDesc.walEnabled(false); } } }
cacheGrpsInfo.put(grp.groupId(), new CacheClientReconnectDiscoveryData.CacheGroupInfo(desc.config(), desc.deploymentId(), 0));
/** * Obtains PageMemory reference from cache descriptor instead of cache context. * * @param grpId Cache group id. * @return PageMemoryEx instance. * @throws IgniteCheckedException if no DataRegion is configured for a name obtained from cache descriptor. */ private PageMemoryEx getPageMemoryForCacheGroup(int grpId) throws IgniteCheckedException { if (grpId == MetaStorage.METASTORAGE_CACHE_ID) return (PageMemoryEx)dataRegion(METASTORE_DATA_REGION_NAME).pageMemory(); // TODO IGNITE-7792 add generic mapping. if (grpId == TxLog.TX_LOG_CACHE_ID) return (PageMemoryEx)dataRegion(TxLog.TX_LOG_CACHE_NAME).pageMemory(); // TODO IGNITE-5075: cache descriptor can be removed. GridCacheSharedContext sharedCtx = context(); CacheGroupDescriptor desc = sharedCtx.cache().cacheGroupDescriptors().get(grpId); if (desc == null) return null; String memPlcName = desc.config().getDataRegionName(); return (PageMemoryEx)sharedCtx.database().dataRegion(memPlcName).pageMemory(); }
/** * @param grpDesc Cache group descriptor. * @param ccfg Cache configuration. * @return Cache store holder. * @throws IgniteCheckedException If failed. */ private CacheStoreHolder initForCache(CacheGroupDescriptor grpDesc, CacheConfiguration ccfg) throws IgniteCheckedException { assert !grpDesc.sharedGroup() || ccfg.getGroupName() != null : ccfg.getName(); File cacheWorkDir = cacheWorkDir(ccfg); String dataRegionName = grpDesc.config().getDataRegionName(); DataRegionMetricsImpl regionMetrics = cctx.database().dataRegion(dataRegionName).memoryMetrics(); int grpId = CU.cacheId(grpDesc.cacheOrGroupName()); AllocatedPageTracker allocatedTracker = regionMetrics.getOrAllocateGroupPageAllocationTracker(grpId); return initDir( cacheWorkDir, grpDesc.groupId(), grpDesc.config().getAffinity().partitions(), allocatedTracker, ccfg.isEncryptionEnabled() ); }
/** * @param fut Exchange future. * @param grpDesc Cache group descriptor. * @throws IgniteCheckedException If failed. */ private void initStartedGroupOnCoordinator(GridDhtPartitionsExchangeFuture fut, final CacheGroupDescriptor grpDesc) throws IgniteCheckedException { assert grpDesc != null && grpDesc.groupId() != 0 : grpDesc; if (grpDesc.config().getCacheMode() == LOCAL) return; int grpId = grpDesc.groupId(); CacheGroupHolder grpHolder = grpHolders.get(grpId); CacheGroupContext grp = cctx.kernalContext().cache().cacheGroup(grpId); if (grpHolder == null) { grpHolder = grp != null ? new CacheGroupHolder1(grp, null) : CacheGroupHolder2.create(cctx, grpDesc, fut.initialVersion(), null); CacheGroupHolder old = grpHolders.put(grpId, grpHolder); assert old == null : old; calculateAndInit(fut.events(), grpHolder.affinity(), fut.initialVersion()); } else if (grpHolder.client() && grp != null) { assert grpHolder.affinity().idealAssignment() != null; grpHolder = new CacheGroupHolder1(grp, grpHolder.affinity()); grpHolders.put(grpId, grpHolder); } }
/** * @param desc First descriptor. * @param desc0 Second descriptor. */ private void checkGroupDescriptorsData(CacheGroupDescriptor desc, CacheGroupDescriptor desc0) { assertEquals(desc.groupName(), desc0.groupName()); assertEquals(desc.sharedGroup(), desc0.sharedGroup()); assertEquals(desc.deploymentId(), desc0.deploymentId()); assertEquals(desc.receivedFrom(), desc0.receivedFrom()); assertEquals(desc.startTopologyVersion(), desc0.startTopologyVersion()); assertEquals(desc.config().getName(), desc0.config().getName()); assertEquals(desc.config().getGroupName(), desc0.config().getGroupName()); assertEquals(desc.caches(), desc0.caches()); }
if (data.descriptor().config().getCacheMode() != LOCAL) { CacheGroupHolder cacheGrp = grpHolders.remove(data.descriptor().groupId());
IgnitePredicate<ClusterNode> nodeFilter = grpDesc.config().getNodeFilter();
assert !cctx.kernalContext().clientNode(); CacheConfiguration<?, ?> ccfg = grpDesc.config();
/** * */ private void assignPartitionsStates() { try { U.doInParallel( cctx.kernalContext().getSystemExecutorService(), nonLocalCacheGroupDescriptors(), grpDesc -> { CacheGroupContext grpCtx = cctx.cache().cacheGroup(grpDesc.groupId()); GridDhtPartitionTopology top = grpCtx != null ? grpCtx.topology() : cctx.exchange().clientTopology(grpDesc.groupId(), events().discoveryCache()); if (!CU.isPersistentCache(grpDesc.config(), cctx.gridConfig().getDataStorageConfiguration())) assignPartitionSizes(top); else assignPartitionStates(top); return null; } ); } catch (IgniteCheckedException e) { throw new IgniteException("Failed to assign partition states", e); } timeBag.finishGlobalStage("Assign partitions states"); }