Search in sources :

Example 1 with Span

use of org.apache.ignite.internal.processors.tracing.Span in project ignite by apache.

the class JmhTracingContextBenchmark method spanCached.

/**
 */
@Benchmark
public void spanCached() {
    for (int i = 0; i < 100; i++) {
        Span span = tracing.create(SpanType.TX);
        MTC.supportInitial(span);
        span.addTag("isolation", () -> "isolation");
        span.addTag("concurrency", () -> "concurrency");
        span.addTag("timeout", () -> "timeout");
        span.addTag("label", () -> "label");
    }
}
Also used : Span(org.apache.ignite.internal.processors.tracing.Span) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 2 with Span

use of org.apache.ignite.internal.processors.tracing.Span in project ignite by apache.

the class IgniteTransactionsImpl method txStart0.

/**
 * @param concurrency Transaction concurrency.
 * @param isolation Transaction isolation.
 * @param timeout Transaction timeout.
 * @param txSize Expected transaction size.
 * @param sysCacheCtx System cache context.
 * @return Transaction.
 */
private GridNearTxLocal txStart0(TransactionConcurrency concurrency, TransactionIsolation isolation, long timeout, int txSize, @Nullable GridCacheContext sysCacheCtx) {
    cctx.kernalContext().gateway().readLock();
    Span span = cctx.kernalContext().tracing().create(TX, null, lb);
    MTC.supportInitial(span);
    span.addTag("isolation", isolation::name);
    span.addTag("concurrency", concurrency::name);
    span.addTag("timeout", () -> String.valueOf(timeout));
    if (lb != null)
        span.addTag("label", () -> lb);
    try {
        GridNearTxLocal tx = cctx.tm().userTx(sysCacheCtx);
        if (tx != null)
            throw new IllegalStateException("Failed to start new transaction " + "(current thread already has a transaction): " + tx);
        tx = cctx.tm().newTx(false, false, sysCacheCtx, concurrency, isolation, timeout, true, null, txSize, lb, tracingEnabled);
        assert tx != null;
        return tx;
    } finally {
        cctx.kernalContext().gateway().readUnlock();
    }
}
Also used : GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) Span(org.apache.ignite.internal.processors.tracing.Span)

Example 3 with Span

use of org.apache.ignite.internal.processors.tracing.Span in project ignite by apache.

the class ServerImpl method sendCustomEvent.

/**
 * {@inheritDoc}
 */
@Override
public void sendCustomEvent(DiscoverySpiCustomMessage evt) {
    try {
        TcpDiscoveryCustomEventMessage msg;
        if (((CustomMessageWrapper) evt).delegate() instanceof DiscoveryServerOnlyCustomMessage)
            msg = new TcpDiscoveryServerOnlyCustomEventMessage(getLocalNodeId(), evt, U.marshal(spi.marshaller(), evt));
        else
            msg = new TcpDiscoveryCustomEventMessage(getLocalNodeId(), evt, U.marshal(spi.marshaller(), evt));
        Span rootSpan = tracing.create(TraceableMessagesTable.traceName(msg.getClass())).addTag(SpanTags.tag(SpanTags.EVENT_NODE, SpanTags.ID), () -> getLocalNodeId().toString()).addTag(SpanTags.tag(SpanTags.EVENT_NODE, SpanTags.CONSISTENT_ID), () -> locNode.consistentId().toString()).addTag(SpanTags.MESSAGE_CLASS, () -> ((CustomMessageWrapper) evt).delegate().getClass().getSimpleName()).addLog(() -> "Created");
        // This root span will be parent both from local and remote nodes.
        msg.spanContainer().serializedSpanBytes(tracing.serialize(rootSpan));
        msgWorker.addMessage(msg);
        rootSpan.addLog(() -> "Sent").end();
    } catch (IgniteCheckedException e) {
        throw new IgniteSpiException("Failed to marshal custom event: " + evt, e);
    }
}
Also used : DiscoveryServerOnlyCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryServerOnlyCustomMessage) CustomMessageWrapper(org.apache.ignite.internal.managers.discovery.CustomMessageWrapper) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) Span(org.apache.ignite.internal.processors.tracing.Span) TcpDiscoveryCustomEventMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryCustomEventMessage) TcpDiscoveryServerOnlyCustomEventMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryServerOnlyCustomEventMessage)

