public boolean killQuery(final QueryId queryId) throws ServiceException, IOException { QueryStatus status = getQueryStatus(queryId); NettyClientBase tmClient = null; try { /* send a kill to the TM */ tmClient = connPool.getConnection(tajoMasterAddr, TajoMasterClientProtocol.class, false); TajoMasterClientProtocolService.BlockingInterface tajoMasterService = tmClient.getStub(); tajoMasterService.killQuery(null, queryId.getProto()); long currentTimeMillis = System.currentTimeMillis(); long timeKillIssued = currentTimeMillis; while ((currentTimeMillis < timeKillIssued + 10000L) && (status.getState() != QueryState.QUERY_KILLED)) { try { Thread.sleep(100L); } catch (InterruptedException ie) { break; } currentTimeMillis = System.currentTimeMillis(); status = getQueryStatus(queryId); } return status.getState() == QueryState.QUERY_KILLED; } catch (Exception e) { LOG.debug("Error when checking for application status", e); return false; } finally { connPool.releaseConnection(tmClient); } }
public ResultSet getQueryResultAndWait(QueryId queryId) throws ServiceException, IOException { if (queryId.equals(QueryIdFactory.NULL_QUERY_ID)) { return createNullResultSet(queryId); } QueryStatus status = getQueryStatus(queryId); while (status != null && isQueryRunnning(status.getState())) { try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } status = getQueryStatus(queryId); } if (status.getState() == QueryState.QUERY_SUCCEEDED) { if (status.hasResult()) { return getQueryResult(queryId); } else { return createNullResultSet(queryId); } } else { LOG.warn("Query (" + status.getQueryId() + ") failed: " + status.getState()); // TODO throw SQLException(?) return createNullResultSet(queryId); } }