Search in sources :

Example 91 with IgniteCheckedException

use of org.apache.ignite.IgniteCheckedException in project ignite by apache.

the class GridCacheSetImpl method iterator0.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
private GridCloseableIterator<T> iterator0() {
    try {
        CacheQuery qry = new GridCacheQueryAdapter<>(ctx, SET, null, null, new GridSetQueryPredicate<>(id, collocated), null, false, false);
        Collection<ClusterNode> nodes = dataNodes(ctx.affinity().affinityTopologyVersion());
        qry.projection(ctx.grid().cluster().forNodes(nodes));
        CacheQueryFuture<Map.Entry<T, ?>> fut = qry.execute();
        CacheWeakQueryIteratorsHolder.WeakReferenceCloseableIterator it = ctx.itHolder().iterator(fut, new CacheIteratorConverter<T, Map.Entry<T, ?>>() {

            @Override
            protected T convert(Map.Entry<T, ?> e) {
                return e.getKey();
            }

            @Override
            protected void remove(T item) {
                GridCacheSetImpl.this.remove(item);
            }
        });
        if (rmvd) {
            ctx.itHolder().removeIterator(it);
            checkRemoved();
        }
        return it;
    } catch (IgniteCheckedException e) {
        throw U.convertException(e);
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) CacheQuery(org.apache.ignite.internal.processors.cache.query.CacheQuery) CacheWeakQueryIteratorsHolder(org.apache.ignite.internal.processors.cache.CacheWeakQueryIteratorsHolder) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SET(org.apache.ignite.internal.processors.cache.query.GridCacheQueryType.SET) Map(java.util.Map) GridCacheQueryAdapter(org.apache.ignite.internal.processors.cache.query.GridCacheQueryAdapter)

Example 92 with IgniteCheckedException

use of org.apache.ignite.IgniteCheckedException in project ignite by apache.

the class GridClusterStateProcessor method changeGlobalState0.

/**
 */
private IgniteInternalFuture<?> changeGlobalState0(final boolean activate, BaselineTopology blt, boolean forceChangeBaselineTopology) {
    if (ctx.isDaemon() || ctx.clientNode()) {
        GridFutureAdapter<Void> fut = new GridFutureAdapter<>();
        sendComputeChangeGlobalState(activate, blt, forceChangeBaselineTopology, fut);
        return fut;
    }
    if (cacheProc.transactions().tx() != null || sharedCtx.lockedTopologyVersion(null) != null) {
        return new GridFinishedFuture<>(new IgniteCheckedException("Failed to " + prettyStr(activate) + " cluster (must invoke the method outside of an active transaction)."));
    }
    DiscoveryDataClusterState curState = globalState;
    if (!curState.transition() && curState.active() == activate && BaselineTopology.equals(curState.baselineTopology(), blt))
        return new GridFinishedFuture<>();
    GridChangeGlobalStateFuture startedFut = null;
    GridChangeGlobalStateFuture fut = stateChangeFut.get();
    while (fut == null || fut.isDone()) {
        fut = new GridChangeGlobalStateFuture(UUID.randomUUID(), activate, ctx);
        if (stateChangeFut.compareAndSet(null, fut)) {
            startedFut = fut;
            break;
        } else
            fut = stateChangeFut.get();
    }
    if (startedFut == null) {
        if (fut.activate != activate) {
            return new GridFinishedFuture<>(new IgniteCheckedException("Failed to " + prettyStr(activate) + ", because another state change operation is currently in progress: " + prettyStr(fut.activate)));
        } else
            return fut;
    }
    List<StoredCacheData> storedCfgs = null;
    if (activate && CU.isPersistenceEnabled(ctx.config())) {
        try {
            Map<String, StoredCacheData> cfgs = ctx.cache().context().pageStore().readCacheConfigurations();
            if (!F.isEmpty(cfgs))
                storedCfgs = new ArrayList<>(cfgs.values());
        } catch (IgniteCheckedException e) {
            U.error(log, "Failed to read stored cache configurations: " + e, e);
            startedFut.onDone(e);
            return startedFut;
        }
    }
    ChangeGlobalStateMessage msg = new ChangeGlobalStateMessage(startedFut.requestId, ctx.localNodeId(), storedCfgs, activate, blt, forceChangeBaselineTopology, System.currentTimeMillis());
    try {
        if (log.isInfoEnabled())
            U.log(log, "Sending " + prettyStr(activate) + " request with BaselineTopology " + blt);
        ctx.discovery().sendCustomEvent(msg);
        if (ctx.isStopping())
            startedFut.onDone(new IgniteCheckedException("Failed to execute " + prettyStr(activate) + " request, " + "node is stopping."));
    } catch (IgniteCheckedException e) {
        U.error(log, "Failed to send global state change request: " + activate, e);
        startedFut.onDone(e);
    }
    return wrapStateChangeFuture(startedFut, msg);
}
Also used : ArrayList(java.util.ArrayList) StoredCacheData(org.apache.ignite.internal.processors.cache.StoredCacheData) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter)

Example 93 with IgniteCheckedException

use of org.apache.ignite.IgniteCheckedException in project ignite by apache.

the class GridClusterStateProcessor method publicApiActiveState.

/**
 * {@inheritDoc}
 */
@Override
public boolean publicApiActiveState(boolean waitForTransition) {
    if (ctx.isDaemon())
        return sendComputeCheckGlobalState();
    DiscoveryDataClusterState globalState = this.globalState;
    assert globalState != null;
    if (globalState.transition() && globalState.activeStateChanging()) {
        Boolean transitionRes = globalState.transitionResult();
        if (transitionRes != null)
            return transitionRes;
        else {
            if (waitForTransition) {
                GridFutureAdapter<Void> fut = transitionFuts.get(globalState.transitionRequestId());
                if (fut != null) {
                    try {
                        fut.get();
                    } catch (IgniteCheckedException ex) {
                        throw new IgniteException(ex);
                    }
                }
                transitionRes = globalState.transitionResult();
                assert transitionRes != null;
                return transitionRes;
            } else
                return false;
        }
    } else
        return globalState.active();
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException)

