Search in sources :

Example 21 with IgniteInClosure

use of org.apache.ignite.lang.IgniteInClosure in project ignite by apache.

the class GridDiscoveryManager method start.

/** {@inheritDoc} */
@Override
public void start(boolean activeOnStart) throws IgniteCheckedException {
    long totSysMemory = -1;
    try {
        totSysMemory = U.<Long>property(os, "totalPhysicalMemorySize");
    } catch (RuntimeException ignored) {
    // No-op.
    }
    ctx.addNodeAttribute(IgniteNodeAttributes.ATTR_PHY_RAM, totSysMemory);
    DiscoverySpi spi = getSpi();
    discoOrdered = discoOrdered();
    histSupported = historySupported();
    isLocDaemon = ctx.isDaemon();
    hasRslvrs = !ctx.config().isClientMode() && !F.isEmpty(ctx.config().getSegmentationResolvers());
    segChkFreq = ctx.config().getSegmentCheckFrequency();
    if (hasRslvrs) {
        if (segChkFreq < 0)
            throw new IgniteCheckedException("Segment check frequency cannot be negative: " + segChkFreq);
        if (segChkFreq > 0 && segChkFreq < 2000)
            U.warn(log, "Configuration parameter 'segmentCheckFrequency' is too low " + "(at least 2000 ms recommended): " + segChkFreq);
        int segResAttemp = ctx.config().getSegmentationResolveAttempts();
        if (segResAttemp < 1)
            throw new IgniteCheckedException("Segment resolve attempts cannot be negative or zero: " + segResAttemp);
        checkSegmentOnStart();
    }
    metricsUpdateTask = ctx.timeout().schedule(new MetricsUpdater(), METRICS_UPDATE_FREQ, METRICS_UPDATE_FREQ);
    spi.setMetricsProvider(createMetricsProvider());
    if (ctx.security().enabled()) {
        if (isSecurityCompatibilityMode())
            ctx.addNodeAttribute(ATTR_SECURITY_COMPATIBILITY_MODE, true);
        spi.setAuthenticator(new DiscoverySpiNodeAuthenticator() {

            @Override
            public SecurityContext authenticateNode(ClusterNode node, SecurityCredentials cred) {
                try {
                    return ctx.security().authenticateNode(node, cred);
                } catch (IgniteCheckedException e) {
                    throw U.convertException(e);
                }
            }

            @Override
            public boolean isGlobalNodeAuthentication() {
                return ctx.security().isGlobalNodeAuthentication();
            }
        });
    }
    spi.setListener(new DiscoverySpiListener() {

        private long gridStartTime;

        /** {@inheritDoc} */
        @Override
        public void onLocalNodeInitialized(ClusterNode locNode) {
            for (IgniteInClosure<ClusterNode> lsnr : localNodeInitLsnrs) lsnr.apply(locNode);
        }

        @Override
        public void onDiscovery(final int type, final long topVer, final ClusterNode node, final Collection<ClusterNode> topSnapshot, final Map<Long, Collection<ClusterNode>> snapshots, @Nullable DiscoverySpiCustomMessage spiCustomMsg) {
            DiscoveryCustomMessage customMsg = spiCustomMsg == null ? null : ((CustomMessageWrapper) spiCustomMsg).delegate();
            if (skipMessage(type, customMsg))
                return;
            final ClusterNode locNode = localNode();
            if (snapshots != null)
                topHist = snapshots;
            boolean verChanged;
            if (type == EVT_NODE_METRICS_UPDATED)
                verChanged = false;
            else {
                if (type != EVT_NODE_SEGMENTED && type != EVT_CLIENT_NODE_DISCONNECTED && type != EVT_CLIENT_NODE_RECONNECTED && type != DiscoveryCustomEvent.EVT_DISCOVERY_CUSTOM_EVT) {
                    minorTopVer = 0;
                    verChanged = true;
                } else
                    verChanged = false;
            }
            if (type == EVT_NODE_FAILED || type == EVT_NODE_LEFT) {
                for (DiscoCache c : discoCacheHist.values()) c.updateAlives(node);
                updateClientNodes(node.id());
            }
            final AffinityTopologyVersion nextTopVer;
            if (type == DiscoveryCustomEvent.EVT_DISCOVERY_CUSTOM_EVT) {
                assert customMsg != null;
                boolean incMinorTopVer = ctx.cache().onCustomEvent(customMsg, new AffinityTopologyVersion(topVer, minorTopVer));
                if (incMinorTopVer) {
                    minorTopVer++;
                    verChanged = true;
                }
                nextTopVer = new AffinityTopologyVersion(topVer, minorTopVer);
                if (verChanged)
                    ctx.cache().onDiscoveryEvent(type, node, nextTopVer);
            } else {
                nextTopVer = new AffinityTopologyVersion(topVer, minorTopVer);
                ctx.cache().onDiscoveryEvent(type, node, nextTopVer);
            }
            if (type == DiscoveryCustomEvent.EVT_DISCOVERY_CUSTOM_EVT) {
                for (Class cls = customMsg.getClass(); cls != null; cls = cls.getSuperclass()) {
                    List<CustomEventListener<DiscoveryCustomMessage>> list = customEvtLsnrs.get(cls);
                    if (list != null) {
                        for (CustomEventListener<DiscoveryCustomMessage> lsnr : list) {
                            try {
                                lsnr.onCustomEvent(nextTopVer, node, customMsg);
                            } catch (Exception e) {
                                U.error(log, "Failed to notify direct custom event listener: " + customMsg, e);
                            }
                        }
                    }
                }
            }
            final DiscoCache discoCache;
            // event notifications, since SPI notifies manager about all events from this listener.
            if (verChanged) {
                discoCache = createDiscoCache(locNode, topSnapshot);
                discoCacheHist.put(nextTopVer, discoCache);
                boolean set = updateTopologyVersionIfGreater(nextTopVer, discoCache);
                assert set || topVer == 0 : "Topology version has not been updated [this.topVer=" + topSnap + ", topVer=" + topVer + ", node=" + node + ", evt=" + U.gridEventName(type) + ']';
            } else
                // Current version.
                discoCache = discoCache();
            // If this is a local join event, just save it and do not notify listeners.
            if (type == EVT_NODE_JOINED && node.id().equals(locNode.id())) {
                if (gridStartTime == 0)
                    gridStartTime = getSpi().getGridStartTime();
                updateTopologyVersionIfGreater(new AffinityTopologyVersion(locNode.order()), discoCache);
                startLatch.countDown();
                DiscoveryEvent discoEvt = new DiscoveryEvent();
                discoEvt.node(ctx.discovery().localNode());
                discoEvt.eventNode(node);
                discoEvt.type(EVT_NODE_JOINED);
                discoEvt.topologySnapshot(topVer, new ArrayList<>(F.view(topSnapshot, FILTER_DAEMON)));
                locJoin.onDone(new T2<>(discoEvt, discoCache));
                return;
            } else if (type == EVT_CLIENT_NODE_DISCONNECTED) {
                assert locNode.isClient() : locNode;
                assert node.isClient() : node;
                ((IgniteKernal) ctx.grid()).onDisconnected();
                locJoin = new GridFutureAdapter<>();
                registeredCaches.clear();
                for (AffinityTopologyVersion histVer : discoCacheHist.keySet()) {
                    Object rmvd = discoCacheHist.remove(histVer);
                    assert rmvd != null : histVer;
                }
                topHist.clear();
                topSnap.set(new Snapshot(AffinityTopologyVersion.ZERO, createDiscoCache(locNode, Collections.<ClusterNode>emptySet())));
            } else if (type == EVT_CLIENT_NODE_RECONNECTED) {
                assert locNode.isClient() : locNode;
                assert node.isClient() : node;
                boolean clusterRestarted = gridStartTime != getSpi().getGridStartTime();
                gridStartTime = getSpi().getGridStartTime();
                ((IgniteKernal) ctx.grid()).onReconnected(clusterRestarted);
                ctx.cluster().clientReconnectFuture().listen(new CI1<IgniteFuture<?>>() {

                    @Override
                    public void apply(IgniteFuture<?> fut) {
                        try {
                            fut.get();
                            discoWrk.addEvent(type, nextTopVer, node, discoCache, topSnapshot, null);
                        } catch (IgniteException ignore) {
                        // No-op.
                        }
                    }
                });
                return;
            }
            if (type == EVT_CLIENT_NODE_DISCONNECTED || type == EVT_NODE_SEGMENTED || !ctx.clientDisconnected())
                discoWrk.addEvent(type, nextTopVer, node, discoCache, topSnapshot, customMsg);
        }
    });
    spi.setDataExchange(new DiscoverySpiDataExchange() {

        @Override
        public DiscoveryDataBag collect(DiscoveryDataBag dataBag) {
            assert dataBag != null;
            assert dataBag.joiningNodeId() != null;
            if (ctx.localNodeId().equals(dataBag.joiningNodeId())) {
                for (GridComponent c : ctx.components()) c.collectJoiningNodeData(dataBag);
            } else {
                for (GridComponent c : ctx.components()) c.collectGridNodeData(dataBag);
            }
            return dataBag;
        }

        @Override
        public void onExchange(DiscoveryDataBag dataBag) {
            if (ctx.localNodeId().equals(dataBag.joiningNodeId())) {
                //NodeAdded msg reached joining node after round-trip over the ring
                for (GridComponent c : ctx.components()) {
                    if (c.discoveryDataType() != null)
                        c.onGridDataReceived(dataBag.gridDiscoveryData(c.discoveryDataType().ordinal()));
                }
            } else {
                //discovery data from newly joined node has to be applied to the current old node
                for (GridComponent c : ctx.components()) {
                    if (c.discoveryDataType() != null) {
                        JoiningNodeDiscoveryData data = dataBag.newJoinerDiscoveryData(c.discoveryDataType().ordinal());
                        if (data != null)
                            c.onJoiningNodeDataReceived(data);
                    }
                }
            }
        }
    });
    startSpi();
    registeredDiscoSpi = true;
    try {
        U.await(startLatch);
    } catch (IgniteInterruptedException e) {
        throw new IgniteCheckedException("Failed to start discovery manager (thread has been interrupted).", e);
    }
    // Start segment check worker only if frequency is greater than 0.
    if (hasRslvrs && segChkFreq > 0) {
        segChkWrk = new SegmentCheckWorker();
        segChkThread = new IgniteThread(segChkWrk);
        segChkThread.start();
    }
    locNode = spi.getLocalNode();
    checkAttributes(discoCache().remoteNodes());
    ctx.service().initCompatibilityMode(discoCache().remoteNodes());
    // Start discovery worker.
    new IgniteThread(discoWrk).start();
    if (log.isDebugEnabled())
        log.debug(startInfo());
}
Also used : GridComponent(org.apache.ignite.internal.GridComponent) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) IgniteFuture(org.apache.ignite.lang.IgniteFuture) CI1(org.apache.ignite.internal.util.typedef.CI1) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) JoiningNodeDiscoveryData(org.apache.ignite.spi.discovery.DiscoveryDataBag.JoiningNodeDiscoveryData) DiscoveryDataBag(org.apache.ignite.spi.discovery.DiscoveryDataBag) IgniteException(org.apache.ignite.IgniteException) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) List(java.util.List) T2(org.apache.ignite.internal.util.typedef.T2) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteKernal(org.apache.ignite.internal.IgniteKernal) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) DiscoverySpiNodeAuthenticator(org.apache.ignite.spi.discovery.DiscoverySpiNodeAuthenticator) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) DiscoverySpiListener(org.apache.ignite.spi.discovery.DiscoverySpiListener) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteException(org.apache.ignite.IgniteException) SecurityCredentials(org.apache.ignite.plugin.security.SecurityCredentials) DiscoverySpiCustomMessage(org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage) ClusterMetricsSnapshot(org.apache.ignite.internal.ClusterMetricsSnapshot) DiscoverySpiDataExchange(org.apache.ignite.spi.discovery.DiscoverySpiDataExchange) DiscoverySpi(org.apache.ignite.spi.discovery.DiscoverySpi) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi) SecurityContext(org.apache.ignite.internal.processors.security.SecurityContext) AtomicLong(java.util.concurrent.atomic.AtomicLong) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) Collection(java.util.Collection) IgniteThread(org.apache.ignite.thread.IgniteThread)

