use of org.apache.ignite.internal.util.future.GridFutureAdapter in project ignite by apache.
the class DistributedMetaStorageImpl method prepareWriteFuture.
/**
* This method will perform some preliminary checks before starting write or cas operation.
* It also updates {@link #updateFuts} in case if everything's ok.
*
* Tricky part is exception handling from "isSupported" method. It can be thrown by
* {@code ZookeeperDiscoveryImpl#checkState()} method, but we can't just leave it as is.
* There are components that rely on distributed metastorage throwing {@link NodeStoppingException}.
*
* @return Future that must be returned immediately or {@code null}.
* @throws IgniteCheckedException If cluster can't perform this update.
*/
private GridFutureAdapter<Boolean> prepareWriteFuture(String key, UUID reqId) throws IgniteCheckedException {
boolean supported;
try {
supported = isSupported(ctx);
} catch (Exception e) {
if (X.hasCause(e, IgniteSpiException.class) && e.getMessage() != null && e.getMessage().contains("Node stopped.")) {
GridFutureAdapter<Boolean> fut = new GridFutureAdapter<>();
fut.onDone(nodeStoppingException());
return fut;
}
throw e;
}
if (!supported)
throw new IgniteCheckedException(NOT_SUPPORTED_MSG);
GridFutureAdapter<Boolean> fut = new GridFutureAdapter<>();
updateFutsStopLock.readLock().lock();
try {
if (stopped) {
fut.onDone(nodeStoppingException());
return fut;
}
updateFuts.put(reqId, fut);
} finally {
updateFutsStopLock.readLock().unlock();
}
return fut;
}
use of org.apache.ignite.internal.util.future.GridFutureAdapter in project ignite by apache.
the class GridCachePartitionExchangeManager method onKernalStart.
/**
* @param active Cluster state.
* @param reconnect Reconnect flag.
* @return Topology version of local join exchange if cluster is active.
* Topology version NONE if cluster is not active or reconnect.
* @throws IgniteCheckedException If failed.
*/
public AffinityTopologyVersion onKernalStart(boolean active, boolean reconnect) throws IgniteCheckedException {
for (ClusterNode n : cctx.discovery().remoteNodes()) cctx.versions().onReceived(n.id(), n.metrics().getLastDataVersion());
DiscoveryLocalJoinData locJoin = cctx.discovery().localJoin();
GridDhtPartitionsExchangeFuture fut = null;
if (reconnect)
reconnectExchangeFut = new GridFutureAdapter<>();
if (active) {
DiscoveryEvent discoEvt = locJoin.event();
DiscoCache discoCache = locJoin.discoCache();
GridDhtPartitionExchangeId exchId = initialExchangeId();
fut = exchangeFuture(exchId, reconnect ? null : discoEvt, reconnect ? null : discoCache, null, null);
} else if (reconnect)
reconnectExchangeFut.onDone();
new IgniteThread(cctx.igniteInstanceName(), "exchange-worker", exchWorker).start();
if (reconnect) {
if (fut != null) {
fut.listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {
@Override
public void apply(IgniteInternalFuture<AffinityTopologyVersion> fut) {
try {
fut.get();
for (CacheGroupContext grp : cctx.cache().cacheGroups()) grp.preloader().onInitialExchangeComplete(null);
reconnectExchangeFut.onDone();
} catch (IgniteCheckedException e) {
for (CacheGroupContext grp : cctx.cache().cacheGroups()) grp.preloader().onInitialExchangeComplete(e);
reconnectExchangeFut.onDone(e);
}
}
});
}
} else if (fut != null) {
if (log.isDebugEnabled())
log.debug("Beginning to wait on local exchange future: " + fut);
boolean first = true;
while (true) {
try {
fut.get(cctx.preloadExchangeTimeout());
break;
} catch (IgniteFutureTimeoutCheckedException ignored) {
if (first) {
U.warn(log, "Failed to wait for initial partition map exchange. " + "Possible reasons are: " + U.nl() + " ^-- Transactions in deadlock." + U.nl() + " ^-- Long running transactions (ignore if this is the case)." + U.nl() + " ^-- Unreleased explicit locks.");
first = false;
} else
U.warn(log, "Still waiting for initial partition map exchange [fut=" + fut + ']');
} catch (IgniteNeedReconnectException e) {
throw e;
} catch (Exception e) {
if (fut.reconnectOnError(e))
throw new IgniteNeedReconnectException(cctx.localNode(), e);
throw e;
}
}
for (CacheGroupContext grp : cctx.cache().cacheGroups()) {
if (locJoin.joinTopologyVersion().equals(grp.localStartVersion()))
grp.preloader().onInitialExchangeComplete(null);
}
if (log.isDebugEnabled())
log.debug("Finished waiting for initial exchange: " + fut.exchangeId());
return fut.initialVersion();
}
return NONE;
}
use of org.apache.ignite.internal.util.future.GridFutureAdapter in project ignite by apache.
the class GridCacheMapEntry method mvccLock.
/**
* {@inheritDoc}
*/
@Override
public GridCacheUpdateTxResult mvccLock(GridDhtTxLocalAdapter tx, MvccSnapshot mvccVer) throws GridCacheEntryRemovedException, IgniteCheckedException {
assert tx != null;
assert mvccVer != null;
final boolean valid = valid(tx.topologyVersion());
final GridCacheVersion newVer;
WALPointer logPtr = null;
lockEntry();
try {
checkObsolete();
newVer = tx.writeVersion();
assert newVer != null : "Failed to get write version for tx: " + tx;
assert tx.local();
MvccUpdateResult res = cctx.offheap().mvccLock(this, mvccVer);
assert res != null;
if (res.resultType() == ResultType.VERSION_MISMATCH)
throw serializationError();
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 MvccAcquireLockListener(tx, this, mvccVer, resFut));
return new GridCacheUpdateTxResult(false, resFut);
}
} finally {
if (lockedByCurrentThread()) {
unlockEntry();
cctx.evicts().touch(this);
}
}
onUpdateFinished(0L);
return new GridCacheUpdateTxResult(valid, logPtr);
}
use of org.apache.ignite.internal.util.future.GridFutureAdapter in project ignite by apache.
the class GridEventConsumeHandler method p2pUnmarshal.
/**
* {@inheritDoc}
*/
@Override
public void p2pUnmarshal(UUID nodeId, GridKernalContext ctx) throws IgniteCheckedException {
assert nodeId != null;
assert ctx != null;
assert ctx.config().isPeerClassLoadingEnabled();
if (filterBytes != null) {
try {
GridDeployment dep = ctx.deploy().getGlobalDeployment(depInfo.deployMode(), clsName, clsName, depInfo.userVersion(), nodeId, depInfo.classLoaderId(), depInfo.participants(), null);
if (dep == null)
throw new IgniteDeploymentCheckedException("Failed to obtain deployment for class: " + clsName);
filter = U.unmarshal(ctx, filterBytes, U.resolveClassLoader(dep.classLoader(), ctx.config()));
((GridFutureAdapter) p2pUnmarshalFut).onDone();
} catch (IgniteCheckedException e) {
((GridFutureAdapter) p2pUnmarshalFut).onDone(e);
throw e;
} catch (ExceptionInInitializerError e) {
((GridFutureAdapter) p2pUnmarshalFut).onDone(e);
throw new IgniteCheckedException("Failed to unmarshal deployable object.", e);
}
}
}
use of org.apache.ignite.internal.util.future.GridFutureAdapter in project ignite by apache.
the class GridKernalGatewayImpl method onDisconnected.
/**
* {@inheritDoc}
*/
@Override
public GridFutureAdapter<?> onDisconnected() {
if (state.get() == GridKernalState.DISCONNECTED) {
assert reconnectFut != null;
return (GridFutureAdapter<?>) reconnectFut.internalFuture();
}
GridFutureAdapter<?> fut = new GridFutureAdapter<>();
reconnectFut = new IgniteFutureImpl<>(fut);
if (!state.compareAndSet(GridKernalState.STARTED, GridKernalState.DISCONNECTED)) {
((GridFutureAdapter<?>) reconnectFut.internalFuture()).onDone(new IgniteCheckedException("Node stopped."));
return null;
}
return fut;
}
Aggregations