Search in sources :

Example 1 with EVT_NODE_JOINED

use of org.apache.ignite.events.EventType.EVT_NODE_JOINED in project ignite by apache.

the class GridDhtPartitionTopologyImpl method resetOwners.

/**
 * {@inheritDoc}
 */
@Override
public Map<UUID, Set<Integer>> resetOwners(Map<Integer, Set<UUID>> ownersByUpdCounters, Set<Integer> haveHist, GridDhtPartitionsExchangeFuture exchFut) {
    Map<UUID, Set<Integer>> res = new HashMap<>();
    Collection<DiscoveryEvent> evts = exchFut.events().events();
    Set<UUID> joinedNodes = U.newHashSet(evts.size());
    for (DiscoveryEvent evt : evts) {
        if (evt.type() == EVT_NODE_JOINED)
            joinedNodes.add(evt.eventNode().id());
    }
    ctx.database().checkpointReadLock();
    try {
        Map<UUID, Set<Integer>> addToWaitGroups = new HashMap<>();
        lock.writeLock().lock();
        try {
            // First process local partitions.
            UUID locNodeId = ctx.localNodeId();
            for (Map.Entry<Integer, Set<UUID>> entry : ownersByUpdCounters.entrySet()) {
                int part = entry.getKey();
                Set<UUID> maxCounterPartOwners = entry.getValue();
                GridDhtLocalPartition locPart = localPartition(part);
                if (locPart == null || locPart.state() != OWNING)
                    continue;
                // Partition state should be mutated only on joining nodes if they are exists for the exchange.
                if (joinedNodes.isEmpty() && !maxCounterPartOwners.contains(locNodeId)) {
                    rebalancePartition(part, !haveHist.contains(part), exchFut);
                    res.computeIfAbsent(locNodeId, n -> new HashSet<>()).add(part);
                }
            }
            // Then process node maps.
            for (Map.Entry<Integer, Set<UUID>> entry : ownersByUpdCounters.entrySet()) {
                int part = entry.getKey();
                Set<UUID> maxCounterPartOwners = entry.getValue();
                for (Map.Entry<UUID, GridDhtPartitionMap> remotes : node2part.entrySet()) {
                    UUID remoteNodeId = remotes.getKey();
                    if (!joinedNodes.isEmpty() && !joinedNodes.contains(remoteNodeId))
                        continue;
                    GridDhtPartitionMap partMap = remotes.getValue();
                    GridDhtPartitionState state = partMap.get(part);
                    if (state != OWNING)
                        continue;
                    if (!maxCounterPartOwners.contains(remoteNodeId)) {
                        partMap.put(part, MOVING);
                        partMap.updateSequence(partMap.updateSequence() + 1, partMap.topologyVersion());
                        if (partMap.nodeId().equals(locNodeId))
                            updateSeq.setIfGreater(partMap.updateSequence());
                        res.computeIfAbsent(remoteNodeId, n -> new HashSet<>()).add(part);
                    }
                }
            }
            for (Map.Entry<UUID, Set<Integer>> entry : res.entrySet()) {
                UUID nodeId = entry.getKey();
                Set<Integer> rebalancedParts = entry.getValue();
                addToWaitGroups.put(nodeId, new HashSet<>(rebalancedParts));
                if (!rebalancedParts.isEmpty()) {
                    Set<Integer> historical = rebalancedParts.stream().filter(haveHist::contains).collect(Collectors.toSet());
                    // Filter out partitions having WAL history.
                    rebalancedParts.removeAll(historical);
                    U.warn(log, "Partitions have been scheduled for rebalancing due to outdated update counter " + "[grp=" + grp.cacheOrGroupName() + ", readyTopVer=" + readyTopVer + ", topVer=" + exchFut.initialVersion() + ", nodeId=" + nodeId + ", partsFull=" + S.compact(rebalancedParts) + ", partsHistorical=" + S.compact(historical) + "]");
                }
            }
            node2part = new GridDhtPartitionFullMap(node2part, updateSeq.incrementAndGet());
        } finally {
            lock.writeLock().unlock();
        }
        List<List<ClusterNode>> ideal = ctx.affinity().affinity(groupId()).idealAssignmentRaw();
        for (Map.Entry<UUID, Set<Integer>> entry : addToWaitGroups.entrySet()) {
            // Add to wait groups to ensure late assignment switch after all partitions are rebalanced.
            for (Integer part : entry.getValue()) {
                ctx.cache().context().affinity().addToWaitGroup(groupId(), part, topologyVersionFuture().initialVersion(), ideal.get(part));
            }
        }
    } finally {
        ctx.database().checkpointReadUnlock();
    }
    return res;
}
Also used : GridPartitionStateMap(org.apache.ignite.internal.util.GridPartitionStateMap) CachePartitionFullCountersMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionFullCountersMap) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) AtomicReferenceArray(java.util.concurrent.atomic.AtomicReferenceArray) GridLongList(org.apache.ignite.internal.util.GridLongList) EVT_CACHE_REBALANCE_PART_DATA_LOST(org.apache.ignite.events.EventType.EVT_CACHE_REBALANCE_PART_DATA_LOST) RollbackRecord(org.apache.ignite.internal.pagemem.wal.record.RollbackRecord) SB(org.apache.ignite.internal.util.typedef.internal.SB) Map(java.util.Map) X(org.apache.ignite.internal.util.typedef.X) GridDhtTopologyFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTopologyFuture) EventType(org.apache.ignite.events.EventType) GridToStringExclude(org.apache.ignite.internal.util.tostring.GridToStringExclude) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) Set(java.util.Set) ALL(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture.ExchangeType.ALL) OWNING(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.OWNING) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) CU(org.apache.ignite.internal.util.typedef.internal.CU) LOST(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.LOST) GridClusterStateProcessor(org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor) ExchangeDiscoveryEvents(org.apache.ignite.internal.processors.cache.ExchangeDiscoveryEvents) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) NotNull(org.jetbrains.annotations.NotNull) GridDhtCacheEntry(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry) RENTING(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.RENTING) GridAtomicLong(org.apache.ignite.internal.util.GridAtomicLong) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) U(org.apache.ignite.internal.util.typedef.internal.U) EVT_DISCOVERY_CUSTOM_EVT(org.apache.ignite.internal.events.DiscoveryCustomEvent.EVT_DISCOVERY_CUSTOM_EVT) HashMap(java.util.HashMap) IgniteLogger(org.apache.ignite.IgniteLogger) DiscoCache(org.apache.ignite.internal.managers.discovery.DiscoCache) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) AffinityAssignment(org.apache.ignite.internal.processors.affinity.AffinityAssignment) HashSet(java.util.HashSet) ClusterNode(org.apache.ignite.cluster.ClusterNode) F0(org.apache.ignite.internal.util.F0) GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) S(org.apache.ignite.internal.util.typedef.internal.S) MOVING(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.MOVING) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) GridDhtPartitionFullMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap) NoSuchElementException(java.util.NoSuchElementException) EVICTED(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.EVICTED) IGNORE(org.apache.ignite.cache.PartitionLossPolicy.IGNORE) F(org.apache.ignite.internal.util.typedef.F) EVT_NODE_JOINED(org.apache.ignite.events.EventType.EVT_NODE_JOINED) Iterator(java.util.Iterator) CachePartitionPartialCountersMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionPartialCountersMap) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) StripedCompositeReadWriteLock(org.apache.ignite.internal.util.StripedCompositeReadWriteLock) NONE(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture.ExchangeType.NONE) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) GridDhtPartitionExchangeId(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionExchangeId) Collections(java.util.Collections) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) HashMap(java.util.HashMap) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) GridDhtPartitionFullMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) GridLongList(org.apache.ignite.internal.util.GridLongList) List(java.util.List) ArrayList(java.util.ArrayList) UUID(java.util.UUID) GridPartitionStateMap(org.apache.ignite.internal.util.GridPartitionStateMap) CachePartitionFullCountersMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionFullCountersMap) Map(java.util.Map) HashMap(java.util.HashMap) GridDhtPartitionFullMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap) CachePartitionPartialCountersMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionPartialCountersMap) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) HashSet(java.util.HashSet)

