Search in sources :

Example 6 with DiscoveryCustomEvent

use of org.apache.ignite.internal.events.DiscoveryCustomEvent in project ignite by apache.

the class ServiceDeploymentTask method init.

/**
 * Initializes deployment task.
 *
 * @throws IgniteCheckedException In case of an error.
 */
protected void init() throws IgniteCheckedException {
    if (isCompleted() || initTaskFut.isDone())
        return;
    assert evt != null && evtTopVer != null : "Illegal state to perform task's initialization :" + this;
    if (log.isDebugEnabled()) {
        log.debug("Started services deployment task init: [depId=" + depId + ", locId=" + ctx.localNodeId() + ", evt=" + evt + ']');
    }
    try {
        if (depActions != null && depActions.deactivate()) {
            srvcProc.onDeActivate(ctx);
            completeSuccess();
            return;
        }
        if (depActions == null) {
            Map<IgniteUuid, ServiceInfo> toDeploy = new HashMap<>();
            final int evtType = evt.type();
            if (evtType == EVT_DISCOVERY_CUSTOM_EVT) {
                DiscoveryCustomMessage msg = ((DiscoveryCustomEvent) evt).customMessage();
                if (msg instanceof CacheAffinityChangeMessage) {
                    CacheAffinityChangeMessage msg0 = (CacheAffinityChangeMessage) msg;
                    Map<IgniteUuid, ServiceInfo> services = srvcProc.deployedServices();
                    if (!services.isEmpty()) {
                        Map<Integer, IgniteUuid> change = msg0.cacheDeploymentIds();
                        if (change != null) {
                            Set<String> names = new HashSet<>();
                            ctx.cache().cacheDescriptors().forEach((name, desc) -> {
                                if (change.containsKey(desc.groupId()))
                                    names.add(name);
                            });
                            services.forEach((srvcId, desc) -> {
                                if (names.contains(desc.cacheName()))
                                    toDeploy.put(srvcId, desc);
                            });
                        }
                    }
                }
            } else {
                assert evtType == EVT_NODE_JOINED || evtType == EVT_NODE_LEFT || evtType == EVT_NODE_FAILED;
                final ClusterNode eventNode = evt.eventNode();
                final Map<IgniteUuid, ServiceInfo> deployedServices = srvcProc.deployedServices();
                if (evtType == EVT_NODE_LEFT || evtType == EVT_NODE_FAILED) {
                    deployedServices.forEach((srvcId, desc) -> {
                        if (desc.topologySnapshot().containsKey(eventNode.id()) || // If affinity service
                        (desc.cacheName() != null && !eventNode.isClient()))
                            toDeploy.put(srvcId, desc);
                    });
                } else {
                    toDeploy.putAll(deployedServices);
                    toDeploy.putAll(srvcProc.servicesReceivedFromJoin(eventNode.id()));
                }
            }
            if (toDeploy.isEmpty()) {
                completeSuccess();
                if (log.isDebugEnabled())
                    log.debug("No services deployment deployment action required.");
                return;
            }
            depActions = new ServiceDeploymentActions();
            depActions.servicesToDeploy(toDeploy);
        }
        ClusterNode crd = srvcProc.coordinator();
        if (crd == null) {
            onAllServersLeft();
            return;
        }
        crdId = crd.id();
        if (crd.isLocal())
            initCoordinator(evtTopVer);
        processDeploymentActions(depActions);
    } catch (Exception e) {
        log.error("Error occurred while initializing deployment task, err=" + e.getMessage(), e);
        completeError(e);
        throw new IgniteCheckedException(e);
    } finally {
        if (!initTaskFut.isDone())
            initTaskFut.onDone();
        if (log.isDebugEnabled()) {
            log.debug("Finished services deployment future init: [depId=" + deploymentId() + ", locId=" + ctx.localNodeId() + ']');
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) HashMap(java.util.HashMap) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) DiscoveryCustomEvent(org.apache.ignite.internal.events.DiscoveryCustomEvent) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheAffinityChangeMessage(org.apache.ignite.internal.processors.cache.CacheAffinityChangeMessage) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteUuid(org.apache.ignite.lang.IgniteUuid) HashSet(java.util.HashSet)

Example 7 with DiscoveryCustomEvent

use of org.apache.ignite.internal.events.DiscoveryCustomEvent in project ignite by apache.

the class GridCachePartitionExchangeManager method onDiscoveryEvent.

/**
 * @param evt Event.
 * @param cache Discovery data cache.
 */
private void onDiscoveryEvent(DiscoveryEvent evt, DiscoCache cache) {
    ClusterNode loc = cctx.localNode();
    assert evt.type() == EVT_NODE_JOINED || evt.type() == EVT_NODE_LEFT || evt.type() == EVT_NODE_FAILED || evt.type() == EVT_DISCOVERY_CUSTOM_EVT;
    final ClusterNode n = evt.eventNode();
    GridDhtPartitionExchangeId exchId = null;
    GridDhtPartitionsExchangeFuture exchFut = null;
    if (evt.type() != EVT_DISCOVERY_CUSTOM_EVT) {
        assert evt.type() != EVT_NODE_JOINED || n.isLocal() || n.order() > loc.order() : "Node joined with smaller-than-local " + "order [newOrder=" + n.order() + ", locOrder=" + loc.order() + ", evt=" + evt + ']';
        exchId = exchangeId(n.id(), affinityTopologyVersion(evt), evt);
        ExchangeActions exchActs = null;
        boolean locJoin = evt.type() == EVT_NODE_JOINED && evt.eventNode().isLocal();
        if (locJoin) {
            LocalJoinCachesContext locJoinCtx = cctx.cache().localJoinCachesContext();
            if (locJoinCtx != null) {
                exchActs = new ExchangeActions();
                exchActs.localJoinContext(locJoinCtx);
            }
        }
        if (!n.isClient() && !n.isDaemon())
            exchActs = cctx.kernalContext().state().autoAdjustExchangeActions(exchActs);
        exchFut = exchangeFuture(exchId, evt, cache, exchActs, null);
    } else {
        DiscoveryCustomMessage customMsg = ((DiscoveryCustomEvent) evt).customMessage();
        if (customMsg instanceof ChangeGlobalStateMessage) {
            ChangeGlobalStateMessage stateChangeMsg = (ChangeGlobalStateMessage) customMsg;
            ExchangeActions exchActions = stateChangeMsg.exchangeActions();
            if (exchActions != null) {
                exchId = exchangeId(n.id(), affinityTopologyVersion(evt), evt);
                exchFut = exchangeFuture(exchId, evt, cache, exchActions, null);
                boolean baselineChanging;
                if (stateChangeMsg.forceChangeBaselineTopology())
                    baselineChanging = true;
                else {
                    DiscoveryDataClusterState state = cctx.kernalContext().state().clusterState();
                    assert state.transition() : state;
                    baselineChanging = exchActions.changedBaseline() || // Or it is the first activation.
                    state.state() != ClusterState.INACTIVE && !state.previouslyActive() && state.previousBaselineTopology() == null;
                }
                exchFut.listen(f -> onClusterStateChangeFinish(f, exchActions, baselineChanging));
            }
        } else if (customMsg instanceof DynamicCacheChangeBatch) {
            DynamicCacheChangeBatch batch = (DynamicCacheChangeBatch) customMsg;
            ExchangeActions exchActions = batch.exchangeActions();
            if (exchActions != null) {
                exchId = exchangeId(n.id(), affinityTopologyVersion(evt), evt);
                exchFut = exchangeFuture(exchId, evt, cache, exchActions, null);
            }
        } else if (customMsg instanceof CacheAffinityChangeMessage) {
            CacheAffinityChangeMessage msg = (CacheAffinityChangeMessage) customMsg;
            if (msg.exchangeId() == null) {
                if (msg.exchangeNeeded()) {
                    exchId = exchangeId(n.id(), affinityTopologyVersion(evt), evt);
                    exchFut = exchangeFuture(exchId, evt, cache, null, msg);
                }
            } else if (msg.exchangeId().topologyVersion().topologyVersion() >= cctx.discovery().localJoinEvent().topologyVersion())
                exchangeFuture(msg.exchangeId(), null, null, null, null).onAffinityChangeMessage(evt.eventNode(), msg);
        } else if (customMsg instanceof DynamicCacheChangeFailureMessage) {
            DynamicCacheChangeFailureMessage msg = (DynamicCacheChangeFailureMessage) customMsg;
            if (msg.exchangeId().topologyVersion().topologyVersion() >= affinityTopologyVersion(cctx.discovery().localJoinEvent()).topologyVersion())
                exchangeFuture(msg.exchangeId(), null, null, null, null).onDynamicCacheChangeFail(evt.eventNode(), msg);
        } else if (customMsg instanceof SnapshotDiscoveryMessage && ((SnapshotDiscoveryMessage) customMsg).needExchange()) {
            exchId = exchangeId(n.id(), affinityTopologyVersion(evt), evt);
            exchFut = exchangeFuture(exchId, evt, null, null, null);
        } else if (customMsg instanceof WalStateAbstractMessage && ((WalStateAbstractMessage) customMsg).needExchange()) {
            exchId = exchangeId(n.id(), affinityTopologyVersion(evt), evt);
            exchFut = exchangeFuture(exchId, evt, null, null, null);
        } else {
            // Process event as custom discovery task if needed.
            CachePartitionExchangeWorkerTask task = cctx.cache().exchangeTaskForCustomDiscoveryMessage(customMsg);
            if (task != null)
                exchWorker.addCustomTask(task);
        }
    }
    if (exchId != null) {
        if (log.isDebugEnabled())
            log.debug("Discovery event (will start exchange): " + exchId);
        // Event callback - without this callback future will never complete.
        exchFut.onEvent(exchId, evt, cache);
        Span span = cctx.kernalContext().tracing().create(EXCHANGE_FUTURE, evt.span());
        if (exchId != null) {
            GridDhtPartitionExchangeId exchIdf = exchId;
            span.addTag(SpanTags.tag(SpanTags.EVENT_NODE, SpanTags.ID), () -> evt.eventNode().id().toString());
            span.addTag(SpanTags.tag(SpanTags.EVENT_NODE, SpanTags.CONSISTENT_ID), () -> evt.eventNode().consistentId().toString());
            span.addTag(SpanTags.tag(SpanTags.EVENT, SpanTags.TYPE), () -> String.valueOf(evt.type()));
            span.addTag(SpanTags.tag(SpanTags.EXCHANGE, SpanTags.ID), () -> String.valueOf(exchIdf.toString()));
            span.addTag(SpanTags.tag(SpanTags.INITIAL, SpanTags.TOPOLOGY_VERSION, SpanTags.MAJOR), () -> String.valueOf(exchIdf.topologyVersion().topologyVersion()));
            span.addTag(SpanTags.tag(SpanTags.INITIAL, SpanTags.TOPOLOGY_VERSION, SpanTags.MINOR), () -> String.valueOf(exchIdf.topologyVersion().minorTopologyVersion()));
        }
        span.addTag(SpanTags.NODE_ID, () -> cctx.localNodeId().toString());
        span.addLog(() -> "Created");
        exchFut.span(span);
        // Start exchange process.
        addFuture(exchFut);
    } else {
        if (log.isDebugEnabled())
            log.debug("Do not start exchange for discovery event: " + evt);
    }
    notifyNodeFail(evt);
    // Notify indexing engine about node leave so that we can re-map coordinator accordingly.
    if (evt.type() == EVT_NODE_LEFT || evt.type() == EVT_NODE_FAILED) {
        SecurityContext secCtx = remoteSecurityContext(cctx.kernalContext());
        exchWorker.addCustomTask(new SchemaNodeLeaveExchangeWorkerTask(secCtx, evt.eventNode()));
        exchWorker.addCustomTask(new WalStateNodeLeaveExchangeTask(secCtx, evt.eventNode()));
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) ChangeGlobalStateMessage(org.apache.ignite.internal.processors.cluster.ChangeGlobalStateMessage) DiscoveryDataClusterState(org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState) GridDhtPartitionExchangeId(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionExchangeId) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) DiscoveryCustomEvent(org.apache.ignite.internal.events.DiscoveryCustomEvent) Span(org.apache.ignite.internal.processors.tracing.Span) SnapshotDiscoveryMessage(org.apache.ignite.internal.processors.cache.persistence.snapshot.SnapshotDiscoveryMessage) SecurityContext(org.apache.ignite.internal.processors.security.SecurityContext) SecurityUtils.remoteSecurityContext(org.apache.ignite.internal.processors.security.SecurityUtils.remoteSecurityContext) SecurityUtils.withRemoteSecurityContext(org.apache.ignite.internal.processors.security.SecurityUtils.withRemoteSecurityContext) OperationSecurityContext(org.apache.ignite.internal.processors.security.OperationSecurityContext) SchemaNodeLeaveExchangeWorkerTask(org.apache.ignite.internal.processors.query.schema.SchemaNodeLeaveExchangeWorkerTask)

Example 8 with DiscoveryCustomEvent

use of org.apache.ignite.internal.events.DiscoveryCustomEvent in project ignite by apache.

the class ServiceDeploymentProcessIdSelfTest method instancesToTest.

/**
 * @return Tests data.
 */
@Parameterized.Parameters(name = "Test event class={0}")
public static Collection<Object[]> instancesToTest() {
    DiscoveryEvent evt = new DiscoveryEvent(new GridTestNode(UUID.randomUUID()), "", 10, new GridTestNode(UUID.randomUUID()));
    DiscoveryCustomEvent customEvt = new DiscoveryCustomEvent();
    customEvt.customMessage(new ServiceChangeBatchRequest(Collections.singletonList(new ServiceUndeploymentRequest(IgniteUuid.randomUuid()))));
    ClusterNode node = new GridTestNode(UUID.randomUUID());
    customEvt.node(node);
    customEvt.eventNode(node);
    return Arrays.asList(new Object[][] { { customEvt.getClass().getSimpleName(), new IgniteBiTuple<>(customEvt, new AffinityTopologyVersion(ThreadLocalRandom.current().nextLong())) }, { evt.getClass().getSimpleName(), new IgniteBiTuple<>(evt, new AffinityTopologyVersion(ThreadLocalRandom.current().nextLong())) } });
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) DiscoveryCustomEvent(org.apache.ignite.internal.events.DiscoveryCustomEvent) GridTestNode(org.apache.ignite.testframework.GridTestNode)

Example 9 with DiscoveryCustomEvent

use of org.apache.ignite.internal.events.DiscoveryCustomEvent in project ignite by apache.

the class ServiceDeploymentProcessIdSelfTest method topologyVersion.

/**
 */
@Test
public void topologyVersion() {
    LOG.info("test with event type: " + testLabel);
    LOG.info("event = " + evt);
    LOG.info("topology version = " + topVer);
    AffinityTopologyVersion topVer = evt instanceof DiscoveryCustomEvent ? null : this.topVer;
    assertEquals(topVer, sut.topologyVersion());
}
Also used : AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) DiscoveryCustomEvent(org.apache.ignite.internal.events.DiscoveryCustomEvent) Test(org.junit.Test)

