Search in sources :

Example 1 with LOCAL

use of org.apache.ignite.cache.CacheMode.LOCAL in project ignite by apache.

the class IgnitePdsPartitionPreloadTest method preloadPartition.

/**
 * @param execNodeFactory Test node factory.
 * @param preloadMode Preload mode.
 */
private void preloadPartition(Supplier<Ignite> execNodeFactory, PreloadMode preloadMode) throws Exception {
    Ignite crd = startGridsMultiThreaded(GRIDS_CNT);
    Ignite testNode = grid(1);
    Object consistentId = testNode.cluster().localNode().consistentId();
    assertEquals(PRIMARY_NODE, testNode.cluster().localNode().consistentId());
    boolean locCacheMode = testNode.cache(DEFAULT_CACHE_NAME).getConfiguration(CacheConfiguration.class).getCacheMode() == LOCAL;
    Integer key = primaryKey(testNode.cache(DEFAULT_CACHE_NAME));
    int preloadPart = crd.affinity(DEFAULT_CACHE_NAME).partition(key);
    int cnt = 0;
    try (IgniteDataStreamer<Integer, Integer> streamer = testNode.dataStreamer(DEFAULT_CACHE_NAME)) {
        int k = 0;
        while (cnt < ENTRY_CNT) {
            if (testNode.affinity(DEFAULT_CACHE_NAME).partition(k) == preloadPart) {
                streamer.addData(k, k);
                cnt++;
            }
            k++;
        }
    }
    forceCheckpoint();
    stopAllGrids();
    startGridsMultiThreaded(GRIDS_CNT);
    testNode = G.allGrids().stream().filter(ignite -> PRIMARY_NODE.equals(ignite.cluster().localNode().consistentId())).findFirst().get();
    if (!locCacheMode)
        assertEquals(testNode, primaryNode(key, DEFAULT_CACHE_NAME));
    Ignite execNode = execNodeFactory.get();
    switch(preloadMode) {
        case SYNC:
            execNode.cache(DEFAULT_CACHE_NAME).preloadPartition(preloadPart);
            if (locCacheMode) {
                testNode = G.allGrids().stream().filter(ignite -> ignite.cluster().localNode().consistentId().equals(consistentId)).findFirst().get();
            }
            break;
        case ASYNC:
            execNode.cache(DEFAULT_CACHE_NAME).preloadPartitionAsync(preloadPart).get();
            if (locCacheMode) {
                testNode = G.allGrids().stream().filter(ignite -> ignite.cluster().localNode().consistentId().equals(consistentId)).findFirst().get();
            }
            break;
        case LOCAL:
            assertTrue(execNode.cache(DEFAULT_CACHE_NAME).localPreloadPartition(preloadPart));
            // For local preloading testNode == execNode
            testNode = execNode;
            break;
    }
    long c0 = testNode.dataRegionMetrics(DEFAULT_REGION).getPagesRead();
    // After partition preloading no pages should be read from store.
    GridIterator<CacheDataRow> cursor = ((IgniteEx) testNode).cachex(DEFAULT_CACHE_NAME).context().offheap().cachePartitionIterator(CU.UNDEFINED_CACHE_ID, preloadPart, null, false);
    int realSize = 0;
    while (cursor.hasNext()) {
        realSize++;
        cursor.next();
    }
    assertEquals("Partition has missed some entries", ENTRY_CNT, realSize);
    assertEquals("Read pages count must be same", c0, testNode.dataRegionMetrics(DEFAULT_REGION).getPagesRead());
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) TRANSACTIONAL_SNAPSHOT(org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT) IgniteEx(org.apache.ignite.internal.IgniteEx) Supplier(java.util.function.Supplier) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) CacheWriteSynchronizationMode(org.apache.ignite.cache.CacheWriteSynchronizationMode) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) G(org.apache.ignite.internal.util.typedef.G) WALMode(org.apache.ignite.configuration.WALMode) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) LOCAL(org.apache.ignite.cache.CacheMode.LOCAL) Predicate(java.util.function.Predicate) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) TRANSACTIONAL(org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL) GridIterator(org.apache.ignite.internal.util.lang.GridIterator) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Ignore(org.junit.Ignore) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) CU(org.apache.ignite.internal.util.typedef.internal.CU) IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) ATOMIC(org.apache.ignite.cache.CacheAtomicityMode.ATOMIC) Collections(java.util.Collections) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) Ignite(org.apache.ignite.Ignite)

Example 2 with LOCAL

use of org.apache.ignite.cache.CacheMode.LOCAL in project ignite by apache.

the class CacheAffinitySharedManager method processClientCacheStartRequests.

/**
 * @param crd Coordinator flag.
 * @param msg Change request.
 * @param topVer Current topology version.
 * @param discoCache Discovery data cache.
 * @return Map of started caches (cache ID to near enabled flag).
 */
