Search in sources :

Example 1 with BaselineTopology

use of org.apache.ignite.internal.processors.cluster.BaselineTopology in project ignite by apache.

the class GridAffinityAssignmentCache method calculate.

/**
 * Calculates ideal assignment for given topology version and events happened since last calculation.
 *
 * @param topVer Topology version to calculate affinity cache for.
 * @param events Discovery events that caused this topology version change.
 * @param discoCache Discovery cache.
 * @return Ideal affinity assignment.
 */
public IdealAffinityAssignment calculate(AffinityTopologyVersion topVer, @Nullable ExchangeDiscoveryEvents events, @Nullable DiscoCache discoCache) {
    if (log.isDebugEnabled())
        log.debug("Calculating ideal affinity [topVer=" + topVer + ", locNodeId=" + ctx.localNodeId() + ", discoEvts=" + events + ']');
    IdealAffinityAssignment prevAssignment = idealAssignment;
    // Already calculated.
    if (prevAssignment != null && prevAssignment.topologyVersion().equals(topVer))
        return prevAssignment;
    // Resolve nodes snapshot for specified topology version.
    List<ClusterNode> sorted;
    if (!locCache) {
        sorted = new ArrayList<>(discoCache.cacheGroupAffinityNodes(groupId()));
        sorted.sort(NodeOrderComparator.getInstance());
    } else
        sorted = Collections.singletonList(ctx.discovery().localNode());
    boolean hasBaseline = false;
    boolean changedBaseline = false;
    BaselineTopology blt = null;
    if (discoCache != null) {
        blt = discoCache.state().baselineTopology();
        hasBaseline = blt != null;
        changedBaseline = !hasBaseline ? baselineTopology != null : !blt.equals(baselineTopology);
    }
    IdealAffinityAssignment assignment;
    if (prevAssignment != null && events != null) {
        /* Skip affinity calculation only when all nodes triggered exchange
               don't belong to affinity for current group (client node or filtered by nodeFilter). */
        boolean skipCalculation = true;
        for (DiscoveryEvent event : events.events()) {
            boolean affinityNode = CU.affinityNode(event.eventNode(), nodeFilter);
            if (affinityNode || event.type() == EVT_DISCOVERY_CUSTOM_EVT) {
                skipCalculation = false;
                break;
            }
        }
        if (hasBaseline && changedBaseline) {
            recalculateBaselineAssignment(topVer, events, prevAssignment, sorted, blt);
            assignment = IdealAffinityAssignment.create(topVer, sorted, baselineAssignmentWithoutOfflineNodes(discoCache));
        } else if (skipCalculation)
            assignment = prevAssignment;
        else if (hasBaseline) {
            if (baselineAssignment == null)
                recalculateBaselineAssignment(topVer, events, prevAssignment, sorted, blt);
            assignment = IdealAffinityAssignment.create(topVer, sorted, baselineAssignmentWithoutOfflineNodes(discoCache));
        } else {
            List<List<ClusterNode>> calculated = aff.assignPartitions(new GridAffinityFunctionContextImpl(sorted, prevAssignment.assignment(), events.lastEvent(), topVer, backups));
            assignment = IdealAffinityAssignment.create(topVer, sorted, calculated);
        }
    } else {
        if (hasBaseline) {
            recalculateBaselineAssignment(topVer, events, prevAssignment, sorted, blt);
            assignment = IdealAffinityAssignment.createWithPreservedPrimaries(topVer, baselineAssignmentWithoutOfflineNodes(discoCache), baselineAssignment);
        } else {
            List<List<ClusterNode>> calculated = aff.assignPartitions(new GridAffinityFunctionContextImpl(sorted, prevAssignment != null ? prevAssignment.assignment() : null, events != null ? events.lastEvent() : null, topVer, backups));
            assignment = IdealAffinityAssignment.create(topVer, sorted, calculated);
        }
    }
    assert assignment != null;
    idealAssignment = assignment;
    if (ctx.cache().cacheMode(cacheOrGrpName) == PARTITIONED && !ctx.clientNode())
        printDistributionIfThresholdExceeded(assignment.assignment(), sorted.size());
    if (hasBaseline) {
        baselineTopology = blt;
        assert baselineAssignment != null;
    } else {
        baselineTopology = null;
        baselineAssignment = null;
    }
    if (locCache)
        initialize(topVer, assignment.assignment());
    return assignment;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) BaselineTopology(org.apache.ignite.internal.processors.cluster.BaselineTopology) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with BaselineTopology

use of org.apache.ignite.internal.processors.cluster.BaselineTopology in project ignite by apache.

the class IgniteClusterImpl method validateBeforeBaselineChange.

/**
 * Executes validation checks of cluster state and BaselineTopology before changing BaselineTopology to new one.
 */
