Search in sources :

Example 66 with GridFutureAdapter

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

the class HadoopV2Job method getTaskContext.

/**
 * {@inheritDoc}
 */
@SuppressWarnings({ "unchecked", "MismatchedQueryAndUpdateOfCollection" })
@Override
public HadoopTaskContext getTaskContext(HadoopTaskInfo info) throws IgniteCheckedException {
    T2<HadoopTaskType, Integer> locTaskId = new T2<>(info.type(), info.taskNumber());
    GridFutureAdapter<HadoopTaskContext> fut = ctxs.get(locTaskId);
    if (fut != null)
        return fut.get();
    GridFutureAdapter<HadoopTaskContext> old = ctxs.putIfAbsent(locTaskId, fut = new GridFutureAdapter<>());
    if (old != null)
        return old.get();
    Class<? extends HadoopTaskContext> cls = taskCtxClsPool.poll();
    try {
        if (cls == null) {
            // If there is no pooled class, then load new one.
            // Note that the classloader identified by the task it was initially created for,
            // but later it may be reused for other tasks.
            HadoopClassLoader ldr = sharedClsLdr != null ? sharedClsLdr : createClassLoader(HadoopClassLoader.nameForTask(info, false));
            cls = (Class<? extends HadoopTaskContext>) ldr.loadClass(HadoopV2TaskContext.class.getName());
            fullCtxClsQueue.add(cls);
        }
        Constructor<?> ctr = cls.getConstructor(HadoopTaskInfo.class, HadoopJobEx.class, HadoopJobId.class, UUID.class, DataInput.class);
        if (jobConfData == null)
            synchronized (jobConf) {
                if (jobConfData == null) {
                    ByteArrayOutputStream buf = new ByteArrayOutputStream();
                    jobConf.write(new DataOutputStream(buf));
                    jobConfData = buf.toByteArray();
                }
            }
        HadoopTaskContext res = (HadoopTaskContext) ctr.newInstance(info, this, jobId, locNodeId, new DataInputStream(new ByteArrayInputStream(jobConfData)));
        fut.onDone(res);
        return res;
    } catch (Throwable e) {
        IgniteCheckedException te = transformException(e);
        fut.onDone(te);
        if (e instanceof Error)
            throw (Error) e;
        throw te;
    }
}
Also used : HadoopClassLoader(org.apache.ignite.internal.processors.hadoop.HadoopClassLoader) HadoopTaskType(org.apache.ignite.internal.processors.hadoop.HadoopTaskType) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) DataInputStream(java.io.DataInputStream) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ByteArrayInputStream(java.io.ByteArrayInputStream) HadoopTaskContext(org.apache.ignite.internal.processors.hadoop.HadoopTaskContext) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) T2(org.apache.ignite.internal.util.typedef.T2)

Example 67 with GridFutureAdapter

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

the class SchemaIndexCacheVisitorImpl method processPartitionsAsync.

/**
 * Process partitions asynchronously.
 *
 * @param parts Partitions.
 * @param clo Closure.
 * @param remainder Remainder.
 * @return Future.
 */
private GridFutureAdapter<Void> processPartitionsAsync(List<GridDhtLocalPartition> parts, SchemaIndexCacheVisitorClosure clo, int remainder) {
    GridFutureAdapter<Void> fut = new GridFutureAdapter<>();
    AsyncWorker worker = new AsyncWorker(parts, clo, remainder, fut);
    new IgniteThread(worker).start();
    return fut;
}
Also used : GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) IgniteThread(org.apache.ignite.thread.IgniteThread)

Example 68 with GridFutureAdapter

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

the class MarshallerContextImpl method getClassName.

/**
 * Gets class name for provided (platformId, typeId) pair.
 *
 * @param platformId id of a platform the class was registered for.
 * @param typeId Type ID.
 * @param skipOtherPlatforms Whether to skip other platforms check (recursion guard).
 * @return Class name
 * @throws ClassNotFoundException If class was not found.
 * @throws IgniteCheckedException In case of any other error.
 */