@Nullable
private Map<Integer, Boolean> processClientCacheStartRequests(boolean crd, ClientCacheChangeDummyDiscoveryMessage msg, AffinityTopologyVersion topVer, DiscoCache discoCache) {
    Map<String, DynamicCacheChangeRequest> startReqs = msg.startRequests();
    List<DynamicCacheDescriptor> startDescs = clientCachesToStart(msg.requestId(), startReqs);
    if (startDescs == null || startDescs.isEmpty()) {
        cctx.cache().completeClientCacheChangeFuture(msg.requestId(), null);
        return null;
    }
    Map<Integer, GridDhtAssignmentFetchFuture> fetchFuts = U.newHashMap(startDescs.size());
    Map<Integer, Boolean> startedInfos = U.newHashMap(startDescs.size());
    List<StartCacheInfo> startCacheInfos = startDescs.stream().map(desc -> {
        DynamicCacheChangeRequest changeReq = startReqs.get(desc.cacheName());
        startedInfos.put(desc.cacheId(), changeReq.nearCacheConfiguration() != null);
        return new StartCacheInfo(desc.cacheConfiguration(), desc, changeReq.nearCacheConfiguration(), topVer, changeReq.disabledAfterStart(), true);
    }).collect(Collectors.toList());
    Set<String> startedCaches = startCacheInfos.stream().map(info -> info.getCacheDescriptor().cacheName()).collect(Collectors.toSet());
    try {
        cctx.cache().prepareStartCaches(startCacheInfos);
    } catch (IgniteCheckedException e) {
        cctx.cache().closeCaches(startedCaches, false);
        cctx.cache().completeClientCacheChangeFuture(msg.requestId(), e);
        return null;
    }
    Set<CacheGroupDescriptor> groupDescs = startDescs.stream().map(DynamicCacheDescriptor::groupDescriptor).collect(Collectors.toSet());
    for (CacheGroupDescriptor grpDesc : groupDescs) {
        try {
            CacheGroupContext grp = cctx.cache().cacheGroup(grpDesc.groupId());
            assert grp != null : grpDesc.groupId();
            assert !grp.affinityNode() || grp.isLocal() : grp.cacheOrGroupName();
            // Skip for local caches.
            if (grp.isLocal())
                continue;
            CacheGroupHolder grpHolder = grpHolders.get(grp.groupId());
            assert !crd || (grpHolder != null && grpHolder.affinity().idealAssignmentRaw() != null);
            if (grpHolder == null)
                grpHolder = getOrCreateGroupHolder(topVer, grpDesc);
            // If current node is not client and current node have no aff holder.
            if (grpHolder.nonAffNode() && !cctx.localNode().isClient()) {
                GridDhtPartitionsExchangeFuture excFut = context().exchange().lastFinishedFuture();
                grp.topology().updateTopologyVersion(excFut, discoCache, -1, false);
                // Exchange free cache creation, just replacing client topology with dht.
                // Topology should be initialized before the use.
                grp.topology().beforeExchange(excFut, true, false);
                grpHolder = new CacheGroupAffNodeHolder(grp, grpHolder.affinity());
                grpHolders.put(grp.groupId(), grpHolder);
                GridClientPartitionTopology clientTop = cctx.exchange().clearClientTopology(grp.groupId());
                if (clientTop != null) {
                    grp.topology().update(grpHolder.affinity().lastVersion(), clientTop.partitionMap(true), clientTop.fullUpdateCounters(), Collections.<Integer>emptySet(), null, null, null, clientTop.lostPartitions());
                    excFut.validate(grp);
                }
                assert grpHolder.affinity().lastVersion().equals(grp.affinity().lastVersion());
            } else if (!crd && !fetchFuts.containsKey(grp.groupId())) {
                boolean topVerLessOrNotInitialized = !grp.topology().initialized() || grp.topology().readyTopologyVersion().compareTo(topVer) < 0;
                if (grp.affinity().lastVersion().compareTo(topVer) < 0 || topVerLessOrNotInitialized) {
                    GridDhtAssignmentFetchFuture fetchFut = new GridDhtAssignmentFetchFuture(cctx, grp.groupId(), topVer, discoCache);
                    fetchFut.init(true);
                    fetchFuts.put(grp.groupId(), fetchFut);
                }
            }
        } catch (IgniteCheckedException e) {
            cctx.cache().closeCaches(startedCaches, false);
            cctx.cache().completeClientCacheChangeFuture(msg.requestId(), e);
            return null;
        }
    }
    for (GridDhtAssignmentFetchFuture fetchFut : fetchFuts.values()) {
        try {
            CacheGroupContext grp = cctx.cache().cacheGroup(fetchFut.groupId());
            assert grp != null;
            GridDhtAffinityAssignmentResponse res = fetchAffinity(topVer, null, discoCache, grp.affinity(), fetchFut);
            GridDhtPartitionFullMap partMap;
            if (res != null) {
                partMap = res.partitionMap();
                assert partMap != null : res;
            } else
                partMap = new GridDhtPartitionFullMap(cctx.localNodeId(), cctx.localNode().order(), 1);
            GridDhtPartitionsExchangeFuture exchFut = context().exchange().lastFinishedFuture();
            grp.topology().updateTopologyVersion(exchFut, discoCache, -1, false);
            GridClientPartitionTopology clientTop = cctx.exchange().clearClientTopology(grp.groupId());
            Set<Integer> lostParts = clientTop == null ? null : clientTop.lostPartitions();
            grp.topology().update(topVer, partMap, null, Collections.emptySet(), null, null, null, lostParts);
            if (clientTop == null)
                grp.topology().detectLostPartitions(topVer, exchFut);
            exchFut.validate(grp);
        } catch (IgniteCheckedException e) {
            cctx.cache().closeCaches(startedCaches, false);
            cctx.cache().completeClientCacheChangeFuture(msg.requestId(), e);
            return null;
        }
    }
    for (DynamicCacheDescriptor desc : startDescs) {
        if (desc.cacheConfiguration().getCacheMode() != LOCAL) {
            CacheGroupContext grp = cctx.cache().cacheGroup(desc.groupId());
            assert grp != null;
            grp.topology().onExchangeDone(null, grp.affinity().cachedAffinity(topVer), true);
        }
    }
    cctx.cache().initCacheProxies(topVer, null);
    startReqs.keySet().forEach(req -> cctx.cache().completeProxyInitialize(req));
    cctx.cache().completeClientCacheChangeFuture(msg.requestId(), null);
    return startedInfos;
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) DiscoveryCustomEvent(org.apache.ignite.internal.events.DiscoveryCustomEvent) Arrays(java.util.Arrays) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) EVT_NODE_LEFT(org.apache.ignite.events.EventType.EVT_NODE_LEFT) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) GridPartitionStateMap(org.apache.ignite.internal.util.GridPartitionStateMap) IgniteSystemProperties(org.apache.ignite.IgniteSystemProperties) GridLongList(org.apache.ignite.internal.util.GridLongList) AFFINITY_CALCULATION(org.apache.ignite.internal.processors.tracing.SpanType.AFFINITY_CALCULATION) Map(java.util.Map) AffinityFunction(org.apache.ignite.cache.affinity.AffinityFunction) CacheGroupAffinityMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CacheGroupAffinityMessage) GridDhtAssignmentFetchFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtAssignmentFetchFuture) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState) IgniteFuture(org.apache.ignite.lang.IgniteFuture) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) LOCAL(org.apache.ignite.cache.CacheMode.LOCAL) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) Event(org.apache.ignite.events.Event) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) IgniteInClosureX(org.apache.ignite.internal.util.lang.IgniteInClosureX) OWNING(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.OWNING) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) NONE(org.apache.ignite.cache.CacheRebalanceMode.NONE) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) EVT_NODE_FAILED(org.apache.ignite.events.EventType.EVT_NODE_FAILED) GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology) CU(org.apache.ignite.internal.util.typedef.internal.CU) Optional(java.util.Optional) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) GridDhtAffinityAssignmentResponse(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtAffinityAssignmentResponse) Span(org.apache.ignite.internal.processors.tracing.Span) GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) DiscoCache(org.apache.ignite.internal.managers.discovery.DiscoCache) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) AffinityAssignment(org.apache.ignite.internal.processors.affinity.AffinityAssignment) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) GridClientPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridClientPartitionTopology) ClusterNode(org.apache.ignite.cluster.ClusterNode) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) IgniteClosure(org.apache.ignite.lang.IgniteClosure) GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) GridDhtPartitionFullMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap) CacheException(javax.cache.CacheException) F(org.apache.ignite.internal.util.typedef.F) EVT_NODE_JOINED(org.apache.ignite.events.EventType.EVT_NODE_JOINED) Iterator(java.util.Iterator) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridConcurrentHashSet(org.apache.ignite.internal.util.GridConcurrentHashSet) GridAffinityAssignmentCache(org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) DiscoveryDataClusterState(org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) GridPlainRunnable(org.apache.ignite.internal.util.lang.GridPlainRunnable) Collections(java.util.Collections) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) GridLocalEventListener(org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener) IgniteUuid(org.apache.ignite.lang.IgniteUuid) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridDhtAssignmentFetchFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtAssignmentFetchFuture) GridClientPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridClientPartitionTopology) GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) GridDhtPartitionFullMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap) GridDhtAffinityAssignmentResponse(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtAffinityAssignmentResponse) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Collections (java.util.Collections)2 LOCAL (org.apache.ignite.cache.CacheMode.LOCAL)2 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)2 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1