Example 10 with DiscoveryCustomEvent

use of org.apache.ignite.internal.events.DiscoveryCustomEvent in project ignite by apache.

the class ServiceDeploymentProcessIdSelfTest method requestId.

/**
 */
@Test
public void requestId() {
    LOG.info("test with event type: " + testLabel);
    LOG.info("event = " + evt);
    LOG.info("topology version = " + topVer);
    IgniteUuid reqId = evt instanceof DiscoveryCustomEvent ? ((DiscoveryCustomEvent) evt).customMessage().id() : null;
    assertEquals(reqId, sut.requestId());
}
Also used : IgniteUuid(org.apache.ignite.lang.IgniteUuid) DiscoveryCustomEvent(org.apache.ignite.internal.events.DiscoveryCustomEvent) Test(org.junit.Test)

Aggregations

DiscoveryCustomEvent (org.apache.ignite.internal.events.DiscoveryCustomEvent)16 DiscoveryCustomMessage (org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage)10 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 DynamicCacheChangeBatch (org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch)7 ClusterNode (org.apache.ignite.cluster.ClusterNode)6 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)5 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 List (java.util.List)3 UUID (java.util.UUID)3 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)3 IgniteNeedReconnectException (org.apache.ignite.internal.IgniteNeedReconnectException)3 CacheGroupContext (org.apache.ignite.internal.processors.cache.CacheGroupContext)3 SnapshotDiscoveryMessage (org.apache.ignite.internal.processors.cache.persistence.snapshot.SnapshotDiscoveryMessage)3 Test (org.junit.Test)3 Map (java.util.Map)2 Set (java.util.Set)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2