diff --git service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java index 460a26b..6396f38 100644 --- service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java +++ service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java @@ -496,14 +496,15 @@ private OperationHandle executeStatementInternal(String statement, operation = getOperationManager().newExecuteStatementOperation(getSession(), statement, confOverlay, runAsync, queryTimeout); opHandle = operation.getHandle(); - operation.run(); addOpHandle(opHandle); + operation.run(); return opHandle; } catch (HiveSQLException e) { // Refering to SQLOperation.java, there is no chance that a HiveSQLException throws and the // async background operation submits to thread pool successfully at the same time. So, Cleanup // opHandle directly when got HiveSQLException if (opHandle != null) { + removeOpHandle(opHandle); getOperationManager().closeOperation(opHandle); } throw e; @@ -536,10 +537,11 @@ public OperationHandle getTypeInfo() GetTypeInfoOperation operation = operationManager.newGetTypeInfoOperation(getSession()); OperationHandle opHandle = operation.getHandle(); try { - operation.run(); addOpHandle(opHandle); + operation.run(); return opHandle; } catch (HiveSQLException e) { + removeOpHandle(opHandle); operationManager.closeOperation(opHandle); throw e; } finally { @@ -556,10 +558,11 @@ public OperationHandle getCatalogs() GetCatalogsOperation operation = operationManager.newGetCatalogsOperation(getSession()); OperationHandle opHandle = operation.getHandle(); try { - operation.run(); addOpHandle(opHandle); + operation.run(); return opHandle; } catch (HiveSQLException e) { + removeOpHandle(opHandle); operationManager.closeOperation(opHandle); throw e; } finally { @@ -577,10 +580,11 @@ public OperationHandle getSchemas(String catalogName, String schemaName) operationManager.newGetSchemasOperation(getSession(), catalogName, schemaName); OperationHandle opHandle = operation.getHandle(); try { - operation.run(); addOpHandle(opHandle); + operation.run(); return opHandle; } catch (HiveSQLException e) { + removeOpHandle(opHandle); operationManager.closeOperation(opHandle); throw e; } finally { @@ -599,10 +603,11 @@ public OperationHandle getTables(String catalogName, String schemaName, String t operationManager.newGetTablesOperation(getSession(), catalogName, schemaName, tableName, tableTypes); OperationHandle opHandle = operation.getHandle(); try { - operation.run(); addOpHandle(opHandle); + operation.run(); return opHandle; } catch (HiveSQLException e) { + removeOpHandle(opHandle); operationManager.closeOperation(opHandle); throw e; } finally { @@ -619,10 +624,11 @@ public OperationHandle getTableTypes() GetTableTypesOperation operation = operationManager.newGetTableTypesOperation(getSession()); OperationHandle opHandle = operation.getHandle(); try { - operation.run(); addOpHandle(opHandle); + operation.run(); return opHandle; } catch (HiveSQLException e) { + removeOpHandle(opHandle); operationManager.closeOperation(opHandle); throw e; } finally { @@ -644,10 +650,11 @@ public OperationHandle getColumns(String catalogName, String schemaName, catalogName, schemaName, tableName, columnName); OperationHandle opHandle = operation.getHandle(); try { - operation.run(); addOpHandle(opHandle); + operation.run(); return opHandle; } catch (HiveSQLException e) { + removeOpHandle(opHandle); operationManager.closeOperation(opHandle); throw e; } finally { @@ -661,6 +668,12 @@ private void addOpHandle(OperationHandle opHandle) { } } + private void removeOpHandle(OperationHandle opHandle) { + synchronized (opHandleSet) { + opHandleSet.remove(opHandle); + } + } + @Override public OperationHandle getFunctions(String catalogName, String schemaName, String functionName) throws HiveSQLException { @@ -671,10 +684,11 @@ public OperationHandle getFunctions(String catalogName, String schemaName, Strin .newGetFunctionsOperation(getSession(), catalogName, schemaName, functionName); OperationHandle opHandle = operation.getHandle(); try { - operation.run(); addOpHandle(opHandle); + operation.run(); return opHandle; } catch (HiveSQLException e) { + removeOpHandle(opHandle); operationManager.closeOperation(opHandle); throw e; } finally { @@ -909,10 +923,11 @@ public OperationHandle getPrimaryKeys(String catalog, String schema, .newGetPrimaryKeysOperation(getSession(), catalog, schema, table); OperationHandle opHandle = operation.getHandle(); try { - operation.run(); addOpHandle(opHandle); + operation.run(); return opHandle; } catch (HiveSQLException e) { + removeOpHandle(opHandle); operationManager.closeOperation(opHandle); throw e; } finally { @@ -933,10 +948,11 @@ public OperationHandle getCrossReference(String primaryCatalog, foreignSchema, foreignTable); OperationHandle opHandle = operation.getHandle(); try { - operation.run(); addOpHandle(opHandle); + operation.run(); return opHandle; } catch (HiveSQLException e) { + removeOpHandle(opHandle); operationManager.closeOperation(opHandle); throw e; } finally {