Example 22 with IgniteInClosure

use of org.apache.ignite.lang.IgniteInClosure in project ignite by apache.

the class GridCacheAdapter method asyncOp.

/**
 * @param tx Transaction.
 * @param op Cache operation.
 * @param opCtx Cache operation context.
 * @param <T> Return type.
 * @return Future.
 */
@SuppressWarnings("unchecked")
protected <T> IgniteInternalFuture<T> asyncOp(GridNearTxLocal tx, final AsyncOp<T> op, final CacheOperationContext opCtx, final boolean retry) {
    IgniteInternalFuture<T> fail = asyncOpAcquire(retry);
    if (fail != null)
        return fail;
    FutureHolder holder = lastFut.get();
    holder.lock();
    try {
        IgniteInternalFuture fut = holder.future();
        final GridNearTxLocal tx0 = tx;
        final CX1 clo = new CX1<IgniteInternalFuture<T>, T>() {

            @Override
            public T applyx(IgniteInternalFuture<T> tFut) throws IgniteCheckedException {
                try {
                    return tFut.get();
                } catch (IgniteTxTimeoutCheckedException | IgniteTxRollbackCheckedException | NodeStoppingException | IgniteConsistencyViolationException e) {
                    throw e;
                } catch (IgniteCheckedException e1) {
                    try {
                        tx0.rollbackNearTxLocalAsync();
                    } catch (Throwable e2) {
                        if (e1 != e2)
                            e1.addSuppressed(e2);
                    }
                    throw e1;
                } finally {
                    ctx.shared().txContextReset();
                }
            }
        };
        if (fut != null && !fut.isDone()) {
            IgniteInternalFuture<T> f = new GridEmbeddedFuture(fut, (IgniteOutClosure<IgniteInternalFuture>) () -> {
                GridFutureAdapter resFut = new GridFutureAdapter();
                ctx.kernalContext().closure().runLocalSafe((GridPlainRunnable) () -> {
                    IgniteInternalFuture fut0;
                    if (ctx.kernalContext().isStopping())
                        fut0 = new GridFinishedFuture<>(new IgniteCheckedException("Operation has been cancelled (node or cache is stopping)."));
                    else if (ctx.gate().isStopped())
                        fut0 = new GridFinishedFuture<>(new CacheStoppedException(ctx.name()));
                    else {
                        ctx.operationContextPerCall(opCtx);
                        ctx.shared().txContextReset();
                        try {
                            fut0 = op.op(tx0).chain(clo);
                        } finally {
                            // It is necessary to clear tx context in this thread as well.
                            ctx.shared().txContextReset();
                            ctx.operationContextPerCall(null);
                        }
                    }
                    fut0.listen((IgniteInClosure<IgniteInternalFuture>) fut01 -> {
                        try {
                            resFut.onDone(fut01.get());
                        } catch (Throwable ex) {
                            resFut.onDone(ex);
                        }
                    });
                }, true);
                return resFut;
            });
            saveFuture(holder, f, retry);
            return f;
        }
        /**
         * Wait for concurrent tx operation to finish.
         * See {@link GridDhtTxLocalAdapter#updateLockFuture(IgniteInternalFuture, IgniteInternalFuture)}
         */
        if (!tx0.txState().implicitSingle())
            tx0.txState().awaitLastFuture(ctx.shared());
        IgniteInternalFuture<T> f;
        try {
            f = op.op(tx).chain(clo);
        } finally {
            // It is necessary to clear tx context in this thread as well.
            ctx.shared().txContextReset();
        }
        saveFuture(holder, f, retry);
        if (tx.implicit())
            ctx.tm().resetContext();
        return f;
    } finally {
        holder.unlock();
    }
}
Also used : IgnitionEx(org.apache.ignite.internal.IgnitionEx) IgniteTxRollbackCheckedException(org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) IgniteTxLocalAdapter(org.apache.ignite.internal.processors.cache.transactions.IgniteTxLocalAdapter) EntryProcessor(javax.cache.processor.EntryProcessor) GridSerializableMap(org.apache.ignite.internal.util.GridSerializableMap) MetricUtils.cacheMetricsRegistryName(org.apache.ignite.internal.processors.metric.impl.MetricUtils.cacheMetricsRegistryName) Map(java.util.Map) Cache(javax.cache.Cache) InvalidObjectException(java.io.InvalidObjectException) DFLT_ALLOW_ATOMIC_OPS_IN_TX(org.apache.ignite.internal.processors.cache.CacheOperationContext.DFLT_ALLOW_ATOMIC_OPS_IN_TX) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) IgniteKernal(org.apache.ignite.internal.IgniteKernal) TC_NO_FAILOVER(org.apache.ignite.internal.processors.task.GridTaskThreadContextKey.TC_NO_FAILOVER) ComputeJobContext(org.apache.ignite.compute.ComputeJobContext) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) Externalizable(java.io.Externalizable) IgniteTxTimeoutCheckedException(org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException) GridToStringExclude(org.apache.ignite.internal.util.tostring.GridToStringExclude) CIX2(org.apache.ignite.internal.util.typedef.CIX2) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CIX3(org.apache.ignite.internal.util.typedef.CIX3) TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) Set(java.util.Set) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) READ_COMMITTED(org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED) ComputeTaskInternalFuture(org.apache.ignite.internal.ComputeTaskInternalFuture) CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) Executors(java.util.concurrent.Executors) IgniteCache(org.apache.ignite.IgniteCache) GridCacheAffinityImpl(org.apache.ignite.internal.processors.cache.affinity.GridCacheAffinityImpl) GridCacheRawVersionedEntry(org.apache.ignite.internal.processors.cache.version.GridCacheRawVersionedEntry) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology) PESSIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC) PlatformCacheEntryFilter(org.apache.ignite.internal.processors.platform.cache.PlatformCacheEntryFilter) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) ComputeJob(org.apache.ignite.compute.ComputeJob) EntryProcessorResult(javax.cache.processor.EntryProcessorResult) Affinity(org.apache.ignite.cache.affinity.Affinity) IgniteTxLocalEx(org.apache.ignite.internal.processors.cache.transactions.IgniteTxLocalEx) U(org.apache.ignite.internal.util.typedef.internal.U) Callable(java.util.concurrent.Callable) IgniteLogger(org.apache.ignite.IgniteLogger) IgniteDrDataStreamerCacheUpdater(org.apache.ignite.internal.processors.dr.IgniteDrDataStreamerCacheUpdater) SecurityPermission(org.apache.ignite.plugin.security.SecurityPermission) Supplier(java.util.function.Supplier) EntryProcessorException(javax.cache.processor.EntryProcessorException) ArrayList(java.util.ArrayList) ClusterNode(org.apache.ignite.cluster.ClusterNode) CI1(org.apache.ignite.internal.util.typedef.CI1) ComputeJobResult(org.apache.ignite.compute.ComputeJobResult) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) MvccUtils(org.apache.ignite.internal.processors.cache.mvcc.MvccUtils) S(org.apache.ignite.internal.util.typedef.internal.S) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) GridInternal(org.apache.ignite.internal.processors.task.GridInternal) C2(org.apache.ignite.internal.util.typedef.C2) C1(org.apache.ignite.internal.util.typedef.C1) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) A(org.apache.ignite.internal.util.typedef.internal.A) IOException(java.io.IOException) Ignite(org.apache.ignite.Ignite) GridDhtInvalidPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtInvalidPartitionException) DataStreamerImpl(org.apache.ignite.internal.processors.datastreamer.DataStreamerImpl) T2(org.apache.ignite.internal.util.typedef.T2) ObjectStreamException(java.io.ObjectStreamException) GridDhtCacheAdapter(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) IgniteConsistencyViolationException(org.apache.ignite.internal.processors.cache.distributed.near.consistency.IgniteConsistencyViolationException) TransactionCheckedException(org.apache.ignite.internal.transactions.TransactionCheckedException) MvccSnapshot(org.apache.ignite.internal.processors.cache.mvcc.MvccSnapshot) BROADCAST(org.apache.ignite.internal.GridClosureCallMode.BROADCAST) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) GridCacheDrInfo(org.apache.ignite.internal.processors.cache.dr.GridCacheDrInfo) CX1(org.apache.ignite.internal.util.typedef.CX1) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteExternalizableExpiryPolicy(org.apache.ignite.internal.processors.cache.distributed.IgniteExternalizableExpiryPolicy) SERIALIZABLE(org.apache.ignite.transactions.TransactionIsolation.SERIALIZABLE) SortedSet(java.util.SortedSet) ObjectOutput(java.io.ObjectOutput) Transaction(org.apache.ignite.transactions.Transaction) IgniteEx(org.apache.ignite.internal.IgniteEx) REPEATABLE_READ(org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ) IgniteSystemProperties(org.apache.ignite.IgniteSystemProperties) DR_LOAD(org.apache.ignite.internal.processors.dr.GridDrType.DR_LOAD) ComputeJobResultPolicy(org.apache.ignite.compute.ComputeJobResultPolicy) X(org.apache.ignite.internal.util.typedef.X) OperationType(org.apache.ignite.internal.processors.performancestatistics.OperationType) GridPlainCallable(org.apache.ignite.internal.util.lang.GridPlainCallable) LoggerResource(org.apache.ignite.resources.LoggerResource) GridDhtTopologyFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTopologyFuture) CachePeekMode(org.apache.ignite.cache.CachePeekMode) IgniteOutClosure(org.apache.ignite.lang.IgniteOutClosure) IgniteThreadFactory(org.apache.ignite.thread.IgniteThreadFactory) Collection(java.util.Collection) IgniteException(org.apache.ignite.IgniteException) CacheEntry(org.apache.ignite.cache.CacheEntry) ReadRepairStrategy(org.apache.ignite.cache.ReadRepairStrategy) TransactionConfiguration(org.apache.ignite.configuration.TransactionConfiguration) IgniteClusterEx(org.apache.ignite.internal.cluster.IgniteClusterEx) OPTIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.OPTIMISTIC) OWNING(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.OWNING) UUID(java.util.UUID) CI2(org.apache.ignite.internal.util.typedef.CI2) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) CacheMetricsMXBean(org.apache.ignite.mxbean.CacheMetricsMXBean) IgniteTxKey(org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey) CU(org.apache.ignite.internal.util.typedef.internal.CU) JobContextResource(org.apache.ignite.resources.JobContextResource) IGNITE_CACHE_RETRIES_COUNT(org.apache.ignite.IgniteSystemProperties.IGNITE_CACHE_RETRIES_COUNT) ObjectInput(java.io.ObjectInput) IgniteProductVersion(org.apache.ignite.lang.IgniteProductVersion) NotNull(org.jetbrains.annotations.NotNull) SortedMap(java.util.SortedMap) DataStreamerEntry(org.apache.ignite.internal.processors.datastreamer.DataStreamerEntry) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) DR_NONE(org.apache.ignite.internal.processors.dr.GridDrType.DR_NONE) ComputeTaskAdapter(org.apache.ignite.compute.ComputeTaskAdapter) AbstractSet(java.util.AbstractSet) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) HashMap(java.util.HashMap) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) IgniteFeatures(org.apache.ignite.internal.IgniteFeatures) Function(java.util.function.Function) LT(org.apache.ignite.internal.util.typedef.internal.LT) CacheInterceptor(org.apache.ignite.cache.CacheInterceptor) IgniteCallable(org.apache.ignite.lang.IgniteCallable) HashSet(java.util.HashSet) GridCompoundReadRepairFuture(org.apache.ignite.internal.processors.cache.distributed.near.consistency.GridCompoundReadRepairFuture) IgniteClosure(org.apache.ignite.lang.IgniteClosure) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) GPC(org.apache.ignite.internal.util.typedef.internal.GPC) IgniteClusterNode(org.apache.ignite.internal.managers.discovery.IgniteClusterNode) NoSuchElementException(java.util.NoSuchElementException) ExecutorService(java.util.concurrent.ExecutorService) TC_SUBGRID(org.apache.ignite.internal.processors.task.GridTaskThreadContextKey.TC_SUBGRID) F(org.apache.ignite.internal.util.typedef.F) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) IgniteTxHeuristicCheckedException(org.apache.ignite.internal.transactions.IgniteTxHeuristicCheckedException) Iterator(java.util.Iterator) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Semaphore(java.util.concurrent.Semaphore) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) GridCloseableIterator(org.apache.ignite.internal.util.lang.GridCloseableIterator) TimeUnit(java.util.concurrent.TimeUnit) GridEmbeddedFuture(org.apache.ignite.internal.util.future.GridEmbeddedFuture) IgniteTransactionsEx(org.apache.ignite.internal.IgniteTransactionsEx) ComputeJobAdapter(org.apache.ignite.compute.ComputeJobAdapter) CacheMetrics(org.apache.ignite.cache.CacheMetrics) GridPlainRunnable(org.apache.ignite.internal.util.lang.GridPlainRunnable) Collections(java.util.Collections) GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) IgniteTxRollbackCheckedException(org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridPlainRunnable(org.apache.ignite.internal.util.lang.GridPlainRunnable) GridEmbeddedFuture(org.apache.ignite.internal.util.future.GridEmbeddedFuture) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) BROADCAST(org.apache.ignite.internal.GridClosureCallMode.BROADCAST) IGNITE_CACHE_RETRIES_COUNT(org.apache.ignite.IgniteSystemProperties.IGNITE_CACHE_RETRIES_COUNT) LT(org.apache.ignite.internal.util.typedef.internal.LT) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) IgniteConsistencyViolationException(org.apache.ignite.internal.processors.cache.distributed.near.consistency.IgniteConsistencyViolationException) IgniteTxTimeoutCheckedException(org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException) CX1(org.apache.ignite.internal.util.typedef.CX1)

