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();
}
}
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();
}
}
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);
}
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;
}
}
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);
}
}
Aggregations