Till Westmann has submitted this change and it was merged.

Change subject: QueryServiceServlet fixes
......................................................................


QueryServiceServlet fixes

- abort requests if the cluster state is not ACTIVE
- execution time is 0 if an error happens before execution starts

Change-Id: Ifff417a0a07771a264f8496f228fda1b10146c6e
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1216
Sonar-Qube: Jenkins <[email protected]>
Tested-by: Jenkins <[email protected]>
Integration-Tests: Jenkins <[email protected]>
Reviewed-by: Michael Blow <[email protected]>
---
M 
asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryServiceServlet.java
1 file changed, 11 insertions(+), 2 deletions(-)

Approvals:
  Michael Blow: Looks good to me, approved
  Jenkins: Verified; No violations found; Verified



diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryServiceServlet.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryServiceServlet.java
index 856aa40..3a22302 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryServiceServlet.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryServiceServlet.java
@@ -39,6 +39,7 @@
 import org.apache.asterix.app.result.ResultReader;
 import org.apache.asterix.app.result.ResultUtil;
 import org.apache.asterix.app.translator.QueryTranslator;
+import org.apache.asterix.common.api.IClusterManagementWork;
 import org.apache.asterix.common.app.SessionConfig;
 import org.apache.asterix.common.config.GlobalConfig;
 import org.apache.asterix.common.exceptions.AsterixException;
@@ -48,6 +49,7 @@
 import org.apache.asterix.lang.common.base.IParser;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.metadata.MetadataManager;
+import org.apache.asterix.runtime.util.ClusterStateManager;
 import org.apache.asterix.translator.IStatementExecutor;
 import org.apache.asterix.translator.IStatementExecutor.Stats;
 import org.apache.asterix.translator.IStatementExecutorFactory;
@@ -434,7 +436,7 @@
 
         int respCode = HttpServletResponse.SC_OK;
         Stats stats = new Stats();
-        long execStart = 0;
+        long execStart = -1;
         long execEnd = -1;
 
         resultWriter.print("{\n");
@@ -443,6 +445,11 @@
         printSignature(resultWriter);
         printType(resultWriter, sessionConfig);
         try {
+            final IClusterManagementWork.ClusterState clusterState = 
ClusterStateManager.INSTANCE.getState();
+            if (clusterState != IClusterManagementWork.ClusterState.ACTIVE) {
+                // using a plain IllegalStateException here to get into the 
right catch clause for a 500
+                throw new IllegalStateException("Cannot execute request, 
cluster is " + clusterState);
+            }
             if (param.statement == null || param.statement.isEmpty()) {
                 throw new AsterixException("Empty request, no statement 
provided");
             }
@@ -477,7 +484,9 @@
             printStatus(resultWriter, ResultStatus.FATAL);
             respCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
         } finally {
-            if (execEnd == -1) {
+            if (execStart == -1) {
+                execEnd = -1;
+            } else if (execEnd == -1) {
                 execEnd = System.nanoTime();
             }
         }

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/1216
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ifff417a0a07771a264f8496f228fda1b10146c6e
Gerrit-PatchSet: 3
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Till Westmann <[email protected]>
Gerrit-Reviewer: Jenkins <[email protected]>
Gerrit-Reviewer: Michael Blow <[email protected]>
Gerrit-Reviewer: Till Westmann <[email protected]>

Reply via email to