use of org.apache.ignite.internal.util.ipc.IpcEndpoint in project ignite by apache.
the class IgniteHadoopFileSystemShmemAbstractSelfTest method testOutOfResources.
/**
* Checks correct behaviour in case when we run out of system
* resources.
*
* @throws Exception If error occurred.
*/
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public void testOutOfResources() throws Exception {
final Collection<IpcEndpoint> eps = new LinkedList<>();
try {
IgniteCheckedException e = (IgniteCheckedException) GridTestUtils.assertThrows(log, new Callable<Object>() {
@SuppressWarnings("InfiniteLoopStatement")
@Override
public Object call() throws Exception {
while (true) {
IpcEndpoint ep = IpcEndpointFactory.connectEndpoint("shmem:10500", log);
eps.add(ep);
}
}
}, IgniteCheckedException.class, null);
assertNotNull(e);
String msg = e.getMessage();
assertTrue("Invalid exception: " + X.getFullStackTrace(e), msg.contains("(error code: 28)") || msg.contains("(error code: 24)") || msg.contains("(error code: 12)"));
} finally {
for (IpcEndpoint ep : eps) ep.close();
}
}
use of org.apache.ignite.internal.util.ipc.IpcEndpoint in project ignite by apache.
the class IgniteHadoopFileSystemShmemExternalToClientAbstractSelfTest method testOutOfResources.
/**
* Checks correct behaviour in case when we run out of system
* resources.
*
* @throws Exception If error occurred.
*/
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public void testOutOfResources() throws Exception {
final Collection<IpcEndpoint> eps = new LinkedList<>();
try {
IgniteCheckedException e = (IgniteCheckedException) GridTestUtils.assertThrows(log, new Callable<Object>() {
@SuppressWarnings("InfiniteLoopStatement")
@Override
public Object call() throws Exception {
while (true) {
IpcEndpoint ep = IpcEndpointFactory.connectEndpoint("shmem:10500", log);
eps.add(ep);
}
}
}, IgniteCheckedException.class, null);
assertNotNull(e);
String msg = e.getMessage();
assertTrue("Invalid exception: " + X.getFullStackTrace(e), msg.contains("(error code: 28)") || msg.contains("(error code: 24)") || msg.contains("(error code: 12)"));
} finally {
for (IpcEndpoint ep : eps) ep.close();
}
}
use of org.apache.ignite.internal.util.ipc.IpcEndpoint in project ignite by apache.
the class IgfsSharedMemoryTestServer method main.
@SuppressWarnings({ "BusyWait", "InfiniteLoopStatement" })
public static void main(String[] args) throws IgniteCheckedException {
System.out.println("Starting server ...");
// Tell our process PID to the wrapper.
X.println(GridJavaProcess.PID_MSG_PREFIX + U.jvmPid());
InputStream is = null;
try {
IpcServerEndpoint srv = new IpcSharedMemoryServerEndpoint(U.defaultWorkDirectory());
new IgniteTestResources().inject(srv);
srv.start();
System.out.println("IPC shared memory server endpoint started");
IpcEndpoint clientEndpoint = srv.accept();
is = clientEndpoint.inputStream();
for (; ; ) {
X.println("Before read.");
is.read();
Thread.sleep(IpcSharedMemoryCrashDetectionSelfTest.RW_SLEEP_TIMEOUT);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
U.closeQuiet(is);
}
}
use of org.apache.ignite.internal.util.ipc.IpcEndpoint in project ignite by apache.
the class HadoopExternalCommunication method createShmemClient.
/**
* @param desc Process descriptor.
* @param port Port.
* @return Client.
* @throws IgniteCheckedException If failed.
*/
@Nullable
protected HadoopCommunicationClient createShmemClient(HadoopProcessDescriptor desc, int port) throws IgniteCheckedException {
int attempt = 1;
int connectAttempts = 1;
long connTimeout0 = connTimeout;
while (true) {
IpcEndpoint clientEndpoint;
try {
clientEndpoint = new IpcSharedMemoryClientEndpoint(port, (int) connTimeout, log);
} catch (IgniteCheckedException e) {
// Reconnect for the second time, if connection is not established.
if (connectAttempts < 2 && X.hasCause(e, ConnectException.class)) {
connectAttempts++;
continue;
}
throw e;
}
HadoopCommunicationClient client = null;
try {
ShmemWorker worker = new ShmemWorker(clientEndpoint, false);
shmemWorkers.add(worker);
GridNioSession ses = worker.session();
HandshakeFinish fin = new HandshakeFinish();
// We are in lock, it is safe to get session and attach
ses.addMeta(HANDSHAKE_FINISH_META, fin);
client = new HadoopTcpNioCommunicationClient(ses);
new IgniteThread(worker).start();
fin.await(connTimeout0);
} catch (HadoopHandshakeTimeoutException e) {
if (log.isDebugEnabled())
log.debug("Handshake timed out (will retry with increased timeout) [timeout=" + connTimeout0 + ", err=" + e.getMessage() + ", client=" + client + ']');
if (client != null)
client.forceClose();
if (attempt == reconCnt || connTimeout0 > maxConnTimeout) {
if (log.isDebugEnabled())
log.debug("Handshake timedout (will stop attempts to perform the handshake) " + "[timeout=" + connTimeout0 + ", maxConnTimeout=" + maxConnTimeout + ", attempt=" + attempt + ", reconCnt=" + reconCnt + ", err=" + e.getMessage() + ", client=" + client + ']');
throw e;
} else {
attempt++;
connTimeout0 *= 2;
continue;
}
} catch (RuntimeException | Error e) {
if (log.isDebugEnabled())
log.debug("Caught exception (will close client) [err=" + e.getMessage() + ", client=" + client + ']');
if (client != null)
client.forceClose();
throw e;
}
return client;
}
}
use of org.apache.ignite.internal.util.ipc.IpcEndpoint in project ignite by apache.
the class IpcSharedMemoryBenchmarkReader method main.
/**
* @param args Args.
* @throws IgniteCheckedException If failed.
*/
public static void main(String[] args) throws IgniteCheckedException {
IpcSharedMemoryNativeLoader.load(null);
int nThreads = (args.length > 0 ? Integer.parseInt(args[0]) : 1);
final AtomicLong transferCntr = new AtomicLong();
Thread collector = new Thread(new Runnable() {
@SuppressWarnings("BusyWait")
@Override
public void run() {
try {
while (!done) {
Thread.sleep(5000);
X.println("Transfer rate: " + transferCntr.getAndSet(0) / (1024 * 1024 * 5) + " MB/sec");
}
} catch (InterruptedException ignored) {
// No-op.
}
}
});
collector.start();
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
System.out.println("Shutting down...");
done = true;
}
});
try (IpcSharedMemoryServerEndpoint srv = new IpcSharedMemoryServerEndpoint(U.defaultWorkDirectory())) {
new IgniteTestResources().inject(srv);
srv.start();
for (int i = 0; i < nThreads; i++) {
final IpcEndpoint endPnt = srv.accept();
new Thread(new Runnable() {
@Override
public void run() {
InputStream space = null;
try {
space = endPnt.inputStream();
byte[] buf = new byte[DST_BUFFER_SIZE];
int pos = 0;
while (!done) {
int maxRead = Math.min(buf.length - pos, DFLT_BUF_SIZE);
int read = space.read(buf, pos, maxRead);
if (read == -1) {
X.println("Space has been closed");
return;
}
transferCntr.addAndGet(read);
pos += read;
if (pos >= buf.length)
pos = 0;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
U.closeQuiet(space);
}
}
}).start();
}
}
JOptionPane.showMessageDialog(null, "Press OK to stop READER.");
done = true;
}
Aggregations