Search in sources :

Example 46 with GridFutureAdapter

use of org.apache.ignite.internal.util.future.GridFutureAdapter in project ignite by apache.

the class DataStreamerImpl method closeEx.

/**
 * @param cancel {@code True} to close with cancellation.
 * @param err Error.
 * @throws IgniteCheckedException If failed.
 */
private IgniteCheckedException closeEx(boolean cancel, IgniteCheckedException err) throws IgniteCheckedException {
    if (!closed.compareAndSet(false, true))
        return null;
    busyLock.writeLock();
    try {
        if (log.isDebugEnabled())
            log.debug("Closing data streamer [ldr=" + this + ", cancel=" + cancel + ']');
        try {
            // Assuming that no methods are called on this loader after this method is called.
            if (cancel) {
                cancelled = true;
                IgniteCheckedException cancellationErr = err;
                if (cancellationErr == null)
                    cancellationErr = new IgniteCheckedException("Data streamer has been cancelled: " + DataStreamerImpl.this);
                for (ThreadBuffer buf : threadBufMap.values()) {
                    GridFutureAdapter internalFut = (GridFutureAdapter) buf.getFuture().internalFuture();
                    internalFut.onDone(cancellationErr);
                }
                for (Buffer buf : bufMappings.values()) buf.cancelAll(cancellationErr);
            } else
                doFlush();
            ctx.event().removeLocalEventListener(discoLsnr);
            ctx.io().removeMessageListener(topic);
        } catch (IgniteCheckedException | IgniteDataStreamerTimeoutException e) {
            fut.onDone(e);
            throw e;
        }
        long failed = failCntr.longValue();
        if (failed > 0 && err == null)
            err = new IgniteCheckedException("Some of DataStreamer operations failed [failedCount=" + failed + "]");
        fut.onDone(err);
        return err;
    } finally {
        busyLock.writeUnlock();
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteDataStreamerTimeoutException(org.apache.ignite.IgniteDataStreamerTimeoutException) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter)

Example 47 with GridFutureAdapter

use of org.apache.ignite.internal.util.future.GridFutureAdapter in project ignite by apache.

the class DataStreamerImpl method addDataInternal.

/**
 * @param entries Entries.
 * @param useThreadBuffer
 * @return Future.
 */
public IgniteFuture<?> addDataInternal(Collection<? extends DataStreamerEntry> entries, boolean useThreadBuffer) {
    checkSecurityPermissions(entries);
    IgniteCacheFutureImpl fut = null;
    GridFutureAdapter internalFut = null;
    Collection entriesList;
    lock(false);
    try {
        long threadId = Thread.currentThread().getId();
        if (useThreadBuffer) {
            ThreadBuffer threadBuf = threadBufMap.get(threadId);
            if (threadBuf == null) {
                fut = createDataLoadFuture();
                // Initial capacity should be more than batch by 12.5% in order to avoid resizing.
                threadBuf = new ThreadBuffer(fut, new ArrayList<>(bufLdrSzPerThread + (bufLdrSzPerThread >> 3)));
                threadBufMap.put(threadId, threadBuf);
            } else
                // Use existed thread-buffer future.
                fut = threadBuf.getFuture();
            entriesList = threadBuf.getEntries();
            entriesList.addAll(entries);
        } else {
            entriesList = entries;
            fut = createDataLoadFuture();
        }
        internalFut = (GridFutureAdapter) fut.internalFuture();
        if (!useThreadBuffer || entriesList.size() >= bufLdrSzPerThread) {
            loadData(entriesList, internalFut);
            if (useThreadBuffer)
                threadBufMap.remove(threadId);
        }
        return fut;
    } catch (Throwable e) {
        if (internalFut != null)
            internalFut.onDone(e);
        if (e instanceof Error || e instanceof IgniteDataStreamerTimeoutException)
            throw e;
        return fut;
    } finally {
        unlock(false);
    }
}
Also used : IgniteCacheFutureImpl(org.apache.ignite.internal.processors.cache.IgniteCacheFutureImpl) IgniteDataStreamerTimeoutException(org.apache.ignite.IgniteDataStreamerTimeoutException) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) ArrayList(java.util.ArrayList) Collection(java.util.Collection)

Example 48 with GridFutureAdapter

use of org.apache.ignite.internal.util.future.GridFutureAdapter in project ignite by apache.

the class DataStreamerImpl method createDataLoadFuture.

/**
 * Creates data load future and register its as active future.
 * @return Data load future.
 */
@NotNull
protected IgniteCacheFutureImpl createDataLoadFuture() {
    GridFutureAdapter internalFut0 = new GridFutureAdapter();
    IgniteCacheFutureImpl fut = new IgniteCacheFutureImpl(internalFut0, ctx.getAsyncContinuationExecutor());
    internalFut0.listen(rmvActiveFut);
    activeFuts.add(internalFut0);
    return fut;
}
Also used : IgniteCacheFutureImpl(org.apache.ignite.internal.processors.cache.IgniteCacheFutureImpl) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) NotNull(org.jetbrains.annotations.NotNull)

Example 49 with GridFutureAdapter

use of org.apache.ignite.internal.util.future.GridFutureAdapter in project ignite by apache.

