phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sama...@apache.org
Subject phoenix git commit: PHOENIX-3334 ConnectionQueryServicesImpl should close HConnection if init fails
Date Wed, 28 Sep 2016 00:51:23 GMT
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 <samarth.jain@salesforce.com>
Authored: Tue Sep 27 17:50:34 2016 -0700
Committer: Samarth <samarth.jain@salesforce.com>
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;


Mime
View raw message