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;
}
}
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;
}
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;
}
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();
}
}
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;
}
Aggregations