/** * @return Cache group ID. */ public int groupId() { assert grpDesc != null : this; return grpDesc.groupId(); }
/** * @param grpId Group ID. * @return {@code True} if given cache group stopping. */ public boolean cacheGroupStopping(int grpId) { if (cacheGrpsToStop != null) { for (CacheGroupActionData grp : cacheGrpsToStop) { if (grp.desc.groupId() == grpId) return true; } } return false; }
/** * @param grpId Group ID. * @return {@code True} if given cache group starting. */ public boolean cacheGroupStarting(int grpId) { if (cacheGrpsToStart != null) { for (CacheGroupActionData grp : cacheGrpsToStart) { if (grp.desc.groupId() == grpId) return true; } } return false; }
/** * Adds cache group to registry. * * @param grpDesc Group description. * @return Previously registered cache group or {@code null} otherwise. */ private CacheGroupDescriptor registerGroup(CacheGroupDescriptor grpDesc) { return registeredGrps.put(grpDesc.groupId(), grpDesc); }
/** * @param grpDesc Cache group descriptor. */ public void removeCacheGroup(CacheGroupDescriptor grpDesc) { CacheGroupAffinity rmvd = registeredCacheGrps.remove(grpDesc.groupId()); assert rmvd != null : grpDesc.cacheOrGroupName(); }
/** * Adds cache and caches groups that is not registered yet to registry. * * @param descs Cache and cache group descriptors. * @return Future that will be completed when all unregistered cache configurations will be persisted. */ public IgniteInternalFuture<?> addUnregistered(Collection<DynamicCacheDescriptor> descs) { Collection<CacheGroupDescriptor> groups = descs.stream() .map(DynamicCacheDescriptor::groupDescriptor) .filter(grpDesc -> !registeredGrps.containsKey(grpDesc.groupId())) .collect(Collectors.toList()); Collection<DynamicCacheDescriptor> caches = descs.stream() .filter(cacheDesc -> !registeredCaches.containsKey(cacheDesc.cacheId())) .collect(Collectors.toList()); return registerAllCachesAndGroups(groups, caches); }
/** * @param topVer Topology version. * @param desc Cache descriptor. * @return Cache holder. * @throws IgniteCheckedException If failed. */ private CacheGroupHolder groupHolder(AffinityTopologyVersion topVer, final CacheGroupDescriptor desc) throws IgniteCheckedException { CacheGroupHolder cacheGrp = grpHolders.get(desc.groupId()); if (cacheGrp != null) return cacheGrp; final CacheGroupContext grp = cctx.cache().cacheGroup(desc.groupId()); if (grp == null) { cctx.io().addCacheGroupHandler(desc.groupId(), GridDhtAffinityAssignmentResponse.class, new IgniteBiInClosure<UUID, GridDhtAffinityAssignmentResponse>() { @Override public void apply(UUID nodeId, GridDhtAffinityAssignmentResponse res) { processAffinityAssignmentResponse(nodeId, res); } } ); cacheGrp = CacheGroupHolder2.create(cctx, desc, topVer, null); } else cacheGrp = new CacheGroupHolder1(grp, null); CacheGroupHolder old = grpHolders.put(desc.groupId(), cacheGrp); assert old == null : old; return cacheGrp; }
/** * @param grpDesc Cache group descriptor. * @param filter Node filter. * @param cacheMode Cache mode. */ public void addCacheGroup(CacheGroupDescriptor grpDesc, IgnitePredicate<ClusterNode> filter, CacheMode cacheMode) { CacheGroupAffinity old = registeredCacheGrps.put(grpDesc.groupId(), new CacheGroupAffinity(grpDesc.cacheOrGroupName(), filter, cacheMode, grpDesc.persistenceEnabled())); assert old == null : old; }
/** {@inheritDoc} */ @Override public void initializeForCache(CacheGroupDescriptor grpDesc, StoredCacheData cacheData) throws IgniteCheckedException { assert storeWorkDir != null; int grpId = grpDesc.groupId(); if (!idxCacheStores.containsKey(grpId)) { CacheStoreHolder holder = initForCache(grpDesc, cacheData.config()); CacheStoreHolder old = idxCacheStores.put(grpId, holder); assert old == null : "Non-null old store holder for cache: " + cacheData.config().getName(); } }
/** * @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; }
/** {@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); } } }
/** * Adds caches and cache groups to start from {@code exchActions}. * Removes caches and caches groups to stop from {@code exchActions}. * * @param exchActions Exchange actions. * @return Future that will be completed when all unregistered cache configurations will be persisted. */ public IgniteInternalFuture<?> update(ExchangeActions exchActions) { for (ExchangeActions.CacheGroupActionData stopAction : exchActions.cacheGroupsToStop()) { CacheGroupDescriptor rmvd = unregisterGroup(stopAction.descriptor().groupId()); assert rmvd != null : stopAction.descriptor().cacheOrGroupName(); } for (ExchangeActions.CacheActionData req : exchActions.cacheStopRequests()) unregisterCache(req.descriptor().cacheId()); Collection<CacheGroupDescriptor> grpDescs = exchActions.cacheGroupsToStart().stream() .map(ExchangeActions.CacheGroupActionData::descriptor) .collect(Collectors.toList()); Collection<DynamicCacheDescriptor> cacheDescs = exchActions.cacheStartRequests().stream() .map(ExchangeActions.CacheActionData::descriptor) .collect(Collectors.toList()); return registerAllCachesAndGroups(grpDescs, cacheDescs); }
/** {@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); }
/** * Prepare page store for start cache. * * @param desc Cache descriptor. * @param affNode {@code true} if it is affinity node for cache. * @throws IgniteCheckedException if failed. */ public void preparePageStore(DynamicCacheDescriptor desc, boolean affNode) throws IgniteCheckedException { if (sharedCtx.pageStore() != null && affNode) initializationProtector.protect( desc.groupDescriptor().groupId(), () -> sharedCtx.pageStore().initializeForCache(desc.groupDescriptor(), desc.toStoredData()) ); }
/** * @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); } }
/** * */ 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"); }
/** * @param desc Cache group descriptor. * @param aff Affinity. * @param fut Exchange future. * @throws IgniteCheckedException If failed. */ private void initAffinity(CacheGroupDescriptor desc, GridAffinityAssignmentCache aff, GridDhtPartitionsExchangeFuture fut) throws IgniteCheckedException { assert desc != null : aff.cacheOrGroupName(); ExchangeDiscoveryEvents evts = fut.context().events(); if (canCalculateAffinity(desc, aff, fut)) calculateAndInit(evts, aff, evts.topologyVersion()); else { GridDhtAssignmentFetchFuture fetchFut = new GridDhtAssignmentFetchFuture(cctx, desc.groupId(), evts.topologyVersion(), evts.discoveryCache()); fetchFut.init(false); fetchAffinity(evts.topologyVersion(), evts, evts.discoveryCache(), aff, fetchFut); } }
/** * @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() ); }