Search in sources :

Example 61 with IgniteCheckedException

use of org.apache.ignite.IgniteCheckedException in project ignite by apache.

the class GridCacheQueryFutureAdapter method internalIterator.

/**
 * @return Iterator.
 * @throws IgniteCheckedException In case of error.
 */
private Iterator<R> internalIterator() throws IgniteCheckedException {
    checkError();
    Iterator<R> it = null;
    while (it == null || !it.hasNext()) {
        Collection<R> c;
        synchronized (this) {
            it = iter;
            if (it != null && it.hasNext())
                break;
            c = queue.poll();
            if (c != null)
                it = iter = c.iterator();
            if (isDone() && queue.peek() == null)
                break;
        }
        if (c == null && !isDone()) {
            loadPage();
            long timeout = qry.query().timeout();
            long waitTime = timeout == 0 ? Long.MAX_VALUE : timeout - (U.currentTimeMillis() - startTime);
            if (waitTime <= 0) {
                it = Collections.<R>emptyList().iterator();
                break;
            }
            synchronized (this) {
                try {
                    if (queue.isEmpty() && !isDone())
                        wait(waitTime);
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                    throw new IgniteCheckedException("Query was interrupted: " + qry, e);
                }
            }
        }
    }
    checkError();
    return it;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException)

Example 62 with IgniteCheckedException

use of org.apache.ignite.IgniteCheckedException in project ignite by apache.

the class IpcSharedMemoryNativeLoader method doLoad.

/**
 * @throws IgniteCheckedException If failed.
 */
private static void doLoad(IgniteLogger log) throws IgniteCheckedException {
    assert Thread.holdsLock(IpcSharedMemoryNativeLoader.class);
    Collection<Throwable> errs = new ArrayList<>();
    try {
        // Load native library (the library directory should be in java.library.path).
        System.loadLibrary(LIB_NAME);
        return;
    } catch (UnsatisfiedLinkError e) {
        errs.add(e);
    }
    File tmpDir = getUserSpecificTempDir();
    File lockFile = new File(tmpDir, "igniteshmem.lock");
    // Obtain lock on file to prevent concurrent extracts.
    try (RandomAccessFile randomAccessFile = new RandomAccessFile(lockFile, "rws");
        FileLock ignored = randomAccessFile.getChannel().lock()) {
        if (extractAndLoad(errs, tmpDir, platformSpecificResourcePath()))
            return;
        if (extractAndLoad(errs, tmpDir, osSpecificResourcePath()))
            return;
        if (extractAndLoad(errs, tmpDir, resourcePath()))
            return;
        try {
            if (log != null)
                LT.warn(log, "Failed to load 'igniteshmem' library from classpath. Will try to load it from IGNITE_HOME.");
            String igniteHome = X.resolveIgniteHome();
            File shmemJar = findShmemJar(errs, igniteHome);
            if (shmemJar != null) {
                try (JarFile jar = new JarFile(shmemJar, false, JarFile.OPEN_READ)) {
                    if (extractAndLoad(errs, jar, tmpDir, platformSpecificResourcePath()))
                        return;
                    if (extractAndLoad(errs, jar, tmpDir, osSpecificResourcePath()))
                        return;
                    if (extractAndLoad(errs, jar, tmpDir, resourcePath()))
                        return;
                }
            }
        } catch (IgniteCheckedException ignore) {
        // No-op.
        }
        // Failed to find the library.
        assert !errs.isEmpty();
        throw new IgniteCheckedException("Failed to load native IPC library: " + errs);
    } catch (IOException e) {
        throw new IgniteCheckedException("Failed to obtain file lock: " + lockFile, e);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) RandomAccessFile(java.io.RandomAccessFile) ArrayList(java.util.ArrayList) FileLock(java.nio.channels.FileLock) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) RandomAccessFile(java.io.RandomAccessFile) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 63 with IgniteCheckedException

use of org.apache.ignite.IgniteCheckedException in project ignite by apache.

the class IpcSharedMemoryNativeLoader method getUserSpecificTempDir.

/**
 * Gets temporary directory unique for each OS user.
 * The directory guaranteed to exist, though may not be empty.
 */
private static File getUserSpecificTempDir() throws IgniteCheckedException {
    String tmp = System.getProperty("java.io.tmpdir");
    String userName = System.getProperty("user.name");
    File tmpDir = new File(tmp, userName);
    if (!tmpDir.exists())
        // noinspection ResultOfMethodCallIgnored
        tmpDir.mkdirs();
    if (!(tmpDir.exists() && tmpDir.isDirectory()))
        throw new IgniteCheckedException("Failed to create temporary directory [dir=" + tmpDir + ']');
    return tmpDir;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) RandomAccessFile(java.io.RandomAccessFile) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 64 with IgniteCheckedException

use of org.apache.ignite.IgniteCheckedException in project ignite by apache.