private void validateBeforeBaselineChange(Collection<? extends BaselineNode> baselineTop) {
    verifyBaselineTopologySupport(ctx.discovery().discoCache());
    if (!ctx.state().clusterState().active())
        throw new IgniteException("Changing BaselineTopology on inactive cluster is not allowed.");
    if (baselineTop != null) {
        if (baselineTop.isEmpty())
            throw new IgniteException("BaselineTopology must contain at least one node.");
        List<BaselineNode> currBlT = Optional.ofNullable(ctx.state().clusterState().baselineTopology()).map(BaselineTopology::currentBaseline).orElse(Collections.emptyList());
        Collection<ClusterNode> srvrs = ctx.cluster().get().forServers().nodes();
        for (BaselineNode node : baselineTop) {
            Object consistentId = node.consistentId();
            if (currBlT.stream().noneMatch(currBlTNode -> Objects.equals(currBlTNode.consistentId(), consistentId)) && srvrs.stream().noneMatch(currServersNode -> Objects.equals(currServersNode.consistentId(), consistentId)))
                throw new IgniteException("Check arguments. Node with consistent ID [" + consistentId + "] not found in server nodes.");
        }
        Collection<Object> onlineNodes = onlineBaselineNodesRequestedForRemoval(baselineTop);
        if (onlineNodes != null) {
            if (!onlineNodes.isEmpty())
                throw new IgniteException("Removing online nodes from BaselineTopology is not supported: " + onlineNodes);
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) ATTR_MACS(org.apache.ignite.internal.IgniteNodeAttributes.ATTR_MACS) ObjectOutput(java.io.ObjectOutput) InetAddress(java.net.InetAddress) SB(org.apache.ignite.internal.util.typedef.internal.SB) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteCluster(org.apache.ignite.IgniteCluster) Map(java.util.Map) BaselineTopology(org.apache.ignite.internal.processors.cluster.BaselineTopology) StartNodeCallable(org.apache.ignite.internal.util.nodestart.StartNodeCallable) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) IgniteFuture(org.apache.ignite.lang.IgniteFuture) INACTIVE(org.apache.ignite.cluster.ClusterState.INACTIVE) IgniteNodeStartUtils.parseFile(org.apache.ignite.internal.util.nodestart.IgniteNodeStartUtils.parseFile) Externalizable(java.io.Externalizable) ClusterGroupEmptyException(org.apache.ignite.cluster.ClusterGroupEmptyException) 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) UUID(java.util.UUID) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BaselineAutoAdjustStatus(org.apache.ignite.internal.processors.cluster.baseline.autoadjust.BaselineAutoAdjustStatus) CU(org.apache.ignite.internal.util.typedef.internal.CU) Optional(java.util.Optional) ObjectInput(java.io.ObjectInput) IgniteProductVersion(org.apache.ignite.lang.IgniteProductVersion) ShutdownPolicy(org.apache.ignite.ShutdownPolicy) IgniteFutureImpl(org.apache.ignite.internal.util.future.IgniteFutureImpl) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) DistributedEnumProperty(org.apache.ignite.internal.processors.configuration.distributed.DistributedEnumProperty) ClusterState(org.apache.ignite.cluster.ClusterState) GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) IgniteLogger(org.apache.ignite.IgniteLogger) DiscoCache(org.apache.ignite.internal.managers.discovery.DiscoCache) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) GridKernalContext(org.apache.ignite.internal.GridKernalContext) ClusterNode(org.apache.ignite.cluster.ClusterNode) CI1(org.apache.ignite.internal.util.typedef.CI1) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) IgniteComponentType(org.apache.ignite.internal.IgniteComponentType) ClusterStartNodeResult(org.apache.ignite.cluster.ClusterStartNodeResult) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) F(org.apache.ignite.internal.util.typedef.F) ATTR_IPS(org.apache.ignite.internal.IgniteNodeAttributes.ATTR_IPS) A(org.apache.ignite.internal.util.typedef.internal.A) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) BaselineNode(org.apache.ignite.cluster.BaselineNode) File(java.io.File) ObjectStreamException(java.io.ObjectStreamException) IgniteSshHelper(org.apache.ignite.internal.util.nodestart.IgniteSshHelper) IgniteRemoteStartSpecification(org.apache.ignite.internal.util.nodestart.IgniteRemoteStartSpecification) Collections(java.util.Collections) IgniteNodeStartUtils.specifications(org.apache.ignite.internal.util.nodestart.IgniteNodeStartUtils.specifications) IgniteException(org.apache.ignite.IgniteException) BaselineNode(org.apache.ignite.cluster.BaselineNode)

Example 3 with BaselineTopology

use of org.apache.ignite.internal.processors.cluster.BaselineTopology in project ignite by apache.

the class IgniteBaselineAffinityTopologyActivationTest method testNodeWithBltIsProhibitedToJoinNewCluster.

/**
 */
