use of org.apache.ignite.events.EventType.EVT_NODE_LEFT in project ignite by apache.
the class IgniteProjectionStartStopRestartSelfTest method beforeTest.
/**
* {@inheritDoc}
*/
@Override
protected void beforeTest() {
if (SSH_KEY != null) {
key = new File(SSH_KEY);
assert key.exists() : "Private key doesn't exist: " + key.getAbsolutePath();
assert key.isFile() : "Private key is not a file: " + key.getAbsolutePath();
} else
pwd = SSH_PWD;
log.info("Username: " + SSH_UNAME);
log.info("Password: " + pwd);
log.info("Key path: " + key);
G.setDaemon(true);
ignite = G.start(CFG_NO_ATTR);
G.setDaemon(false);
ignite.events().localListen((IgnitePredicate<Event>) evt -> {
info("Received event: " + evt.shortDisplay());
if (evt.type() == EVT_NODE_JOINED) {
joinedCnt.incrementAndGet();
if (joinedLatch != null)
joinedLatch.countDown();
} else if (evt.type() == EVT_NODE_LEFT || evt.type() == EVT_NODE_FAILED) {
leftCnt.incrementAndGet();
if (leftLatch != null)
leftLatch.countDown();
}
return true;
}, EVT_NODE_JOINED, EVT_NODE_LEFT, EVT_NODE_FAILED);
}
use of org.apache.ignite.events.EventType.EVT_NODE_LEFT in project ignite by apache.
the class GridEventStorageManager method query.
/**
* @param p Grid event predicate.
* @param nodes Collection of nodes.
* @param timeout Maximum time to wait for result, if {@code 0}, then wait until result is received.
* @return Collection of events.
* @throws IgniteCheckedException Thrown in case of any errors.
*/
private <T extends Event> List<T> query(IgnitePredicate<T> p, Collection<? extends ClusterNode> nodes, long timeout) throws IgniteCheckedException {
assert p != null;
assert nodes != null;
if (nodes.isEmpty()) {
U.warn(log, "Failed to query events for empty nodes collection.");
return Collections.emptyList();
}
GridIoManager ioMgr = ctx.io();
final List<T> evts = new ArrayList<>();
final AtomicReference<Throwable> err = new AtomicReference<>();
final Set<UUID> uids = new HashSet<>();
final Object qryMux = new Object();
for (ClusterNode node : nodes) uids.add(node.id());
GridLocalEventListener evtLsnr = new GridLocalEventListener() {
@Override
public void onEvent(Event evt) {
assert evt instanceof DiscoveryEvent;
synchronized (qryMux) {
uids.remove(((DiscoveryEvent) evt).eventNode().id());
if (uids.isEmpty())
qryMux.notifyAll();
}
}
};
GridMessageListener resLsnr = new GridMessageListener() {
@Override
public void onMessage(UUID nodeId, Object msg, byte plc) {
assert nodeId != null;
assert msg != null;
if (!(msg instanceof GridEventStorageMessage)) {
U.error(log, "Received unknown message: " + msg);
return;
}
GridEventStorageMessage res = (GridEventStorageMessage) msg;
try {
if (res.eventsBytes() != null)
res.events(U.<Collection<Event>>unmarshal(marsh, res.eventsBytes(), U.resolveClassLoader(ctx.config())));
if (res.exceptionBytes() != null)
res.exception(U.<Throwable>unmarshal(marsh, res.exceptionBytes(), U.resolveClassLoader(ctx.config())));
} catch (IgniteCheckedException e) {
U.error(log, "Failed to unmarshal events query response: " + msg, e);
return;
}
synchronized (qryMux) {
if (uids.remove(nodeId)) {
if (res.events() != null)
evts.addAll((Collection<T>) res.events());
} else
U.warn(log, "Received duplicate response (ignoring) [nodeId=" + nodeId + ", msg=" + res + ']');
if (res.exception() != null)
err.set(res.exception());
if (uids.isEmpty() || err.get() != null)
qryMux.notifyAll();
}
}
};
Object resTopic = TOPIC_EVENT.topic(IgniteUuid.fromUuid(ctx.localNodeId()));
try {
addLocalEventListener(evtLsnr, new int[] { EVT_NODE_LEFT, EVT_NODE_FAILED });
ioMgr.addMessageListener(resTopic, resLsnr);
byte[] serFilter = U.marshal(marsh, p);
GridDeployment dep = ctx.deploy().deploy(p.getClass(), U.detectClassLoader(p.getClass()));
if (dep == null)
throw new IgniteDeploymentCheckedException("Failed to deploy event filter: " + p);
GridEventStorageMessage msg = new GridEventStorageMessage(resTopic, serFilter, p.getClass().getName(), dep.classLoaderId(), dep.deployMode(), dep.userVersion(), dep.participants());
sendMessage(nodes, TOPIC_EVENT, msg, PUBLIC_POOL);
if (timeout == 0)
timeout = Long.MAX_VALUE;
long startNanos = System.nanoTime();
long passedMillis = 0L;
Collection<UUID> uidsCp = null;
synchronized (qryMux) {
try {
while (!uids.isEmpty() && err.get() == null && passedMillis < timeout) {
qryMux.wait(timeout - passedMillis);
passedMillis = U.millisSinceNanos(startNanos);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IgniteCheckedException("Got interrupted while waiting for event query responses.", e);
}
if (err.get() != null)
throw new IgniteCheckedException("Failed to query events due to exception on remote node.", err.get());
if (!uids.isEmpty())
uidsCp = new LinkedList<>(uids);
}
// Outside of synchronization.
if (uidsCp != null) {
for (Iterator<UUID> iter = uidsCp.iterator(); iter.hasNext(); ) // Ignore nodes that have left the grid.
if (ctx.discovery().node(iter.next()) == null)
iter.remove();
if (!uidsCp.isEmpty())
throw new IgniteCheckedException("Failed to receive event query response from following nodes: " + uidsCp);
}
} finally {
ioMgr.removeMessageListener(resTopic, resLsnr);
removeLocalEventListener(evtLsnr);
}
return evts;
}
use of org.apache.ignite.events.EventType.EVT_NODE_LEFT in project ignite by apache.
the class IgniteSnapshotManager method start0.
/**
* {@inheritDoc}
*/
@Override
protected void start0() throws IgniteCheckedException {
super.start0();
GridKernalContext ctx = cctx.kernalContext();
if (ctx.clientNode())
return;
if (!CU.isPersistenceEnabled(ctx.config()))
return;
assert cctx.pageStore() instanceof FilePageStoreManager;
storeMgr = (FilePageStoreManager) cctx.pageStore();
pdsSettings = cctx.kernalContext().pdsFolderResolver().resolveFolders();
locSnpDir = resolveSnapshotWorkDirectory(ctx.config());
tmpWorkDir = U.resolveWorkDirectory(storeMgr.workDir().getAbsolutePath(), DFLT_SNAPSHOT_TMP_DIR, true);
U.ensureDirectory(locSnpDir, "snapshot work directory", log);
U.ensureDirectory(tmpWorkDir, "temp directory for snapshot creation", log);
handlers.initialize(ctx, ctx.pools().getSnapshotExecutorService());
MetricRegistry mreg = cctx.kernalContext().metric().registry(SNAPSHOT_METRICS);
mreg.register("LastSnapshotStartTime", () -> lastSeenSnpFut.startTime, "The system time of the last cluster snapshot request start time on this node.");
mreg.register("LastSnapshotEndTime", () -> lastSeenSnpFut.endTime, "The system time of the last cluster snapshot request end time on this node.");
mreg.register("LastSnapshotName", () -> lastSeenSnpFut.name, String.class, "The name of last started cluster snapshot request on this node.");
mreg.register("LastSnapshotErrorMessage", () -> lastSeenSnpFut.error() == null ? "" : lastSeenSnpFut.error().getMessage(), String.class, "The error message of last started cluster snapshot request which fail with an error. " + "This value will be empty if last snapshot request has been completed successfully.");
mreg.register("LocalSnapshotNames", this::localSnapshotNames, List.class, "The list of names of all snapshots currently saved on the local node with respect to " + "the configured via IgniteConfiguration snapshot working path.");
restoreCacheGrpProc.registerMetrics();
cctx.exchange().registerExchangeAwareComponent(this);
ctx.internalSubscriptionProcessor().registerMetastorageListener(this);
cctx.gridEvents().addDiscoveryEventListener(discoLsnr = (evt, discoCache) -> {
if (!busyLock.enterBusy())
return;
try {
UUID leftNodeId = evt.eventNode().id();
if (evt.type() == EVT_NODE_LEFT || evt.type() == EVT_NODE_FAILED) {
SnapshotOperationRequest snpReq = clusterSnpReq;
String err = "Snapshot operation interrupted, because baseline node left the cluster: " + leftNodeId;
boolean reqNodeLeft = snpReq != null && snpReq.nodes().contains(leftNodeId);
// the final snapshot phase (SNAPSHOT_END), we start it from a new one.
if (reqNodeLeft && snpReq.startStageEnded() && U.isLocalNodeCoordinator(ctx.discovery())) {
snpReq.error(new ClusterTopologyCheckedException(err));
endSnpProc.start(snpReq.requestId(), snpReq);
}
for (AbstractSnapshotFutureTask<?> sctx : locSnpTasks.values()) {
if (sctx.sourceNodeId().equals(leftNodeId) || (reqNodeLeft && snpReq.snapshotName().equals(sctx.snapshotName())))
sctx.acceptException(new ClusterTopologyCheckedException(err));
}
restoreCacheGrpProc.onNodeLeft(leftNodeId);
snpRmtMgr.onNodeLeft(leftNodeId);
}
} finally {
busyLock.leaveBusy();
}
}, EVT_NODE_LEFT, EVT_NODE_FAILED);
cctx.gridIO().addMessageListener(DFLT_INITIAL_SNAPSHOT_TOPIC, snpRmtMgr);
cctx.kernalContext().io().addTransmissionHandler(DFLT_INITIAL_SNAPSHOT_TOPIC, snpRmtMgr);
ctx.systemView().registerView(SNAPSHOT_SYS_VIEW, SNAPSHOT_SYS_VIEW_DESC, new SnapshotViewWalker(), () -> F.flatCollections(F.transform(localSnapshotNames(), this::readSnapshotMetadatas)), this::snapshotViewSupplier);
}
use of org.apache.ignite.events.EventType.EVT_NODE_LEFT in project ignite by apache.
the class DistributedProcessCoordinatorLeftTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
cfg.setLocalEventListeners(Collections.singletonMap(event -> {
nodeLeftLatch.countDown();
try {
msgSendLatch.await();
} catch (InterruptedException e) {
fail("Unexpected interrupt.");
}
return false;
}, new int[] { EVT_NODE_LEFT, EVT_NODE_FAILED }));
cfg.setFailureHandler(new FailureHandler() {
@Override
public boolean onFailure(Ignite ignite, FailureContext failureCtx) {
failure.set(true);
return false;
}
});
return cfg;
}
Aggregations