Example 23 with IgniteInClosure

use of org.apache.ignite.lang.IgniteInClosure in project ignite by apache.

the class ClusterCachesInfo method processCacheChangeRequests.

/**
 * @param exchangeActions Exchange actions to update.
 * @param reqs Requests.
 * @param topVer Topology version.
 * @param persistedCfgs {@code True} if process start of persisted caches during cluster activation.
 * @return Process result.
 */
private CacheChangeProcessResult processCacheChangeRequests(ExchangeActions exchangeActions, Collection<DynamicCacheChangeRequest> reqs, AffinityTopologyVersion topVer, boolean persistedCfgs) {
    CacheChangeProcessResult res = new CacheChangeProcessResult();
    final List<T2<DynamicCacheChangeRequest, AffinityTopologyVersion>> reqsToComplete = new ArrayList<>();
    for (DynamicCacheChangeRequest req : reqs) processCacheChangeRequest0(req, exchangeActions, topVer, persistedCfgs, res, reqsToComplete);
    if (!F.isEmpty(res.addedDescs)) {
        AffinityTopologyVersion startTopVer = res.needExchange ? topVer.nextMinorVersion() : topVer;
        for (DynamicCacheDescriptor desc : res.addedDescs) {
            assert desc.template() || res.needExchange;
            desc.startTopologyVersion(startTopVer);
        }
    }
    if (!F.isEmpty(reqsToComplete)) {
        ctx.closure().callLocalSafe(new GridPlainCallable<Void>() {

            @Override
            public Void call() {
                for (T2<DynamicCacheChangeRequest, AffinityTopologyVersion> t : reqsToComplete) {
                    final DynamicCacheChangeRequest req = t.get1();
                    AffinityTopologyVersion waitTopVer = t.get2();
                    IgniteInternalFuture<?> fut = waitTopVer != null ? ctx.cache().context().exchange().affinityReadyFuture(waitTopVer) : null;
                    if (fut == null || fut.isDone())
                        ctx.cache().completeCacheStartFuture(req, false, null);
                    else {
                        fut.listen(new IgniteInClosure<IgniteInternalFuture<?>>() {

                            @Override
                            public void apply(IgniteInternalFuture<?> fut) {
                                ctx.cache().completeCacheStartFuture(req, false, null);
                            }
                        });
                    }
                }
                return null;
            }
        });
    }
    return res;
}
Also used : AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ArrayList(java.util.ArrayList) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) T2(org.apache.ignite.internal.util.typedef.T2)

