Search in sources :

Example 81 with IgniteCheckedException

use of org.apache.ignite.IgniteCheckedException 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();
    }
}
Also used : IpcEndpoint(org.apache.ignite.internal.util.ipc.IpcEndpoint) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) LinkedList(java.util.LinkedList) Callable(java.util.concurrent.Callable)

Example 82 with IgniteCheckedException

use of org.apache.ignite.IgniteCheckedException 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();
    }
}
Also used : IpcEndpoint(org.apache.ignite.internal.util.ipc.IpcEndpoint) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) LinkedList(java.util.LinkedList) Callable(java.util.concurrent.Callable)

Example 83 with IgniteCheckedException

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

the class DmlStatementsProcessor method executeUpdateStatement.

/**
 * Actually perform SQL DML operation locally.
 *
 * @param schemaName Schema name.
 * @param cctx Cache context.
 * @param c Connection.
 * @param prepared Prepared statement for DML query.
 * @param fieldsQry Fields query.
 * @param loc Local query flag.
 * @param filters Cache name and key filter.
 * @param cancel Query cancel state holder.
 * @return Pair [number of successfully processed items; keys that have failed to be processed]
 * @throws IgniteCheckedException if failed.
 */
@SuppressWarnings({ "ConstantConditions", "unchecked" })
private UpdateResult executeUpdateStatement(String schemaName, final GridCacheContext cctx, Connection c, Prepared prepared, SqlFieldsQuery fieldsQry, boolean loc, IndexingQueryFilter filters, GridQueryCancel cancel) throws IgniteCheckedException {
    Integer errKeysPos = null;
    UpdatePlan plan = getPlanForStatement(schemaName, c, prepared, fieldsQry, loc, errKeysPos);
    UpdateResult fastUpdateRes = plan.processFast(fieldsQry.getArgs());
    if (fastUpdateRes != null)
        return fastUpdateRes;
    if (plan.distributedPlan() != null) {
        UpdateResult result = doDistributedUpdate(schemaName, fieldsQry, plan, cancel);
        // null is returned in case not all nodes support distributed DML.
        if (result != null)
            return result;
    }
    Iterable<List<?>> cur;
    // sub-query and not some dummy stuff like "select 1, 2, 3;"
    if (!loc && !plan.isLocalSubquery()) {
        assert !F.isEmpty(plan.selectQuery());
        SqlFieldsQuery newFieldsQry = new SqlFieldsQuery(plan.selectQuery(), fieldsQry.isCollocated()).setArgs(fieldsQry.getArgs()).setDistributedJoins(fieldsQry.isDistributedJoins()).setEnforceJoinOrder(fieldsQry.isEnforceJoinOrder()).setLocal(fieldsQry.isLocal()).setPageSize(fieldsQry.getPageSize()).setTimeout(fieldsQry.getTimeout(), TimeUnit.MILLISECONDS);
        cur = (QueryCursorImpl<List<?>>) idx.querySqlFields(schemaName, newFieldsQry, null, true, true, cancel).get(0);
    } else if (plan.hasRows())
        cur = plan.createRows(fieldsQry.getArgs());
    else {
        final GridQueryFieldsResult res = idx.queryLocalSqlFields(schemaName, plan.selectQuery(), F.asList(fieldsQry.getArgs()), filters, fieldsQry.isEnforceJoinOrder(), fieldsQry.getTimeout(), cancel);
        cur = new QueryCursorImpl<>(new Iterable<List<?>>() {

            @Override
            public Iterator<List<?>> iterator() {
                try {
                    return new GridQueryCacheObjectsIterator(res.iterator(), idx.objectContext(), true);
                } catch (IgniteCheckedException e) {
                    throw new IgniteException(e);
                }
            }
        }, cancel);
    }
    int pageSize = loc ? 0 : fieldsQry.getPageSize();
    return processDmlSelectResult(cctx, plan, cur, pageSize);
}
Also used : QueryCursorImpl(org.apache.ignite.internal.processors.cache.QueryCursorImpl) GridQueryCacheObjectsIterator(org.apache.ignite.internal.processors.query.GridQueryCacheObjectsIterator) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) GridQueryFieldsResult(org.apache.ignite.internal.processors.query.GridQueryFieldsResult) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) GridQueryCacheObjectsIterator(org.apache.ignite.internal.processors.query.GridQueryCacheObjectsIterator) IgniteSingletonIterator(org.apache.ignite.internal.util.lang.IgniteSingletonIterator) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) UpdatePlan(org.apache.ignite.internal.processors.query.h2.dml.UpdatePlan)