private String getClassName(byte platformId, int typeId, boolean skipOtherPlatforms) throws ClassNotFoundException, IgniteCheckedException {
    ConcurrentMap<Integer, MappedName> cache = getCacheFor(platformId);
    MappedName mappedName = cache.get(typeId);
    String clsName;
    if (mappedName != null)
        clsName = mappedName.className();
    else {
        clsName = fileStore.readMapping(platformId, typeId);
        if (clsName != null)
            cache.putIfAbsent(typeId, new MappedName(clsName, true));
        else if (clientNode) {
            mappedName = cache.get(typeId);
            if (mappedName == null) {
                GridFutureAdapter<MappingExchangeResult> fut = transport.requestMapping(new MarshallerMappingItem(platformId, typeId, null), cache);
                clsName = fut.get().className();
            } else
                clsName = mappedName.className();
            if (clsName == null)
                throw new ClassNotFoundException("Requesting mapping from grid failed for [platformId=" + platformId + ", typeId=" + typeId + "]");
            return clsName;
        } else {
            String platformName = platformName(platformId);
            if (!skipOtherPlatforms) {
                // Look for this class in other platforms to provide a better error message.
                for (byte otherPlatformId : otherPlatforms(platformId)) {
                    try {
                        clsName = getClassName(otherPlatformId, typeId, true);
                    } catch (ClassNotFoundException ignored) {
                        continue;
                    }
                    String otherPlatformName = platformName(otherPlatformId);
                    throw new ClassNotFoundException("Failed to resolve " + otherPlatformName + " class '" + clsName + "' in " + platformName + " [platformId=" + platformId + ", typeId=" + typeId + "].");
                }
            }
            throw new ClassNotFoundException("Failed to resolve class name [" + "platformId=" + platformId + ", platform=" + platformName + ", typeId=" + typeId + "]");
        }
    }
    return clsName;
}
Also used : MarshallerMappingItem(org.apache.ignite.internal.processors.marshaller.MarshallerMappingItem) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) MappedName(org.apache.ignite.internal.processors.marshaller.MappedName)

Example 69 with GridFutureAdapter

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

the class DurableBackgroundTasksProcessor method onReadyForRead.

/**
 * {@inheritDoc}
 */
@Override
public void onReadyForRead(ReadOnlyMetastorage metastorage) {
    if (!stopLock.enterBusy())
        return;
    try {
        metaStorageOperation(metaStorage -> {
            assert metaStorage != null;
            metaStorage.iterate(TASK_PREFIX, (k, v) -> {
                DurableBackgroundTask task = ((DurableBackgroundTask<?>) v);
                DurableBackgroundTask convertedTask = task.convertAfterRestoreIfNeeded();
                boolean converted = false;
                if (task != convertedTask) {
                    assert !task.name().equals(convertedTask.name()) : "Duplicate task names [original=" + task.name() + ", converted=" + convertedTask.name() + ']';
                    GridFutureAdapter<?> outFut = new GridFutureAdapter<>();
                    outFut.onDone();
                    DurableBackgroundTaskState<?> state = new DurableBackgroundTaskState<>(task, outFut, true, false);
                    state.state(COMPLETED);
                    tasks.put(task.name(), state);
                    task = convertedTask;
                    converted = true;
                }
                tasks.put(task.name(), new DurableBackgroundTaskState<>(task, new GridFutureAdapter<>(), true, converted));
            }, true);
        });
    } finally {
        stopLock.leaveBusy();
    }
}
Also used : DurableBackgroundTask(org.apache.ignite.internal.processors.cache.persistence.metastorage.pendingtask.DurableBackgroundTask) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter)

Example 70 with GridFutureAdapter

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

the class GridCacheMapEntry method mvccRemove.

/**
 * {@inheritDoc}
 */
