Search in sources :

Example 16 with CacheGroupContext

use of org.apache.ignite.internal.processors.cache.CacheGroupContext in project ignite by apache.

the class GridDhtPartitionsExchangeFuture method updatePartitionFullMap.

/**
 * Updates partition map in all caches.
 *
 * @param resTopVer Result topology version.
 * @param msg Partitions full messages.
 */
private void updatePartitionFullMap(AffinityTopologyVersion resTopVer, GridDhtPartitionsFullMessage msg) {
    cctx.versions().onExchange(msg.lastVersion().order());
    assert partHistSuppliers.isEmpty();
    partHistSuppliers.putAll(msg.partitionHistorySuppliers());
    for (Map.Entry<Integer, GridDhtPartitionFullMap> entry : msg.partitions().entrySet()) {
        Integer grpId = entry.getKey();
        CacheGroupContext grp = cctx.cache().cacheGroup(grpId);
        if (grp != null) {
            CachePartitionFullCountersMap cntrMap = msg.partitionUpdateCounters(grpId, grp.topology().partitions());
            grp.topology().update(resTopVer, entry.getValue(), cntrMap, msg.partsToReload(cctx.localNodeId(), grpId), null);
        } else {
            ClusterNode oldest = cctx.discovery().oldestAliveServerNode(AffinityTopologyVersion.NONE);
            if (oldest != null && oldest.isLocal()) {
                GridDhtPartitionTopology top = cctx.exchange().clientTopology(grpId, events().discoveryCache());
                CachePartitionFullCountersMap cntrMap = msg.partitionUpdateCounters(grpId, top.partitions());
                top.update(resTopVer, entry.getValue(), cntrMap, Collections.emptySet(), null);
            }
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionTopology) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 17 with CacheGroupContext

use of org.apache.ignite.internal.processors.cache.CacheGroupContext in project ignite by apache.

the class GridDhtPartitionsExchangeFuture method onAllServersLeft.

/**
 */
private void onAllServersLeft() {
    assert cctx.kernalContext().clientNode() : cctx.localNode();
    List<ClusterNode> empty = Collections.emptyList();
    for (CacheGroupContext grp : cctx.cache().cacheGroups()) {
        List<List<ClusterNode>> affAssignment = new ArrayList<>(grp.affinity().partitions());
        for (int i = 0; i < grp.affinity().partitions(); i++) affAssignment.add(empty);
        grp.affinity().idealAssignment(affAssignment);
        grp.affinity().initialize(initialVersion(), affAssignment);
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext)

Example 18 with CacheGroupContext

use of org.apache.ignite.internal.processors.cache.CacheGroupContext in project ignite by apache.

the class GridDhtPartitionsExchangeFuture method distributedExchange.

/**
 * @throws IgniteCheckedException If failed.
 */
private void distributedExchange() throws IgniteCheckedException {
    assert crd != null;
    assert !cctx.kernalContext().clientNode();
    for (CacheGroupContext grp : cctx.cache().cacheGroups()) {
        if (grp.isLocal())
            continue;
        grp.preloader().onTopologyChanged(this);
    }
    cctx.database().releaseHistoryForPreloading();
    // To correctly rebalance when persistence is enabled, it is necessary to reserve history within exchange.
    partHistReserved = cctx.database().reserveHistoryForExchange();
    waitPartitionRelease();
    boolean topChanged = firstDiscoEvt.type() != EVT_DISCOVERY_CUSTOM_EVT || affChangeMsg != null;
    for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
        if (cacheCtx.isLocal() || cacheStopping(cacheCtx.cacheId()))
            continue;
        if (topChanged) {
            // Partition release future is done so we can flush the write-behind store.
            cacheCtx.store().forceFlush();
        }
    }
    if (!exchCtx.mergeExchanges()) {
        for (CacheGroupContext grp : cctx.cache().cacheGroups()) {
            if (grp.isLocal() || cacheGroupStopping(grp.groupId()))
                continue;
            // It is possible affinity is not initialized yet if node joins to cluster.
            if (grp.affinity().lastVersion().topologyVersion() > 0)
                grp.topology().beforeExchange(this, !centralizedAff && !forceAffReassignment, false);
        }
    }
    // It is necessary to run database callback after all topology callbacks, so partition states could be
    // correctly restored from the persistent store.
    cctx.database().beforeExchange(this);
    changeWalModeIfNeeded();
    if (crd.isLocal()) {
        if (remaining.isEmpty())
            onAllReceived(null);
    } else
        sendPartitions(crd);
    initDone();
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext)

Example 19 with CacheGroupContext

use of org.apache.ignite.internal.processors.cache.CacheGroupContext in project ignite by apache.

the class GridCacheDatabaseSharedManager method onCacheGroupsStopped.

/**
 * {@inheritDoc}
 */
@Override
public void onCacheGroupsStopped(Collection<IgniteBiTuple<CacheGroupContext, Boolean>> stoppedGrps) {
    Map<PageMemoryEx, Collection<Integer>> destroyed = new HashMap<>();
    for (IgniteBiTuple<CacheGroupContext, Boolean> tup : stoppedGrps) {
        CacheGroupContext gctx = tup.get1();
        if (!gctx.persistenceEnabled())
            continue;
        snapshotMgr.onCacheGroupStop(gctx);
        PageMemoryEx pageMem = (PageMemoryEx) gctx.dataRegion().pageMemory();
        Collection<Integer> grpIds = destroyed.get(pageMem);
        if (grpIds == null) {
            grpIds = new HashSet<>();
            destroyed.put(pageMem, grpIds);
        }
        grpIds.add(tup.get1().groupId());
        pageMem.onCacheGroupDestroyed(tup.get1().groupId());
    }
    Collection<IgniteInternalFuture<Void>> clearFuts = new ArrayList<>(destroyed.size());
    for (Map.Entry<PageMemoryEx, Collection<Integer>> entry : destroyed.entrySet()) {
        final Collection<Integer> grpIds = entry.getValue();
        clearFuts.add(entry.getKey().clearAsync((grpId, pageIdg) -> grpIds.contains(grpId), false));
    }
    for (IgniteInternalFuture<Void> clearFut : clearFuts) {
        try {
            clearFut.get();
        } catch (IgniteCheckedException e) {
            log.error("Failed to clear page memory", e);
        }
    }
    if (cctx.pageStore() != null) {
        for (IgniteBiTuple<CacheGroupContext, Boolean> tup : stoppedGrps) {
            CacheGroupContext grp = tup.get1();
            if (grp.affinityNode()) {
                try {
                    cctx.pageStore().shutdownForCacheGroup(grp, tup.get2());
                } catch (IgniteCheckedException e) {
                    U.error(log, "Failed to gracefully clean page store resources for destroyed cache " + "[cache=" + grp.cacheOrGroupName() + "]", e);
                }
            }
        }
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile) OverlappingFileLockException(java.nio.channels.OverlappingFileLockException) Arrays(java.util.Arrays) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) MetastorageLifecycleListener(org.apache.ignite.internal.processors.cache.persistence.metastorage.MetastorageLifecycleListener) CheckpointWriteOrder(org.apache.ignite.configuration.CheckpointWriteOrder) IGNITE_PDS_SKIP_CRC(org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_SKIP_CRC) UnsafeMemoryProvider(org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider) FileIO(org.apache.ignite.internal.processors.cache.persistence.file.FileIO) GridPortRecord(org.apache.ignite.internal.processors.port.GridPortRecord) Matcher(java.util.regex.Matcher) PagePartitionMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO) METASTORAGE_CACHE_ID(org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage.METASTORAGE_CACHE_ID) Map(java.util.Map) PageUtils(org.apache.ignite.internal.pagemem.PageUtils) Path(java.nio.file.Path) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheGroupDescriptor(org.apache.ignite.internal.processors.cache.CacheGroupDescriptor) Set(java.util.Set) DataEntry(org.apache.ignite.internal.pagemem.wal.record.DataEntry) IGNITE_PDS_MAX_CHECKPOINT_MEMORY_HISTORY_SIZE(org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_MAX_CHECKPOINT_MEMORY_HISTORY_SIZE) ByteOrder(java.nio.ByteOrder) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgnitePageStoreManager(org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager) PageIdUtils(org.apache.ignite.internal.pagemem.PageIdUtils) MappedFileMemoryProvider(org.apache.ignite.internal.mem.file.MappedFileMemoryProvider) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) PageSnapshot(org.apache.ignite.internal.pagemem.wal.record.PageSnapshot) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) AtomicIntegerFieldUpdater(java.util.concurrent.atomic.AtomicIntegerFieldUpdater) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) IgniteThread(org.apache.ignite.thread.IgniteThread) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState) U(org.apache.ignite.internal.util.typedef.internal.U) IgniteLogger(org.apache.ignite.IgniteLogger) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) WALPointer(org.apache.ignite.internal.pagemem.wal.WALPointer) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ArrayList(java.util.ArrayList) GridKernalContext(org.apache.ignite.internal.GridKernalContext) READ(java.nio.file.StandardOpenOption.READ) ConcurrentLinkedHashMap(org.jsr166.ConcurrentLinkedHashMap) ClusterNode(org.apache.ignite.cluster.ClusterNode) CI1(org.apache.ignite.internal.util.typedef.CI1) GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) S(org.apache.ignite.internal.util.typedef.internal.S) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) SoftReference(java.lang.ref.SoftReference) DataStorageMetrics(org.apache.ignite.DataStorageMetrics) Files(java.nio.file.Files) GridUnsafe(org.apache.ignite.internal.util.GridUnsafe) IOException(java.io.IOException) IGNITE_PDS_WAL_REBALANCE_THRESHOLD(org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_WAL_REBALANCE_THRESHOLD) File(java.io.File) T2(org.apache.ignite.internal.util.typedef.T2) PageMemoryImpl(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImpl) FileFilter(java.io.FileFilter) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) Paths(java.nio.file.Paths) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) IgniteCacheSnapshotManager(org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteCacheSnapshotManager) GridInClosure3X(org.apache.ignite.internal.util.lang.GridInClosure3X) PartitionDestroyRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PartitionDestroyRecord) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) PageStore(org.apache.ignite.internal.pagemem.store.PageStore) StoredCacheData(org.apache.ignite.internal.processors.cache.StoredCacheData) CheckpointMetricsTracker(org.apache.ignite.internal.processors.cache.persistence.pagemem.CheckpointMetricsTracker) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition) GridWorker(org.apache.ignite.internal.util.worker.GridWorker) ByteBuffer(java.nio.ByteBuffer) FileLock(java.nio.channels.FileLock) IgniteSystemProperties(org.apache.ignite.IgniteSystemProperties) SB(org.apache.ignite.internal.util.typedef.internal.SB) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PureJavaCrc32(org.apache.ignite.internal.processors.cache.persistence.wal.crc.PureJavaCrc32) DataStorageMetricsMXBean(org.apache.ignite.mxbean.DataStorageMetricsMXBean) FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer) FilePageStore(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore) IgniteFuture(org.apache.ignite.lang.IgniteFuture) CacheState(org.apache.ignite.internal.pagemem.wal.record.CacheState) IgniteOutClosure(org.apache.ignite.lang.IgniteOutClosure) EventType(org.apache.ignite.events.EventType) Collection(java.util.Collection) IgniteException(org.apache.ignite.IgniteException) WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) StandardOpenOption(java.nio.file.StandardOpenOption) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) StorageException(org.apache.ignite.internal.pagemem.wal.StorageException) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) MetaStorage(org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage) UUID(java.util.UUID) ObjectName(javax.management.ObjectName) NavigableMap(java.util.NavigableMap) NodeInvalidator(org.apache.ignite.internal.NodeInvalidator) DirectMemoryProvider(org.apache.ignite.internal.mem.DirectMemoryProvider) DataRecord(org.apache.ignite.internal.pagemem.wal.record.DataRecord) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) PageDeltaRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PageDeltaRecord) ExchangeActions(org.apache.ignite.internal.processors.cache.ExchangeActions) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) CU(org.apache.ignite.internal.util.typedef.internal.CU) Pattern(java.util.regex.Pattern) NotNull(org.jetbrains.annotations.NotNull) LongAdder(java.util.concurrent.atomic.LongAdder) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) GridMultiCollectionWrapper(org.apache.ignite.internal.util.GridMultiCollectionWrapper) HashMap(java.util.HashMap) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) LT(org.apache.ignite.internal.util.typedef.internal.LT) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) IgniteUtils(org.apache.ignite.internal.util.IgniteUtils) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) PageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO) IgniteThreadPoolExecutor(org.apache.ignite.thread.IgniteThreadPoolExecutor) MemoryRecoveryRecord(org.apache.ignite.internal.pagemem.wal.record.MemoryRecoveryRecord) ExecutorService(java.util.concurrent.ExecutorService) SnapshotOperation(org.apache.ignite.internal.processors.cache.persistence.snapshot.SnapshotOperation) GridDiscoveryManager(org.apache.ignite.internal.managers.discovery.GridDiscoveryManager) PartitionAllocationMap(org.apache.ignite.internal.processors.cache.persistence.partstate.PartitionAllocationMap) F(org.apache.ignite.internal.util.typedef.F) MetastoreDataRecord(org.apache.ignite.internal.pagemem.wal.record.MetastoreDataRecord) Iterator(java.util.Iterator) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) CountDownFuture(org.apache.ignite.internal.util.future.CountDownFuture) DataPageEvictionMode(org.apache.ignite.configuration.DataPageEvictionMode) CheckpointRecord(org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord) GridToStringInclude(org.apache.ignite.internal.util.tostring.GridToStringInclude) TimeUnit(java.util.concurrent.TimeUnit) PartitionMetaStateRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PartitionMetaStateRecord) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) Comparator(java.util.Comparator) FileChannel(java.nio.channels.FileChannel) Collections(java.util.Collections) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) ConcurrentLinkedHashMap(org.jsr166.ConcurrentLinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Collection(java.util.Collection) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) Map(java.util.Map) ConcurrentLinkedHashMap(org.jsr166.ConcurrentLinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) NavigableMap(java.util.NavigableMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) PartitionAllocationMap(org.apache.ignite.internal.processors.cache.persistence.partstate.PartitionAllocationMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap)

