use of org.apache.ignite.internal.IgniteInterruptedCheckedException in project ignite by apache.
the class TcpDiscoveryMulticastIpFinder method requestAddresses.
/**
* Sends multicast address request message and waits for reply. Response wait time and number
* of request attempts are configured as properties {@link #setResponseWaitTime} and
* {@link #setAddressRequestAttempts}.
*
* @param mcastAddr Multicast address where to send request.
* @param sockItf Optional interface multicast socket should be bound to.
* @return Tuple where first value is collection of received addresses, second is boolean which is
* {@code true} if got error on send.
*/
private T2<Collection<InetSocketAddress>, Boolean> requestAddresses(InetAddress mcastAddr, @Nullable InetAddress sockItf) {
Collection<InetSocketAddress> rmtAddrs = new HashSet<>();
boolean sndErr = false;
try {
DatagramPacket reqPckt = new DatagramPacket(MSG_ADDR_REQ_DATA, MSG_ADDR_REQ_DATA.length, mcastAddr, mcastPort);
byte[] resData = new byte[AddressResponse.MAX_DATA_LENGTH];
DatagramPacket resPckt = new DatagramPacket(resData, resData.length);
boolean sndError = false;
for (int i = 0; i < addrReqAttempts; i++) {
MulticastSocket sock = null;
try {
sock = new MulticastSocket(0);
// Use 'false' to enable support for more than one node on the same machine.
sock.setLoopbackMode(false);
if (sockItf != null)
sock.setInterface(sockItf);
sock.setSoTimeout(resWaitTime);
if (ttl != -1)
sock.setTimeToLive(ttl);
reqPckt.setData(MSG_ADDR_REQ_DATA);
try {
sock.send(reqPckt);
} catch (IOException e) {
sndErr = true;
if (!handleNetworkError(e))
break;
if (i < addrReqAttempts - 1) {
if (log.isDebugEnabled())
log.debug("Failed to send multicast address request (will retry in 500 ms): " + e);
U.sleep(500);
} else {
if (log.isDebugEnabled())
log.debug("Failed to send multicast address request: " + e);
}
sndError = true;
continue;
}
long rcvEnd = U.currentTimeMillis() + resWaitTime;
try {
while (U.currentTimeMillis() < rcvEnd) {
// Try to receive multiple responses.
sock.receive(resPckt);
byte[] data = resPckt.getData();
if (!U.bytesEqual(U.IGNITE_HEADER, 0, data, 0, U.IGNITE_HEADER.length)) {
U.error(log, "Failed to verify message header.");
continue;
}
AddressResponse addrRes;
try {
addrRes = new AddressResponse(data);
} catch (IgniteCheckedException e) {
LT.error(log, e, "Failed to deserialize multicast response.");
continue;
}
rmtAddrs.addAll(addrRes.addresses());
}
} catch (SocketTimeoutException ignored) {
if (// DatagramSocket.receive timeout has expired.
log.isDebugEnabled())
log.debug("Address receive timeout.");
}
} catch (IOException e) {
U.error(log, "Failed to request nodes addresses.", e);
} finally {
U.close(sock);
}
if (// Wait some time before re-sending address request.
i < addrReqAttempts - 1)
U.sleep(200);
}
if (log.isDebugEnabled())
log.debug("Received nodes addresses: " + rmtAddrs);
if (rmtAddrs.isEmpty() && sndError)
U.quietAndWarn(log, "Failed to send multicast message (is multicast enabled on this node?).");
return new T2<>(rmtAddrs, sndErr);
} catch (IgniteInterruptedCheckedException ignored) {
U.warn(log, "Got interrupted while sending address request.");
Thread.currentThread().interrupt();
return new T2<>(rmtAddrs, sndErr);
}
}
use of org.apache.ignite.internal.IgniteInterruptedCheckedException in project ignite by apache.
the class TcpDiscoverySharedFsIpFinder method initFolder.
/**
* Initializes folder to work with.
*
* @return Folder.
* @throws org.apache.ignite.spi.IgniteSpiException If failed.
*/
private File initFolder() throws IgniteSpiException {
if (initGuard.compareAndSet(false, true)) {
if (path == null)
throw new IgniteSpiException("Shared file system path is null " + "(it should be configured via setPath(..) configuration property).");
if (path.equals(DFLT_PATH) && warnGuard.compareAndSet(false, true))
U.warn(log, "Default local computer-only share is used by IP finder.");
try {
File tmp;
if (new File(path).exists())
tmp = new File(path);
else {
try {
tmp = U.resolveWorkDirectory(ignite.configuration().getWorkDirectory(), path, false);
} catch (IgniteCheckedException e) {
throw new IgniteSpiException("Failed to resolve directory [path=" + path + ", exception=" + e.getMessage() + ']');
}
}
if (!tmp.isDirectory())
throw new IgniteSpiException("Failed to initialize shared file system path " + "(path must point to folder): " + path);
if (!tmp.canRead() || !tmp.canWrite())
throw new IgniteSpiException("Failed to initialize shared file system path " + "(path must be readable and writable): " + path);
folder = tmp;
} finally {
initLatch.countDown();
}
} else {
try {
U.await(initLatch);
} catch (IgniteInterruptedCheckedException e) {
throw new IgniteSpiException("Thread has been interrupted.", e);
}
if (folder == null)
throw new IgniteSpiException("Failed to initialize shared file system folder (check logs for errors).");
}
return folder;
}
use of org.apache.ignite.internal.IgniteInterruptedCheckedException in project ignite by apache.
the class GridContinuousProcessor method registerHandler.
/**
* @param nodeId Node ID.
* @param routineId Consume ID.
* @param hnd Handler.
* @param bufSize Buffer size.
* @param interval Time interval.
* @param autoUnsubscribe Automatic unsubscribe flag.
* @param loc Local registration flag.
* @return Whether listener was actually registered.
* @throws IgniteCheckedException In case of error.
*/
private boolean registerHandler(final UUID nodeId, final UUID routineId, final GridContinuousHandler hnd, int bufSize, final long interval, boolean autoUnsubscribe, boolean loc) throws IgniteCheckedException {
assert nodeId != null;
assert routineId != null;
assert hnd != null;
assert bufSize > 0;
assert interval >= 0;
final RemoteRoutineInfo info = new RemoteRoutineInfo(nodeId, hnd, bufSize, interval, autoUnsubscribe);
boolean doRegister = loc;
if (!doRegister) {
stopLock.lock();
try {
doRegister = !stopped.remove(routineId) && rmtInfos.putIfAbsent(routineId, info) == null;
} finally {
stopLock.unlock();
}
}
if (doRegister) {
if (log.isDebugEnabled())
log.debug("Register handler: [nodeId=" + nodeId + ", routineId=" + routineId + ", info=" + info + ']');
if (interval > 0) {
IgniteThread checker = new IgniteThread(new GridWorker(ctx.igniteInstanceName(), "continuous-buffer-checker", log) {
@SuppressWarnings("ConstantConditions")
@Override
protected void body() {
long interval0 = interval;
while (!isCancelled()) {
try {
U.sleep(interval0);
} catch (IgniteInterruptedCheckedException ignored) {
break;
}
IgniteBiTuple<GridContinuousBatch, Long> t = info.checkInterval();
final GridContinuousBatch batch = t.get1();
if (batch != null && batch.size() > 0) {
try {
Collection<Object> toSnd = batch.collect();
boolean msg = toSnd.iterator().next() instanceof Message;
CI1<IgniteException> ackC = new CI1<IgniteException>() {
@Override
public void apply(IgniteException e) {
if (e == null)
info.hnd.onBatchAcknowledged(routineId, batch, ctx);
}
};
sendNotification(nodeId, routineId, null, toSnd, hnd.orderedTopic(), msg, ackC);
} catch (ClusterTopologyCheckedException ignored) {
if (log.isDebugEnabled())
log.debug("Failed to send notification to node (is node alive?): " + nodeId);
} catch (IgniteCheckedException e) {
U.error(log, "Failed to send notification to node: " + nodeId, e);
}
}
interval0 = t.get2();
}
}
});
bufCheckThreads.put(routineId, checker);
checker.start();
}
GridContinuousHandler.RegisterStatus status = hnd.register(nodeId, routineId, ctx);
if (status == GridContinuousHandler.RegisterStatus.DELAYED) {
info.markDelayedRegister();
return false;
} else
return status == GridContinuousHandler.RegisterStatus.REGISTERED;
}
return false;
}
use of org.apache.ignite.internal.IgniteInterruptedCheckedException in project ignite by apache.
the class GridCachePartitionEvictionDuringReadThroughSelfTest method testPartitionRent.
/**
* @throws Exception if failed.
*/
public void testPartitionRent() throws Exception {
fail("https://issues.apache.org/jira/browse/IGNITE-5759");
startGrid(DATA_READ_GRID_IDX);
final AtomicBoolean done = new AtomicBoolean();
IgniteInternalFuture<Long> gridAndCacheAccessFut = GridTestUtils.runMultiThreadedAsync(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
final Set<Integer> keysSet = new LinkedHashSet<>();
keysSet.add(1);
keysSet.add(2);
keysSet.add(FAILING_KEY);
keysSet.add(4);
keysSet.add(5);
while (!done.get()) {
try {
grid(DATA_READ_GRID_IDX).<Integer, Integer>cache("config").getAll(keysSet);
} catch (Throwable ignore) {
// No-op.
}
if (Thread.currentThread().isInterrupted())
throw new IgniteInterruptedCheckedException("Execution of [" + Thread.currentThread().getName() + "] Interrupted. Test is probably timed out");
}
return null;
}
}, 4, "loader");
IgniteInternalFuture<Void> startFut = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
for (int i = 1; i < 5; i++) {
startGrid(i);
awaitPartitionMapExchange();
}
return null;
}
});
try {
startFut.get();
} catch (Exception e) {
gridAndCacheAccessFut.cancel();
U.error(log, e);
throw e;
}
done.set(true);
gridAndCacheAccessFut.get();
}
use of org.apache.ignite.internal.IgniteInterruptedCheckedException in project ignite by apache.
the class GridCachePartitionExchangeManager method onKernalStop0.
/**
* {@inheritDoc}
*/
@Override
protected void onKernalStop0(boolean cancel) {
exchWorker.onKernalStop();
cctx.gridEvents().removeDiscoveryEventListener(discoLsnr);
cctx.io().removeHandler(false, 0, GridDhtPartitionsSingleMessage.class);
cctx.io().removeHandler(false, 0, GridDhtPartitionsFullMessage.class);
cctx.io().removeHandler(false, 0, GridDhtPartitionsSingleRequest.class);
stopErr = cctx.kernalContext().clientDisconnected() ? new IgniteClientDisconnectedCheckedException(cctx.kernalContext().cluster().clientReconnectFuture(), "Client node disconnected: " + cctx.igniteInstanceName()) : new IgniteInterruptedCheckedException("Node is stopping: " + cctx.igniteInstanceName());
// Stop exchange worker
U.cancel(exchWorker);
if (log.isDebugEnabled())
log.debug("Before joining on exchange worker: " + exchWorker);
U.join(exchWorker, log);
// Finish all exchange futures.
ExchangeFutureSet exchFuts0 = exchFuts;
for (CachePartitionExchangeWorkerTask task : exchWorker.futQ) {
if (task instanceof GridDhtPartitionsExchangeFuture)
((GridDhtPartitionsExchangeFuture) task).onDone(stopErr);
}
if (exchFuts0 != null) {
for (GridDhtPartitionsExchangeFuture f : exchFuts.values()) f.onDone(stopErr);
}
for (AffinityReadyFuture f : readyFuts.values()) f.onDone(stopErr);
if (!cctx.kernalContext().clientNode()) {
for (int cnt = 0; cnt < cctx.gridConfig().getRebalanceThreadPoolSize(); cnt++) cctx.io().removeOrderedHandler(true, rebalanceTopic(cnt));
}
ResendTimeoutObject resendTimeoutObj = pendingResend.getAndSet(null);
if (resendTimeoutObj != null)
cctx.time().removeTimeoutObject(resendTimeoutObj);
}
Aggregations