the class IpcSharedMemoryServerEndpoint method accept.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("ErrorNotRethrown")
@Override
public IpcEndpoint accept() throws IgniteCheckedException {
    while (!Thread.currentThread().isInterrupted()) {
        Socket sock = null;
        boolean accepted = false;
        try {
            sock = srvSock.accept();
            accepted = true;
            InputStream inputStream = sock.getInputStream();
            ObjectInputStream in = new ObjectInputStream(inputStream);
            ObjectOutputStream out = new ObjectOutputStream(sock.getOutputStream());
            IpcSharedMemorySpace inSpace = null;
            IpcSharedMemorySpace outSpace = null;
            boolean err = true;
            try {
                IpcSharedMemoryInitRequest req = (IpcSharedMemoryInitRequest) in.readObject();
                if (log.isDebugEnabled())
                    log.debug("Processing request: " + req);
                IgnitePair<String> p = inOutToken(req.pid(), size);
                String file1 = p.get1();
                String file2 = p.get2();
                assert file1 != null;
                assert file2 != null;
                // Create tokens.
                new File(file1).createNewFile();
                new File(file2).createNewFile();
                if (log.isDebugEnabled())
                    log.debug("Created token files: " + p);
                inSpace = new IpcSharedMemorySpace(file1, req.pid(), pid, size, true, log);
                outSpace = new IpcSharedMemorySpace(file2, pid, req.pid(), size, false, log);
                IpcSharedMemoryClientEndpoint ret = new IpcSharedMemoryClientEndpoint(inSpace, outSpace, log);
                out.writeObject(new IpcSharedMemoryInitResponse(file2, outSpace.sharedMemoryId(), file1, inSpace.sharedMemoryId(), pid, size));
                err = !in.readBoolean();
                endpoints.add(ret);
                return ret;
            } catch (UnsatisfiedLinkError e) {
                throw IpcSharedMemoryUtils.linkError(e);
            } catch (IOException e) {
                if (log.isDebugEnabled())
                    log.debug("Failed to process incoming connection " + "(was connection closed by another party):" + e.getMessage());
            } catch (ClassNotFoundException e) {
                U.error(log, "Failed to process incoming connection.", e);
            } catch (ClassCastException e) {
                String msg = "Failed to process incoming connection (most probably, shared memory " + "rest endpoint has been configured by mistake).";
                LT.warn(log, msg);
                sendErrorResponse(out, e);
            } catch (IpcOutOfSystemResourcesException e) {
                if (!omitOutOfResourcesWarn)
                    LT.warn(log, OUT_OF_RESOURCES_MSG);
                sendErrorResponse(out, e);
            } catch (IgniteCheckedException e) {
                LT.error(log, e, "Failed to process incoming shared memory connection.");
                sendErrorResponse(out, e);
            } finally {
                // Exception has been thrown, need to free system resources.
                if (err) {
                    if (inSpace != null)
                        inSpace.forceClose();
                    // Safety.
                    if (outSpace != null)
                        outSpace.forceClose();
                }
            }
        } catch (IOException e) {
            if (!Thread.currentThread().isInterrupted() && !accepted)
                throw new IgniteCheckedException("Failed to accept incoming connection.", e);
            if (!closed)
                LT.error(log, null, "Failed to process incoming shared memory connection: " + e.getMessage());
        } finally {
            U.closeQuiet(sock);
        }
    }
    throw new IgniteInterruptedCheckedException("Socket accept was interrupted.");
}
Also used : ObjectInputStream(java.io.ObjectInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) ObjectInputStream(java.io.ObjectInputStream)

Example 65 with IgniteCheckedException

use of org.apache.ignite.IgniteCheckedException in project ignite by apache.

the class GridShmemCommunicationClient method sendMessage.

/**
 * {@inheritDoc}
 */
@Override
public synchronized boolean sendMessage(UUID nodeId, Message msg, IgniteInClosure<IgniteException> c) throws IgniteCheckedException {
    assert nodeId != null;
    if (closed())
        throw new IgniteCheckedException("Communication client was closed: " + this);
    assert writeBuf.hasArray();
    try {
        int cnt = U.writeMessageFully(msg, shmem.outputStream(), writeBuf, formatter.writer(nodeId));
        metricsLsnr.onBytesSent(cnt);
    } catch (IOException e) {
        throw new IgniteCheckedException("Failed to send message to remote node: " + shmem, e);
    }
    markUsed();
    if (c != null)
        c.apply(null);
    return false;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IOException(java.io.IOException) IpcSharedMemoryClientEndpoint(org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryClientEndpoint)

Aggregations

IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1568 IgniteException (org.apache.ignite.IgniteException)388 ArrayList (java.util.ArrayList)237 IOException (java.io.IOException)226 ClusterNode (org.apache.ignite.cluster.ClusterNode)215 Map (java.util.Map)181 UUID (java.util.UUID)163 HashMap (java.util.HashMap)160 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)150 Test (org.junit.Test)143 List (java.util.List)139 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)138 Nullable (org.jetbrains.annotations.Nullable)134 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)118 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)109 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)105 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)104 Collection (java.util.Collection)97 HashSet (java.util.HashSet)97 Ignite (org.apache.ignite.Ignite)96