Example 4 with Span

use of org.apache.ignite.internal.processors.tracing.Span in project ignite by apache.

the class ClientImpl method sendCustomEvent.

/**
 * {@inheritDoc}
 */
@Override
public void sendCustomEvent(DiscoverySpiCustomMessage evt) {
    State state = this.state;
    if (state == DISCONNECTED)
        throw new IgniteClientDisconnectedException(null, "Failed to send custom message: client is disconnected.");
    if (state == STOPPED || state == SEGMENTED || state == STARTING)
        throw new IgniteException("Failed to send custom message: client is " + state.name().toLowerCase() + ".");
    try {
        TcpDiscoveryCustomEventMessage msg;
        if (((CustomMessageWrapper) evt).delegate() instanceof DiscoveryServerOnlyCustomMessage)
            msg = new TcpDiscoveryServerOnlyCustomEventMessage(getLocalNodeId(), evt, U.marshal(spi.marshaller(), evt));
        else
            msg = new TcpDiscoveryCustomEventMessage(getLocalNodeId(), evt, U.marshal(spi.marshaller(), evt));
        Span rootSpan = tracing.create(TraceableMessagesTable.traceName(msg.getClass())).addTag(SpanTags.tag(SpanTags.EVENT_NODE, SpanTags.ID), () -> getLocalNodeId().toString()).addTag(SpanTags.tag(SpanTags.EVENT_NODE, SpanTags.CONSISTENT_ID), () -> locNode.consistentId().toString()).addTag(SpanTags.MESSAGE_CLASS, () -> ((CustomMessageWrapper) evt).delegate().getClass().getSimpleName()).addLog(() -> "Created");
        // This root span will be parent both from local and remote nodes.
        msg.spanContainer().serializedSpanBytes(tracing.serialize(rootSpan));
        sockWriter.sendMessage(msg);
        rootSpan.addLog(() -> "Sent").end();
    } catch (IgniteCheckedException e) {
        throw new IgniteSpiException("Failed to marshal custom event: " + evt, e);
    }
}
Also used : DiscoveryServerOnlyCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryServerOnlyCustomMessage) CustomMessageWrapper(org.apache.ignite.internal.managers.discovery.CustomMessageWrapper) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) Span(org.apache.ignite.internal.processors.tracing.Span) TcpDiscoveryCustomEventMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryCustomEventMessage) TcpDiscoveryServerOnlyCustomEventMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryServerOnlyCustomEventMessage)

Example 5 with Span

use of org.apache.ignite.internal.processors.tracing.Span 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)

Aggregations

Span (org.apache.ignite.internal.processors.tracing.Span)14 TraceSurroundings (org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 CustomMessageWrapper (org.apache.ignite.internal.managers.discovery.CustomMessageWrapper)2 DiscoveryServerOnlyCustomMessage (org.apache.ignite.internal.managers.discovery.DiscoveryServerOnlyCustomMessage)2 GridNearTxLocal (org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal)2 NoopSpan (org.apache.ignite.internal.processors.tracing.NoopSpan)2 TcpDiscoveryCustomEventMessage (org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryCustomEventMessage)2 TcpDiscoveryServerOnlyCustomEventMessage (org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryServerOnlyCustomEventMessage)2 Benchmark (org.openjdk.jmh.annotations.Benchmark)2 Channel (java.nio.channels.Channel)1 BitSet (java.util.BitSet)1 Collection (java.util.Collection)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 UUID (java.util.UUID)1