@Override
public final GridCacheUpdateTxResult mvccRemove(IgniteInternalTx tx, UUID affNodeId, AffinityTopologyVersion topVer, MvccSnapshot mvccVer, boolean needHistory, boolean needOldVal, @Nullable CacheEntryPredicate filter, boolean retVal) throws IgniteCheckedException, GridCacheEntryRemovedException {
    assert tx != null;
    assert mvccVer != null;
    final boolean valid = valid(tx.topologyVersion());
    final GridCacheVersion newVer;
    WALPointer logPtr = null;
    lockEntry();
    MvccUpdateResult res;
    try {
        checkObsolete();
        newVer = tx.writeVersion();
        assert newVer != null : "Failed to get write version for tx: " + tx;
        res = cctx.offheap().mvccRemove(this, mvccVer, tx.local(), needHistory, needOldVal, filter, retVal);
        assert res != null;
        if (res.resultType() == ResultType.VERSION_MISMATCH)
            throw serializationError();
        else if (res.resultType() == ResultType.PREV_NULL)
            return new GridCacheUpdateTxResult(false);
        else if (res.resultType() == ResultType.FILTERED) {
            GridCacheUpdateTxResult updRes = new GridCacheUpdateTxResult(false);
            updRes.filtered(true);
            return updRes;
        } else if (res.resultType() == ResultType.LOCKED) {
            unlockEntry();
            MvccVersion lockVer = res.resultVersion();
            GridFutureAdapter<GridCacheUpdateTxResult> resFut = new GridFutureAdapter<>();
            IgniteInternalFuture<?> lockFut = cctx.kernalContext().coordinators().waitForLock(cctx, mvccVer, lockVer);
            lockFut.listen(new MvccRemoveLockListener(tx, this, affNodeId, topVer, mvccVer, needHistory, resFut, needOldVal, retVal, filter));
            return new GridCacheUpdateTxResult(false, resFut);
        }
        if (cctx.deferredDelete() && deletedUnlocked() && !detached())
            deletedUnlocked(false);
        if (res.resultType() == ResultType.PREV_NOT_NULL) {
            TxCounters counters = tx.txCounters(true);
            if (compareIgnoreOpCounter(res.resultVersion(), mvccVer) == 0) {
                if (// Do not count own update removal.
                res.isKeyAbsentBefore())
                    counters.decrementUpdateCounter(cctx.cacheId(), partition());
            } else
                counters.incrementUpdateCounter(cctx.cacheId(), partition());
            counters.accumulateSizeDelta(cctx.cacheId(), partition(), -1);
        }
        if (cctx.group().persistenceEnabled() && cctx.group().walEnabled())
            logPtr = logMvccUpdate(tx, null, 0, 0L, mvccVer);
        update(null, 0, 0, newVer, true);
        recordNodeId(affNodeId, topVer);
    } finally {
        if (lockedByCurrentThread()) {
            unlockEntry();
            cctx.evicts().touch(this);
        }
    }
    onUpdateFinished(0L);
    GridCacheUpdateTxResult updRes = valid ? new GridCacheUpdateTxResult(true, 0L, logPtr) : new GridCacheUpdateTxResult(false, logPtr);
    if (retVal && (res.resultType() == ResultType.PREV_NOT_NULL || res.resultType() == ResultType.VERSION_FOUND))
        updRes.prevValue(res.oldValue());
    if (needOldVal && compareIgnoreOpCounter(res.resultVersion(), mvccVer) != 0 && (res.resultType() == ResultType.PREV_NOT_NULL || res.resultType() == ResultType.REMOVED_NOT_NULL))
        updRes.oldValue(res.oldValue());
    updRes.mvccHistory(res.history());
    return updRes;
}
Also used : TxCounters(org.apache.ignite.internal.processors.cache.transactions.TxCounters) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) MvccVersion(org.apache.ignite.internal.processors.cache.mvcc.MvccVersion) MvccUpdateResult(org.apache.ignite.internal.processors.cache.tree.mvcc.data.MvccUpdateResult) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)

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