Search in sources :

Example 11 with GridCompoundFuture

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

the class GridCacheProcessor method dynamicStartCaches.

/**
     * Dynamically starts multiple caches.
     *
     * @param ccfgList Collection of cache configuration.
     * @param cacheType Cache type.
     * @param failIfExists Fail if exists flag.
     * @param checkThreadTx If {@code true} checks that current thread does not have active transactions.
     * @return Future that will be completed when all caches are deployed.
     */
private IgniteInternalFuture<?> dynamicStartCaches(Collection<CacheConfiguration> ccfgList, CacheType cacheType, boolean failIfExists, boolean checkThreadTx) {
    if (checkThreadTx)
        checkEmptyTransactions();
    List<DynamicCacheChangeRequest> reqList = new ArrayList<>(ccfgList.size());
    try {
        for (CacheConfiguration ccfg : ccfgList) {
            DynamicCacheChangeRequest req = prepareCacheChangeRequest(ccfg, ccfg.getName(), null, cacheType, false, failIfExists, true);
            if (req != null)
                reqList.add(req);
        }
    } catch (Exception e) {
        return new GridFinishedFuture<>(e);
    }
    if (!reqList.isEmpty()) {
        GridCompoundFuture<?, ?> compoundFut = new GridCompoundFuture<>();
        for (DynamicCacheStartFuture fut : initiateCacheChanges(reqList, failIfExists)) compoundFut.add((IgniteInternalFuture) fut);
        compoundFut.markInitialized();
        return compoundFut;
    } else
        return new GridFinishedFuture<>();
}
Also used : ArrayList(java.util.ArrayList) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) JMException(javax.management.JMException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteException(org.apache.ignite.IgniteException) CacheExistsException(org.apache.ignite.cache.CacheExistsException) GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture)

Example 12 with GridCompoundFuture

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

the class GridCacheSharedContext method partitionReleaseFuture.

/**
     * Captures all ongoing operations that we need to wait before we can proceed to the next topology version.
     * This method must be called only after
     * {@link GridDhtPartitionTopology#updateTopologyVersion(GridDhtPartitionExchangeId, GridDhtPartitionsExchangeFuture, long, boolean)}
     * method is called so that all new updates will wait to switch to the new version.
     * This method will capture:
     * <ul>
     *     <li>All non-released cache locks</li>
     *     <li>All non-committed transactions (local and remote)</li>
     *     <li>All pending atomic updates</li>
     *     <li>All pending DataStreamer updates</li>
     * </ul>
     *
     * Captured updates are wrapped in a future that will be completed once pending objects are released.
     *
     * @param topVer Topology version.
     * @return {@code true} if waiting was successful.
     */
@SuppressWarnings({ "unchecked" })
public IgniteInternalFuture<?> partitionReleaseFuture(AffinityTopologyVersion topVer) {
    GridCompoundFuture f = new GridCompoundFuture();
    f.add(mvcc().finishExplicitLocks(topVer));
    f.add(tm().finishTxs(topVer));
    f.add(mvcc().finishAtomicUpdates(topVer));
    f.add(mvcc().finishDataStreamerUpdates());
    f.markInitialized();
    return f;
}
Also used : GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture)

Example 13 with GridCompoundFuture

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

the class GridCacheMvccManager method finishExplicitLocks.

/**
     * Creates a future that will wait for all explicit locks acquired on given topology
     * version to be released.
     *
     * @param topVer Topology version to wait for.
     * @return Explicit locks release future.
     */
public IgniteInternalFuture<?> finishExplicitLocks(AffinityTopologyVersion topVer) {
    GridCompoundFuture<Object, Object> res = new GridCompoundFuture<>();
    for (GridCacheExplicitLockSpan span : pendingExplicit.values()) {
        AffinityTopologyVersion snapshot = span.topologyVersion();
        if (snapshot != null && snapshot.compareTo(topVer) < 0)
            res.add(span.releaseFuture());
    }
    res.markInitialized();
    return res;
}
Also used : AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture)

Example 14 with GridCompoundFuture

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