Example 24 with IgniteInClosure

use of org.apache.ignite.lang.IgniteInClosure in project ignite by apache.

the class GridNearTxLocal method chainFinishFuture.

/**
 * @param fut Already started finish future.
 * @param commit Commit flag.
 * @param clearThreadMap Clear thread map.
 * @return Finish future.
 */
private IgniteInternalFuture<IgniteInternalTx> chainFinishFuture(final NearTxFinishFuture fut, final boolean commit, final boolean clearThreadMap, final boolean onTimeout) {
    assert fut != null;
    if (fut.commit() != commit) {
        final GridNearTxLocal tx = this;
        if (!commit) {
            final GridNearTxFinishFuture rollbackFut = new GridNearTxFinishFuture<>(cctx, this, false);
            fut.listen(new IgniteInClosure<IgniteInternalFuture<IgniteInternalTx>>() {

                @Override
                public void apply(IgniteInternalFuture<IgniteInternalTx> fut0) {
                    if (FINISH_FUT_UPD.compareAndSet(tx, fut, rollbackFut)) {
                        switch(tx.state()) {
                            case COMMITTED:
                                if (log.isDebugEnabled())
                                    log.debug("Failed to rollback, transaction is already committed: " + tx);
                            case ROLLED_BACK:
                                rollbackFut.forceFinish();
                                assert rollbackFut.isDone() : rollbackFut;
                                break;
                            default:
                                // First finish attempt was unsuccessful. Try again.
                                rollbackFut.finish(false, clearThreadMap, onTimeout);
                        }
                    } else {
                        finishFut.listen(new IgniteInClosure<IgniteInternalFuture<IgniteInternalTx>>() {

                            @Override
                            public void apply(IgniteInternalFuture<IgniteInternalTx> fut) {
                                try {
                                    fut.get();
                                    rollbackFut.markInitialized();
                                } catch (IgniteCheckedException e) {
                                    rollbackFut.onDone(e);
                                }
                            }
                        });
                    }
                }
            });
            return rollbackFut;
        } else {
            final GridFutureAdapter<IgniteInternalTx> fut0 = new GridFutureAdapter<>();
            fut.listen(new IgniteInClosure<IgniteInternalFuture<IgniteInternalTx>>() {

                @Override
                public void apply(IgniteInternalFuture<IgniteInternalTx> fut) {
                    if (timedOut())
                        fut0.onDone(new IgniteTxTimeoutCheckedException("Failed to commit transaction, " + "transaction is concurrently rolled back on timeout: " + tx));
                    else
                        fut0.onDone(new IgniteTxRollbackCheckedException("Failed to commit transaction, " + "transaction is concurrently rolled back: " + tx));
                }
            });
            return fut0;
        }
    }
    return fut;
}
Also used : IgniteTxRollbackCheckedException(org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) IgniteTxTimeoutCheckedException(org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException)