the class GridClusterStateProcessor method onGridDataReceived.

/**
 * {@inheritDoc}
 */
@Override
public void onGridDataReceived(DiscoveryDataBag.GridDiscoveryData data) {
    if (data.commonData() instanceof DiscoveryDataClusterState) {
        if (globalState != null && globalState.baselineTopology() != null)
            // (where some nodes don't support BaselineTopology)
            throw new IgniteException("Node with BaselineTopology cannot join" + " mixed cluster running in compatibility mode");
        globalState = (DiscoveryDataClusterState) data.commonData();
        compatibilityMode = true;
        ctx.cache().context().readOnlyMode(globalState.state() == ACTIVE_READ_ONLY);
        return;
    }
    BaselineStateAndHistoryData stateDiscoData = (BaselineStateAndHistoryData) data.commonData();
    if (stateDiscoData != null) {
        DiscoveryDataClusterState state = stateDiscoData.globalState;
        if (state.transition())
            transitionFuts.put(state.transitionRequestId(), new GridFutureAdapter<Void>());
        globalState = state;
        if (stateDiscoData.recentHistory != null) {
            for (BaselineTopologyHistoryItem item : stateDiscoData.recentHistory.history()) bltHist.bufferHistoryItemForStore(item);
        }
        ctx.cache().context().readOnlyMode(globalState.state() == ACTIVE_READ_ONLY);
    }
}
Also used : IgniteException(org.apache.ignite.IgniteException) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter)

Example 50 with GridFutureAdapter

use of org.apache.ignite.internal.util.future.GridFutureAdapter 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()) {
        String baseline = msg.baselineTopology() == null ? ": null" : "[id=" + msg.baselineTopology().id() + ']';
        U.log(log, "Received " + prettyStr(msg.state()) + " request with BaselineTopology" + baseline + " initiator node ID: " + msg.initiatorNodeId());
    }
    if (msg.baselineTopology() != null)
        compatibilityMode = false;
    if (state.transition()) {
        if (isApplicable(msg, state)) {
            GridChangeGlobalStateFuture fut = changeStateFuture(msg);
            if (fut != null)
                fut.onDone(concurrentStateChangeError(msg.state(), state.state()));
        } 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)) {
        if (msg.state() == INACTIVE && !msg.forceDeactivation() && allNodesSupports(ctx.discovery().serverNodes(topVer), SAFE_CLUSTER_DEACTIVATION)) {
            List<String> inMemCaches = listInMemoryUserCaches();
            if (!inMemCaches.isEmpty()) {
                GridChangeGlobalStateFuture stateFut = changeStateFuture(msg);
                if (stateFut != null) {
                    stateFut.onDone(new IgniteException(DATA_LOST_ON_DEACTIVATION_WARNING + " In memory caches: " + inMemCaches + " .To deactivate cluster pass '--force' flag."));
                }
                return false;
            }
        }
        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: " + prettyStr(msg.state()));
        BaselineTopologyHistoryItem bltHistItem = BaselineTopologyHistoryItem.fromBaseline(state.baselineTopology());
        transitionFuts.put(msg.requestId(), new GridFutureAdapter<Void>());
        DiscoveryDataClusterState newState = globalState = DiscoveryDataClusterState.createTransitionState(msg.state(), state, activate(state.state(), msg.state()) || msg.forceChangeBaselineTopology() ? msg.baselineTopology() : state.baselineTopology(), msg.requestId(), topVer, nodeIds);
        ctx.durableBackgroundTask().onStateChangeStarted(msg);
        if (msg.forceChangeBaselineTopology())
            newState.setTransitionResult(msg.requestId(), msg.state());
        AffinityTopologyVersion stateChangeTopVer = topVer.nextMinorVersion();
        StateChangeRequest req = new StateChangeRequest(msg, bltHistItem, state.state(), stateChangeTopVer);
        exchangeActions.stateChangeRequest(req);
        msg.exchangeActions(exchangeActions);
        if (newState.state() != state.state()) {
            if (ctx.event().isRecordable(EventType.EVT_CLUSTER_STATE_CHANGE_STARTED)) {
                ctx.pools().getStripedExecutorService().execute(() -> ctx.event().record(new ClusterStateChangeStartedEvent(state.state(), newState.state(), ctx.discovery().localNode(), "Cluster state change started.")));
            }
        }
        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) Set(java.util.Set) HashSet(java.util.HashSet) 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) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) ClusterStateChangeStartedEvent(org.apache.ignite.events.ClusterStateChangeStartedEvent) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)110 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)59 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)34 IgniteException (org.apache.ignite.IgniteException)23 ArrayList (java.util.ArrayList)21 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)21 List (java.util.List)20 UUID (java.util.UUID)20 ClusterNode (org.apache.ignite.cluster.ClusterNode)20 IgniteEx (org.apache.ignite.internal.IgniteEx)20 HashMap (java.util.HashMap)19 Map (java.util.Map)19 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)18 Test (org.junit.Test)18 Nullable (org.jetbrains.annotations.Nullable)17 Ignite (org.apache.ignite.Ignite)15 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)15 HashSet (java.util.HashSet)14 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)14 T2 (org.apache.ignite.internal.util.typedef.T2)13