use of org.apache.ignite.internal.IgniteInterruptedCheckedException in project ignite by apache.
the class DataStreamerImpl method acquireRemapSemaphore.
/**
*
*/
private void acquireRemapSemaphore() throws IgniteInterruptedCheckedException {
try {
if (remapSem.availablePermits() != REMAP_SEMAPHORE_PERMISSIONS_COUNT) {
if (timeout == DFLT_UNLIMIT_TIMEOUT) {
// Wait until failed data being processed.
remapSem.acquire(REMAP_SEMAPHORE_PERMISSIONS_COUNT);
remapSem.release(REMAP_SEMAPHORE_PERMISSIONS_COUNT);
} else {
// Wait until failed data being processed.
boolean res = remapSem.tryAcquire(REMAP_SEMAPHORE_PERMISSIONS_COUNT, timeout, TimeUnit.MILLISECONDS);
if (res)
remapSem.release(REMAP_SEMAPHORE_PERMISSIONS_COUNT);
else
throw new IgniteDataStreamerTimeoutException("Data streamer exceeded timeout " + "while was waiting for failed data resending finished.");
}
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IgniteInterruptedCheckedException(e);
}
}
use of org.apache.ignite.internal.IgniteInterruptedCheckedException in project ignite by apache.
the class ClientImpl method pingNode.
/** {@inheritDoc} */
@Override
public boolean pingNode(@NotNull final UUID nodeId) {
if (nodeId.equals(getLocalNodeId()))
return true;
TcpDiscoveryNode node = rmtNodes.get(nodeId);
if (node == null || !node.visible())
return false;
GridFutureAdapter<Boolean> fut = pingFuts.get(nodeId);
if (fut == null) {
fut = new GridFutureAdapter<>();
GridFutureAdapter<Boolean> oldFut = pingFuts.putIfAbsent(nodeId, fut);
if (oldFut != null)
fut = oldFut;
else {
State state = this.state;
if (spi.getSpiContext().isStopping() || state == STOPPED || state == SEGMENTED) {
if (pingFuts.remove(nodeId, fut))
fut.onDone(false);
return false;
} else if (state == DISCONNECTED) {
if (pingFuts.remove(nodeId, fut))
fut.onDone(new IgniteClientDisconnectedCheckedException(null, "Failed to ping node, client node disconnected."));
} else {
final GridFutureAdapter<Boolean> finalFut = fut;
timer.schedule(new TimerTask() {
@Override
public void run() {
if (pingFuts.remove(nodeId, finalFut)) {
if (ClientImpl.this.state == DISCONNECTED)
finalFut.onDone(new IgniteClientDisconnectedCheckedException(null, "Failed to ping node, client node disconnected."));
else
finalFut.onDone(false);
}
}
}, spi.netTimeout);
sockWriter.sendMessage(new TcpDiscoveryClientPingRequest(getLocalNodeId(), nodeId));
}
}
}
try {
return fut.get();
} catch (IgniteInterruptedCheckedException ignored) {
return false;
} catch (IgniteCheckedException e) {
throw new IgniteSpiException(e);
}
}
use of org.apache.ignite.internal.IgniteInterruptedCheckedException in project ignite by apache.
the class ServerImpl method sendJoinRequestMessage.
/**
* Tries to send join request message to a random node presenting in topology.
* Address is provided by {@link org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder} and message is
* sent to first node connection succeeded to.
*
* @return {@code true} if send succeeded.
* @throws IgniteSpiException If any error occurs.
*/
@SuppressWarnings({ "BusyWait" })
private boolean sendJoinRequestMessage() throws IgniteSpiException {
TcpDiscoveryAbstractMessage joinReq = new TcpDiscoveryJoinRequestMessage(locNode, spi.collectExchangeData(new DiscoveryDataPacket(getLocalNodeId())));
// Time when it has been detected, that addresses from IP finder do not respond.
long noResStart = 0;
while (true) {
Collection<InetSocketAddress> addrs = spi.resolvedAddresses();
if (F.isEmpty(addrs))
return false;
boolean retry = false;
Collection<Exception> errs = new ArrayList<>();
for (InetSocketAddress addr : addrs) {
try {
IgniteSpiOperationTimeoutHelper timeoutHelper = new IgniteSpiOperationTimeoutHelper(spi, true);
Integer res;
try {
SecurityUtils.serializeVersion(1);
res = sendMessageDirectly(joinReq, addr, timeoutHelper);
} finally {
SecurityUtils.restoreDefaultSerializeVersion();
}
assert res != null;
noResAddrs.remove(addr);
// Address is responsive, reset period start.
noResStart = 0;
switch(res) {
case RES_WAIT:
// Concurrent startup, try sending join request again or wait if no success.
retry = true;
break;
case RES_OK:
if (log.isDebugEnabled())
log.debug("Join request message has been sent to address [addr=" + addr + ", req=" + joinReq + ']');
// Join request sending succeeded, wait for response from topology.
return true;
default:
// Concurrent startup, try next node.
if (res == RES_CONTINUE_JOIN) {
if (!fromAddrs.contains(addr))
retry = true;
} else {
if (log.isDebugEnabled())
log.debug("Unexpected response to join request: " + res);
retry = true;
}
break;
}
} catch (IgniteSpiException e) {
errs.add(e);
if (log.isDebugEnabled()) {
IOException ioe = X.cause(e, IOException.class);
log.debug("Failed to send join request message [addr=" + addr + ", msg=" + (ioe != null ? ioe.getMessage() : e.getMessage()) + ']');
onException("Failed to send join request message [addr=" + addr + ", msg=" + (ioe != null ? ioe.getMessage() : e.getMessage()) + ']', ioe);
}
noResAddrs.add(addr);
}
}
if (retry) {
if (log.isDebugEnabled())
log.debug("Concurrent discovery SPI start has been detected (local node should wait).");
try {
U.sleep(2000);
} catch (IgniteInterruptedCheckedException e) {
throw new IgniteSpiException("Thread has been interrupted.", e);
}
} else if (!spi.ipFinder.isShared() && !ipFinderHasLocAddr) {
IgniteCheckedException e = null;
if (!errs.isEmpty()) {
e = new IgniteCheckedException("Multiple connection attempts failed.");
for (Exception err : errs) e.addSuppressed(err);
}
if (e != null && X.hasCause(e, ConnectException.class)) {
LT.warn(log, "Failed to connect to any address from IP finder " + "(make sure IP finder addresses are correct and firewalls are disabled on all host machines): " + toOrderedList(addrs), true);
}
if (spi.joinTimeout > 0) {
if (noResStart == 0)
noResStart = U.currentTimeMillis();
else if (U.currentTimeMillis() - noResStart > spi.joinTimeout)
throw new IgniteSpiException("Failed to connect to any address from IP finder within join timeout " + "(make sure IP finder addresses are correct, and operating system firewalls are disabled " + "on all host machines, or consider increasing 'joinTimeout' configuration property): " + addrs, e);
}
try {
U.sleep(2000);
} catch (IgniteInterruptedCheckedException ex) {
throw new IgniteSpiException("Thread has been interrupted.", ex);
}
} else
break;
}
return false;
}
use of org.apache.ignite.internal.IgniteInterruptedCheckedException in project ignite by apache.
the class GridCachePartitionedQueueEntryMoveSelfTest method testQueue.
/**
* @throws Exception If failed.
*/
public void testQueue() throws Exception {
final String queueName = "qq";
System.out.println(U.filler(20, '\n'));
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
IgniteInternalFuture<?> fut1 = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws IgniteInterruptedCheckedException {
Ignite ignite = grid(0);
IgniteQueue<Integer> queue = ignite.queue(queueName, QUEUE_CAP, config(true));
for (int i = 0; i < QUEUE_CAP * 2; i++) {
if (i == QUEUE_CAP) {
latch1.countDown();
U.await(latch2);
}
try {
info(">>> Putting value: " + i);
queue.put(i);
info(">>> Value is in queue: " + i);
} catch (Error | RuntimeException e) {
error("Failed to put value: " + i, e);
throw e;
}
}
return null;
}
});
latch1.await();
startAdditionalNodes(BACKUP_CNT + 2, queueName);
System.out.println(U.filler(20, '\n'));
latch2.countDown();
IgniteInternalFuture<?> fut2 = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws IgniteCheckedException {
Ignite ignite = grid(GRID_CNT);
IgniteQueue<Integer> queue = ignite.queue(queueName, QUEUE_CAP, config(true));
int cnt = 0;
do {
try {
Integer i = queue.poll();
if (i != null) {
info(">>> Polled value: " + cnt);
cnt++;
} else {
info(">>> Waiting for value...");
U.sleep(2000);
}
} catch (Error | RuntimeException e) {
error("Failed to poll value.", e);
throw e;
}
} while (cnt < QUEUE_CAP * 2);
return null;
}
});
fut1.get();
fut2.get();
}
use of org.apache.ignite.internal.IgniteInterruptedCheckedException in project ignite by apache.
the class StartNodeCallableImpl method call.
/** {@inheritDoc} */
@Override
public ClusterStartNodeResult call() {
JSch ssh = new JSch();
Session ses = null;
try {
if (spec.key() != null)
ssh.addIdentity(spec.key().getAbsolutePath());
ses = ssh.getSession(spec.username(), spec.host(), spec.port());
if (spec.password() != null)
ses.setPassword(spec.password());
ses.setConfig("StrictHostKeyChecking", "no");
ses.connect(timeout);
boolean win = isWindows(ses);
char separator = win ? '\\' : '/';
spec.fixPaths(separator);
String igniteHome = spec.igniteHome();
if (igniteHome == null)
igniteHome = win ? DFLT_IGNITE_HOME_WIN : DFLT_IGNITE_HOME_LINUX;
String script = spec.script();
if (script == null)
script = DFLT_SCRIPT_LINUX;
String cfg = spec.configuration();
if (cfg == null)
cfg = "";
String startNodeCmd;
String scriptOutputFileName = FILE_NAME_DATE_FORMAT.format(new Date()) + '-' + UUID.randomUUID().toString().substring(0, 8) + ".log";
if (win)
throw new UnsupportedOperationException("Apache Ignite cannot be auto-started on Windows from IgniteCluster.startNodes(…) API.");
else {
// Assume Unix.
int spaceIdx = script.indexOf(' ');
String scriptPath = spaceIdx > -1 ? script.substring(0, spaceIdx) : script;
String scriptArgs = spaceIdx > -1 ? script.substring(spaceIdx + 1) : "";
String rmtLogArgs = buildRemoteLogArguments(spec.username(), spec.host());
String tmpDir = env(ses, "$TMPDIR", "/tmp/");
String scriptOutputDir = tmpDir + "ignite-startNodes";
shell(ses, "mkdir " + scriptOutputDir);
// Mac os don't support ~ in double quotes. Trying get home path from remote system.
if (igniteHome.startsWith("~")) {
String homeDir = env(ses, "$HOME", "~");
igniteHome = igniteHome.replaceFirst("~", homeDir);
}
startNodeCmd = new SB().a("nohup ").a("\"").a(igniteHome).a('/').a(scriptPath).a("\"").a(" ").a(scriptArgs).a(!cfg.isEmpty() ? " \"" : "").a(cfg).a(!cfg.isEmpty() ? "\"" : "").a(rmtLogArgs).a(" > ").a(scriptOutputDir).a("/").a(scriptOutputFileName).a(" 2>& 1 &").toString();
}
info("Starting remote node with SSH command: " + startNodeCmd, spec.logger(), log);
shell(ses, startNodeCmd);
return new ClusterStartNodeResultImpl(spec.host(), true, null);
} catch (IgniteInterruptedCheckedException e) {
return new ClusterStartNodeResultImpl(spec.host(), false, e.getMessage());
} catch (Exception e) {
return new ClusterStartNodeResultImpl(spec.host(), false, X.getFullStackTrace(e));
} finally {
if (ses != null && ses.isConnected())
ses.disconnect();
}
}
Aggregations