Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 41626200CB4 for ; Tue, 27 Jun 2017 23:41:02 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 400C2160BDC; Tue, 27 Jun 2017 21:41:02 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 12FA0160BD8 for ; Tue, 27 Jun 2017 23:41:00 +0200 (CEST) Received: (qmail 6782 invoked by uid 500); 27 Jun 2017 21:40:59 -0000 Mailing-List: contact commits-help@asterixdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@asterixdb.apache.org Delivered-To: mailing list commits@asterixdb.apache.org Received: (qmail 6771 invoked by uid 99); 27 Jun 2017 21:40:59 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 27 Jun 2017 21:40:59 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 2350BDFB30; Tue, 27 Jun 2017 21:40:59 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: mblow@apache.org To: commits@asterixdb.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: asterixdb git commit: [ASTERIXDB-1955][CLUS][RT] Refactor, Keep-Alive Date: Tue, 27 Jun 2017 21:40:59 +0000 (UTC) archived-at: Tue, 27 Jun 2017 21:41:02 -0000 Repository: asterixdb Updated Branches: refs/heads/master d8536d7a1 -> 1308eae51 [ASTERIXDB-1955][CLUS][RT] Refactor, Keep-Alive - Add getFaultToleranceStrategy to ICcApplicationContext interface, eliminate casts to implementation where interface suffices - Minor refactoring in ResultUtil - Don't close keep-alive connections in case of Unauthorized (401) status Change-Id: Id75dd55861976390b1098a496ff2c0345c991389 Reviewed-on: https://asterix-gerrit.ics.uci.edu/1855 Sonar-Qube: Jenkins Tested-by: Jenkins BAD: Jenkins Integration-Tests: Jenkins Reviewed-by: abdullah alamoudi Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/1308eae5 Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/1308eae5 Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/1308eae5 Branch: refs/heads/master Commit: 1308eae519a613873c85ee6c16a0a6ce766ffb72 Parents: d8536d7 Author: Michael Blow Authored: Mon Jun 26 23:11:46 2017 -0400 Committer: Michael Blow Committed: Tue Jun 27 14:40:25 2017 -0700 ---------------------------------------------------------------------- .../asterix/api/http/server/ResultUtil.java | 23 +++++++++++++++----- .../message/NCLifecycleTaskReportMessage.java | 3 +-- .../message/StartupTaskRequestMessage.java | 3 +-- .../hyracks/bootstrap/CCApplication.java | 3 ++- .../asterix/test/common/ResultExtractor.java | 2 +- .../common/dataflow/ICcApplicationContext.java | 6 +++++ .../runtime/utils/CcApplicationContext.java | 1 + .../hyracks/http/server/ChunkedResponse.java | 14 ++++++++---- .../hyracks/http/server/FullResponse.java | 10 ++++++--- 9 files changed, 46 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/asterixdb/blob/1308eae5/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ResultUtil.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ResultUtil.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ResultUtil.java index f004446..fa2f667 100644 --- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ResultUtil.java +++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ResultUtil.java @@ -116,19 +116,26 @@ public class ResultUtil { } public static void printError(PrintWriter pw, Throwable e, boolean comma) { + printError(pw, e, 1, comma); + } + + public static void printError(PrintWriter pw, Throwable e, int code, boolean comma) { Throwable rootCause = getRootCause(e); - final boolean addStack = false; - pw.print("\t\""); - pw.print(AbstractQueryApiServlet.ResultFields.ERRORS.str()); - pw.print("\": [{ \n"); - printField(pw, QueryServiceServlet.ErrorField.CODE.str(), "1"); String msg = rootCause.getMessage(); if (!(rootCause instanceof AlgebricksException || rootCause instanceof HyracksException || rootCause instanceof TokenMgrError || rootCause instanceof org.apache.asterix.aqlplus.parser.TokenMgrError)) { msg = rootCause.getClass().getSimpleName() + (msg == null ? "" : ": " + msg); } - printField(pw, QueryServiceServlet.ErrorField.MSG.str(), JSONUtil.escape(msg), addStack); + printError(pw, msg, code, comma); + } + + public static void printError(PrintWriter pw, String msg, int code, boolean comma) { + pw.print("\t\""); + pw.print(AbstractQueryApiServlet.ResultFields.ERRORS.str()); + pw.print("\": [{ \n"); + printField(pw, QueryServiceServlet.ErrorField.CODE.str(), code); + printField(pw, QueryServiceServlet.ErrorField.MSG.str(), JSONUtil.escape(msg), false); pw.print(comma ? "\t}],\n" : "\t}]\n"); } @@ -136,6 +143,10 @@ public class ResultUtil { printField(pw, name, value, true); } + public static void printField(PrintWriter pw, String name, long value) { + printField(pw, name, value, true); + } + public static void printField(PrintWriter pw, String name, String value, boolean comma) { printFieldInternal(pw, name, "\"" + value + "\"", comma); } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/1308eae5/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/replication/message/NCLifecycleTaskReportMessage.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/replication/message/NCLifecycleTaskReportMessage.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/replication/message/NCLifecycleTaskReportMessage.java index 03c7ac6..a01d70a 100644 --- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/replication/message/NCLifecycleTaskReportMessage.java +++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/replication/message/NCLifecycleTaskReportMessage.java @@ -21,7 +21,6 @@ package org.apache.asterix.app.replication.message; import org.apache.asterix.common.dataflow.ICcApplicationContext; import org.apache.asterix.common.messaging.api.ICcAddressedMessage; import org.apache.asterix.common.replication.INCLifecycleMessage; -import org.apache.asterix.runtime.utils.CcApplicationContext; import org.apache.hyracks.api.exceptions.HyracksDataException; public class NCLifecycleTaskReportMessage implements INCLifecycleMessage, ICcAddressedMessage { @@ -38,7 +37,7 @@ public class NCLifecycleTaskReportMessage implements INCLifecycleMessage, ICcAdd @Override public void handle(ICcApplicationContext appCtx) throws HyracksDataException, InterruptedException { - ((CcApplicationContext) appCtx).getFaultToleranceStrategy().process(this); + appCtx.getFaultToleranceStrategy().process(this); } public String getNodeId() { http://git-wip-us.apache.org/repos/asf/asterixdb/blob/1308eae5/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/replication/message/StartupTaskRequestMessage.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/replication/message/StartupTaskRequestMessage.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/replication/message/StartupTaskRequestMessage.java index cfe999c..21dee9c 100644 --- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/replication/message/StartupTaskRequestMessage.java +++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/replication/message/StartupTaskRequestMessage.java @@ -26,7 +26,6 @@ import org.apache.asterix.common.messaging.api.ICcAddressedMessage; import org.apache.asterix.common.messaging.api.INCMessageBroker; import org.apache.asterix.common.replication.INCLifecycleMessage; import org.apache.asterix.common.transactions.IRecoveryManager.SystemState; -import org.apache.asterix.runtime.utils.CcApplicationContext; import org.apache.hyracks.api.exceptions.HyracksDataException; import org.apache.hyracks.control.nc.NodeControllerService; @@ -54,7 +53,7 @@ public class StartupTaskRequestMessage implements INCLifecycleMessage, ICcAddres @Override public void handle(ICcApplicationContext appCtx) throws HyracksDataException, InterruptedException { - ((CcApplicationContext) appCtx).getFaultToleranceStrategy().process(this); + appCtx.getFaultToleranceStrategy().process(this); } public SystemState getState() { http://git-wip-us.apache.org/repos/asf/asterixdb/blob/1308eae5/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplication.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplication.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplication.java index 21afdf1..35e0466 100644 --- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplication.java +++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplication.java @@ -62,6 +62,7 @@ import org.apache.asterix.common.config.ClusterProperties; import org.apache.asterix.common.config.ExternalProperties; import org.apache.asterix.common.config.MetadataProperties; import org.apache.asterix.common.context.IStorageComponentProvider; +import org.apache.asterix.common.dataflow.ICcApplicationContext; import org.apache.asterix.common.library.ILibraryManager; import org.apache.asterix.common.replication.IFaultToleranceStrategy; import org.apache.asterix.common.replication.IReplicationStrategy; @@ -342,7 +343,7 @@ public class CCApplication extends BaseCCApplication { } @Override - public CcApplicationContext getApplicationContext() { + public ICcApplicationContext getApplicationContext() { return appCtx; } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/1308eae5/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/ResultExtractor.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/ResultExtractor.java b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/ResultExtractor.java index 76b3510..0bba635 100644 --- a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/ResultExtractor.java +++ b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/ResultExtractor.java @@ -36,7 +36,7 @@ import com.google.common.collect.Iterators; /** * extracts results from the response of the QueryServiceServlet. * As the response is not necessarily valid JSON, non-JSON content has to be extracted in some cases. - * The current implementation creates a toomany copies of the data to be usable for larger results. + * The current implementation creates a too many copies of the data to be usable for larger results. */ public class ResultExtractor { http://git-wip-us.apache.org/repos/asf/asterixdb/blob/1308eae5/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/dataflow/ICcApplicationContext.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/dataflow/ICcApplicationContext.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/dataflow/ICcApplicationContext.java index b7adfde..249bd56 100644 --- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/dataflow/ICcApplicationContext.java +++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/dataflow/ICcApplicationContext.java @@ -21,6 +21,7 @@ package org.apache.asterix.common.dataflow; import org.apache.asterix.common.api.IApplicationContext; import org.apache.asterix.common.cluster.IGlobalRecoveryManager; import org.apache.asterix.common.context.IStorageComponentProvider; +import org.apache.asterix.common.replication.IFaultToleranceStrategy; import org.apache.asterix.common.transactions.IResourceIdManager; import org.apache.hyracks.api.application.ICCServiceContext; import org.apache.hyracks.api.client.IHyracksClientConnection; @@ -57,6 +58,11 @@ public interface ICcApplicationContext extends IApplicationContext { IGlobalRecoveryManager getGlobalRecoveryManager(); /** + * @return the fault tolerance strategy in use for the cluster + */ + IFaultToleranceStrategy getFaultToleranceStrategy(); + + /** * @return the active lifecycle listener at Cluster controller */ IJobLifecycleListener getActiveLifecycleListener(); http://git-wip-us.apache.org/repos/asf/asterixdb/blob/1308eae5/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/utils/CcApplicationContext.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/utils/CcApplicationContext.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/utils/CcApplicationContext.java index f9b54dc..4cd243c 100644 --- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/utils/CcApplicationContext.java +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/utils/CcApplicationContext.java @@ -204,6 +204,7 @@ public class CcApplicationContext implements ICcApplicationContext { return metadataBootstrapSupplier.get(); } + @Override public IFaultToleranceStrategy getFaultToleranceStrategy() { return ftStrategy; } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/1308eae5/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/ChunkedResponse.java ---------------------------------------------------------------------- diff --git a/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/ChunkedResponse.java b/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/ChunkedResponse.java index 8fd444b..1c30991 100644 --- a/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/ChunkedResponse.java +++ b/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/ChunkedResponse.java @@ -66,6 +66,7 @@ public class ChunkedResponse implements IServletResponse { private ByteBuf error; private ChannelFuture future; private boolean done; + private final boolean keepAlive; public ChunkedResponse(ChannelHandlerContext ctx, FullHttpRequest request, int chunkSize) { this.ctx = ctx; @@ -73,7 +74,8 @@ public class ChunkedResponse implements IServletResponse { writer = new PrintWriter(outputStream); response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.INTERNAL_SERVER_ERROR); response.headers().set(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED); - if (HttpUtil.isKeepAlive(request)) { + keepAlive = HttpUtil.isKeepAlive(request); + if (keepAlive) { response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE); } } @@ -112,13 +114,17 @@ public class ChunkedResponse implements IServletResponse { } future = ctx.channel().close(); } else { + if (keepAlive && response.status() != HttpResponseStatus.UNAUTHORIZED) { + response.headers().remove(HttpHeaderNames.CONNECTION); + } // we didn't send anything to the user, we need to send an unchunked error response fullResponse(response.protocolVersion(), response.status(), error == null ? ctx.alloc().buffer(0, 0) : error, response.headers()); } - - // since the request failed, we need to close the channel on complete - future.addListener(ChannelFutureListener.CLOSE); + if (response.status() != HttpResponseStatus.UNAUTHORIZED) { + // since the request failed, we need to close the channel on complete + future.addListener(ChannelFutureListener.CLOSE); + } } done = true; } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/1308eae5/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/FullResponse.java ---------------------------------------------------------------------- diff --git a/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/FullResponse.java b/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/FullResponse.java index 1023686..598048e 100644 --- a/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/FullResponse.java +++ b/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/FullResponse.java @@ -61,11 +61,15 @@ public class FullResponse implements IServletResponse { public void close() throws IOException { writer.close(); FullHttpResponse fullResponse = response.replace(Unpooled.copiedBuffer(baos.toByteArray())); - if (keepAlive && response.status() == HttpResponseStatus.OK) { - fullResponse.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, fullResponse.content().readableBytes()); + if (keepAlive) { + if (response.status() == HttpResponseStatus.OK || response.status() == HttpResponseStatus.UNAUTHORIZED) { + fullResponse.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, fullResponse.content().readableBytes()); + } else { + fullResponse.headers().remove(HttpHeaderNames.CONNECTION); + } } future = ctx.writeAndFlush(fullResponse); - if (response.status() != HttpResponseStatus.OK) { + if (response.status() != HttpResponseStatus.OK && response.status() != HttpResponseStatus.UNAUTHORIZED) { future.addListener(ChannelFutureListener.CLOSE); } }