use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class GridNearAtomicUpdateFuture method mapOnTopology.
/** {@inheritDoc} */
@Override
protected void mapOnTopology() {
AffinityTopologyVersion topVer;
if (cache.topology().stopping()) {
completeFuture(null, new IgniteCheckedException("Failed to perform cache operation (cache is stopped): " + cache.name()), null);
return;
}
GridDhtTopologyFuture fut = cache.topology().topologyVersionFuture();
if (fut.isDone()) {
Throwable err = fut.validateCache(cctx, recovery, false, null, keys);
if (err != null) {
completeFuture(null, err, null);
return;
}
topVer = fut.topologyVersion();
} else {
assert !topLocked : this;
fut.listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {
@Override
public void apply(IgniteInternalFuture<AffinityTopologyVersion> t) {
cctx.kernalContext().closure().runLocalSafe(new Runnable() {
@Override
public void run() {
mapOnTopology();
}
});
}
});
return;
}
map(topVer, remapKeys);
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class GridPartitionedSingleGetFuture method onNodeLeft.
/** {@inheritDoc} */
@Override
public boolean onNodeLeft(UUID nodeId) {
if (!processResponse(nodeId))
return false;
if (canRemap) {
final AffinityTopologyVersion updTopVer = new AffinityTopologyVersion(Math.max(topVer.topologyVersion() + 1, cctx.discovery().topologyVersion()));
cctx.affinity().affinityReadyFuture(updTopVer).listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {
@Override
public void apply(IgniteInternalFuture<AffinityTopologyVersion> fut) {
try {
fut.get();
remap(updTopVer);
} catch (IgniteCheckedException e) {
onDone(e);
}
}
});
} else
remap(topVer);
return true;
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class GridDhtColocatedLockFuture method mapOnTopology.
/**
* Acquires topology future and checks it completeness under the read lock. If it is not complete,
* will asynchronously wait for it's completeness and then try again.
*
* @param remap Remap flag.
* @param c Optional closure to run after map.
*/
private void mapOnTopology(final boolean remap, @Nullable final Runnable c) {
// We must acquire topology snapshot from the topology version future.
cctx.topology().readLock();
try {
if (cctx.topology().stopping()) {
onDone(new IgniteCheckedException("Failed to perform cache operation (cache is stopped): " + cctx.name()));
return;
}
GridDhtTopologyFuture fut = cctx.topologyVersionFuture();
if (fut.isDone()) {
Throwable err = fut.validateCache(cctx, recovery, read, null, keys);
if (err != null) {
onDone(err);
return;
}
AffinityTopologyVersion topVer = fut.topologyVersion();
if (remap) {
if (tx != null)
tx.onRemap(topVer);
synchronized (this) {
this.topVer = topVer;
}
} else {
if (tx != null)
tx.topologyVersion(topVer);
synchronized (this) {
if (this.topVer == null)
this.topVer = topVer;
}
}
map(keys, remap, false);
if (c != null)
c.run();
markInitialized();
} else {
fut.listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {
@Override
public void apply(IgniteInternalFuture<AffinityTopologyVersion> fut) {
try {
fut.get();
mapOnTopology(remap, c);
} catch (IgniteCheckedException e) {
onDone(e);
} finally {
cctx.shared().txContextReset();
}
}
});
}
} finally {
cctx.topology().readUnlock();
}
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class GridDhtColocatedLockFuture method proceedMapping0.
/**
* Gets next near lock mapping and either acquires dht locks locally or sends near lock request to
* remote primary node.
*
* @throws IgniteCheckedException If mapping can not be completed.
*/
private void proceedMapping0() throws IgniteCheckedException {
GridNearLockMapping map;
synchronized (this) {
map = mappings.poll();
}
// If there are no more mappings to process, complete the future.
if (map == null)
return;
final GridNearLockRequest req = map.request();
final Collection<KeyCacheObject> mappedKeys = map.distributedKeys();
final ClusterNode node = map.node();
if (filter != null && filter.length != 0)
req.filter(filter, cctx);
if (node.isLocal())
lockLocally(mappedKeys, req.topologyVersion());
else {
final MiniFuture fut = new MiniFuture(node, mappedKeys, ++miniId);
req.miniId(fut.futureId());
// Append new future.
add(fut);
IgniteInternalFuture<?> txSync = null;
if (inTx())
txSync = cctx.tm().awaitFinishAckAsync(node.id(), tx.threadId());
if (txSync == null || txSync.isDone()) {
try {
cctx.io().send(node, req, cctx.ioPolicy());
if (msgLog.isDebugEnabled()) {
msgLog.debug("Collocated lock fut, sent request [txId=" + lockVer + ", inTx=" + inTx() + ", node=" + node.id() + ']');
}
} catch (ClusterTopologyCheckedException ex) {
assert fut != null;
fut.onResult(ex);
}
} else {
txSync.listen(new CI1<IgniteInternalFuture<?>>() {
@Override
public void apply(IgniteInternalFuture<?> t) {
try {
cctx.io().send(node, req, cctx.ioPolicy());
if (msgLog.isDebugEnabled()) {
msgLog.debug("Collocated lock fut, sent request [txId=" + lockVer + ", inTx=" + inTx() + ", node=" + node.id() + ']');
}
} catch (ClusterTopologyCheckedException ex) {
assert fut != null;
fut.onResult(ex);
} catch (IgniteCheckedException e) {
if (msgLog.isDebugEnabled()) {
msgLog.debug("Collocated lock fut, failed to send request [txId=" + lockVer + ", inTx=" + inTx() + ", node=" + node.id() + ", err=" + e + ']');
}
onError(e);
}
}
});
}
}
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class GridDhtPreloader method processAffinityAssignmentRequest.
/**
* @param node Node.
* @param req Request.
*/
private void processAffinityAssignmentRequest(final ClusterNode node, final GridDhtAffinityAssignmentRequest req) {
final AffinityTopologyVersion topVer = req.topologyVersion();
if (log.isDebugEnabled())
log.debug("Processing affinity assignment request [node=" + node + ", req=" + req + ']');
cctx.affinity().affinityReadyFuture(req.topologyVersion()).listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {
@Override
public void apply(IgniteInternalFuture<AffinityTopologyVersion> fut) {
if (log.isDebugEnabled())
log.debug("Affinity is ready for topology version, will send response [topVer=" + topVer + ", node=" + node + ']');
AffinityAssignment assignment = cctx.affinity().assignment(topVer);
GridDhtAffinityAssignmentResponse res = new GridDhtAffinityAssignmentResponse(req.futureId(), cctx.cacheId(), topVer, assignment.assignment());
if (cctx.affinity().affinityCache().centralizedAffinityFunction()) {
assert assignment.idealAssignment() != null;
res.idealAffinityAssignment(assignment.idealAssignment());
}
try {
cctx.io().send(node, res, AFFINITY_POOL);
} catch (IgniteCheckedException e) {
U.error(log, "Failed to send affinity assignment response to remote node [node=" + node + ']', e);
}
}
});
}
Aggregations