Search in sources :

Example 56 with AffinityTopologyVersion

use of org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion in project ignite by apache.

the class RendezvousAffinityFunctionSimpleBenchmark method nodesModificationChangeLast.

/**
 * Modify the topology by remove the last / add new node.
 *
 * @param nodes Topology.
 * @param prevAssignment Previous afinity.
 * @param iter Number of iteration.
 * @param backups Backups count.
 * @return Affinity context.
 */
private GridAffinityFunctionContextImpl nodesModificationChangeLast(List<ClusterNode> nodes, List<List<ClusterNode>> prevAssignment, int iter, int backups) {
    DiscoveryEvent discoEvt;
    discoEvt = iter % 2 == 0 ? addNode(nodes, iter) : removeNode(nodes, nodes.size() - 1);
    return new GridAffinityFunctionContextImpl(nodes, prevAssignment, discoEvt, new AffinityTopologyVersion(nodes.size()), backups);
}
Also used : GridAffinityFunctionContextImpl(org.apache.ignite.internal.processors.affinity.GridAffinityFunctionContextImpl) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent)

Example 57 with AffinityTopologyVersion

use of org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion in project ignite by apache.

the class GridClusterStateProcessor method onStateChangeMessage.

/**
 * {@inheritDoc}
 */
@Override
public boolean onStateChangeMessage(AffinityTopologyVersion topVer, ChangeGlobalStateMessage msg, DiscoCache discoCache) {
    DiscoveryDataClusterState state = globalState;
    if (log.isInfoEnabled())
        U.log(log, "Received " + prettyStr(msg.activate()) + " request with BaselineTopology" + (msg.baselineTopology() == null ? ": null" : "[id=" + msg.baselineTopology().id() + "]"));
    if (msg.baselineTopology() != null)
        compatibilityMode = false;
    if (state.transition()) {
        if (isApplicable(msg, state)) {
            GridChangeGlobalStateFuture fut = changeStateFuture(msg);
            if (fut != null)
                fut.onDone(concurrentStateChangeError(msg.activate()));
        } else {
            final GridChangeGlobalStateFuture stateFut = changeStateFuture(msg);
            GridFutureAdapter<Void> transitionFut = transitionFuts.get(state.transitionRequestId());
            if (stateFut != null && transitionFut != null) {
                transitionFut.listen(new IgniteInClosure<IgniteInternalFuture<Void>>() {

                    @Override
                    public void apply(IgniteInternalFuture<Void> fut) {
                        try {
                            fut.get();
                            stateFut.onDone();
                        } catch (Exception ex) {
                            stateFut.onDone(ex);
                        }
                    }
                });
            }
        }
    } else {
        if (isApplicable(msg, state)) {
            ExchangeActions exchangeActions;
            try {
                exchangeActions = ctx.cache().onStateChangeRequest(msg, topVer, state);
            } catch (IgniteCheckedException e) {
                GridChangeGlobalStateFuture fut = changeStateFuture(msg);
                if (fut != null)
                    fut.onDone(e);
                return false;
            }
            Set<UUID> nodeIds = U.newHashSet(discoCache.allNodes().size());
            for (ClusterNode node : discoCache.allNodes()) nodeIds.add(node.id());
            GridChangeGlobalStateFuture fut = changeStateFuture(msg);
            if (fut != null)
                fut.setRemaining(nodeIds, topVer.nextMinorVersion());
            if (log.isInfoEnabled())
                log.info("Started state transition: " + msg.activate());
            BaselineTopologyHistoryItem bltHistItem = BaselineTopologyHistoryItem.fromBaseline(globalState.baselineTopology());
            transitionFuts.put(msg.requestId(), new GridFutureAdapter<Void>());
            globalState = DiscoveryDataClusterState.createTransitionState(globalState, msg.activate(), msg.activate() ? msg.baselineTopology() : globalState.baselineTopology(), msg.requestId(), topVer, nodeIds);
            if (msg.forceChangeBaselineTopology())
                globalState.setTransitionResult(msg.requestId(), msg.activate());
            AffinityTopologyVersion stateChangeTopVer = topVer.nextMinorVersion();
            StateChangeRequest req = new StateChangeRequest(msg, bltHistItem, msg.activate() != state.active(), stateChangeTopVer);
            exchangeActions.stateChangeRequest(req);
            msg.exchangeActions(exchangeActions);
            return true;
        } else {
            // State already changed.
            GridChangeGlobalStateFuture stateFut = changeStateFuture(msg);
            if (stateFut != null)
                stateFut.onDone();
        }
    }
    return false;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) ExchangeActions(org.apache.ignite.internal.processors.cache.ExchangeActions) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) StateChangeRequest(org.apache.ignite.internal.processors.cache.StateChangeRequest) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) UUID(java.util.UUID)

