use of org.apache.ignite.internal.util.future.GridFutureAdapter in project ignite by apache.
the class DataStreamerImpl method closeEx.
/**
* @param cancel {@code True} to close with cancellation.
* @param err Error.
* @throws IgniteCheckedException If failed.
*/
private IgniteCheckedException closeEx(boolean cancel, IgniteCheckedException err) throws IgniteCheckedException {
if (!closed.compareAndSet(false, true))
return null;
busyLock.writeLock();
try {
if (log.isDebugEnabled())
log.debug("Closing data streamer [ldr=" + this + ", cancel=" + cancel + ']');
try {
// Assuming that no methods are called on this loader after this method is called.
if (cancel) {
cancelled = true;
IgniteCheckedException cancellationErr = err;
if (cancellationErr == null)
cancellationErr = new IgniteCheckedException("Data streamer has been cancelled: " + DataStreamerImpl.this);
for (ThreadBuffer buf : threadBufMap.values()) {
GridFutureAdapter internalFut = (GridFutureAdapter) buf.getFuture().internalFuture();
internalFut.onDone(cancellationErr);
}
for (Buffer buf : bufMappings.values()) buf.cancelAll(cancellationErr);
} else
doFlush();
ctx.event().removeLocalEventListener(discoLsnr);
ctx.io().removeMessageListener(topic);
} catch (IgniteCheckedException | IgniteDataStreamerTimeoutException e) {
fut.onDone(e);
throw e;
}
long failed = failCntr.longValue();
if (failed > 0 && err == null)
err = new IgniteCheckedException("Some of DataStreamer operations failed [failedCount=" + failed + "]");
fut.onDone(err);
return err;
} finally {
busyLock.writeUnlock();
}
}
use of org.apache.ignite.internal.util.future.GridFutureAdapter in project ignite by apache.
the class DataStreamerImpl method addDataInternal.
/**
* @param entries Entries.
* @param useThreadBuffer
* @return Future.
*/
public IgniteFuture<?> addDataInternal(Collection<? extends DataStreamerEntry> entries, boolean useThreadBuffer) {
checkSecurityPermissions(entries);
IgniteCacheFutureImpl fut = null;
GridFutureAdapter internalFut = null;
Collection entriesList;
lock(false);
try {
long threadId = Thread.currentThread().getId();
if (useThreadBuffer) {
ThreadBuffer threadBuf = threadBufMap.get(threadId);
if (threadBuf == null) {
fut = createDataLoadFuture();
// Initial capacity should be more than batch by 12.5% in order to avoid resizing.
threadBuf = new ThreadBuffer(fut, new ArrayList<>(bufLdrSzPerThread + (bufLdrSzPerThread >> 3)));
threadBufMap.put(threadId, threadBuf);
} else
// Use existed thread-buffer future.
fut = threadBuf.getFuture();
entriesList = threadBuf.getEntries();
entriesList.addAll(entries);
} else {
entriesList = entries;
fut = createDataLoadFuture();
}
internalFut = (GridFutureAdapter) fut.internalFuture();
if (!useThreadBuffer || entriesList.size() >= bufLdrSzPerThread) {
loadData(entriesList, internalFut);
if (useThreadBuffer)
threadBufMap.remove(threadId);
}
return fut;
} catch (Throwable e) {
if (internalFut != null)
internalFut.onDone(e);
if (e instanceof Error || e instanceof IgniteDataStreamerTimeoutException)
throw e;
return fut;
} finally {
unlock(false);
}
}
use of org.apache.ignite.internal.util.future.GridFutureAdapter in project ignite by apache.
the class DataStreamerImpl method createDataLoadFuture.
/**
* Creates data load future and register its as active future.
* @return Data load future.
*/
@NotNull
protected IgniteCacheFutureImpl createDataLoadFuture() {
GridFutureAdapter internalFut0 = new GridFutureAdapter();
IgniteCacheFutureImpl fut = new IgniteCacheFutureImpl(internalFut0, ctx.getAsyncContinuationExecutor());
internalFut0.listen(rmvActiveFut);
activeFuts.add(internalFut0);
return fut;
}
use of org.apache.ignite.internal.util.future.GridFutureAdapter in project ignite by apache.
the class GridClusterStateProcessor method onGridDataReceived.
/**
* {@inheritDoc}
*/
@Override
public void onGridDataReceived(DiscoveryDataBag.GridDiscoveryData data) {
if (data.commonData() instanceof DiscoveryDataClusterState) {
if (globalState != null && globalState.baselineTopology() != null)
// (where some nodes don't support BaselineTopology)
throw new IgniteException("Node with BaselineTopology cannot join" + " mixed cluster running in compatibility mode");
globalState = (DiscoveryDataClusterState) data.commonData();
compatibilityMode = true;
ctx.cache().context().readOnlyMode(globalState.state() == ACTIVE_READ_ONLY);
return;
}
BaselineStateAndHistoryData stateDiscoData = (BaselineStateAndHistoryData) data.commonData();
if (stateDiscoData != null) {
DiscoveryDataClusterState state = stateDiscoData.globalState;
if (state.transition())
transitionFuts.put(state.transitionRequestId(), new GridFutureAdapter<Void>());
globalState = state;
if (stateDiscoData.recentHistory != null) {
for (BaselineTopologyHistoryItem item : stateDiscoData.recentHistory.history()) bltHist.bufferHistoryItemForStore(item);
}
ctx.cache().context().readOnlyMode(globalState.state() == ACTIVE_READ_ONLY);
}
}
use of org.apache.ignite.internal.util.future.GridFutureAdapter in project ignite by apache.
the class GridClusterStateProcessor method onStateChangeMessage.
/**
* {@inheritDoc}
*/
@Override
public boolean onStateChangeMessage(AffinityTopologyVersion topVer, ChangeGlobalStateMessage msg, DiscoCache discoCache) {
DiscoveryDataClusterState state = globalState;
if (log.isInfoEnabled()) {
String baseline = msg.baselineTopology() == null ? ": null" : "[id=" + msg.baselineTopology().id() + ']';
U.log(log, "Received " + prettyStr(msg.state()) + " request with BaselineTopology" + baseline + " initiator node ID: " + msg.initiatorNodeId());
}
if (msg.baselineTopology() != null)
compatibilityMode = false;
if (state.transition()) {
if (isApplicable(msg, state)) {
GridChangeGlobalStateFuture fut = changeStateFuture(msg);
if (fut != null)
fut.onDone(concurrentStateChangeError(msg.state(), state.state()));
} else {
final GridChangeGlobalStateFuture stateFut = changeStateFuture(msg);
GridFutureAdapter<Void> transitionFut = transitionFuts.get(state.transitionRequestId());
if (stateFut != null && transitionFut != null) {
transitionFut.listen(new IgniteInClosure<IgniteInternalFuture<Void>>() {
@Override
public void apply(IgniteInternalFuture<Void> fut) {
try {
fut.get();
stateFut.onDone();
} catch (Exception ex) {
stateFut.onDone(ex);
}
}
});
}
}
} else if (isApplicable(msg, state)) {
if (msg.state() == INACTIVE && !msg.forceDeactivation() && allNodesSupports(ctx.discovery().serverNodes(topVer), SAFE_CLUSTER_DEACTIVATION)) {
List<String> inMemCaches = listInMemoryUserCaches();
if (!inMemCaches.isEmpty()) {
GridChangeGlobalStateFuture stateFut = changeStateFuture(msg);
if (stateFut != null) {
stateFut.onDone(new IgniteException(DATA_LOST_ON_DEACTIVATION_WARNING + " In memory caches: " + inMemCaches + " .To deactivate cluster pass '--force' flag."));
}
return false;
}
}
ExchangeActions exchangeActions;
try {
exchangeActions = ctx.cache().onStateChangeRequest(msg, topVer, state);
} catch (IgniteCheckedException e) {
GridChangeGlobalStateFuture fut = changeStateFuture(msg);
if (fut != null)
fut.onDone(e);
return false;
}
Set<UUID> nodeIds = U.newHashSet(discoCache.allNodes().size());
for (ClusterNode node : discoCache.allNodes()) nodeIds.add(node.id());
GridChangeGlobalStateFuture fut = changeStateFuture(msg);
if (fut != null)
fut.setRemaining(nodeIds, topVer.nextMinorVersion());
if (log.isInfoEnabled())
log.info("Started state transition: " + prettyStr(msg.state()));
BaselineTopologyHistoryItem bltHistItem = BaselineTopologyHistoryItem.fromBaseline(state.baselineTopology());
transitionFuts.put(msg.requestId(), new GridFutureAdapter<Void>());
DiscoveryDataClusterState newState = globalState = DiscoveryDataClusterState.createTransitionState(msg.state(), state, activate(state.state(), msg.state()) || msg.forceChangeBaselineTopology() ? msg.baselineTopology() : state.baselineTopology(), msg.requestId(), topVer, nodeIds);
ctx.durableBackgroundTask().onStateChangeStarted(msg);
if (msg.forceChangeBaselineTopology())
newState.setTransitionResult(msg.requestId(), msg.state());
AffinityTopologyVersion stateChangeTopVer = topVer.nextMinorVersion();
StateChangeRequest req = new StateChangeRequest(msg, bltHistItem, state.state(), stateChangeTopVer);
exchangeActions.stateChangeRequest(req);
msg.exchangeActions(exchangeActions);
if (newState.state() != state.state()) {
if (ctx.event().isRecordable(EventType.EVT_CLUSTER_STATE_CHANGE_STARTED)) {
ctx.pools().getStripedExecutorService().execute(() -> ctx.event().record(new ClusterStateChangeStartedEvent(state.state(), newState.state(), ctx.discovery().localNode(), "Cluster state change started.")));
}
}
return true;
} else {
// State already changed.
GridChangeGlobalStateFuture stateFut = changeStateFuture(msg);
if (stateFut != null)
stateFut.onDone();
}
return false;
}
Aggregations