Example 25 with IgniteInClosure

use of org.apache.ignite.lang.IgniteInClosure in project ignite by apache.

the class AbstractClientCompatibilityTest method testOldClientToCurrentServer.

/**
 * @throws Exception If failed.
 */
@Test
public void testOldClientToCurrentServer() throws Exception {
    try (Ignite ignite = startGrid(0)) {
        initNode(ignite);
        if (verFormatted.equals(IgniteVersionUtils.VER_STR))
            testClient(verFormatted);
        else {
            String fileName = IgniteCompatibilityNodeRunner.storeToFile((IgniteInClosure<String>) this::testClient);
            GridJavaProcess proc = GridJavaProcess.exec(RemoteClientRunner.class.getName(), IgniteVersionUtils.VER_STR + ' ' + fileName, log, log::info, null, null, getProcessProxyJvmArgs(verFormatted), null);
            try {
                GridTestUtils.waitForCondition(() -> !proc.getProcess().isAlive(), 5_000L);
                assertEquals(0, proc.getProcess().exitValue());
            } finally {
                if (proc.getProcess().isAlive())
                    proc.kill();
            }
        }
    }
}
Also used : GridJavaProcess(org.apache.ignite.internal.util.GridJavaProcess) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) Ignite(org.apache.ignite.Ignite) Test(org.junit.Test) IgniteCompatibilityAbstractTest(org.apache.ignite.compatibility.testframework.junits.IgniteCompatibilityAbstractTest)

Aggregations

IgniteInClosure (org.apache.ignite.lang.IgniteInClosure)39 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)25 List (java.util.List)22 ArrayList (java.util.ArrayList)20 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)18 HashMap (java.util.HashMap)17 Map (java.util.Map)16 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)16 Ignite (org.apache.ignite.Ignite)15 Test (org.junit.Test)15 UUID (java.util.UUID)14 IgniteCache (org.apache.ignite.IgniteCache)14 IgniteException (org.apache.ignite.IgniteException)13 Collection (java.util.Collection)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)12 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)12 U (org.apache.ignite.internal.util.typedef.internal.U)12 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)12 Nullable (org.jetbrains.annotations.Nullable)12