Example 58 with AffinityTopologyVersion

use of org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion in project ignite by apache.

the class GridClusterStateProcessor method sendComputeCheckGlobalState.

/**
 *  Check cluster state.
 *
 *  @return Cluster state, {@code True} if cluster active, {@code False} if inactive.
 */
private boolean sendComputeCheckGlobalState() {
    AffinityTopologyVersion topVer = ctx.discovery().topologyVersionEx();
    if (log.isInfoEnabled()) {
        log.info("Sending check cluster state request from node [id=" + ctx.localNodeId() + ", topVer=" + topVer + ", client=" + ctx.clientNode() + ", daemon" + ctx.isDaemon() + "]");
    }
    IgniteCompute comp = ((ClusterGroupAdapter) ctx.cluster().get().forServers()).compute();
    return comp.call(new IgniteCallable<Boolean>() {

        @IgniteInstanceResource
        private Ignite ig;

        @Override
        public Boolean call() throws Exception {
            return ig.active();
        }
    });
}
Also used : IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) Ignite(org.apache.ignite.Ignite) IgniteCompute(org.apache.ignite.IgniteCompute) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) ClusterGroupAdapter(org.apache.ignite.internal.cluster.ClusterGroupAdapter)

Example 59 with AffinityTopologyVersion

use of org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion in project ignite by apache.

the class GridClusterStateProcessor method sendComputeChangeGlobalState.

/**
 * @param activate New cluster state.
 * @param resFut State change future.
 */
private void sendComputeChangeGlobalState(boolean activate, BaselineTopology blt, boolean forceBlt, final GridFutureAdapter<Void> resFut) {
    AffinityTopologyVersion topVer = ctx.discovery().topologyVersionEx();
    if (log.isInfoEnabled()) {
        log.info("Sending " + prettyStr(activate) + " request from node [id=" + ctx.localNodeId() + ", topVer=" + topVer + ", client=" + ctx.clientNode() + ", daemon=" + ctx.isDaemon() + "]");
    }
    IgniteCompute comp = ((ClusterGroupAdapter) ctx.cluster().get().forServers()).compute();
    IgniteFuture<Void> fut = comp.runAsync(new ClientChangeGlobalStateComputeRequest(activate, blt, forceBlt));
    fut.listen(new CI1<IgniteFuture>() {

        @Override
        public void apply(IgniteFuture fut) {
            try {
                fut.get();
                resFut.onDone();
            } catch (Exception e) {
                resFut.onDone(e);
            }
        }
    });
}
Also used : AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteFuture(org.apache.ignite.lang.IgniteFuture) IgniteCompute(org.apache.ignite.IgniteCompute) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) ClusterGroupAdapter(org.apache.ignite.internal.cluster.ClusterGroupAdapter)

Example 60 with AffinityTopologyVersion

use of org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion in project ignite by apache.

the class GridCacheNearReadersSelfTest method testTwoNodesTwoKeysOneBackup.

/**
 * @throws Exception If failed.
 */
