use of org.apache.ignite.internal.cluster.ClusterTopologyCheckedException in project ignite by apache.
the class GridNearGetFuture method map.
/**
* @param keys Keys.
* @param mapped Mappings to check for duplicates.
* @param topVer Topology version to map on.
*/
private void map(Collection<KeyCacheObject> keys, Map<ClusterNode, LinkedHashMap<KeyCacheObject, Boolean>> mapped, final AffinityTopologyVersion topVer) {
Collection<ClusterNode> affNodes = CU.affinityNodes(cctx, topVer);
if (affNodes.isEmpty()) {
assert !cctx.affinityNode();
onDone(new ClusterTopologyServerNotFoundException("Failed to map keys for near-only cache (all partition " + "nodes left the grid)."));
return;
}
Map<ClusterNode, LinkedHashMap<KeyCacheObject, Boolean>> mappings = U.newHashMap(affNodes.size());
Map<KeyCacheObject, GridNearCacheEntry> savedEntries = null;
{
boolean success = false;
try {
// Assign keys to primary nodes.
for (KeyCacheObject key : keys) savedEntries = map(key, mappings, topVer, mapped, savedEntries);
success = true;
} finally {
// Exception has been thrown, must release reserved near entries.
if (!success) {
GridCacheVersion obsolete = cctx.versions().next(topVer);
if (savedEntries != null) {
for (GridNearCacheEntry reserved : savedEntries.values()) {
reserved.releaseEviction();
if (reserved.markObsolete(obsolete))
reserved.context().cache().removeEntry(reserved);
}
}
}
}
}
if (isDone())
return;
final Map<KeyCacheObject, GridNearCacheEntry> saved = savedEntries != null ? savedEntries : Collections.<KeyCacheObject, GridNearCacheEntry>emptyMap();
final int keysSize = keys.size();
// Create mini futures.
for (Map.Entry<ClusterNode, LinkedHashMap<KeyCacheObject, Boolean>> entry : mappings.entrySet()) {
final ClusterNode n = entry.getKey();
final LinkedHashMap<KeyCacheObject, Boolean> mappedKeys = entry.getValue();
assert !mappedKeys.isEmpty();
// If this is the primary or backup node for the keys.
if (n.isLocal()) {
final GridDhtFuture<Collection<GridCacheEntryInfo>> fut = dht().getDhtAsync(n.id(), -1, mappedKeys, false, readThrough, topVer, subjId, taskName == null ? 0 : taskName.hashCode(), expiryPlc, skipVals, recovery);
final Collection<Integer> invalidParts = fut.invalidPartitions();
if (!F.isEmpty(invalidParts)) {
Collection<KeyCacheObject> remapKeys = new ArrayList<>(keysSize);
for (KeyCacheObject key : keys) {
if (key != null && invalidParts.contains(cctx.affinity().partition(key)))
remapKeys.add(key);
}
AffinityTopologyVersion updTopVer = cctx.shared().exchange().readyAffinityVersion();
assert updTopVer.compareTo(topVer) > 0 : "Got invalid partitions for local node but topology version did " + "not change [topVer=" + topVer + ", updTopVer=" + updTopVer + ", invalidParts=" + invalidParts + ']';
// Remap recursively.
map(remapKeys, mappings, updTopVer);
}
// Add new future.
add(fut.chain(new C1<IgniteInternalFuture<Collection<GridCacheEntryInfo>>, Map<K, V>>() {
@Override
public Map<K, V> apply(IgniteInternalFuture<Collection<GridCacheEntryInfo>> fut) {
try {
return loadEntries(n.id(), mappedKeys.keySet(), fut.get(), saved, topVer);
} catch (Exception e) {
U.error(log, "Failed to get values from dht cache [fut=" + fut + "]", e);
onDone(e);
return Collections.emptyMap();
}
}
}));
} else {
if (!trackable) {
trackable = true;
cctx.mvcc().addFuture(this, futId);
}
MiniFuture fut = new MiniFuture(n, mappedKeys, saved, topVer, CU.createBackupPostProcessingClosure(topVer, log, cctx, null, expiryPlc, readThrough, skipVals));
GridCacheMessage req = new GridNearGetRequest(cctx.cacheId(), futId, fut.futureId(), ver, mappedKeys, readThrough, topVer, subjId, taskName == null ? 0 : taskName.hashCode(), expiryPlc != null ? expiryPlc.forCreate() : -1L, expiryPlc != null ? expiryPlc.forAccess() : -1L, true, skipVals, cctx.deploymentEnabled(), recovery);
// Append new future.
add(fut);
try {
cctx.io().send(n, req, cctx.ioPolicy());
} catch (IgniteCheckedException e) {
// Fail the whole thing.
if (e instanceof ClusterTopologyCheckedException)
fut.onNodeLeft();
else
fut.onResult(e);
}
}
}
}
use of org.apache.ignite.internal.cluster.ClusterTopologyCheckedException in project ignite by apache.
the class GridNearAtomicSingleUpdateFuture method onAllReceived.
/**
* @return Non-null topology version if update should be remapped.
*/
private AffinityTopologyVersion onAllReceived() {
assert Thread.holdsLock(this);
assert futureMapped() : this;
AffinityTopologyVersion remapTopVer0 = null;
if (remapTopVer == null) {
if (err != null && X.hasCause(err, CachePartialUpdateCheckedException.class) && X.hasCause(err, ClusterTopologyCheckedException.class) && storeFuture() && --remapCnt > 0) {
ClusterTopologyCheckedException topErr = X.cause(err, ClusterTopologyCheckedException.class);
if (!(topErr instanceof ClusterTopologyServerNotFoundException)) {
CachePartialUpdateCheckedException cause = X.cause(err, CachePartialUpdateCheckedException.class);
assert cause != null && cause.topologyVersion() != null : err;
remapTopVer0 = new AffinityTopologyVersion(cause.topologyVersion().topologyVersion() + 1);
err = null;
}
}
} else
remapTopVer0 = remapTopVer;
if (remapTopVer0 != null) {
cctx.mvcc().removeAtomicFuture(futId);
reqState = null;
topVer = AffinityTopologyVersion.ZERO;
futId = 0;
remapTopVer = null;
}
return remapTopVer0;
}
use of org.apache.ignite.internal.cluster.ClusterTopologyCheckedException in project ignite by apache.
the class IgniteUtils method exceptionConverters.
/**
* Gets map with converters to convert internal checked exceptions to public API unchecked exceptions.
*
* @return Exception converters.
*/
private static Map<Class<? extends IgniteCheckedException>, C1<IgniteCheckedException, IgniteException>> exceptionConverters() {
Map<Class<? extends IgniteCheckedException>, C1<IgniteCheckedException, IgniteException>> m = new HashMap<>();
m.put(IgniteInterruptedCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new IgniteInterruptedException(e.getMessage(), (InterruptedException) e.getCause());
}
});
m.put(IgniteFutureCancelledCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new IgniteFutureCancelledException(e.getMessage(), e);
}
});
m.put(IgniteFutureTimeoutCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new IgniteFutureTimeoutException(e.getMessage(), e);
}
});
m.put(ClusterGroupEmptyCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new ClusterGroupEmptyException(e.getMessage(), e);
}
});
m.put(ClusterTopologyCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
ClusterTopologyException topEx = new ClusterTopologyException(e.getMessage(), e);
ClusterTopologyCheckedException checked = (ClusterTopologyCheckedException) e;
if (checked.retryReadyFuture() != null)
topEx.retryReadyFuture(new IgniteFutureImpl<>(checked.retryReadyFuture()));
return topEx;
}
});
m.put(IgniteDeploymentCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new IgniteDeploymentException(e.getMessage(), e);
}
});
m.put(ComputeTaskTimeoutCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new ComputeTaskTimeoutException(e.getMessage(), e);
}
});
m.put(ComputeTaskCancelledCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new ComputeTaskCancelledException(e.getMessage(), e);
}
});
m.put(IgniteTxRollbackCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new TransactionRollbackException(e.getMessage(), e);
}
});
m.put(IgniteTxHeuristicCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new TransactionHeuristicException(e.getMessage(), e);
}
});
m.put(IgniteTxTimeoutCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
if (e.getCause() instanceof TransactionDeadlockException)
return new TransactionTimeoutException(e.getMessage(), e.getCause());
return new TransactionTimeoutException(e.getMessage(), e);
}
});
m.put(IgniteTxOptimisticCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new TransactionOptimisticException(e.getMessage(), e);
}
});
m.put(IgniteClientDisconnectedCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new IgniteClientDisconnectedException(((IgniteClientDisconnectedCheckedException) e).reconnectFuture(), e.getMessage(), e);
}
});
return m;
}
use of org.apache.ignite.internal.cluster.ClusterTopologyCheckedException in project ignite by apache.
the class GridNearTxLocal method enlistWriteEntry.
/**
* @param cacheCtx Cache context.
* @param cacheKey Key.
* @param val Value.
* @param entryProcessor Entry processor.
* @param invokeArgs Optional arguments for EntryProcessor.
* @param expiryPlc Explicitly specified expiry policy for entry.
* @param retval Return value flag.
* @param lockOnly Lock only flag.
* @param filter Filter.
* @param drVer DR version.
* @param drTtl DR ttl.
* @param drExpireTime DR expire time.
* @param ret Return value.
* @param enlisted Enlisted keys collection.
* @param skipStore Skip store flag.
* @param singleRmv {@code True} for single remove operation.
* @param hasFilters {@code True} if filters not empty.
* @param needVal {@code True} if value is needed.
* @param needReadVer {@code True} if need read entry version.
* @return {@code True} if entry value should be loaded.
* @throws IgniteCheckedException If failed.
*/
private boolean enlistWriteEntry(GridCacheContext cacheCtx, @Nullable AffinityTopologyVersion entryTopVer, final KeyCacheObject cacheKey, @Nullable final Object val, @Nullable final EntryProcessor<?, ?, ?> entryProcessor, @Nullable final Object[] invokeArgs, @Nullable final ExpiryPolicy expiryPlc, final boolean retval, final boolean lockOnly, final CacheEntryPredicate[] filter, final GridCacheVersion drVer, final long drTtl, long drExpireTime, final GridCacheReturn ret, @Nullable final Collection<KeyCacheObject> enlisted, boolean skipStore, boolean singleRmv, boolean hasFilters, final boolean needVal, boolean needReadVer, boolean keepBinary, boolean recovery) throws IgniteCheckedException {
boolean loadMissed = false;
final boolean rmv = val == null && entryProcessor == null;
IgniteTxKey txKey = cacheCtx.txKey(cacheKey);
IgniteTxEntry txEntry = entry(txKey);
// First time access.
if (txEntry == null) {
while (true) {
GridCacheEntryEx entry = entryEx(cacheCtx, txKey, entryTopVer != null ? entryTopVer : topologyVersion());
try {
entry.unswap(false);
// Check if lock is being explicitly acquired by the same thread.
if (!implicit && cctx.kernalContext().config().isCacheSanityCheckEnabled() && entry.lockedByThread(threadId, xidVer)) {
throw new IgniteCheckedException("Cannot access key within transaction if lock is " + "externally held [key=" + CU.value(cacheKey, cacheCtx, false) + ", entry=" + entry + ", xidVer=" + xidVer + ", threadId=" + threadId + ", locNodeId=" + cctx.localNodeId() + ']');
}
CacheObject old = null;
GridCacheVersion readVer = null;
if (optimistic() && !implicit()) {
try {
if (needReadVer) {
EntryGetResult res = primaryLocal(entry) ? entry.innerGetVersioned(null, this, /*metrics*/
retval, /*events*/
retval, CU.subjectId(this, cctx), entryProcessor, resolveTaskName(), null, keepBinary, null) : null;
if (res != null) {
old = res.value();
readVer = res.version();
}
} else {
old = entry.innerGet(null, this, /*read through*/
false, /*metrics*/
retval, /*events*/
retval, CU.subjectId(this, cctx), entryProcessor, resolveTaskName(), null, keepBinary);
}
} catch (ClusterTopologyCheckedException e) {
entry.context().evicts().touch(entry, topologyVersion());
throw e;
}
} else
old = entry.rawGet();
final GridCacheOperation op = lockOnly ? NOOP : rmv ? DELETE : entryProcessor != null ? TRANSFORM : old != null ? UPDATE : CREATE;
if (old != null && hasFilters && !filter(entry.context(), cacheKey, old, filter)) {
ret.set(cacheCtx, old, false, keepBinary);
if (!readCommitted()) {
if (optimistic() && serializable()) {
txEntry = addEntry(op, old, entryProcessor, invokeArgs, entry, expiryPlc, filter, true, drTtl, drExpireTime, drVer, skipStore, keepBinary, CU.isNearEnabled(cacheCtx));
} else {
txEntry = addEntry(READ, old, null, null, entry, null, CU.empty0(), false, -1L, -1L, null, skipStore, keepBinary, CU.isNearEnabled(cacheCtx));
}
txEntry.markValid();
if (needReadVer) {
assert readVer != null;
txEntry.entryReadVersion(singleRmv ? SER_READ_NOT_EMPTY_VER : readVer);
}
}
if (readCommitted())
cacheCtx.evicts().touch(entry, topologyVersion());
// While.
break;
}
CacheObject cVal = cacheCtx.toCacheObject(val);
if (op == CREATE || op == UPDATE)
cacheCtx.validateKeyAndValue(cacheKey, cVal);
txEntry = addEntry(op, cVal, entryProcessor, invokeArgs, entry, expiryPlc, filter, true, drTtl, drExpireTime, drVer, skipStore, keepBinary, CU.isNearEnabled(cacheCtx));
if (enlisted != null)
enlisted.add(cacheKey);
if (!pessimistic() && !implicit()) {
txEntry.markValid();
if (old == null) {
if (needVal)
loadMissed = true;
else {
assert !implicit() || !transform : this;
assert txEntry.op() != TRANSFORM : txEntry;
if (retval)
ret.set(cacheCtx, null, true, keepBinary);
else
ret.success(true);
}
} else {
if (needReadVer) {
assert readVer != null;
txEntry.entryReadVersion(singleRmv ? SER_READ_NOT_EMPTY_VER : readVer);
}
if (retval && !transform)
ret.set(cacheCtx, old, true, keepBinary);
else {
if (txEntry.op() == TRANSFORM) {
GridCacheVersion ver;
try {
ver = entry.version();
} catch (GridCacheEntryRemovedException ex) {
assert optimistic() : txEntry;
if (log.isDebugEnabled())
log.debug("Failed to get entry version " + "[err=" + ex.getMessage() + ']');
ver = null;
}
addInvokeResult(txEntry, old, ret, ver);
} else
ret.success(true);
}
}
} else // Pessimistic.
{
if (retval && !transform)
ret.set(cacheCtx, old, true, keepBinary);
else
ret.success(true);
}
// While.
break;
} catch (GridCacheEntryRemovedException ignore) {
if (log.isDebugEnabled())
log.debug("Got removed entry in transaction putAll0 method: " + entry);
}
}
} else {
if (entryProcessor == null && txEntry.op() == TRANSFORM)
throw new IgniteCheckedException("Failed to enlist write value for key (cannot have update value in " + "transaction after EntryProcessor is applied): " + CU.value(cacheKey, cacheCtx, false));
GridCacheEntryEx entry = txEntry.cached();
CacheObject v = txEntry.value();
boolean del = txEntry.op() == DELETE && rmv;
if (!del) {
if (hasFilters && !filter(entry.context(), cacheKey, v, filter)) {
ret.set(cacheCtx, v, false, keepBinary);
return loadMissed;
}
GridCacheOperation op = rmv ? DELETE : entryProcessor != null ? TRANSFORM : v != null ? UPDATE : CREATE;
CacheObject cVal = cacheCtx.toCacheObject(val);
if (op == CREATE || op == UPDATE)
cacheCtx.validateKeyAndValue(cacheKey, cVal);
txEntry = addEntry(op, cVal, entryProcessor, invokeArgs, entry, expiryPlc, filter, true, drTtl, drExpireTime, drVer, skipStore, keepBinary, CU.isNearEnabled(cacheCtx));
if (enlisted != null)
enlisted.add(cacheKey);
if (txEntry.op() == TRANSFORM) {
GridCacheVersion ver;
try {
ver = entry.version();
} catch (GridCacheEntryRemovedException e) {
assert optimistic() : txEntry;
if (log.isDebugEnabled())
log.debug("Failed to get entry version: [msg=" + e.getMessage() + ']');
ver = null;
}
addInvokeResult(txEntry, txEntry.value(), ret, ver);
}
}
if (!pessimistic()) {
txEntry.markValid();
if (retval && !transform)
ret.set(cacheCtx, v, true, keepBinary);
else
ret.success(true);
}
}
return loadMissed;
}
use of org.apache.ignite.internal.cluster.ClusterTopologyCheckedException in project ignite by apache.
the class GridTaskProcessor method sendSessionAttributes.
/**
* This method will make the best attempt to send attributes to all jobs.
*
* @param attrs Deserialized session attributes.
* @param ses Task session.
* @throws IgniteCheckedException If send to any of the jobs failed.
*/
@SuppressWarnings({ "SynchronizationOnLocalVariableOrMethodParameter", "BusyWait" })
private void sendSessionAttributes(Map<?, ?> attrs, GridTaskSessionImpl ses) throws IgniteCheckedException {
assert attrs != null;
assert ses != null;
Collection<ComputeJobSibling> siblings = ses.getJobSiblings();
GridIoManager commMgr = ctx.io();
long timeout = ses.getEndTime() - U.currentTimeMillis();
if (timeout <= 0) {
U.warn(log, "Session attributes won't be set due to task timeout: " + attrs);
return;
}
Set<UUID> rcvrs = new HashSet<>();
UUID locNodeId = ctx.localNodeId();
synchronized (ses) {
if (ses.isClosed()) {
if (log.isDebugEnabled())
log.debug("Setting session attributes on closed session (will ignore): " + ses);
return;
}
ses.setInternal(attrs);
// ID will be associated with a certain session state.
for (ComputeJobSibling s : siblings) {
GridJobSiblingImpl sib = (GridJobSiblingImpl) s;
UUID nodeId = sib.nodeId();
if (!nodeId.equals(locNodeId) && !sib.isJobDone() && !rcvrs.contains(nodeId))
rcvrs.add(nodeId);
}
}
if (ctx.event().isRecordable(EVT_TASK_SESSION_ATTR_SET)) {
Event evt = new TaskEvent(ctx.discovery().localNode(), "Changed attributes: " + attrs, EVT_TASK_SESSION_ATTR_SET, ses.getId(), ses.getTaskName(), ses.getTaskClassName(), false, null);
ctx.event().record(evt);
}
IgniteCheckedException ex = null;
// Every job gets an individual message to keep track of ghost requests.
for (ComputeJobSibling s : ses.getJobSiblings()) {
GridJobSiblingImpl sib = (GridJobSiblingImpl) s;
UUID nodeId = sib.nodeId();
// Pair can be null if job is finished.
if (rcvrs.remove(nodeId)) {
ClusterNode node = ctx.discovery().node(nodeId);
// Check that node didn't change (it could happen in case of failover).
if (node != null) {
boolean loc = node.id().equals(ctx.localNodeId()) && !ctx.config().isMarshalLocalJobs();
GridTaskSessionRequest req = new GridTaskSessionRequest(ses.getId(), null, loc ? null : U.marshal(marsh, attrs), attrs);
// should be preserved here.
try {
commMgr.sendOrderedMessage(node, sib.jobTopic(), req, SYSTEM_POOL, timeout, false);
} catch (IgniteCheckedException e) {
node = e instanceof ClusterTopologyCheckedException ? null : ctx.discovery().node(nodeId);
if (node != null) {
try {
// Since communication on remote node may stop before
// we get discovery notification, we give ourselves the
// best effort to detect it.
Thread.sleep(DISCO_TIMEOUT);
} catch (InterruptedException ignore) {
U.warn(log, "Got interrupted while sending session attributes.");
}
node = ctx.discovery().node(nodeId);
}
String err = "Failed to send session attribute request message to node " + "(normal case if node left grid) [node=" + node + ", req=" + req + ']';
if (node != null)
U.warn(log, err);
else if (log.isDebugEnabled())
log.debug(err);
if (ex == null)
ex = e;
}
}
}
}
if (ex != null)
throw ex;
}
Aggregations