use of org.apache.ignite.internal.cluster.ClusterTopologyCheckedException in project gridgain by gridgain.
the class GridCacheProcessor method resetCacheState.
/**
* Resets cache state after the cache has been moved to recovery state.
*
* @param cacheNames Cache names.
* @return Future that will be completed when state is changed for all caches.
*/
public IgniteInternalFuture<?> resetCacheState(Collection<String> cacheNames) throws ClusterTopologyCheckedException {
sharedCtx.tm().checkEmptyTransactions(() -> format(CHECK_EMPTY_TRANSACTIONS_ERROR_MSG_FORMAT, cacheNames, "resetCacheState"));
Collection<DynamicCacheChangeRequest> reqs = new ArrayList<>(cacheNames.size());
for (String cacheName : cacheNames) {
final IgniteInternalCache<Object, Object> cache0 = internalCache(cacheName);
if (cache0 == null)
continue;
// Check if all lost partitions has at least one affinity owner.
final Collection<Integer> lostParts = cache0.lostPartitions();
if (lostParts.isEmpty())
continue;
for (Integer part : lostParts) {
final Collection<ClusterNode> owners = cache0.affinity().mapPartitionToPrimaryAndBackups(part);
if (owners.isEmpty())
throw new ClusterTopologyCheckedException("Cannot reset lost partitions because no baseline nodes " + "are online [cache=" + cacheName + ", partition=" + part + ']');
}
DynamicCacheChangeRequest req = DynamicCacheChangeRequest.resetLostPartitions(ctx, cacheName);
reqs.add(req);
}
return initiateCacheChanges(reqs).stream().collect(IgniteCollectors.toCompoundFuture());
}
use of org.apache.ignite.internal.cluster.ClusterTopologyCheckedException in project gridgain by gridgain.
the class GridCacheIoManager method send.
/**
* Sends communication message.
*
* @param nodeId ID of node to send the message to.
* @param msg Message to send.
* @param plc IO policy.
* @throws IgniteCheckedException If sending failed.
*/
public void send(UUID nodeId, GridCacheMessage msg, byte plc) throws IgniteCheckedException {
ClusterNode n = cctx.discovery().node(nodeId);
if (n == null)
throw new ClusterTopologyCheckedException("Failed to send message because node left grid [nodeId=" + nodeId + ", msg=" + msg + ']');
send(n, msg, plc);
}
use of org.apache.ignite.internal.cluster.ClusterTopologyCheckedException in project gridgain by gridgain.
the class CacheContinuousQueryHandler method onEntryUpdate.
/**
* @param evt Continuous query event.
* @param notify Notify flag.
* @param loc Listener deployed on this node.
* @param recordIgniteEvt Record ignite event.
*/
private void onEntryUpdate(CacheContinuousQueryEvent<K, V> evt, boolean notify, boolean loc, boolean recordIgniteEvt) {
try {
GridCacheContext<K, V> cctx = cacheContext(ctx);
if (cctx == null)
return;
CacheContinuousQueryEntry entry = evt.entry();
IgniteClosure<CacheEntryEvent<? extends K, ? extends V>, ?> trans = getTransformer();
if (loc) {
if (!locOnly) {
Collection<CacheEntryEvent<? extends K, ? extends V>> evts = handleEvent(ctx, entry);
notifyLocalListener(evts, trans);
if (!internal && !skipPrimaryCheck)
sendBackupAcknowledge(ackBufBackup.onAcknowledged(entry), routineId, ctx);
} else {
if (!entry.isFiltered())
notifyLocalListener(F.<CacheEntryEvent<? extends K, ? extends V>>asList(evt), trans);
}
} else {
if (!entry.isFiltered()) {
if (trans != null)
entry = transformToEntry(trans, evt);
prepareEntry(cctx, nodeId, entry);
}
Object entryOrList = handleEntry(cctx, entry);
if (entryOrList != null) {
if (log.isDebugEnabled())
log.debug("Send the following event to listener: " + entryOrList);
ctx.continuous().addNotification(nodeId, routineId, entryOrList, topic, sync, true);
}
}
} catch (ClusterTopologyCheckedException ex) {
if (log.isDebugEnabled())
log.debug("Failed to send event notification to node, node left cluster " + "[node=" + nodeId + ", err=" + ex + ']');
} catch (IgniteCheckedException ex) {
U.error(ctx.log(CU.CONTINUOUS_QRY_LOG_CATEGORY), "Failed to send event notification to node: " + nodeId, ex);
}
if (recordIgniteEvt && notify) {
CacheEntryEventFilter filter;
try {
filter = getEventFilter();
} catch (IgniteCheckedException e) {
if (log.isDebugEnabled()) {
log.debug("Failed to trigger a continuoue query event. " + "[routineId=" + routineId + ", cacheName=" + cacheName + ", err=" + e + "]");
}
return;
}
// noinspection unchecked
ctx.event().record(new CacheQueryReadEvent<K, V>(ctx.discovery().localNode(), "Continuous query executed.", EVT_CACHE_QUERY_OBJECT_READ, CacheQueryType.CONTINUOUS.name(), cacheName, null, null, null, filter instanceof CacheEntryEventSerializableFilter ? (CacheEntryEventSerializableFilter) filter : null, null, nodeId, taskName(), evt.getKey(), evt.getValue(), evt.getOldValue(), null));
}
}
use of org.apache.ignite.internal.cluster.ClusterTopologyCheckedException in project gridgain by gridgain.
the class GridEventConsumeHandler method register.
/**
* {@inheritDoc}
*/
@Override
public RegisterStatus register(final UUID nodeId, final UUID routineId, final GridKernalContext ctx) throws IgniteCheckedException {
assert nodeId != null;
assert routineId != null;
assert ctx != null;
if (cb != null)
ctx.resource().injectGeneric(cb);
final boolean loc = nodeId.equals(ctx.localNodeId());
lsnr = new GridLocalEventListener() {
/**
* node ID, routine ID, event
*/
private final Queue<T3<UUID, UUID, Event>> notificationQueue = new LinkedList<>();
private boolean notificationInProgress;
@Override
public void onEvent(Event evt) {
if (filterDropsEvent(evt))
return;
if (loc) {
if (!cb.apply(nodeId, evt))
ctx.continuous().stopRoutine(routineId);
} else {
if (ctx.discovery().node(nodeId) == null)
return;
synchronized (notificationQueue) {
notificationQueue.add(new T3<>(nodeId, routineId, evt));
if (!notificationInProgress) {
ctx.pools().getSystemExecutorService().execute(new Runnable() {
@Override
public void run() {
if (!ctx.continuous().lockStopping())
return;
try {
while (true) {
T3<UUID, UUID, Event> t3;
synchronized (notificationQueue) {
t3 = notificationQueue.poll();
if (t3 == null) {
notificationInProgress = false;
return;
}
}
try {
Event evt = t3.get3();
EventWrapper wrapper = new EventWrapper(evt);
if (evt instanceof CacheEvent) {
String cacheName = ((CacheEvent) evt).cacheName();
ClusterNode node = ctx.discovery().node(t3.get1());
if (node == null)
continue;
if (ctx.config().isPeerClassLoadingEnabled()) {
GridCacheContext cctx = ctx.cache().internalCache(cacheName).context();
if (cctx.deploymentEnabled() && ctx.discovery().cacheNode(node, cacheName)) {
wrapper.p2pMarshal(ctx.config().getMarshaller());
wrapper.cacheName = cacheName;
cctx.deploy().prepare(wrapper);
}
}
}
ctx.continuous().addNotification(t3.get1(), t3.get2(), wrapper, null, false, false);
} catch (ClusterTopologyCheckedException ignored) {
// No-op.
} catch (Throwable e) {
U.error(ctx.log(GridEventConsumeHandler.class), "Failed to send event notification to node: " + nodeId, e);
}
}
} finally {
ctx.continuous().unlockStopping();
}
}
});
notificationInProgress = true;
}
}
}
}
};
if (F.isEmpty(types))
types = EVTS_ALL;
p2pUnmarshalFut.listen((fut) -> {
if (fut.error() == null) {
try {
initFilter(filter, ctx);
} catch (IgniteCheckedException e) {
throw F.wrap(e);
}
ctx.event().addLocalEventListener(lsnr, types);
}
});
return RegisterStatus.REGISTERED;
}
use of org.apache.ignite.internal.cluster.ClusterTopologyCheckedException in project gridgain by gridgain.
the class GridJobSiblingImpl method cancel.
/**
* {@inheritDoc}
*/
@Override
public void cancel() {
GridTaskSessionImpl ses = ctx.session().getSession(sesId);
Collection<ClusterNode> nodes = ses == null ? ctx.discovery().remoteNodes() : ctx.discovery().nodes(ses.getTopology());
for (ClusterNode node : nodes) {
if (!ctx.localNodeId().equals(node.id())) {
try {
ctx.io().sendToGridTopic(node, TOPIC_JOB_CANCEL, new GridJobCancelRequest(sesId, jobId), SYSTEM_POOL);
} catch (ClusterTopologyCheckedException e) {
IgniteLogger log = ctx.log(GridJobSiblingImpl.class);
if (log.isDebugEnabled())
log.debug("Failed to send cancel request, node left [nodeId=" + node.id() + ", ses=" + ses + ']');
} catch (IgniteCheckedException e) {
// Avoid stack trace for left nodes.
if (ctx.discovery().node(node.id()) != null && ctx.discovery().pingNodeNoError(node.id()))
U.error(ctx.log(GridJobSiblingImpl.class), "Failed to send cancel request to node " + "[nodeId=" + node.id() + ", ses=" + ses + ']', e);
}
}
}
// Cancel local jobs directly.
ctx.job().cancelJob(sesId, jobId, false);
}
Aggregations