Example 20 with CacheGroupContext

use of org.apache.ignite.internal.processors.cache.CacheGroupContext in project ignite by apache.

the class GridCacheDatabaseSharedManager method partsForCheckpointHistorySearch.

/**
 * @return Map of group id -> Set parts.
 */
private Map<Integer, Set<Integer>> partsForCheckpointHistorySearch() {
    Map<Integer, Set<Integer>> part4CheckpointHistSearch = new HashMap<>();
    for (CacheGroupContext grp : cctx.cache().cacheGroups()) {
        if (grp.isLocal())
            continue;
        for (GridDhtLocalPartition part : grp.topology().currentLocalPartitions()) {
            if (part.state() != GridDhtPartitionState.OWNING || part.dataStore().fullSize() <= walRebalanceThreshold)
                continue;
            Set<Integer> parts = part4CheckpointHistSearch.get(grp.groupId());
            if (parts == null)
                part4CheckpointHistSearch.put(grp.groupId(), parts = new HashSet<>());
            parts.add(part.id());
        }
    }
    return part4CheckpointHistSearch;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Set(java.util.Set) HashSet(java.util.HashSet) ConcurrentLinkedHashMap(org.jsr166.ConcurrentLinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext)

Aggregations

CacheGroupContext (org.apache.ignite.internal.processors.cache.CacheGroupContext)21 HashMap (java.util.HashMap)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)7 Map (java.util.Map)6 ConcurrentMap (java.util.concurrent.ConcurrentMap)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 LinkedHashMap (java.util.LinkedHashMap)5 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)5 GridDhtPartitionTopology (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionTopology)5 ArrayList (java.util.ArrayList)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 List (java.util.List)3 UUID (java.util.UUID)3 ClusterNode (org.apache.ignite.cluster.ClusterNode)3 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)3 GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition)3 HashSet (java.util.HashSet)2 Set (java.util.Set)2 IgniteNeedReconnectException (org.apache.ignite.internal.IgniteNeedReconnectException)2 DiscoveryCustomEvent (org.apache.ignite.internal.events.DiscoveryCustomEvent)2