@Test
public void testNodeWithBltIsProhibitedToJoinNewCluster() throws Exception {
    BaselineTopologyVerifier nullVerifier = new BaselineTopologyVerifier() {

        @Override
        public void verify(BaselineTopology blt) {
            assertNull(blt);
        }
    };
    Ignite nodeC = startGridWithConsistentId("C");
    nodeC.cluster().active(true);
    stopGrid("C", false);
    Ignite nodeA = startGridWithConsistentId("A");
    Ignite nodeB = startGridWithConsistentId("B");
    verifyBaselineTopologyOnNodes(nullVerifier, new Ignite[] { nodeA, nodeB });
    boolean expectedExceptionThrown = false;
    try {
        startGridWithConsistentId("C");
    } catch (IgniteCheckedException e) {
        expectedExceptionThrown = true;
        if (e.getCause() != null && e.getCause().getCause() != null) {
            Throwable rootCause = e.getCause().getCause();
            if (!(rootCause instanceof IgniteSpiException) || !rootCause.getMessage().contains("Node with set up BaselineTopology"))
                Assert.fail("Unexpected ignite exception was thrown: " + e);
        } else
            throw e;
    }
    assertTrue("Expected exception wasn't thrown.", expectedExceptionThrown);
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) BaselineTopology(org.apache.ignite.internal.processors.cluster.BaselineTopology) Ignite(org.apache.ignite.Ignite) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 4 with BaselineTopology

use of org.apache.ignite.internal.processors.cluster.BaselineTopology in project ignite by apache.

the class IgniteBaselineAffinityTopologyActivationTest method testRemoveBaselineTopology.

/**
 * Verifies that baseline topology is removed successfully through baseline changing API.
 */
@Test
public void testRemoveBaselineTopology() throws Exception {
    BaselineTopologyVerifier verifier = new BaselineTopologyVerifier() {

        @Override
        public void verify(BaselineTopology blt) {
            assertNull(blt);
        }
    };
    Ignite nodeA = startGridWithConsistentId("A");
    Ignite nodeB = startGridWithConsistentId("B");
    Ignite nodeC = startGridWithConsistentId("C");
    nodeA.cluster().baselineAutoAdjustEnabled(false);
    nodeA.cluster().active(true);
    nodeA.cluster().setBaselineTopology(null);
    verifyBaselineTopologyOnNodes(verifier, new Ignite[] { nodeA, nodeB, nodeC });
}
Also used : BaselineTopology(org.apache.ignite.internal.processors.cluster.BaselineTopology) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 5 with BaselineTopology

use of org.apache.ignite.internal.processors.cluster.BaselineTopology in project ignite by apache.

the class IgniteBaselineAffinityTopologyActivationTest method testAddNodeToBaselineTopology.

/**
 */
@Test
public void testAddNodeToBaselineTopology() throws Exception {
    final long expectedActivationHash = (long) "A".hashCode() + "B".hashCode() + "C".hashCode() + "D".hashCode();
    BaselineTopologyVerifier verifier = new BaselineTopologyVerifier() {

        @Override
        public void verify(BaselineTopology blt) {
            assertNotNull(blt);
            assertEquals(4, blt.consistentIds().size());
            long activationHash = U.field(blt, "branchingPntHash");
            assertEquals(expectedActivationHash, activationHash);
        }
    };
    Ignite nodeA = startGridWithConsistentId("A");
    Ignite nodeB = startGridWithConsistentId("B");
    Ignite nodeC = startGridWithConsistentId("C");
    nodeA.cluster().baselineAutoAdjustEnabled(false);
    nodeC.cluster().active(true);
    IgniteEx nodeD = (IgniteEx) startGridWithConsistentId("D");
    nodeD.cluster().setBaselineTopology(baselineNodes(nodeA.cluster().forServers().nodes()));
    verifyBaselineTopologyOnNodes(verifier, new Ignite[] { nodeA, nodeB, nodeC, nodeD });
}
Also used : BaselineTopology(org.apache.ignite.internal.processors.cluster.BaselineTopology) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

BaselineTopology (org.apache.ignite.internal.processors.cluster.BaselineTopology)16 Ignite (org.apache.ignite.Ignite)8 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)8 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)4 ClusterNode (org.apache.ignite.cluster.ClusterNode)4 List (java.util.List)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 BaselineNode (org.apache.ignite.cluster.BaselineNode)3 Collection (java.util.Collection)2 UUID (java.util.UUID)2 IgniteException (org.apache.ignite.IgniteException)2 ClusterState (org.apache.ignite.cluster.ClusterState)2 BaselineTopologyHistory (org.apache.ignite.internal.processors.cluster.BaselineTopologyHistory)2 Nullable (org.jetbrains.annotations.Nullable)2 Externalizable (java.io.Externalizable)1 File (java.io.File)1 IOException (java.io.IOException)1 ObjectInput (java.io.ObjectInput)1 ObjectOutput (java.io.ObjectOutput)1