Example 2 with EVT_NODE_JOINED

use of org.apache.ignite.events.EventType.EVT_NODE_JOINED in project ignite by apache.

the class IgniteProjectionStartStopRestartSelfTest method beforeTest.

/**
 * {@inheritDoc}
 */
@Override
protected void beforeTest() {
    if (SSH_KEY != null) {
        key = new File(SSH_KEY);
        assert key.exists() : "Private key doesn't exist: " + key.getAbsolutePath();
        assert key.isFile() : "Private key is not a file: " + key.getAbsolutePath();
    } else
        pwd = SSH_PWD;
    log.info("Username: " + SSH_UNAME);
    log.info("Password: " + pwd);
    log.info("Key path: " + key);
    G.setDaemon(true);
    ignite = G.start(CFG_NO_ATTR);
    G.setDaemon(false);
    ignite.events().localListen((IgnitePredicate<Event>) evt -> {
        info("Received event: " + evt.shortDisplay());
        if (evt.type() == EVT_NODE_JOINED) {
            joinedCnt.incrementAndGet();
            if (joinedLatch != null)
                joinedLatch.countDown();
        } else if (evt.type() == EVT_NODE_LEFT || evt.type() == EVT_NODE_FAILED) {
            leftCnt.incrementAndGet();
            if (leftLatch != null)
                leftLatch.countDown();
        }
        return true;
    }, EVT_NODE_JOINED, EVT_NODE_LEFT, EVT_NODE_FAILED);
}
Also used : EVT_NODE_LEFT(org.apache.ignite.events.EventType.EVT_NODE_LEFT) U(org.apache.ignite.internal.util.typedef.internal.U) UNAME(org.apache.ignite.internal.util.nodestart.IgniteNodeStartUtils.UNAME) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ClusterNode(org.apache.ignite.cluster.ClusterNode) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteClosure(org.apache.ignite.lang.IgniteClosure) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) IgniteCluster(org.apache.ignite.IgniteCluster) Map(java.util.Map) X(org.apache.ignite.internal.util.typedef.X) IGNITE_HOME(org.apache.ignite.internal.util.nodestart.IgniteNodeStartUtils.IGNITE_HOME) NODES(org.apache.ignite.internal.util.nodestart.IgniteNodeStartUtils.NODES) ClusterStartNodeResult(org.apache.ignite.cluster.ClusterStartNodeResult) G(org.apache.ignite.internal.util.typedef.G) F(org.apache.ignite.internal.util.typedef.F) EVT_NODE_JOINED(org.apache.ignite.events.EventType.EVT_NODE_JOINED) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) CFG(org.apache.ignite.internal.util.nodestart.IgniteNodeStartUtils.CFG) DFLT_TIMEOUT(org.apache.ignite.internal.util.nodestart.IgniteNodeStartUtils.DFLT_TIMEOUT) Iterator(java.util.Iterator) EventType(org.apache.ignite.events.EventType) GridTestProperties(org.apache.ignite.testframework.config.GridTestProperties) PASSWD(org.apache.ignite.internal.util.nodestart.IgniteNodeStartUtils.PASSWD) Collection(java.util.Collection) IgniteException(org.apache.ignite.IgniteException) Event(org.apache.ignite.events.Event) IgniteNodeStartUtils(org.apache.ignite.internal.util.nodestart.IgniteNodeStartUtils) KEY(org.apache.ignite.internal.util.nodestart.IgniteNodeStartUtils.KEY) Test(org.junit.Test) UUID(java.util.UUID) Ignite(org.apache.ignite.Ignite) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) File(java.io.File) CountDownLatch(java.util.concurrent.CountDownLatch) Nullable(org.jetbrains.annotations.Nullable) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) EVT_NODE_FAILED(org.apache.ignite.events.EventType.EVT_NODE_FAILED) Paths(java.nio.file.Paths) Collections(java.util.Collections) SCRIPT(org.apache.ignite.internal.util.nodestart.IgniteNodeStartUtils.SCRIPT) Event(org.apache.ignite.events.Event) File(java.io.File)

Aggregations

ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 UUID (java.util.UUID)2 IgniteException (org.apache.ignite.IgniteException)2 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 EventType (org.apache.ignite.events.EventType)2 EVT_NODE_JOINED (org.apache.ignite.events.EventType.EVT_NODE_JOINED)2 F (org.apache.ignite.internal.util.typedef.F)2 X (org.apache.ignite.internal.util.typedef.X)2 U (org.apache.ignite.internal.util.typedef.internal.U)2 Nullable (org.jetbrains.annotations.Nullable)2 File (java.io.File)1 Paths (java.nio.file.Paths)1 List (java.util.List)1 NoSuchElementException (java.util.NoSuchElementException)1