the class GridCacheMvccManager method finishDataStreamerUpdates.

/**
     *
     * @return Finish update future.
     */
@SuppressWarnings("unchecked")
public IgniteInternalFuture<?> finishDataStreamerUpdates() {
    GridCompoundFuture<Object, Object> res = new GridCompoundFuture<>();
    for (IgniteInternalFuture fut : dataStreamerFuts) res.add(fut);
    res.markInitialized();
    return res;
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture)

Example 15 with GridCompoundFuture

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

the class IgniteTxHandler method processDhtTxFinishRequest.

/**
     * @param nodeId Node ID.
     * @param req Request.
     */
@SuppressWarnings({ "unchecked" })
private void processDhtTxFinishRequest(final UUID nodeId, final GridDhtTxFinishRequest req) {
    assert nodeId != null;
    assert req != null;
    if (req.checkCommitted()) {
        boolean committed = req.waitRemoteTransactions() || !ctx.tm().addRolledbackTx(null, req.version());
        if (!committed || req.syncMode() != FULL_SYNC)
            sendReply(nodeId, req, committed, null);
        else {
            IgniteInternalFuture<?> fut = ctx.tm().remoteTxFinishFuture(req.version());
            fut.listen(new CI1<IgniteInternalFuture<?>>() {

                @Override
                public void apply(IgniteInternalFuture<?> fut) {
                    sendReply(nodeId, req, true, null);
                }
            });
        }
        return;
    }
    final GridDhtTxRemote dhtTx = ctx.tm().tx(req.version());
    GridNearTxRemote nearTx = ctx.tm().nearTx(req.version());
    final GridCacheVersion nearTxId = (dhtTx != null ? dhtTx.nearXidVersion() : (nearTx != null ? nearTx.nearXidVersion() : null));
    if (txFinishMsgLog.isDebugEnabled()) {
        txFinishMsgLog.debug("Received dht finish request [txId=" + nearTxId + ", dhtTxId=" + req.version() + ", node=" + nodeId + ']');
    }
    // Safety - local transaction will finish explicitly.
    if (nearTx != null && nearTx.local())
        nearTx = null;
    finish(nodeId, dhtTx, req);
    if (nearTx != null)
        finish(nodeId, nearTx, req);
    if (req.replyRequired()) {
        IgniteInternalFuture completeFut;
        IgniteInternalFuture<IgniteInternalTx> dhtFin = dhtTx == null ? null : dhtTx.done() ? null : dhtTx.finishFuture();
        final IgniteInternalFuture<IgniteInternalTx> nearFin = nearTx == null ? null : nearTx.done() ? null : nearTx.finishFuture();
        if (dhtFin != null && nearFin != null) {
            GridCompoundFuture fut = new GridCompoundFuture();
            fut.add(dhtFin);
            fut.add(nearFin);
            fut.markInitialized();
            completeFut = fut;
        } else
            completeFut = dhtFin != null ? dhtFin : nearFin;
        if (completeFut != null) {
            completeFut.listen(new CI1<IgniteInternalFuture<IgniteInternalTx>>() {

                @Override
                public void apply(IgniteInternalFuture<IgniteInternalTx> fut) {
                    sendReply(nodeId, req, true, nearTxId);
                }
            });
        } else
            sendReply(nodeId, req, true, nearTxId);
    } else
        sendReply(nodeId, req, true, null);
    IgniteInternalTx tx0 = ctx.tm().tx(req.version());
    IgniteInternalTx nearTx0 = ctx.tm().nearTx(req.version());
    assert req.txState() != null || (tx0 == null && nearTx0 == null) : req + " tx=" + tx0 + " nearTx=" + nearTx0;
}
Also used : GridDhtTxRemote(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxRemote) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridNearTxRemote(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxRemote) GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture)

Aggregations

GridCompoundFuture (org.apache.ignite.internal.util.future.GridCompoundFuture)15 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)6 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)3 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)3 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)2 GridDhtTxRemote (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxRemote)2 GridNearTxRemote (org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxRemote)2 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 List (java.util.List)1 UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1