Search in sources :

Example 41 with GridFinishedFuture

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

the class GridServiceProcessor method deployAll.

/**
 * @param cfgs Service configurations.
 * @param dfltNodeFilter Default NodeFilter.
 * @return Future for deployment.
 */
private IgniteInternalFuture<?> deployAll(Collection<ServiceConfiguration> cfgs, @Nullable IgnitePredicate<ClusterNode> dfltNodeFilter) {
    assert cfgs != null;
    PreparedConfigurations srvCfg = prepareServiceConfigurations(cfgs, dfltNodeFilter);
    List<ServiceConfiguration> cfgsCp = srvCfg.cfgs;
    List<GridServiceDeploymentFuture> failedFuts = srvCfg.failedFuts;
    Collections.sort(cfgsCp, new Comparator<ServiceConfiguration>() {

        @Override
        public int compare(ServiceConfiguration cfg1, ServiceConfiguration cfg2) {
            return cfg1.getName().compareTo(cfg2.getName());
        }
    });
    GridServiceDeploymentCompoundFuture res;
    while (true) {
        res = new GridServiceDeploymentCompoundFuture();
        if (ctx.deploy().enabled())
            ctx.cache().context().deploy().ignoreOwnership(true);
        try {
            if (cfgsCp.size() == 1)
                writeServiceToCache(res, cfgsCp.get(0));
            else if (cfgsCp.size() > 1) {
                try (Transaction tx = serviceCache().txStart(PESSIMISTIC, READ_COMMITTED)) {
                    for (ServiceConfiguration cfg : cfgsCp) {
                        try {
                            writeServiceToCache(res, cfg);
                        } catch (IgniteCheckedException e) {
                            if (X.hasCause(e, ClusterTopologyCheckedException.class))
                                // Retry.
                                throw e;
                            else
                                U.error(log, e.getMessage());
                        }
                    }
                    tx.commit();
                }
            }
            break;
        } catch (IgniteException | IgniteCheckedException e) {
            for (String name : res.servicesToRollback()) depFuts.remove(name).onDone(e);
            if (X.hasCause(e, ClusterTopologyCheckedException.class)) {
                if (log.isDebugEnabled())
                    log.debug("Topology changed while deploying services (will retry): " + e.getMessage());
            } else {
                res.onDone(new IgniteCheckedException(new ServiceDeploymentException("Failed to deploy provided services.", e, cfgs)));
                return res;
            }
        } finally {
            if (ctx.deploy().enabled())
                ctx.cache().context().deploy().ignoreOwnership(false);
        }
    }
    if (ctx.clientDisconnected()) {
        IgniteClientDisconnectedCheckedException err = new IgniteClientDisconnectedCheckedException(ctx.cluster().clientReconnectFuture(), "Failed to deploy services, client node disconnected: " + cfgs);
        for (String name : res.servicesToRollback()) {
            GridServiceDeploymentFuture fut = depFuts.remove(name);
            if (fut != null)
                fut.onDone(err);
        }
        return new GridFinishedFuture<>(err);
    }
    if (failedFuts != null) {
        for (GridServiceDeploymentFuture fut : failedFuts) res.add(fut, false);
    }
    res.markInitialized();
    return res;
}
Also used : ServiceDeploymentException(org.apache.ignite.services.ServiceDeploymentException) IgniteSystemProperties.getString(org.apache.ignite.IgniteSystemProperties.getString) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) Transaction(org.apache.ignite.transactions.Transaction) IgniteException(org.apache.ignite.IgniteException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 42 with GridFinishedFuture

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

the class GridServiceProcessor method cancelAll.

/**
 * @param svcNames Name of service to deploy.
 * @return Future.
 */
@SuppressWarnings("unchecked")
public IgniteInternalFuture<?> cancelAll(Collection<String> svcNames) {
    List<String> svcNamesCp = new ArrayList<>(svcNames);
    Collections.sort(svcNamesCp);
    GridCompoundFuture res;
    while (true) {
        res = null;
        List<String> toRollback = new ArrayList<>();
        try (Transaction tx = serviceCache().txStart(PESSIMISTIC, READ_COMMITTED)) {
            for (String name : svcNames) {
                if (res == null)
                    res = new GridCompoundFuture<>();
                try {
                    CancelResult cr = removeServiceFromCache(name);
                    if (cr.rollback)
                        toRollback.add(name);
                    res.add(cr.fut);
                } catch (IgniteException | IgniteCheckedException e) {
                    if (X.hasCause(e, ClusterTopologyCheckedException.class))
                        // Retry.
                        throw e;
                    else {
                        U.error(log, "Failed to undeploy service: " + name, e);
                        res.add(new GridFinishedFuture<>(e));
                    }
                }
            }
            tx.commit();
            break;
        } catch (IgniteException | IgniteCheckedException e) {
            for (String name : toRollback) undepFuts.remove(name).onDone(e);
            if (X.hasCause(e, ClusterTopologyCheckedException.class)) {
                if (log.isDebugEnabled())
                    log.debug("Topology changed while cancelling service (will retry): " + e.getMessage());
            } else
                return new GridFinishedFuture<>(e);
        }
    }
    if (res != null) {
        res.markInitialized();
        return res;
    } else
        return new GridFinishedFuture<>();
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Transaction(org.apache.ignite.transactions.Transaction) IgniteException(org.apache.ignite.IgniteException) ArrayList(java.util.ArrayList) IgniteSystemProperties.getString(org.apache.ignite.IgniteSystemProperties.getString) GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture)

Example 43 with GridFinishedFuture

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

the class GridIoManager method sendIoTest.

/**
 * @param node Node.
 * @param payload Payload.
 * @param procFromNioThread If {@code true} message is processed from NIO thread.
 * @return Response future.
 */
public IgniteInternalFuture<List<IgniteIoTestMessage>> sendIoTest(ClusterNode node, byte[] payload, boolean procFromNioThread) {
    long id = ioTestId.getAndIncrement();
    IoTestFuture fut = new IoTestFuture(id, 1);
    IgniteIoTestMessage msg = new IgniteIoTestMessage(id, true, payload);
    msg.processFromNioThread(procFromNioThread);
    ioTestMap().put(id, fut);
    try {
        sendToGridTopic(node, GridTopic.TOPIC_IO_TEST, msg, GridIoPolicy.SYSTEM_POOL);
    } catch (IgniteCheckedException e) {
        ioTestMap().remove(msg.id());
        return new GridFinishedFuture(e);
    }
    return fut;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture)

Example 44 with GridFinishedFuture

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

the class GridIoManager method sendIoTest.

/**
 * @param nodes Nodes.
 * @param payload Payload.
 * @param procFromNioThread If {@code true} message is processed from NIO thread.
 * @return Response future.
 */
public IgniteInternalFuture sendIoTest(List<ClusterNode> nodes, byte[] payload, boolean procFromNioThread) {
    long id = ioTestId.getAndIncrement();
    IoTestFuture fut = new IoTestFuture(id, nodes.size());
    IgniteIoTestMessage msg = new IgniteIoTestMessage(id, true, payload);
    msg.processFromNioThread(procFromNioThread);
    ioTestMap().put(id, fut);
    for (int i = 0; i < nodes.size(); i++) {
        ClusterNode node = nodes.get(i);
        try {
            sendToGridTopic(node, GridTopic.TOPIC_IO_TEST, msg, GridIoPolicy.SYSTEM_POOL);
        } catch (IgniteCheckedException e) {
            ioTestMap().remove(msg.id());
            return new GridFinishedFuture(e);
        }
    }
    return fut;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture)

Example 45 with GridFinishedFuture

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

the class GridDhtAtomicCache method getAllAsync0.

/**
 * Entry point to all public API get methods.
 *
 * @param keys Keys.
 * @param forcePrimary Force primary flag.
 * @param taskName Task name.
 * @param deserializeBinary Deserialize binary flag.
 * @param expiryPlc Expiry policy.
 * @param skipVals Skip values flag.
 * @param skipStore Skip store flag.
 * @param needVer Need version.
 * @return Get future.
 */
private IgniteInternalFuture<Map<K, V>> getAllAsync0(@Nullable Collection<KeyCacheObject> keys, boolean forcePrimary, String taskName, boolean deserializeBinary, boolean recovery, ReadRepairStrategy readRepairStrategy, @Nullable ExpiryPolicy expiryPlc, boolean skipVals, boolean skipStore, boolean needVer) {
    AffinityTopologyVersion topVer = ctx.affinity().affinityTopologyVersion();
    final IgniteCacheExpiryPolicy expiry = skipVals ? null : expiryPolicy(expiryPlc);
    final boolean evt = !skipVals;
    if (readRepairStrategy != null) {
        return new GridNearReadRepairCheckOnlyFuture(ctx, ctx.cacheKeysView(keys), readRepairStrategy, !skipStore, taskName, deserializeBinary, recovery, expiry, skipVals, needVer, false, null).multi();
    }
    // Optimisation: try to resolve value locally and escape 'get future' creation.
    if (!forcePrimary && ctx.config().isReadFromBackup() && ctx.affinityNode() && ctx.group().topology().lostPartitions().isEmpty()) {
        ctx.shared().database().checkpointReadLock();
        try {
            Map<K, V> locVals = U.newHashMap(keys.size());
            boolean success = true;
            boolean readNoEntry = ctx.readNoEntry(expiry, false);
            // Optimistically expect that all keys are available locally (avoid creation of get future).
            for (KeyCacheObject key : keys) {
                if (readNoEntry) {
                    CacheDataRow row = ctx.offheap().read(ctx, key);
                    if (row != null) {
                        long expireTime = row.expireTime();
                        if (expireTime == 0 || expireTime > U.currentTimeMillis()) {
                            ctx.addResult(locVals, key, row.value(), skipVals, false, deserializeBinary, true, null, row.version(), 0, 0, needVer, U.deploymentClassLoader(ctx.kernalContext(), U.contextDeploymentClassLoaderId(ctx.kernalContext())));
                            if (evt) {
                                ctx.events().readEvent(key, null, null, row.value(), taskName, !deserializeBinary);
                            }
                        } else
                            success = false;
                    } else
                        success = false;
                } else {
                    GridCacheEntryEx entry = null;
                    while (true) {
                        try {
                            entry = entryEx(key);
                            // If our DHT cache do has value, then we peek it.
                            if (entry != null) {
                                boolean isNew = entry.isNewLocked();
                                EntryGetResult getRes = null;
                                CacheObject v = null;
                                GridCacheVersion ver = null;
                                if (needVer) {
                                    getRes = entry.innerGetVersioned(null, null, /*update-metrics*/
                                    false, /*event*/
                                    evt, null, taskName, expiry, true, null);
                                    if (getRes != null) {
                                        v = getRes.value();
                                        ver = getRes.version();
                                    }
                                } else {
                                    v = entry.innerGet(null, null, /*read-through*/
                                    false, /*update-metrics*/
                                    false, /*event*/
                                    evt, null, taskName, expiry, !deserializeBinary);
                                }
                                // Entry was not in memory or in swap, so we remove it from cache.
                                if (v == null) {
                                    if (isNew && entry.markObsoleteIfEmpty(nextVersion()))
                                        removeEntry(entry);
                                    success = false;
                                } else {
                                    ctx.addResult(locVals, key, v, skipVals, false, deserializeBinary, true, getRes, ver, 0, 0, needVer, U.deploymentClassLoader(ctx.kernalContext(), U.contextDeploymentClassLoaderId(ctx.kernalContext())));
                                }
                            } else
                                success = false;
                            // While.
                            break;
                        } catch (GridCacheEntryRemovedException ignored) {
                        // No-op, retry.
                        } catch (GridDhtInvalidPartitionException ignored) {
                            success = false;
                            // While.
                            break;
                        } finally {
                            if (entry != null)
                                entry.touch();
                        }
                    }
                }
                if (!success)
                    break;
                else if (!skipVals && ctx.statisticsEnabled())
                    metrics0().onRead(true);
            }
            if (success) {
                sendTtlUpdateRequest(expiry);
                return new GridFinishedFuture<>(locVals);
            }
        } catch (IgniteCheckedException e) {
            return new GridFinishedFuture<>(e);
        } finally {
            ctx.shared().database().checkpointReadUnlock();
        }
    }
    if (expiry != null)
        expiry.reset();
    // Either reload or not all values are available locally.
    GridPartitionedGetFuture<K, V> fut = new GridPartitionedGetFuture<>(ctx, keys, !skipStore, forcePrimary, taskName, deserializeBinary, recovery, expiry, skipVals, needVer, false, null, null, null);
    fut.init(topVer);
    return fut;
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) GridDhtInvalidPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtInvalidPartitionException) GridPartitionedGetFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridPartitionedGetFuture) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) GridNearReadRepairCheckOnlyFuture(org.apache.ignite.internal.processors.cache.distributed.near.consistency.GridNearReadRepairCheckOnlyFuture) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) EntryGetResult(org.apache.ignite.internal.processors.cache.EntryGetResult) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) IgniteCacheExpiryPolicy(org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Aggregations

GridFinishedFuture (org.apache.ignite.internal.util.future.GridFinishedFuture)75 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)55 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)23 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)21 ArrayList (java.util.ArrayList)20 Map (java.util.Map)18 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)17 HashMap (java.util.HashMap)16 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)15 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)15 IgniteException (org.apache.ignite.IgniteException)14 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)14 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)14 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)14 LinkedHashMap (java.util.LinkedHashMap)13 IgniteTxRollbackCheckedException (org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException)12 GridClosureException (org.apache.ignite.internal.util.lang.GridClosureException)12 HashSet (java.util.HashSet)11 List (java.util.List)11 ClusterNode (org.apache.ignite.cluster.ClusterNode)11