Ensure Job Destroyed on Channel Drop
Change-Id: I011f15906a4b53936a1191bf505fddea674093df
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/ChannelDropStatement.java b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/ChannelDropStatement.java
index fb71770..f4ea2f3 100644
--- a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/ChannelDropStatement.java
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/ChannelDropStatement.java
@@ -38,6 +38,7 @@
import org.apache.asterix.translator.IStatementExecutor;
import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
import org.apache.hyracks.api.client.IHyracksClientConnection;
+import org.apache.hyracks.api.exceptions.ErrorCode;
import org.apache.hyracks.api.exceptions.HyracksDataException;
import org.apache.hyracks.api.job.JobId;
@@ -114,6 +115,8 @@
activeEventHandler.unregisterListener(listener);
if (hyracksJobId != null) {
hcc.destroyJob(hyracksJobId);
+ // wait for job completion to release any resources to be dropped
+ ensureJobDestroyed(hcc, hyracksJobId);
}
//Create a metadata provider to use in nested jobs.
@@ -144,4 +147,19 @@
}
}
+ private void ensureJobDestroyed(IHyracksClientConnection hcc, JobId hyracksJobId) throws Exception {
+ try {
+ hcc.waitForCompletion(hyracksJobId);
+ } catch (Exception e) {
+ // if the job has already been destroyed, it is safe to complete
+ if (e instanceof HyracksDataException) {
+ HyracksDataException hde = (HyracksDataException) e;
+ if (hde.getComponent().equals(ErrorCode.HYRACKS)
+ && hde.getErrorCode() == ErrorCode.JOB_HAS_BEEN_CLEARED_FROM_HISTORY) {
+ return;
+ }
+ }
+ throw e;
+ }
+ }
}
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.9.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.9.ddl.sqlpp
new file mode 100644
index 0000000..0fc703f
--- /dev/null
+++ b/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.9.ddl.sqlpp
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+* Description : Room Occupants Test
+* Expected Res : Success
+* Date : Nov 2017
+*/
+
+use channels;
+
+drop channel roomRecords;