public void testTwoNodesTwoKeysOneBackup() throws Exception {
    aff.backups(1);
    grids = 2;
    aff.partitions(grids);
    startGrids();
    ClusterNode n1 = F.first(aff.nodes(aff.partition(1), grid(0).cluster().nodes()));
    ClusterNode n2 = F.first(aff.nodes(aff.partition(2), grid(0).cluster().nodes()));
    assertNotNull(n1);
    assertNotNull(n2);
    assertNotSame(n1, n2);
    assertFalse("Nodes cannot be equal: " + n1, n1.equals(n2));
    Ignite g1 = grid(n1.id());
    Ignite g2 = grid(n2.id());
    awaitPartitionMapExchange();
    GridCacheContext ctx = ((IgniteKernal) g1).internalCache(DEFAULT_CACHE_NAME).context();
    List<KeyCacheObject> cacheKeys = F.asList(ctx.toCacheKeyObject(1), ctx.toCacheKeyObject(2));
    IgniteInternalFuture<Object> f1 = ((IgniteKernal) g1).internalCache(DEFAULT_CACHE_NAME).preloader().request(ctx, cacheKeys, new AffinityTopologyVersion(2));
    if (f1 != null)
        f1.get();
    IgniteInternalFuture<Object> f2 = ((IgniteKernal) g2).internalCache(DEFAULT_CACHE_NAME).preloader().request(((IgniteKernal) g2).internalCache(DEFAULT_CACHE_NAME).context(), cacheKeys, new AffinityTopologyVersion(2));
    if (f2 != null)
        f2.get();
    IgniteCache<Integer, String> cache1 = g1.cache(DEFAULT_CACHE_NAME);
    IgniteCache<Integer, String> cache2 = g2.cache(DEFAULT_CACHE_NAME);
    assertEquals(g1.affinity(DEFAULT_CACHE_NAME).mapKeyToNode(1), g1.cluster().localNode());
    assertFalse(g1.affinity(DEFAULT_CACHE_NAME).mapKeyToNode(2).equals(g1.cluster().localNode()));
    assertEquals(g1.affinity(DEFAULT_CACHE_NAME).mapKeyToNode(2), g2.cluster().localNode());
    assertFalse(g2.affinity(DEFAULT_CACHE_NAME).mapKeyToNode(1).equals(g2.cluster().localNode()));
    // Store first value in cache.
    assertNull(cache1.getAndPut(1, "v1"));
    assertTrue(cache1.containsKey(1));
    assertTrue(cache2.containsKey(1));
    assertEquals("v1", nearPeek(cache1, 1));
    assertEquals("v1", nearPeek(cache2, 1));
    assertEquals("v1", dhtPeek(cache1, 1));
    assertEquals("v1", dhtPeek(cache2, 1));
    assertNull(near(cache1).peekEx(1));
    assertNull(near(cache2).peekEx(1));
    GridDhtCacheEntry e1 = (GridDhtCacheEntry) dht(cache1).entryEx(1);
    // Store second value in cache.
    assertNull(cache1.getAndPut(2, "v2"));
    assertTrue(cache1.containsKey(2));
    assertTrue(cache2.containsKey(2));
    assertEquals("v2", nearPeek(cache1, 2));
    assertEquals("v2", nearPeek(cache2, 2));
    assertEquals("v2", dhtPeek(cache1, 2));
    assertEquals("v2", dhtPeek(cache2, 2));
    assertNull(near(cache1).peekEx(2));
    assertNull(near(cache2).peekEx(2));
    GridDhtCacheEntry c2e2 = (GridDhtCacheEntry) dht(cache2).entryEx(2);
    // Nodes are backups of each other, so no readers should be added.
    assertFalse(c2e2.readers().contains(n1.id()));
    assertFalse(e1.readers().contains(n2.id()));
    // Get key1 on node2 (value should come from local DHT cache, as it has a backup).
    assertEquals("v1", cache2.get(1));
    // Since DHT cache2 has the value, Near cache2 should not have it.
    assertNull(near(cache2).peekEx(1));
    e1 = (GridDhtCacheEntry) dht(cache1).entryEx(1);
    // Since v1 was retrieved locally from cache2, cache1 should not know about it.
    assertFalse(e1.readers().contains(n2.id()));
    // Evict locally from cache2.
    // It should not be successful since it's not allowed to evict entry on backup node.
    cache2.localEvict(Collections.singleton(1));
    assertNull(near(cache2).peekEx(1));
    assertEquals("v1", dhtPeek(cache2, 1));
    assertEquals("v1", cache1.getAndPut(1, "z1"));
    e1 = (GridDhtCacheEntry) dht(cache1).entryEx(1);
    // Node 1 should not have node2 in readers map.
    assertFalse(e1.readers().contains(n2.id()));
    assertNull(near(cache2).peekEx(1));
    assertEquals("z1", dhtPeek(cache2, 1));
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridDhtCacheEntry(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry) Ignite(org.apache.ignite.Ignite) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Aggregations

AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)242 ClusterNode (org.apache.ignite.cluster.ClusterNode)87 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)75 ArrayList (java.util.ArrayList)60 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)46 List (java.util.List)36 UUID (java.util.UUID)35 Ignite (org.apache.ignite.Ignite)33 Map (java.util.Map)32 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)31 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)30 HashMap (java.util.HashMap)27 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)22 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)20 IgniteKernal (org.apache.ignite.internal.IgniteKernal)20 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)20 IgniteException (org.apache.ignite.IgniteException)19 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)17 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)17 GridAffinityFunctionContextImpl (org.apache.ignite.internal.processors.affinity.GridAffinityFunctionContextImpl)15