use of co.cask.cdap.proto.QueryStatus in project cdap by caskdata.
the class HiveExploreServiceTimeoutTest method testTimeoutFetchAllResults.
@Test
public void testTimeoutFetchAllResults() throws Exception {
Set<Long> beforeTxns = transactionManager.getCurrentState().getInProgress().keySet();
QueryHandle handle = exploreService.execute(NAMESPACE_ID, "select key, value from " + MY_TABLE_NAME);
Set<Long> queryTxns = Sets.difference(transactionManager.getCurrentState().getInProgress().keySet(), beforeTxns);
Assert.assertFalse(queryTxns.isEmpty());
QueryStatus status = waitForCompletionStatus(handle, 200, TimeUnit.MILLISECONDS, 20);
Assert.assertEquals(QueryStatus.OpStatus.FINISHED, status.getStatus());
Assert.assertTrue(status.hasResults());
List<ColumnDesc> schema = exploreService.getResultSchema(handle);
// noinspection StatementWithEmptyBody
while (!exploreService.nextResults(handle, 100).isEmpty()) {
// nothing to do
}
// Sleep for some time for txn to get closed
TimeUnit.SECONDS.sleep(1);
// Make sure that the transaction got closed
Assert.assertEquals(ImmutableSet.<Long>of(), Sets.intersection(queryTxns, transactionManager.getCurrentState().getInProgress().keySet()).immutableCopy());
// Check if calls using inactive handle still work
Assert.assertEquals(status, exploreService.getStatus(handle));
Assert.assertEquals(schema, exploreService.getResultSchema(handle));
exploreService.close(handle);
// Sleep for timeout to happen
TimeUnit.SECONDS.sleep(INACTIVE_OPERATION_TIMEOUT_SECS + 3);
try {
exploreService.getStatus(handle);
Assert.fail("Should throw HandleNotFoundException due to operation cleanup");
} catch (HandleNotFoundException e) {
// Expected exception due to timeout
}
}
use of co.cask.cdap.proto.QueryStatus in project cdap by caskdata.
the class HiveExploreServiceTimeoutTest method testTimeoutNoResults.
@Test
public void testTimeoutNoResults() throws Exception {
Set<Long> beforeTxns = transactionManager.getCurrentState().getInProgress().keySet();
QueryHandle handle = exploreService.execute(NAMESPACE_ID, "drop table if exists not_existing_table_name");
Set<Long> queryTxns = Sets.difference(transactionManager.getCurrentState().getInProgress().keySet(), beforeTxns);
Assert.assertFalse(queryTxns.isEmpty());
QueryStatus status = waitForCompletionStatus(handle, 200, TimeUnit.MILLISECONDS, 20);
Assert.assertEquals(QueryStatus.OpStatus.FINISHED, status.getStatus());
Assert.assertFalse(status.hasResults());
List<ColumnDesc> schema = exploreService.getResultSchema(handle);
// Sleep for some time for txn to get closed
TimeUnit.SECONDS.sleep(1);
// Make sure that the transaction got closed
Assert.assertEquals(ImmutableSet.<Long>of(), Sets.intersection(queryTxns, transactionManager.getCurrentState().getInProgress().keySet()).immutableCopy());
// Check if calls using inactive handle still work
Assert.assertEquals(status, exploreService.getStatus(handle));
Assert.assertEquals(schema, exploreService.getResultSchema(handle));
exploreService.close(handle);
// Sleep for timeout to happen
TimeUnit.SECONDS.sleep(INACTIVE_OPERATION_TIMEOUT_SECS + 3);
try {
exploreService.getStatus(handle);
Assert.fail("Should throw HandleNotFoundException due to operation cleanup");
} catch (HandleNotFoundException e) {
// Expected exception due to timeout
}
}
use of co.cask.cdap.proto.QueryStatus in project cdap by caskdata.
the class BaseHiveExploreService method getStatus.
@Override
public QueryStatus getStatus(QueryHandle handle) throws ExploreException, HandleNotFoundException, SQLException {
startAndWait();
InactiveOperationInfo inactiveOperationInfo = inactiveHandleCache.getIfPresent(handle);
if (inactiveOperationInfo != null) {
// Operation has been made inactive, so return the saved status.
LOG.trace("Returning saved status for inactive handle {}", handle);
return inactiveOperationInfo.getStatus();
}
try {
// Fetch status from Hive
QueryStatus status = fetchStatus(getActiveOperationInfo(handle));
LOG.trace("Status of handle {} is {}", handle, status);
// No results or error, so can be timed out aggressively
if (status.getStatus() == QueryStatus.OpStatus.FINISHED && !status.hasResults()) {
// In case of a query that writes to a Dataset, we will always fall into this condition,
// and timing out aggressively will also close the transaction and make the writes visible
timeoutAggressively(handle, getResultSchema(handle), status);
} else if (status.getStatus() == QueryStatus.OpStatus.ERROR) {
// getResultSchema will fail if the query is in error
timeoutAggressively(handle, ImmutableList.<ColumnDesc>of(), status);
}
return status;
} catch (HiveSQLException e) {
throw getSqlException(e);
}
}
use of co.cask.cdap.proto.QueryStatus in project cdap by caskdata.
the class BaseHiveExploreService method getQueries.
@Override
public List<QueryInfo> getQueries(NamespaceId namespace) throws ExploreException, SQLException {
startAndWait();
List<QueryInfo> result = new ArrayList<>();
String namespaceHiveDb = getHiveDatabase(namespace.getNamespace());
for (Map.Entry<QueryHandle, OperationInfo> entry : activeHandleCache.asMap().entrySet()) {
try {
if (namespaceHiveDb.equals(entry.getValue().getHiveDatabase())) {
// we use empty query statement for get tables, get schemas, we don't need to return it this method call.
if (!entry.getValue().getStatement().isEmpty()) {
QueryStatus status = getStatus(entry.getKey());
result.add(new QueryInfo(entry.getValue().getTimestamp(), entry.getValue().getStatement(), entry.getKey(), status, true));
}
}
} catch (HandleNotFoundException e) {
// ignore the handle not found exception. this method returns all queries and handle, if the
// handle is removed from the internal cache, then there is no point returning them from here.
}
}
for (Map.Entry<QueryHandle, InactiveOperationInfo> entry : inactiveHandleCache.asMap().entrySet()) {
InactiveOperationInfo inactiveOperationInfo = entry.getValue();
if (namespaceHiveDb.equals(inactiveOperationInfo.getHiveDatabase())) {
// we use empty query statement for get tables, get schemas, we don't need to return it this method call.
if (!inactiveOperationInfo.getStatement().isEmpty()) {
if (inactiveOperationInfo.getStatus() == null) {
LOG.error("Null status for query {}, handle {}", inactiveOperationInfo.getStatement(), entry.getKey());
}
result.add(new QueryInfo(inactiveOperationInfo.getTimestamp(), inactiveOperationInfo.getStatement(), entry.getKey(), inactiveOperationInfo.getStatus(), false));
}
}
}
Collections.sort(result);
return result;
}
use of co.cask.cdap.proto.QueryStatus in project cdap by caskdata.
the class Hive14ExploreService method doFetchStatus.
@Override
protected QueryStatus doFetchStatus(OperationHandle operationHandle) throws HiveSQLException, ExploreException, HandleNotFoundException {
OperationStatus operationStatus;
CLIService cliService = getCliService();
// Call the getOperationStatus method based on the number of arguments it expects.
try {
if (getOperationStatus.getParameterTypes().length == 2) {
operationStatus = (OperationStatus) getOperationStatus.invoke(cliService, operationHandle, true);
} else {
operationStatus = (OperationStatus) getOperationStatus.invoke(cliService, operationHandle);
}
} catch (IndexOutOfBoundsException | IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException("Failed to get the status of the operation.", e);
}
@SuppressWarnings("ThrowableResultOfMethodCallIgnored") HiveSQLException hiveExn = operationStatus.getOperationException();
if (hiveExn != null) {
return new QueryStatus(hiveExn.getMessage(), hiveExn.getSQLState());
}
return new QueryStatus(QueryStatus.OpStatus.valueOf(operationStatus.getState().toString()), operationHandle.hasResultSet());
}
Aggregations