use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class GridCachePartitionExchangeManager method initialExchangeId.
/**
* @return Initial exchange ID.
*/
private GridDhtPartitionExchangeId initialExchangeId() {
DiscoveryEvent discoEvt = cctx.discovery().localJoinEvent();
assert discoEvt != null;
final AffinityTopologyVersion startTopVer = affinityTopologyVersion(discoEvt);
assert discoEvt.topologyVersion() == startTopVer.topologyVersion();
return exchangeId(cctx.localNode().id(), startTopVer, discoEvt);
}
use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class GridCacheDeploymentManager method start0.
/**
* {@inheritDoc}
*/
@Override
public void start0() throws IgniteCheckedException {
globalLdr = new CacheClassLoader(cctx.gridConfig().getClassLoader());
depEnabled = cctx.gridDeploy().enabled();
if (depEnabled) {
discoLsnr = new GridLocalEventListener() {
@Override
public void onEvent(Event evt) {
assert evt.type() == EVT_NODE_FAILED || evt.type() == EVT_NODE_LEFT : "Unexpected event: " + evt;
UUID id = ((DiscoveryEvent) evt).eventNode().id();
if (log.isDebugEnabled())
log.debug("Processing node departure: " + id);
for (Map.Entry<IgniteUuid, CachedDeploymentInfo<K, V>> entry : deps.entrySet()) {
CachedDeploymentInfo<K, V> d = entry.getValue();
if (log.isDebugEnabled())
log.debug("Examining cached info: " + d);
if (d.senderId().equals(id) || d.removeParticipant(id)) {
deps.remove(entry.getKey(), d);
if (log.isDebugEnabled())
log.debug("Removed cached info [d=" + d + ", deps=" + deps + ']');
}
}
allParticipants.remove(id);
}
};
cctx.gridEvents().addLocalEventListener(discoLsnr, EVT_NODE_LEFT, EVT_NODE_FAILED);
}
}
use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class GridCachePartitionExchangeManager method mergeExchanges.
/**
* @param curFut Current exchange future.
* @param msg Message.
* @return {@code True} if node is stopping.
* @throws IgniteInterruptedCheckedException If interrupted.
*/
public boolean mergeExchanges(final GridDhtPartitionsExchangeFuture curFut, GridDhtPartitionsFullMessage msg) throws IgniteInterruptedCheckedException {
AffinityTopologyVersion resVer = msg.resultTopologyVersion();
if (exchWorker.waitForExchangeFuture(resVer))
return true;
for (CachePartitionExchangeWorkerTask task : exchWorker.futQ) {
if (task instanceof GridDhtPartitionsExchangeFuture) {
GridDhtPartitionsExchangeFuture fut = (GridDhtPartitionsExchangeFuture) task;
if (fut.initialVersion().compareTo(resVer) > 0) {
if (log.isInfoEnabled()) {
log.info("Merge exchange future on finish stop [curFut=" + curFut.initialVersion() + ", resVer=" + resVer + ", nextFutVer=" + fut.initialVersion() + ']');
}
break;
}
if (log.isInfoEnabled()) {
log.info("Merge exchange future on finish [curFut=" + curFut.initialVersion() + ", mergedFut=" + fut.initialVersion() + ", evt=" + IgniteUtils.gridEventName(fut.firstEvent().type()) + ", evtNode=" + fut.firstEvent().eventNode().id() + ", evtNodeClient=" + CU.clientNode(fut.firstEvent().eventNode()) + ']');
}
DiscoveryEvent evt = fut.firstEvent();
curFut.context().events().addEvent(fut.initialVersion(), fut.firstEvent(), fut.firstEventCache());
if (evt.type() == EVT_NODE_JOINED) {
final GridDhtPartitionsSingleMessage pendingMsg = fut.mergeJoinExchangeOnDone(curFut);
if (pendingMsg != null) {
if (log.isInfoEnabled()) {
log.info("Merged join exchange future on finish, will reply to node [" + "curFut=" + curFut.initialVersion() + ", mergedFut=" + fut.initialVersion() + ", evtNode=" + evt.eventNode().id() + ']');
}
curFut.waitAndReplyToNode(evt.eventNode().id(), pendingMsg);
}
}
}
}
ExchangeDiscoveryEvents evts = curFut.context().events();
assert evts.topologyVersion().equals(resVer) : "Invalid exchange merge result [ver=" + evts.topologyVersion() + ", expVer=" + resVer + ']';
return false;
}
use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class GridDeploymentPerLoaderStore method start.
/**
* {@inheritDoc}
*/
@Override
public void start() throws IgniteCheckedException {
ctxLdr = U.detectClassLoader(getClass());
discoLsnr = new GridLocalEventListener() {
@Override
public void onEvent(Event evt) {
assert evt instanceof DiscoveryEvent;
UUID nodeId = ((DiscoveryEvent) evt).eventNode().id();
if (evt.type() == EVT_NODE_LEFT || evt.type() == EVT_NODE_FAILED) {
Collection<IsolatedDeployment> rmv = new LinkedList<>();
synchronized (mux) {
for (Iterator<IsolatedDeployment> iter = cache.values().iterator(); iter.hasNext(); ) {
IsolatedDeployment dep = iter.next();
if (dep.senderNodeId().equals(nodeId)) {
dep.undeploy();
iter.remove();
rmv.add(dep);
}
}
}
for (IsolatedDeployment dep : rmv) dep.recordUndeployed();
}
}
};
ctx.event().addLocalEventListener(discoLsnr, EVT_NODE_FAILED, EVT_NODE_LEFT);
if (log.isDebugEnabled())
log.debug(startInfo());
}
use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class GridIoManager method onKernalStart0.
/**
* {@inheritDoc}
*/
@SuppressWarnings({ "deprecation", "SynchronizationOnLocalVariableOrMethodParameter" })
@Override
public void onKernalStart0() throws IgniteCheckedException {
discoLsnr = new GridLocalEventListener() {
@SuppressWarnings({ "TooBroadScope", "fallthrough" })
@Override
public void onEvent(Event evt) {
assert evt instanceof DiscoveryEvent : "Invalid event: " + evt;
DiscoveryEvent discoEvt = (DiscoveryEvent) evt;
UUID nodeId = discoEvt.eventNode().id();
switch(evt.type()) {
case EVT_NODE_JOINED:
// We can't receive messages from undiscovered nodes.
assert waitMap.get(nodeId) == null;
break;
case EVT_NODE_LEFT:
case EVT_NODE_FAILED:
for (Map.Entry<Object, ConcurrentMap<UUID, GridCommunicationMessageSet>> e : msgSetMap.entrySet()) {
ConcurrentMap<UUID, GridCommunicationMessageSet> map = e.getValue();
GridCommunicationMessageSet set;
boolean empty;
synchronized (map) {
set = map.remove(nodeId);
empty = map.isEmpty();
}
if (set != null) {
if (log.isDebugEnabled())
log.debug("Removed message set due to node leaving grid: " + set);
// Unregister timeout listener.
ctx.timeout().removeTimeoutObject(set);
// Node may still send stale messages for this topic
// even after discovery notification is done.
closedTopics.add(set.topic());
}
if (empty)
msgSetMap.remove(e.getKey(), map);
}
// Clean up delayed and ordered messages (need exclusive lock).
lock.writeLock().lock();
try {
Deque<DelayedMessage> waitList = waitMap.remove(nodeId);
if (log.isDebugEnabled())
log.debug("Removed messages from discovery startup delay list " + "(sender node left topology): " + waitList);
} finally {
lock.writeLock().unlock();
}
break;
default:
assert false : "Unexpected event: " + evt;
}
}
};
ctx.event().addLocalEventListener(discoLsnr, EVT_NODE_JOINED, EVT_NODE_LEFT, EVT_NODE_FAILED);
// Make sure that there are no stale messages due to window between communication
// manager start and kernal start.
// 1. Process wait list.
Collection<Collection<DelayedMessage>> delayedMsgs = new ArrayList<>();
lock.writeLock().lock();
try {
started = true;
for (Entry<UUID, Deque<DelayedMessage>> e : waitMap.entrySet()) {
if (ctx.discovery().node(e.getKey()) != null) {
Deque<DelayedMessage> waitList = waitMap.remove(e.getKey());
if (log.isDebugEnabled())
log.debug("Processing messages from discovery startup delay list: " + waitList);
if (waitList != null)
delayedMsgs.add(waitList);
}
}
} finally {
lock.writeLock().unlock();
}
// After write lock released.
if (!delayedMsgs.isEmpty()) {
for (Collection<DelayedMessage> col : delayedMsgs) for (DelayedMessage msg : col) commLsnr.onMessage(msg.nodeId(), msg.message(), msg.callback());
}
// 2. Process messages sets.
for (Map.Entry<Object, ConcurrentMap<UUID, GridCommunicationMessageSet>> e : msgSetMap.entrySet()) {
ConcurrentMap<UUID, GridCommunicationMessageSet> map = e.getValue();
for (GridCommunicationMessageSet set : map.values()) {
if (ctx.discovery().node(set.nodeId()) == null) {
// All map modifications should be synced for consistency.
boolean rmv;
synchronized (map) {
rmv = map.remove(set.nodeId(), set);
}
if (rmv) {
if (log.isDebugEnabled())
log.debug("Removed message set due to node leaving grid: " + set);
// Unregister timeout listener.
ctx.timeout().removeTimeoutObject(set);
}
}
}
boolean rmv;
synchronized (map) {
rmv = map.isEmpty();
}
if (rmv) {
msgSetMap.remove(e.getKey(), map);
// Node may still send stale messages for this topic
// even after discovery notification is done.
closedTopics.add(e.getKey());
}
}
}
Aggregations