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 122F6200B9B for ; Wed, 28 Sep 2016 02:51:25 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 10A60160AE5; Wed, 28 Sep 2016 00:51:25 +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 2F256160AD2 for ; Wed, 28 Sep 2016 02:51:24 +0200 (CEST) Received: (qmail 32988 invoked by uid 500); 28 Sep 2016 00:51:23 -0000 Mailing-List: contact commits-help@phoenix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@phoenix.apache.org Delivered-To: mailing list commits@phoenix.apache.org Received: (qmail 32979 invoked by uid 99); 28 Sep 2016 00:51:23 -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; Wed, 28 Sep 2016 00:51:23 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 41ECBDFB6F; Wed, 28 Sep 2016 00:51:23 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: samarth@apache.org To: commits@phoenix.apache.org Message-Id: <490680efc9f042f68773d844a570df69@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: phoenix git commit: PHOENIX-3334 ConnectionQueryServicesImpl should close HConnection if init fails Date: Wed, 28 Sep 2016 00:51:23 +0000 (UTC) archived-at: Wed, 28 Sep 2016 00:51:25 -0000 Repository: phoenix Updated Branches: refs/heads/4.x-HBase-0.98 591f3ce6e -> 504732ad5 PHOENIX-3334 ConnectionQueryServicesImpl should close HConnection if init fails Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/504732ad Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/504732ad Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/504732ad Branch: refs/heads/4.x-HBase-0.98 Commit: 504732ad50d73c716d1386e0b6d4500967710f39 Parents: 591f3ce Author: Samarth Authored: Tue Sep 27 17:50:34 2016 -0700 Committer: Samarth Committed: Tue Sep 27 17:50:34 2016 -0700 ---------------------------------------------------------------------- .../exception/RetriableUpgradeException.java | 31 ++++++++++++++++++++ .../exception/UpgradeInProgressException.java | 3 +- .../exception/UpgradeNotRequiredException.java | 3 +- .../exception/UpgradeRequiredException.java | 3 +- .../query/ConnectionQueryServicesImpl.java | 24 ++++++++++++++- 5 files changed, 57 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/504732ad/phoenix-core/src/main/java/org/apache/phoenix/exception/RetriableUpgradeException.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/exception/RetriableUpgradeException.java b/phoenix-core/src/main/java/org/apache/phoenix/exception/RetriableUpgradeException.java new file mode 100644 index 0000000..b0f747d --- /dev/null +++ b/phoenix-core/src/main/java/org/apache/phoenix/exception/RetriableUpgradeException.java @@ -0,0 +1,31 @@ +/* + * 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. + */ +package org.apache.phoenix.exception; + +import java.sql.SQLException; + +/** + * + * Super class for upgrade related exceptions whose occurrence shouldn't prevent the + * client from retrying or reestablishing connection. + */ +public abstract class RetriableUpgradeException extends SQLException { + public RetriableUpgradeException(String message, String sqlState, int sqlExceptionCode) { + super(message, sqlState, sqlExceptionCode); + } +} http://git-wip-us.apache.org/repos/asf/phoenix/blob/504732ad/phoenix-core/src/main/java/org/apache/phoenix/exception/UpgradeInProgressException.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/exception/UpgradeInProgressException.java b/phoenix-core/src/main/java/org/apache/phoenix/exception/UpgradeInProgressException.java index 5b15216..08ae304 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/exception/UpgradeInProgressException.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/exception/UpgradeInProgressException.java @@ -17,9 +17,8 @@ */ package org.apache.phoenix.exception; -import java.sql.SQLException; -public class UpgradeInProgressException extends SQLException { +public class UpgradeInProgressException extends RetriableUpgradeException { public UpgradeInProgressException(String upgradeFrom, String upgradeTo) { super("Cluster is being concurrently upgraded from " + upgradeFrom + " to " + upgradeTo + ". Please retry establishing connection.", SQLExceptionCode.CONCURRENT_UPGRADE_IN_PROGRESS http://git-wip-us.apache.org/repos/asf/phoenix/blob/504732ad/phoenix-core/src/main/java/org/apache/phoenix/exception/UpgradeNotRequiredException.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/exception/UpgradeNotRequiredException.java b/phoenix-core/src/main/java/org/apache/phoenix/exception/UpgradeNotRequiredException.java index 0490319..7e94977 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/exception/UpgradeNotRequiredException.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/exception/UpgradeNotRequiredException.java @@ -17,9 +17,8 @@ */ package org.apache.phoenix.exception; -import java.sql.SQLException; -public class UpgradeNotRequiredException extends SQLException { +public class UpgradeNotRequiredException extends RetriableUpgradeException { public UpgradeNotRequiredException() { super("Operation not allowed since cluster has already been upgraded. ", SQLExceptionCode.UPGRADE_NOT_REQUIRED .getSQLState(), SQLExceptionCode.UPGRADE_NOT_REQUIRED.getErrorCode()); http://git-wip-us.apache.org/repos/asf/phoenix/blob/504732ad/phoenix-core/src/main/java/org/apache/phoenix/exception/UpgradeRequiredException.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/exception/UpgradeRequiredException.java b/phoenix-core/src/main/java/org/apache/phoenix/exception/UpgradeRequiredException.java index 005a1bd..9352a50 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/exception/UpgradeRequiredException.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/exception/UpgradeRequiredException.java @@ -17,9 +17,8 @@ */ package org.apache.phoenix.exception; -import java.sql.SQLException; -public class UpgradeRequiredException extends SQLException { +public class UpgradeRequiredException extends RetriableUpgradeException { public UpgradeRequiredException() { super("Operation not allowed since cluster hasn't been upgraded. Call EXECUTE UPGRADE. ", http://git-wip-us.apache.org/repos/asf/phoenix/blob/504732ad/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java index 0c2039f..ab2e912 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java @@ -131,6 +131,7 @@ import org.apache.phoenix.coprocessor.generated.MetaDataProtos.MetaDataResponse; import org.apache.phoenix.coprocessor.generated.MetaDataProtos.MetaDataService; import org.apache.phoenix.coprocessor.generated.MetaDataProtos.UpdateIndexStateRequest; import org.apache.phoenix.exception.PhoenixIOException; +import org.apache.phoenix.exception.RetriableUpgradeException; import org.apache.phoenix.exception.SQLExceptionCode; import org.apache.phoenix.exception.SQLExceptionInfo; import org.apache.phoenix.exception.UpgradeInProgressException; @@ -2313,8 +2314,11 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement return null; } checkClosed(); + boolean hConnectionEstablished = false; + boolean success = false; try { openConnection(); + hConnectionEstablished = true; boolean isDoNotUpgradePropSet = UpgradeUtil.isNoUpgradeSet(props); try (HBaseAdmin admin = getAdmin()) { boolean mappedSystemCatalogExists = admin @@ -2361,6 +2365,11 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement } } scheduleRenewLeaseTasks(); + success = true; + } catch (RetriableUpgradeException e) { + // Don't set it as initializationException because otherwise the clien't won't be able + // to retry establishing connection. + throw e; } catch (Exception e) { if (e instanceof SQLException) { initializationException = (SQLException)e; @@ -2369,7 +2378,20 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement initializationException = new SQLException(e); } } finally { - initialized = true; + try { + if (!success && hConnectionEstablished) { + connection.close(); + } + } catch (IOException e) { + SQLException ex = new SQLException(e); + if (initializationException != null) { + initializationException.setNextException(ex); + } else { + initializationException = ex; + } + } finally { + initialized = true; + } } } return null;