Example 94 with IgniteCheckedException

use of org.apache.ignite.IgniteCheckedException in project ignite by apache.

the class HadoopV2Job method input.

/**
 * {@inheritDoc}
 */
@Override
public Collection<HadoopInputSplit> input() {
    ClassLoader oldLdr = HadoopCommonUtils.setContextClassLoader(jobConf.getClassLoader());
    try {
        String jobDirPath = jobConf.get(MRJobConfig.MAPREDUCE_JOB_DIR);
        if (jobDirPath == null) {
            // Assume that we have needed classes and try to generate input splits ourself.
            if (jobConf.getUseNewMapper())
                return HadoopV2Splitter.splitJob(jobCtx);
            else
                return HadoopV1Splitter.splitJob(jobConf);
        }
        Path jobDir = new Path(jobDirPath);
        try {
            FileSystem fs = fileSystem(jobDir.toUri(), jobConf);
            JobSplit.TaskSplitMetaInfo[] metaInfos = SplitMetaInfoReader.readSplitMetaInfo(hadoopJobID, fs, jobConf, jobDir);
            if (F.isEmpty(metaInfos))
                throw new IgniteCheckedException("No input splits found.");
            Path splitsFile = JobSubmissionFiles.getJobSplitFile(jobDir);
            try (FSDataInputStream in = fs.open(splitsFile)) {
                Collection<HadoopInputSplit> res = new ArrayList<>(metaInfos.length);
                for (JobSplit.TaskSplitMetaInfo metaInfo : metaInfos) {
                    long off = metaInfo.getStartOffset();
                    String[] hosts = metaInfo.getLocations();
                    in.seek(off);
                    String clsName = Text.readString(in);
                    HadoopFileBlock block = HadoopV1Splitter.readFileBlock(clsName, in, hosts);
                    if (block == null)
                        block = HadoopV2Splitter.readFileBlock(clsName, in, hosts);
                    res.add(block != null ? block : new HadoopExternalSplit(hosts, off));
                }
                return res;
            }
        } catch (Throwable e) {
            if (e instanceof Error)
                throw (Error) e;
            else
                throw transformException(e);
        }
    } catch (IgniteCheckedException e) {
        throw new IgniteException(e);
    } finally {
        HadoopCommonUtils.restoreContextClassLoader(oldLdr);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) ArrayList(java.util.ArrayList) HadoopInputSplit(org.apache.ignite.hadoop.HadoopInputSplit) HadoopFileBlock(org.apache.ignite.internal.processors.hadoop.HadoopFileBlock) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) JobSplit(org.apache.hadoop.mapreduce.split.JobSplit) IgniteException(org.apache.ignite.IgniteException) FileSystem(org.apache.hadoop.fs.FileSystem) HadoopClassLoader(org.apache.ignite.internal.processors.hadoop.HadoopClassLoader) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) HadoopExternalSplit(org.apache.ignite.internal.processors.hadoop.HadoopExternalSplit)

Example 95 with IgniteCheckedException

use of org.apache.ignite.IgniteCheckedException in project ignite by apache.

the class HadoopV2Job method dispose.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("ThrowFromFinallyBlock")
@Override
public void dispose(boolean external) throws IgniteCheckedException {
    try {
        if (rsrcMgr != null && !external) {
            File jobLocDir = jobLocalDir(igniteWorkDirectory(), locNodeId, jobId);
            if (jobLocDir.exists())
                U.delete(jobLocDir);
        }
    } finally {
        taskCtxClsPool.clear();
        Throwable err = null;
        // with the task class loaders:
        while (true) {
            Class<? extends HadoopTaskContext> cls = fullCtxClsQueue.poll();
            if (cls == null)
                break;
            try {
                final ClassLoader ldr = cls.getClassLoader();
                try {
                    // Stop Hadoop daemons for this *task*:
                    stopHadoopFsDaemons(ldr);
                } catch (Exception e) {
                    if (err == null)
                        err = e;
                }
                // Also close all the FileSystems cached in
                // HadoopLazyConcurrentMap for this *task* class loader:
                closeCachedTaskFileSystems(ldr);
            } catch (Throwable e) {
                if (err == null)
                    err = e;
                if (e instanceof Error)
                    throw (Error) e;
            }
        }
        assert fullCtxClsQueue.isEmpty();
        try {
            // Close all cached file systems for this *Job*:
            fsMap.close();
        } catch (Exception e) {
            if (err == null)
                err = e;
        }
        if (err != null)
            throw U.cast(err);
    }
}
Also used : HadoopClassLoader(org.apache.ignite.internal.processors.hadoop.HadoopClassLoader) File(java.io.File) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) HadoopUtils.transformException(org.apache.ignite.internal.processors.hadoop.impl.HadoopUtils.transformException) IOException(java.io.IOException)

Aggregations

IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1568 IgniteException (org.apache.ignite.IgniteException)388 ArrayList (java.util.ArrayList)237 IOException (java.io.IOException)226 ClusterNode (org.apache.ignite.cluster.ClusterNode)215 Map (java.util.Map)181 UUID (java.util.UUID)163 HashMap (java.util.HashMap)160 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)150 Test (org.junit.Test)143 List (java.util.List)139 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)138 Nullable (org.jetbrains.annotations.Nullable)134 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)118 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)109 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)105 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)104 Collection (java.util.Collection)97 HashSet (java.util.HashSet)97 Ignite (org.apache.ignite.Ignite)96