You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ja...@apache.org on 2018/11/06 20:40:14 UTC

phoenix git commit: PHOENIX-5004 Fix org.jboss.netty.channel.ChannelException: Failed to bind to: flapper (addendum)

Repository: phoenix
Updated Branches:
  refs/heads/omid2 e13de05a2 -> 0f2b1b8ba


PHOENIX-5004 Fix org.jboss.netty.channel.ChannelException: Failed to bind to: flapper (addendum)


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/0f2b1b8b
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/0f2b1b8b
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/0f2b1b8b

Branch: refs/heads/omid2
Commit: 0f2b1b8ba9995e668edac908ef0bf1b4d72167ec
Parents: e13de05
Author: James Taylor <ja...@apache.org>
Authored: Tue Nov 6 12:39:45 2018 -0800
Committer: James Taylor <ja...@apache.org>
Committed: Tue Nov 6 12:39:45 2018 -0800

----------------------------------------------------------------------
 .../transaction/OmidTransactionProvider.java    | 25 +++-----------------
 .../phoenix/query/QueryServicesTestImpl.java    |  8 ++++---
 .../java/org/apache/phoenix/util/TestUtil.java  | 14 +++++++++++
 3 files changed, 22 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/0f2b1b8b/phoenix-core/src/main/java/org/apache/phoenix/transaction/OmidTransactionProvider.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/transaction/OmidTransactionProvider.java b/phoenix-core/src/main/java/org/apache/phoenix/transaction/OmidTransactionProvider.java
index 98b56ad..610a5d1 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/transaction/OmidTransactionProvider.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/transaction/OmidTransactionProvider.java
@@ -18,7 +18,6 @@
 package org.apache.phoenix.transaction;
 
 import java.io.IOException;
-import java.net.ServerSocket;
 import java.sql.SQLException;
 import java.util.Arrays;
 
@@ -42,14 +41,11 @@ import org.apache.phoenix.exception.SQLExceptionInfo;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.ConnectionInfo;
 import org.apache.phoenix.transaction.TransactionFactory.Provider;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import com.google.inject.Guice;
 import com.google.inject.Injector;
 
 public class OmidTransactionProvider implements PhoenixTransactionProvider {
-    private static final Logger logger = LoggerFactory.getLogger(OmidTransactionProvider.class);
     private static final OmidTransactionProvider INSTANCE = new OmidTransactionProvider();
     public static final String OMID_TSO_PORT = "phoenix.omid.tso.port";
     public static final String OMID_TSO_CONFLICT_MAP_SIZE = "phoenix.omid.tso.conflict.map.size";
@@ -122,31 +118,16 @@ public class OmidTransactionProvider implements PhoenixTransactionProvider {
         return commitTableClient;
     }
     
-    /**
-     * Find a random free port in localhost for binding.
-     * @return A port number or -1 for failure.
-     */
-    private static int getRandomPort() {
-      try (ServerSocket socket = new ServerSocket(0)) {
-        return socket.getLocalPort();
-      } catch (IOException e) {
-        return -1;
-      }
-    }
-
     @Override
     public PhoenixTransactionService getTransactionService(Configuration config, ConnectionInfo connectionInfo) throws  SQLException{
         TSOServerConfig tsoConfig = new TSOServerConfig();
         TSOServer tso;
 
-        int port;
         String portStr = config.get(OMID_TSO_PORT);
-        if (portStr == null) { // For testing, we generate a random port.
-            port = getRandomPort();
-            logger.warn("Using random port for " + OMID_TSO_PORT + " of " + port);
-        } else {
-            port = Integer.parseInt(portStr);
+        if (portStr == null) {
+            throw new IllegalArgumentException(OMID_TSO_PORT + " config parameter must be bound");
         }
+        int  port = Integer.parseInt(portStr);
 
         tsoConfig.setPort(port);
         tsoConfig.setConflictMapSize(config.getInt(OMID_TSO_CONFLICT_MAP_SIZE, DEFAULT_OMID_TSO_CONFLICT_MAP_SIZE));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/0f2b1b8b/phoenix-core/src/test/java/org/apache/phoenix/query/QueryServicesTestImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/QueryServicesTestImpl.java b/phoenix-core/src/test/java/org/apache/phoenix/query/QueryServicesTestImpl.java
index ab45633..49fb8e8 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/query/QueryServicesTestImpl.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/query/QueryServicesTestImpl.java
@@ -22,10 +22,11 @@ import static org.apache.phoenix.query.QueryServicesOptions.withDefaults;
 
 import org.apache.curator.shaded.com.google.common.io.Files;
 import org.apache.hadoop.hbase.regionserver.wal.IndexedWALEditCodec;
+import org.apache.phoenix.transaction.OmidTransactionProvider;
 import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.ReadOnlyProps;
+import org.apache.phoenix.util.TestUtil;
 import org.apache.tephra.TxConstants;
-import org.apache.twill.internal.utils.Networks;
 
 
 /**
@@ -128,11 +129,12 @@ public final class QueryServicesTestImpl extends BaseQueryServicesImpl {
                 .set(TxConstants.Manager.CFG_DO_PERSIST, false)
                 .set(TxConstants.Service.CFG_DATA_TX_CLIENT_RETRY_STRATEGY, "n-times")
                 .set(TxConstants.Service.CFG_DATA_TX_CLIENT_ATTEMPTS, 1)
-                .set(TxConstants.Service.CFG_DATA_TX_BIND_PORT, Networks.getRandomPort())
-                .set(TxConstants.Service.CFG_DATA_TX_CLIENT_DISCOVERY_TIMEOUT_SEC, 60)
+                .set(TxConstants.Service.CFG_DATA_TX_BIND_PORT, TestUtil.getRandomPort())
                 .set(TxConstants.Manager.CFG_TX_SNAPSHOT_DIR, Files.createTempDir().getAbsolutePath())
                 .set(TxConstants.Manager.CFG_TX_TIMEOUT, DEFAULT_TXN_TIMEOUT_SECONDS)
                 .set(TxConstants.Manager.CFG_TX_SNAPSHOT_INTERVAL, 5L)
+                // setup default test configs for Omid
+                .set(OmidTransactionProvider.OMID_TSO_PORT, TestUtil.getRandomPort())
                 ;
     }
     

http://git-wip-us.apache.org/repos/asf/phoenix/blob/0f2b1b8b/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java b/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
index f0a26b9..f3faa0c 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
@@ -36,6 +36,7 @@ import static org.junit.Assert.fail;
 import java.io.File;
 import java.io.IOException;
 import java.math.BigDecimal;
+import java.net.ServerSocket;
 import java.sql.Connection;
 import java.sql.Date;
 import java.sql.DriverManager;
@@ -1105,4 +1106,17 @@ public class TestUtil {
         }
         return filteredData;
     }
+    
+    /**
+     * Find a random free port in localhost for binding.
+     * @return A port number or -1 for failure.
+     */
+    public static int getRandomPort() {
+        try (ServerSocket socket = new ServerSocket(0)) {
+            socket.setReuseAddress(true);
+            return socket.getLocalPort();
+        } catch (IOException e) {
+            return -1;
+        }
+    }
 }