Example 84 with IgniteCheckedException

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

the class DmlStatementsProcessor method updateSqlFieldsBatched.

/**
 * Execute DML statement, possibly with few re-attempts in case of concurrent data modifications.
 *
 * @param schemaName Schema.
 * @param conn Connection.
 * @param prepared Prepared statement.
 * @param fieldsQry Original query.
 * @param loc Query locality flag.
 * @param filters Cache name and key filter.
 * @param cancel Cancel.
 * @return Update result (modified items count and failed keys).
 * @throws IgniteCheckedException if failed.
 */
private Collection<UpdateResult> updateSqlFieldsBatched(String schemaName, Connection conn, Prepared prepared, SqlFieldsQueryEx fieldsQry, boolean loc, IndexingQueryFilter filters, GridQueryCancel cancel) throws IgniteCheckedException {
    List<Object[]> argss = fieldsQry.batchedArguments();
    UpdatePlan plan = getPlanForStatement(schemaName, conn, prepared, fieldsQry, loc, null);
    if (plan.hasRows() && plan.mode() == UpdateMode.INSERT) {
        GridCacheContext<?, ?> cctx = plan.cacheContext();
        CacheOperationContext opCtx = setKeepBinaryContext(cctx);
        try {
            List<List<List<?>>> cur = plan.createRows(argss);
            List<UpdateResult> res = processDmlSelectResultBatched(plan, cur, fieldsQry.getPageSize());
            return res;
        } finally {
            cctx.operationContextPerCall(opCtx);
        }
    } else {
        // Fallback to previous mode.
        Collection<UpdateResult> ress = new ArrayList<>(argss.size());
        SQLException batchException = null;
        int[] cntPerRow = new int[argss.size()];
        int cntr = 0;
        for (Object[] args : argss) {
            SqlFieldsQueryEx qry0 = (SqlFieldsQueryEx) fieldsQry.copy();
            qry0.clearBatchedArgs();
            qry0.setArgs(args);
            UpdateResult res;
            try {
                res = updateSqlFields(schemaName, conn, prepared, qry0, loc, filters, cancel);
                cntPerRow[cntr++] = (int) res.counter();
                ress.add(res);
            } catch (Exception e) {
                String sqlState;
                int code;
                if (e instanceof IgniteSQLException) {
                    sqlState = ((IgniteSQLException) e).sqlState();
                    code = ((IgniteSQLException) e).statusCode();
                } else {
                    sqlState = SqlStateCode.INTERNAL_ERROR;
                    code = IgniteQueryErrorCode.UNKNOWN;
                }
                batchException = chainException(batchException, new SQLException(e.getMessage(), sqlState, code, e));
                cntPerRow[cntr++] = Statement.EXECUTE_FAILED;
            }
        }
        if (batchException != null) {
            BatchUpdateException e = new BatchUpdateException(batchException.getMessage(), batchException.getSQLState(), batchException.getErrorCode(), cntPerRow, batchException);
            throw new IgniteCheckedException(e);
        }
        return ress;
    }
}
Also used : CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext) SQLException(java.sql.SQLException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) ArrayList(java.util.ArrayList) IgniteQueryErrorCode.createJdbcSqlException(org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode.createJdbcSqlException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) BatchUpdateException(java.sql.BatchUpdateException) EntryProcessorException(javax.cache.processor.EntryProcessorException) SQLException(java.sql.SQLException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SqlFieldsQueryEx(org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) List(java.util.List) ArrayList(java.util.ArrayList) UpdatePlan(org.apache.ignite.internal.processors.query.h2.dml.UpdatePlan) BatchUpdateException(java.sql.BatchUpdateException)

Example 85 with IgniteCheckedException

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

the class IgfsMarshaller method marshall.

/**
 * Serializes the message and sends it into the given output stream.
 * @param msg Message.
 * @param hdr Message header.
 * @param out Output.
 * @throws IgniteCheckedException If failed.
 */
public void marshall(IgfsMessage msg, byte[] hdr, ObjectOutput out) throws IgniteCheckedException {
    assert hdr != null;
    assert hdr.length == HEADER_SIZE;
    try {
        switch(msg.command()) {
            case HANDSHAKE:
                {
                    out.write(hdr);
                    IgfsHandshakeRequest req = (IgfsHandshakeRequest) msg;
                    U.writeString(out, req.igfsName());
                    U.writeString(out, req.logDirectory());
                    break;
                }
            case STATUS:
                {
                    out.write(hdr);
                    break;
                }
            case EXISTS:
            case INFO:
            case PATH_SUMMARY:
            case UPDATE:
            case RENAME:
            case DELETE:
            case MAKE_DIRECTORIES:
            case LIST_PATHS:
            case LIST_FILES:
            case AFFINITY:
            case SET_TIMES:
            case OPEN_READ:
            case OPEN_APPEND:
            case OPEN_CREATE:
                {
                    out.write(hdr);
                    IgfsPathControlRequest req = (IgfsPathControlRequest) msg;
                    U.writeString(out, req.userName());
                    writePath(out, req.path());
                    writePath(out, req.destinationPath());
                    out.writeBoolean(req.flag());
                    out.writeBoolean(req.colocate());
                    IgfsUtils.writeStringMap(out, req.properties());
                    // Minor optimization.
                    if (msg.command() == AFFINITY) {
                        out.writeLong(req.start());
                        out.writeLong(req.length());
                    } else if (msg.command() == OPEN_CREATE) {
                        out.writeInt(req.replication());
                        out.writeLong(req.blockSize());
                    } else if (msg.command() == SET_TIMES) {
                        out.writeLong(req.accessTime());
                        out.writeLong(req.modificationTime());
                    } else if (msg.command() == OPEN_READ && req.flag())
                        out.writeInt(req.sequentialReadsBeforePrefetch());
                    break;
                }
            case CLOSE:
            case READ_BLOCK:
            case WRITE_BLOCK:
                {
                    assert msg.command() != WRITE_BLOCK : "WRITE_BLOCK should be marshalled manually.";
                    IgfsStreamControlRequest req = (IgfsStreamControlRequest) msg;
                    U.longToBytes(req.streamId(), hdr, 12);
                    if (msg.command() == READ_BLOCK)
                        U.intToBytes(req.length(), hdr, 20);
                    out.write(hdr);
                    if (msg.command() == READ_BLOCK)
                        out.writeLong(req.position());
                    break;
                }
            case CONTROL_RESPONSE:
                {
                    out.write(hdr);
                    IgfsControlResponse res = (IgfsControlResponse) msg;
                    res.writeExternal(out);
                    break;
                }
            case MODE_RESOLVER:
                {
                    out.write(hdr);
                    break;
                }
            default:
                {
                    assert false : "Invalid command: " + msg.command();
                    throw new IllegalArgumentException("Failed to marshal message (invalid command): " + msg.command());
                }
        }
    } catch (IOException e) {
        throw new IgniteCheckedException("Failed to send message to IGFS data node (is data node up and running?)", e);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IOException(java.io.IOException)

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