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/05/09 20:31:41 UTC

[01/10] phoenix git commit: PHOENIX-4685 Properly handle connection caching for Phoenix inside RegionServers-addendum(Rajeshbabu)

Repository: phoenix
Updated Branches:
  refs/heads/4.x-cdh5.11 8ed7eb0f5 -> 810ed4e37


PHOENIX-4685 Properly handle connection caching for Phoenix inside RegionServers-addendum(Rajeshbabu)


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

Branch: refs/heads/4.x-cdh5.11
Commit: 5ee89b440e4394b043674a2a0379339ef14789c6
Parents: 90dc5ef
Author: Rajeshbabu Chintaguntla <ra...@apache.org>
Authored: Wed May 9 18:13:38 2018 +0530
Committer: James Taylor <jt...@salesforce.com>
Committed: Wed May 9 13:27:36 2018 -0700

----------------------------------------------------------------------
 .../src/main/java/org/apache/phoenix/util/ServerUtil.java         | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/5ee89b44/phoenix-core/src/main/java/org/apache/phoenix/util/ServerUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/ServerUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/ServerUtil.java
index d80b6fc..9190373 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/ServerUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/ServerUtil.java
@@ -26,6 +26,7 @@ import java.io.IOException;
 import java.sql.SQLException;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ExecutorService;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -66,8 +67,6 @@ import org.apache.phoenix.hbase.index.write.IndexWriterUtils;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.query.QueryServicesOptions;
 import org.apache.phoenix.schema.StaleRegionBoundaryCacheException;
-import org.jboss.netty.util.internal.ConcurrentHashMap;
-
 
 @SuppressWarnings("deprecation")
 public class ServerUtil {


[02/10] phoenix git commit: PHOENIX-4685 Properly handle connection caching for Phoenix inside RegionServers-addendum(Rajeshbabu)

Posted by ja...@apache.org.
PHOENIX-4685 Properly handle connection caching for Phoenix inside RegionServers-addendum(Rajeshbabu)


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

Branch: refs/heads/4.x-cdh5.11
Commit: 90dc5ef487d467d169551ce7410ec8a6bc8c7dbd
Parents: dde1054
Author: Rajeshbabu Chintaguntla <ra...@apache.org>
Authored: Tue May 8 20:37:50 2018 +0530
Committer: James Taylor <jt...@salesforce.com>
Committed: Wed May 9 13:27:36 2018 -0700

----------------------------------------------------------------------
 phoenix-core/src/main/java/org/apache/phoenix/util/ServerUtil.java | 1 -
 1 file changed, 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/90dc5ef4/phoenix-core/src/main/java/org/apache/phoenix/util/ServerUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/ServerUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/ServerUtil.java
index 2dab076..d80b6fc 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/ServerUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/ServerUtil.java
@@ -27,7 +27,6 @@ import java.sql.SQLException;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.ExecutorService;
-import java.util.function.Function;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 


[05/10] phoenix git commit: PHOENIX-3856 StatementContext class constructor not honouring supplied scan object (Sukumar Maddineni)

Posted by ja...@apache.org.
PHOENIX-3856 StatementContext class constructor not honouring supplied scan object (Sukumar Maddineni)


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

Branch: refs/heads/4.x-cdh5.11
Commit: d23239fd0acd4613c565c179f4880621300f3405
Parents: 1976926
Author: James Taylor <jt...@salesforce.com>
Authored: Thu May 3 09:32:57 2018 -0700
Committer: James Taylor <jt...@salesforce.com>
Committed: Wed May 9 13:29:39 2018 -0700

----------------------------------------------------------------------
 .../src/main/java/org/apache/phoenix/compile/StatementContext.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/d23239fd/phoenix-core/src/main/java/org/apache/phoenix/compile/StatementContext.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/StatementContext.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/StatementContext.java
index c105046..3e5c8f2 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/StatementContext.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/StatementContext.java
@@ -98,7 +98,7 @@ public class StatementContext {
     }
 
     public StatementContext(PhoenixStatement statement, Scan scan) {
-        this(statement, FromCompiler.EMPTY_TABLE_RESOLVER, new Scan(), new SequenceManager(statement));
+        this(statement, FromCompiler.EMPTY_TABLE_RESOLVER, scan, new SequenceManager(statement));
     }
 
     public StatementContext(PhoenixStatement statement, ColumnResolver resolver) {


[03/10] phoenix git commit: PHOENIX-4685 Properly handle connection caching for Phoenix inside RegionServers(Rajeshbabu)

Posted by ja...@apache.org.
PHOENIX-4685 Properly handle connection caching for Phoenix inside RegionServers(Rajeshbabu)


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

Branch: refs/heads/4.x-cdh5.11
Commit: dde1054f34fe1784447307600d0949f35e6f475a
Parents: 8ed7eb0
Author: Rajeshbabu Chintaguntla <ra...@apache.org>
Authored: Tue May 8 09:26:41 2018 +0530
Committer: James Taylor <jt...@salesforce.com>
Committed: Wed May 9 13:27:36 2018 -0700

----------------------------------------------------------------------
 .../DelegateRegionCoprocessorEnvironment.java   |   7 +-
 .../UngroupedAggregateRegionObserver.java       |  14 +-
 .../org/apache/phoenix/hbase/index/Indexer.java |  19 +--
 .../hbase/index/write/IndexWriterUtils.java     |  27 +---
 .../index/PhoenixTransactionalIndexer.java      |  18 +--
 .../org/apache/phoenix/util/ServerUtil.java     | 141 ++++++++++++++++---
 6 files changed, 142 insertions(+), 84 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/dde1054f/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/DelegateRegionCoprocessorEnvironment.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/DelegateRegionCoprocessorEnvironment.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/DelegateRegionCoprocessorEnvironment.java
index 284d53c..a791f4a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/DelegateRegionCoprocessorEnvironment.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/DelegateRegionCoprocessorEnvironment.java
@@ -32,6 +32,7 @@ import org.apache.hadoop.hbase.regionserver.RegionServerServices;
 import org.apache.phoenix.hbase.index.table.HTableFactory;
 import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
 import org.apache.phoenix.util.ServerUtil;
+import org.apache.phoenix.util.ServerUtil.ConnectionType;
 
 /**
  * Class to encapsulate {@link RegionCoprocessorEnvironment} for phoenix coprocessors. Often we
@@ -44,10 +45,10 @@ public class DelegateRegionCoprocessorEnvironment implements RegionCoprocessorEn
     private RegionCoprocessorEnvironment delegate;
     private HTableFactory tableFactory;
 
-    public DelegateRegionCoprocessorEnvironment(Configuration config, RegionCoprocessorEnvironment delegate) {
-        this.config = config;
+    public DelegateRegionCoprocessorEnvironment(RegionCoprocessorEnvironment delegate, ConnectionType connectionType) {
+        this.config = ServerUtil.ConnectionFactory.getTypeSpecificConfiguration(connectionType, delegate.getConfiguration());
         this.delegate = delegate;
-        this.tableFactory = ServerUtil.getDelegateHTableFactory(this, config);
+        this.tableFactory = ServerUtil.getDelegateHTableFactory(this, connectionType);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/dde1054f/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
index 6bee65c..14213f4 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
@@ -144,6 +144,7 @@ import org.apache.phoenix.util.ReadOnlyProps;
 import org.apache.phoenix.util.ScanUtil;
 import org.apache.phoenix.util.SchemaUtil;
 import org.apache.phoenix.util.ServerUtil;
+import org.apache.phoenix.util.ServerUtil.ConnectionType;
 import org.apache.phoenix.util.StringUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -225,14 +226,7 @@ public class UngroupedAggregateRegionObserver extends BaseScannerRegionObserver
         upsertSelectConfig.setClass(RpcControllerFactory.CUSTOM_CONTROLLER_CONF_KEY,
             InterRegionServerIndexRpcControllerFactory.class, RpcControllerFactory.class);
 
-        compactionConfig = PropertiesUtil.cloneConfig(e.getConfiguration());
-        // lower the number of rpc retries, so we don't hang the compaction
-        compactionConfig.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER,
-            e.getConfiguration().getInt(QueryServices.METADATA_WRITE_RETRIES_NUMBER,
-                QueryServicesOptions.DEFAULT_METADATA_WRITE_RETRIES_NUMBER));
-        compactionConfig.setInt(HConstants.HBASE_CLIENT_PAUSE,
-            e.getConfiguration().getInt(QueryServices.METADATA_WRITE_RETRY_PAUSE,
-                QueryServicesOptions.DEFAULT_METADATA_WRITE_RETRY_PAUSE));
+        compactionConfig = ServerUtil.getCompactionConfig(e.getConfiguration());
 
         // For retries of index write failures, use the same # of retries as the rebuilder
         indexWriteConfig = PropertiesUtil.cloneConfig(e.getConfiguration());
@@ -984,7 +978,9 @@ public class UngroupedAggregateRegionObserver extends BaseScannerRegionObserver
                     InternalScanner internalScanner = scanner;
                     try {
                         long clientTimeStamp = EnvironmentEdgeManager.currentTimeMillis();
-                        DelegateRegionCoprocessorEnvironment compactionConfEnv = new DelegateRegionCoprocessorEnvironment(compactionConfig, c.getEnvironment());
+                        DelegateRegionCoprocessorEnvironment compactionConfEnv =
+                                new DelegateRegionCoprocessorEnvironment(c.getEnvironment(),
+                                        ConnectionType.COMPACTION_CONNECTION);
                         StatisticsCollector stats = StatisticsCollectorFactory.createStatisticsCollector(
                             compactionConfEnv, table.getNameAsString(), clientTimeStamp,
                             store.getFamily().getName());

http://git-wip-us.apache.org/repos/asf/phoenix/blob/dde1054f/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/Indexer.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/Indexer.java b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/Indexer.java
index 1ef09fe..e4e6991 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/Indexer.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/Indexer.java
@@ -93,6 +93,7 @@ import org.apache.phoenix.util.EnvironmentEdgeManager;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.ScanUtil;
 import org.apache.phoenix.util.ServerUtil;
+import org.apache.phoenix.util.ServerUtil.ConnectionType;
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Multimap;
@@ -220,25 +221,11 @@ public class Indexer extends BaseRegionObserver {
     
         this.builder = new IndexBuildManager(env);
         // Clone the config since it is shared
-        Configuration clonedConfig = PropertiesUtil.cloneConfig(e.getConfiguration());
-        /*
-         * Set the rpc controller factory so that the HTables used by IndexWriter would
-         * set the correct priorities on the remote RPC calls.
-         */
-        clonedConfig.setClass(RpcControllerFactory.CUSTOM_CONTROLLER_CONF_KEY,
-                InterRegionServerIndexRpcControllerFactory.class, RpcControllerFactory.class);
-        // lower the number of rpc retries.  We inherit config from HConnectionManager#setServerSideHConnectionRetries,
-        // which by default uses a multiplier of 10.  That is too many retries for our synchronous index writes
-        clonedConfig.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER,
-            env.getConfiguration().getInt(INDEX_WRITER_RPC_RETRIES_NUMBER,
-                DEFAULT_INDEX_WRITER_RPC_RETRIES_NUMBER));
-        clonedConfig.setInt(HConstants.HBASE_CLIENT_PAUSE, env.getConfiguration()
-            .getInt(INDEX_WRITER_RPC_PAUSE, DEFAULT_INDEX_WRITER_RPC_PAUSE));
-        DelegateRegionCoprocessorEnvironment indexWriterEnv = new DelegateRegionCoprocessorEnvironment(clonedConfig, env);
+        DelegateRegionCoprocessorEnvironment indexWriterEnv = new DelegateRegionCoprocessorEnvironment(env, ConnectionType.INDEX_WRITER_CONNECTION);
         // setup the actual index writer
         this.writer = new IndexWriter(indexWriterEnv, serverName + "-index-writer");
         
-        this.rowLockWaitDuration = clonedConfig.getInt("hbase.rowlock.wait.duration",
+        this.rowLockWaitDuration = env.getConfiguration().getInt("hbase.rowlock.wait.duration",
                 DEFAULT_ROWLOCK_WAIT_DURATION);
         this.lockManager = new LockManager();
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/dde1054f/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/write/IndexWriterUtils.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/write/IndexWriterUtils.java b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/write/IndexWriterUtils.java
index 0d3004f..ef53b9f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/write/IndexWriterUtils.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/write/IndexWriterUtils.java
@@ -26,6 +26,7 @@ import org.apache.phoenix.hbase.index.table.HTableFactory;
 import org.apache.phoenix.hbase.index.util.IndexManagementUtil;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.ServerUtil;
+import org.apache.phoenix.util.ServerUtil.ConnectionType;
 
 public class IndexWriterUtils {
 
@@ -50,9 +51,9 @@ public class IndexWriterUtils {
    * threads. Currently, HBase doesn't support a custom thread-pool to back the HTable via the
    * coprocesor hooks, so we can't modify this behavior.
    */
-  private static final String INDEX_WRITER_PER_TABLE_THREADS_CONF_KEY =
+  public static final String INDEX_WRITER_PER_TABLE_THREADS_CONF_KEY =
       "index.writer.threads.pertable.max";
-  private static final int DEFAULT_NUM_PER_TABLE_THREADS = Integer.MAX_VALUE;
+  public static final int DEFAULT_NUM_PER_TABLE_THREADS = Integer.MAX_VALUE;
 
   /** Configuration key that HBase uses to set the max number of threads for an HTable */
   public static final String HTABLE_THREAD_KEY = "hbase.htable.threads.max";
@@ -79,19 +80,7 @@ public class IndexWriterUtils {
   }
 
     public static HTableFactory getDefaultDelegateHTableFactory(CoprocessorEnvironment env) {
-        // create a simple delegate factory, setup the way we need
-        Configuration conf = PropertiesUtil.cloneConfig(env.getConfiguration());
-        setHTableThreads(conf);
-        return ServerUtil.getDelegateHTableFactory(env, conf);
-    }
-
-    private static void setHTableThreads(Configuration conf) {
-        // set the number of threads allowed per table.
-        int htableThreads =
-                conf.getInt(IndexWriterUtils.INDEX_WRITER_PER_TABLE_THREADS_CONF_KEY,
-                    IndexWriterUtils.DEFAULT_NUM_PER_TABLE_THREADS);
-        LOG.trace("Creating HTableFactory with " + htableThreads + " threads for each HTable.");
-        IndexManagementUtil.setIfNotSet(conf, HTABLE_THREAD_KEY, htableThreads);
+        return ServerUtil.getDelegateHTableFactory(env, ConnectionType.INDEX_WRITER_CONNECTION_WITH_CUSTOM_THREADS);
     }
 
     /**
@@ -99,12 +88,8 @@ public class IndexWriterUtils {
      * instead to avoid tying up the handler
      */
     public static HTableFactory getNoRetriesHTableFactory(CoprocessorEnvironment env) {
-        Configuration conf = PropertiesUtil.cloneConfig(env.getConfiguration());
-        setHTableThreads(conf);
-        // note in HBase 2+, numTries = numRetries + 1
-        // in prior versions, numTries = numRetries
-        conf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1);
-        return ServerUtil.getDelegateHTableFactory(env, conf);
+        return ServerUtil.getDelegateHTableFactory(env,
+            ConnectionType.INDEX_WRITER_CONNECTION_WITH_CUSTOM_THREADS_NO_RETRIES);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/dde1054f/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixTransactionalIndexer.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixTransactionalIndexer.java b/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixTransactionalIndexer.java
index 610ea44..0893bf6 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixTransactionalIndexer.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixTransactionalIndexer.java
@@ -55,6 +55,7 @@ import org.apache.phoenix.trace.util.NullSpan;
 import org.apache.phoenix.transaction.PhoenixTransactionContext;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.ServerUtil;
+import org.apache.phoenix.util.ServerUtil.ConnectionType;
 
 /**
  * Do all the work of managing local index updates for a transactional table from a single coprocessor. Since the transaction
@@ -90,22 +91,7 @@ public class PhoenixTransactionalIndexer extends BaseRegionObserver {
         Configuration conf = e.getConfiguration();
         String serverName = env.getRegionServerServices().getServerName().getServerName();
         codec = new PhoenixIndexCodec(conf, env.getRegion().getRegionInfo().getStartKey(), env.getRegion().getRegionInfo().getEndKey(), env.getRegionInfo().getTable().getName());
-        // Clone the config since it is shared
-        Configuration clonedConfig = PropertiesUtil.cloneConfig(e.getConfiguration());
-        /*
-         * Set the rpc controller factory so that the HTables used by IndexWriter would
-         * set the correct priorities on the remote RPC calls.
-         */
-        clonedConfig.setClass(RpcControllerFactory.CUSTOM_CONTROLLER_CONF_KEY,
-                InterRegionServerIndexRpcControllerFactory.class, RpcControllerFactory.class);
-        // lower the number of rpc retries.  We inherit config from HConnectionManager#setServerSideHConnectionRetries,
-        // which by default uses a multiplier of 10.  That is too many retries for our synchronous index writes
-        clonedConfig.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER,
-            env.getConfiguration().getInt(INDEX_WRITER_RPC_RETRIES_NUMBER,
-                DEFAULT_INDEX_WRITER_RPC_RETRIES_NUMBER));
-        clonedConfig.setInt(HConstants.HBASE_CLIENT_PAUSE, env.getConfiguration()
-            .getInt(INDEX_WRITER_RPC_PAUSE, DEFAULT_INDEX_WRITER_RPC_PAUSE));
-        DelegateRegionCoprocessorEnvironment indexWriterEnv = new DelegateRegionCoprocessorEnvironment(clonedConfig, env);
+        DelegateRegionCoprocessorEnvironment indexWriterEnv = new DelegateRegionCoprocessorEnvironment(env, ConnectionType.INDEX_WRITER_CONNECTION);
         // setup the actual index writer
         // For transactional tables, we keep the index active upon a write failure
         // since we have the all versus none behavior for transactions. Also, we

http://git-wip-us.apache.org/repos/asf/phoenix/blob/dde1054f/phoenix-core/src/main/java/org/apache/phoenix/util/ServerUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/ServerUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/ServerUtil.java
index 4b3cc43..2dab076 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/ServerUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/ServerUtil.java
@@ -17,11 +17,17 @@
  */
 package org.apache.phoenix.util;
 
+import static org.apache.phoenix.hbase.index.write.IndexWriterUtils.DEFAULT_INDEX_WRITER_RPC_PAUSE;
+import static org.apache.phoenix.hbase.index.write.IndexWriterUtils.DEFAULT_INDEX_WRITER_RPC_RETRIES_NUMBER;
+import static org.apache.phoenix.hbase.index.write.IndexWriterUtils.INDEX_WRITER_RPC_PAUSE;
+import static org.apache.phoenix.hbase.index.write.IndexWriterUtils.INDEX_WRITER_RPC_RETRIES_NUMBER;
+
 import java.io.IOException;
 import java.sql.SQLException;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.ExecutorService;
+import java.util.function.Function;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -35,12 +41,15 @@ import org.apache.hadoop.hbase.DoNotRetryIOException;
 import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.NotServingRegionException;
 import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.ClusterConnection;
 import org.apache.hadoop.hbase.client.CoprocessorHConnection;
 import org.apache.hadoop.hbase.client.HConnection;
 import org.apache.hadoop.hbase.client.HTableInterface;
 import org.apache.hadoop.hbase.client.HTablePool;
 import org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException;
 import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
+import org.apache.hadoop.hbase.ipc.RpcControllerFactory;
+import org.apache.hadoop.hbase.ipc.controller.InterRegionServerIndexRpcControllerFactory;
 import org.apache.hadoop.hbase.regionserver.Region;
 import org.apache.hadoop.hbase.regionserver.HRegionServer;
 import org.apache.hadoop.hbase.regionserver.RegionServerServices;
@@ -52,8 +61,13 @@ import org.apache.phoenix.exception.SQLExceptionInfo;
 import org.apache.phoenix.hbase.index.table.CoprocessorHTableFactory;
 import org.apache.phoenix.hbase.index.table.HTableFactory;
 import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
+import org.apache.phoenix.hbase.index.util.IndexManagementUtil;
 import org.apache.phoenix.hbase.index.util.VersionUtil;
+import org.apache.phoenix.hbase.index.write.IndexWriterUtils;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.query.QueryServicesOptions;
 import org.apache.phoenix.schema.StaleRegionBoundaryCacheException;
+import org.jboss.netty.util.internal.ConcurrentHashMap;
 
 
 @SuppressWarnings("deprecation")
@@ -269,12 +283,12 @@ public class ServerUtil {
                     endKey) < 0));
     }
 
-    public static HTableFactory getDelegateHTableFactory(CoprocessorEnvironment env, Configuration conf) {
+    public static HTableFactory getDelegateHTableFactory(CoprocessorEnvironment env, ConnectionType connectionType) {
         if (env instanceof RegionCoprocessorEnvironment) {
             RegionCoprocessorEnvironment e = (RegionCoprocessorEnvironment) env;
             RegionServerServices services = e.getRegionServerServices();
             if (services instanceof HRegionServer) {
-                return new CoprocessorHConnectionTableFactory(conf, (HRegionServer) services);
+                return new CoprocessorHConnectionTableFactory(env.getConfiguration(), (HRegionServer) services, connectionType);
             }
         }
         return new CoprocessorHTableFactory(env);
@@ -286,44 +300,133 @@ public class ServerUtil {
      * https://issues.apache.org/jira/browse/HBASE-18359
      */
     public static class CoprocessorHConnectionTableFactory implements HTableFactory {
-        @GuardedBy("CoprocessorHConnectionTableFactory.this")
-        private HConnection connection;
         private final Configuration conf;
         private final HRegionServer server;
+        private final ConnectionType connectionType;
 
-        CoprocessorHConnectionTableFactory(Configuration conf, HRegionServer server) {
+        CoprocessorHConnectionTableFactory(Configuration conf, HRegionServer server, ConnectionType connectionType) {
             this.conf = conf;
             this.server = server;
+            this.connectionType = connectionType;
         }
 
-        private synchronized HConnection getConnection(Configuration conf) throws IOException {
-            if (connection == null || connection.isClosed()) {
-                connection = new CoprocessorHConnection(conf, server);
-            }
-            return connection;
+        private ClusterConnection getConnection() throws IOException {
+            return ConnectionFactory.getConnection(connectionType, conf, server);
         }
 
         @Override
         public HTableInterface getTable(ImmutableBytesPtr tablename) throws IOException {
-            return getConnection(conf).getTable(tablename.copyBytesIfNecessary());
+            return getConnection().getTable(tablename.copyBytesIfNecessary());
         }
 
         @Override
         public synchronized void shutdown() {
-            try {
-                if (connection != null && !connection.isClosed()) {
-                    connection.close();
-                }
-            } catch (Throwable e) {
-                LOG.warn("Error while trying to close the HConnection used by CoprocessorHConnectionTableFactory", e);
-            }
+            // We need not close the cached connections as they are shared across the server.
         }
 
         @Override
         public HTableInterface getTable(ImmutableBytesPtr tablename, ExecutorService pool)
                 throws IOException {
-            return getConnection(conf).getTable(tablename.copyBytesIfNecessary(), pool);
+            return getConnection().getTable(tablename.copyBytesIfNecessary(), pool);
+        }
+    }
+
+    public static enum ConnectionType {
+        COMPACTION_CONNECTION,
+        INDEX_WRITER_CONNECTION,
+        INDEX_WRITER_CONNECTION_WITH_CUSTOM_THREADS,
+        INDEX_WRITER_CONNECTION_WITH_CUSTOM_THREADS_NO_RETRIES,
+        DEFAULT_SERVER_CONNECTION;
+    }
+
+    public static class ConnectionFactory {
+        
+        private static Map<ConnectionType, ClusterConnection> connections =
+                new ConcurrentHashMap<ConnectionType, ClusterConnection>();
+
+        public static ClusterConnection getConnection(final ConnectionType connectionType, final Configuration conf, final HRegionServer server) throws IOException {
+            ClusterConnection connection = null;
+            if((connection = connections.get(connectionType)) == null) {
+                synchronized (CoprocessorHConnectionTableFactory.class) {
+                    if(connections.get(connectionType) == null) {
+                        connection = new CoprocessorHConnection(conf, server);
+                        connections.put(connectionType, connection);
+                        return connection;
+                    }
+                }
+            }
+            return connection;
         }
+
+        public static Configuration getTypeSpecificConfiguration(ConnectionType connectionType, Configuration conf) {
+            switch (connectionType) {
+            case COMPACTION_CONNECTION:
+                return getCompactionConfig(conf);
+            case DEFAULT_SERVER_CONNECTION:
+                return conf;
+            case INDEX_WRITER_CONNECTION:
+                return getIndexWriterConnection(conf);
+            case INDEX_WRITER_CONNECTION_WITH_CUSTOM_THREADS:
+                return getIndexWriterConfigurationWithCustomThreads(conf);
+            case INDEX_WRITER_CONNECTION_WITH_CUSTOM_THREADS_NO_RETRIES:
+                return getNoRetriesIndexWriterConfigurationWithCustomThreads(conf);
+            default:
+                return conf;
+            }
+        }
+    }
+
+    public static Configuration getCompactionConfig(Configuration conf) {
+        Configuration compactionConfig = PropertiesUtil.cloneConfig(conf);
+        // lower the number of rpc retries, so we don't hang the compaction
+        compactionConfig.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER,
+            conf.getInt(QueryServices.METADATA_WRITE_RETRIES_NUMBER,
+                QueryServicesOptions.DEFAULT_METADATA_WRITE_RETRIES_NUMBER));
+        compactionConfig.setInt(HConstants.HBASE_CLIENT_PAUSE,
+            conf.getInt(QueryServices.METADATA_WRITE_RETRY_PAUSE,
+                QueryServicesOptions.DEFAULT_METADATA_WRITE_RETRY_PAUSE));
+        return compactionConfig;
+    }
+
+    public static Configuration getIndexWriterConnection(Configuration conf) {
+        Configuration clonedConfig = PropertiesUtil.cloneConfig(conf);
+        /*
+         * Set the rpc controller factory so that the HTables used by IndexWriter would
+         * set the correct priorities on the remote RPC calls.
+         */
+        clonedConfig.setClass(RpcControllerFactory.CUSTOM_CONTROLLER_CONF_KEY,
+                InterRegionServerIndexRpcControllerFactory.class, RpcControllerFactory.class);
+        // lower the number of rpc retries.  We inherit config from HConnectionManager#setServerSideHConnectionRetries,
+        // which by default uses a multiplier of 10.  That is too many retries for our synchronous index writes
+        clonedConfig.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER,
+            conf.getInt(INDEX_WRITER_RPC_RETRIES_NUMBER,
+                DEFAULT_INDEX_WRITER_RPC_RETRIES_NUMBER));
+        clonedConfig.setInt(HConstants.HBASE_CLIENT_PAUSE, conf
+            .getInt(INDEX_WRITER_RPC_PAUSE, DEFAULT_INDEX_WRITER_RPC_PAUSE));
+        return clonedConfig;
+    }
+
+    public static Configuration getIndexWriterConfigurationWithCustomThreads(Configuration conf) {
+        Configuration clonedConfig = PropertiesUtil.cloneConfig(conf);
+        setHTableThreads(clonedConfig);
+        return clonedConfig;
+    }
+
+    private static void setHTableThreads(Configuration conf) {
+        // set the number of threads allowed per table.
+        int htableThreads =
+                conf.getInt(IndexWriterUtils.INDEX_WRITER_PER_TABLE_THREADS_CONF_KEY,
+                    IndexWriterUtils.DEFAULT_NUM_PER_TABLE_THREADS);
+        IndexManagementUtil.setIfNotSet(conf, IndexWriterUtils.HTABLE_THREAD_KEY, htableThreads);
+    }
+    
+    public static Configuration getNoRetriesIndexWriterConfigurationWithCustomThreads(Configuration conf) {
+        Configuration clonedConf = getIndexWriterConfigurationWithCustomThreads(conf);
+        // note in HBase 2+, numTries = numRetries + 1
+        // in prior versions, numTries = numRetries
+        clonedConf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1);
+        return clonedConf;
+
     }
 
 }


[04/10] phoenix git commit: PHOENIX-4732 Improve config defaults for async secondary index MR jobs

Posted by ja...@apache.org.
PHOENIX-4732 Improve config defaults for async secondary index MR jobs


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

Branch: refs/heads/4.x-cdh5.11
Commit: 197692686b83f45ce622f806acf3fad968e8c238
Parents: 5ee89b4
Author: James Taylor <jt...@salesforce.com>
Authored: Tue May 8 15:26:44 2018 -0700
Committer: James Taylor <jt...@salesforce.com>
Committed: Wed May 9 13:29:37 2018 -0700

----------------------------------------------------------------------
 .../index/automation/PhoenixMRJobSubmitter.java | 48 ++++++++++++++++++--
 .../apache/phoenix/util/PhoenixMRJobUtil.java   | 18 +++-----
 2 files changed, 52 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/19769268/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/automation/PhoenixMRJobSubmitter.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/automation/PhoenixMRJobSubmitter.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/automation/PhoenixMRJobSubmitter.java
index 9c447e8..d86802a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/automation/PhoenixMRJobSubmitter.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/automation/PhoenixMRJobSubmitter.java
@@ -45,6 +45,7 @@ import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hbase.HBaseConfiguration;
 import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
+import org.apache.hadoop.mapreduce.MRJobConfig;
 import org.apache.hadoop.security.UserGroupInformation;
 import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
 import org.apache.phoenix.mapreduce.index.IndexTool;
@@ -53,8 +54,8 @@ import org.apache.phoenix.schema.PTable.IndexType;
 import org.apache.phoenix.schema.PTableType;
 import org.apache.phoenix.schema.types.PDate;
 import org.apache.phoenix.util.PhoenixMRJobUtil;
-import org.apache.phoenix.util.UpgradeUtil;
 import org.apache.phoenix.util.PhoenixMRJobUtil.MR_SCHEDULER_TYPE;
+import org.apache.phoenix.util.UpgradeUtil;
 import org.apache.phoenix.util.ZKBasedMasterElectionUtil;
 import org.codehaus.jettison.json.JSONArray;
 import org.codehaus.jettison.json.JSONObject;
@@ -69,8 +70,28 @@ public class PhoenixMRJobSubmitter {
     // Lock to elect a master node that submits the Phoenix Secondary Index MR Jobs
     private static final String PHOENIX_LOCKS_PARENT =
             "/phoenix/automated-mr-index-build-leader-election";
+    public static final String PHOENIX_MR_CLIENT_SCANNER_TIMEOUT_PERIOD =
+            "phoenix.mr.client.scanner.timeout.period";
+    public static final String PHOENIX_MR_RPC_TIMEOUT =
+            "phoenix.mr.rpc.timeout";
+    public static final String PHOENIX_MR_TASK_TIMEOUT =
+            "phoenix.mr.task.timeout";
+    public static final String PHOENIX_MR_CLIENT_RETRIES_NUMBER =
+            "phoenix.mr.client.retries.number";
+    public static final String PHOENIX_MR_CLIENT_PAUSE =
+            "phoenix.mr.client.retries.number";
+    public static final String PHOENIX_MR_ZK_RECOVERY_RETRY =
+            "phoenix.mr.zk.recovery.retry";
     private static final String AUTO_INDEX_BUILD_LOCK_NAME = "ActiveStandbyElectorLock";
-
+    private static final int DEFAULT_TIMEOUT_IN_MILLIS = 600000;
+    public static final int DEFAULT_MR_CLIENT_SCANNER_TIMEOUT_PERIOD = DEFAULT_TIMEOUT_IN_MILLIS;
+    public static final int DEFAULT_MR_RPC_TIMEOUT = DEFAULT_TIMEOUT_IN_MILLIS;
+    public static final int DEFAULT_MR_TASK_TIMEOUT = DEFAULT_TIMEOUT_IN_MILLIS;
+    // Reduced HBase/Zookeeper Client Retries
+    public static final int DEFAULT_MR_CLIENT_RETRIES_NUMBER = 10;
+    public static final int DEFAULT_MR_CLIENT_PAUSE = 1000;
+    public static final int DEFAULT_MR_ZK_RECOVERY_RETRY = 1;
+    
     public static final String CANDIDATE_INDEX_INFO_QUERY = "SELECT "
             + PhoenixDatabaseMetaData.INDEX_TYPE + ","
             + PhoenixDatabaseMetaData.DATA_TABLE_NAME + ", "
@@ -103,7 +124,28 @@ public class PhoenixMRJobSubmitter {
         }
         this.conf = conf;
 
-        PhoenixMRJobUtil.updateTimeoutsToFailFast(conf);
+        // Have Phoenix specific properties for defaults to enable potential override
+        conf.setLong(HConstants.HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD, 
+                conf.getLong(PHOENIX_MR_CLIENT_SCANNER_TIMEOUT_PERIOD,
+                        DEFAULT_MR_CLIENT_SCANNER_TIMEOUT_PERIOD));
+        conf.setLong(HConstants.HBASE_RPC_TIMEOUT_KEY, 
+                conf.getLong(PHOENIX_MR_RPC_TIMEOUT,
+                        DEFAULT_MR_RPC_TIMEOUT));
+        conf.setLong(MRJobConfig.TASK_TIMEOUT, 
+                conf.getLong(PHOENIX_MR_TASK_TIMEOUT,
+                        DEFAULT_MR_TASK_TIMEOUT));
+
+        // Reduced HBase Client Retries
+        conf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 
+                conf.getInt(PHOENIX_MR_CLIENT_RETRIES_NUMBER,
+                        DEFAULT_MR_CLIENT_RETRIES_NUMBER));
+        conf.setInt(HConstants.HBASE_CLIENT_PAUSE, 
+                conf.getInt(PHOENIX_MR_CLIENT_PAUSE,
+                        DEFAULT_MR_CLIENT_PAUSE));
+        conf.setInt("zookeeper.recovery.retry", 
+                conf.getInt(PHOENIX_MR_ZK_RECOVERY_RETRY,
+                        DEFAULT_MR_ZK_RECOVERY_RETRY));
+        
         String schedulerType =
                 conf.get(PhoenixMRJobUtil.PHOENIX_MR_SCHEDULER_TYPE_NAME,
                     MR_SCHEDULER_TYPE.NONE.toString());

http://git-wip-us.apache.org/repos/asf/phoenix/blob/19769268/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixMRJobUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixMRJobUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixMRJobUtil.java
index 4f01237..42732b9 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixMRJobUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixMRJobUtil.java
@@ -52,21 +52,19 @@ public class PhoenixMRJobUtil {
     private static final String ACTIVE_STANDBY_ELECTOR_LOCK = "ActiveStandbyElectorLock";
     private static final String RM_APPS_GET_ENDPOINT = "/ws/v1/cluster/apps";
 
-    // Reduced HBase Client Retries
-    private static final int CLIENT_RETRIES_NUMBER = 2;
-    private static final long CLIENT_PAUSE_TIME = 1000;
-    private static final int ZOOKEEPER_RECOVERY_RETRY_COUNT = 1;
-
     public static final String PHOENIX_INDEX_MR_QUEUE_NAME_PROPERTY =
             "phoenix.index.mr.scheduler.capacity.queuename";
     public static final String PHOENIX_INDEX_MR_MAP_MEMORY_PROPERTY =
             "phoenix.index.mr.scheduler.capacity.mapMemoryMB";
+    public static final String PHOENIX_MR_CONCURRENT_MAP_LIMIT_PROPERTY =
+    		"phoenix.mr.concurrent.map.limit";
 
     // Default MR Capacity Scheduler Configurations for Phoenix MR Index Build
     // Jobs
     public static final String QUEUE_NAME = "mapreduce.job.queuename";
     public static final String DEFAULT_QUEUE_NAME = "default";
     public static final String MAP_MEMORY_MB = "mapreduce.map.memory.mb";
+    public static final int DEFAULT_MR_CONCURRENT_MAP_LIMIT = 20;
     public static final int DEFAULT_MAP_MEMROY_MB = 5120;
     public static final String MAP_JAVA_OPTS = "mapreduce.map.java.opts";
     public static final String XMX_OPT = "-Xmx";
@@ -211,12 +209,6 @@ public class PhoenixMRJobUtil {
         return rmPort;
     }
 
-    public static void updateTimeoutsToFailFast(Configuration conf) {
-        conf.set("hbase.client.retries.number", String.valueOf(CLIENT_RETRIES_NUMBER));
-        conf.set("zookeeper.recovery.retry", String.valueOf(ZOOKEEPER_RECOVERY_RETRY_COUNT));
-        conf.set("hbase.client.pause", String.valueOf(CLIENT_PAUSE_TIME));
-    }
-
     /**
      * This method set the configuration values for Capacity scheduler.
      * @param conf - Configuration to which Capacity Queue information to be added
@@ -224,6 +216,10 @@ public class PhoenixMRJobUtil {
     public static void updateCapacityQueueInfo(Configuration conf) {
         conf.set(QUEUE_NAME,
             conf.get(PHOENIX_INDEX_MR_QUEUE_NAME_PROPERTY, DEFAULT_QUEUE_NAME));
+
+        conf.setInt(MRJobConfig.JOB_RUNNING_MAP_LIMIT,
+                conf.getInt(PHOENIX_MR_CONCURRENT_MAP_LIMIT_PROPERTY, DEFAULT_MR_CONCURRENT_MAP_LIMIT));
+
         int mapMemoryMB = conf.getInt(PHOENIX_INDEX_MR_MAP_MEMORY_PROPERTY, DEFAULT_MAP_MEMROY_MB);
 
         conf.setInt(MAP_MEMORY_MB, mapMemoryMB);


[09/10] phoenix git commit: PHOENIX-3270 Remove @Ignore tag for TransactionIT.testNonTxToTxTableFailure()

Posted by ja...@apache.org.
PHOENIX-3270 Remove @Ignore tag for TransactionIT.testNonTxToTxTableFailure()


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

Branch: refs/heads/4.x-cdh5.11
Commit: 59aa56ea3f34592a25f141fdafc03d2da5b905ab
Parents: d23239f
Author: James Taylor <jt...@salesforce.com>
Authored: Thu May 3 09:52:57 2018 -0700
Committer: James Taylor <jt...@salesforce.com>
Committed: Wed May 9 13:29:40 2018 -0700

----------------------------------------------------------------------
 .../it/java/org/apache/phoenix/tx/ParameterizedTransactionIT.java  | 2 --
 1 file changed, 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/59aa56ea/phoenix-core/src/it/java/org/apache/phoenix/tx/ParameterizedTransactionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/tx/ParameterizedTransactionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/tx/ParameterizedTransactionIT.java
index 580f055..ec1cf3a 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/tx/ParameterizedTransactionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/tx/ParameterizedTransactionIT.java
@@ -57,7 +57,6 @@ import org.apache.phoenix.transaction.PhoenixTransactionContext;
 import org.apache.phoenix.util.ByteUtil;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.TestUtil;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
@@ -323,7 +322,6 @@ public class ParameterizedTransactionIT extends ParallelStatsDisabledIT {
         assertFalse(rs.next());
     }
     
-    @Ignore
     @Test
     public void testNonTxToTxTableFailure() throws Exception {
         String nonTxTableName = generateUniqueName();


[10/10] phoenix git commit: PHOENIX-4727 Parameterize transaction tests with TRANSACTION_PROVIDER

Posted by ja...@apache.org.
PHOENIX-4727 Parameterize transaction tests with TRANSACTION_PROVIDER


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

Branch: refs/heads/4.x-cdh5.11
Commit: de4c348b04a344537893dcef865895409d6b61e7
Parents: 59aa56e
Author: James Taylor <jt...@salesforce.com>
Authored: Mon May 7 18:23:03 2018 -0700
Committer: James Taylor <jt...@salesforce.com>
Committed: Wed May 9 13:29:40 2018 -0700

----------------------------------------------------------------------
 .../phoenix/end2end/index/MutableIndexIT.java   | 21 +++---
 .../org/apache/phoenix/tx/TransactionIT.java    | 75 +++++++++++++++-----
 .../java/org/apache/phoenix/util/TestUtil.java  |  6 +-
 3 files changed, 74 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/de4c348b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexIT.java
index 631f97f..e968e99 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexIT.java
@@ -81,11 +81,11 @@ public class MutableIndexIT extends ParallelStatsDisabledIT {
     protected final boolean localIndex;
     private final String tableDDLOptions;
 	
-    public MutableIndexIT(boolean localIndex, boolean transactional, boolean columnEncoded) {
+    public MutableIndexIT(Boolean localIndex, String txProvider, Boolean columnEncoded) {
 		this.localIndex = localIndex;
 		StringBuilder optionBuilder = new StringBuilder();
-		if (transactional) {
-			optionBuilder.append("TRANSACTIONAL=true");
+		if (txProvider != null) {
+			optionBuilder.append("TRANSACTIONAL=true," + PhoenixDatabaseMetaData.TRANSACTION_PROVIDER + "='" + txProvider + "'");
 		}
 		if (!columnEncoded) {
             if (optionBuilder.length()!=0)
@@ -107,12 +107,15 @@ public class MutableIndexIT extends ParallelStatsDisabledIT {
     }
     
 	@Parameters(name="MutableIndexIT_localIndex={0},transactional={1},columnEncoded={2}") // name is used by failsafe as file name in reports
-    public static Collection<Boolean[]> data() {
-        return Arrays.asList(new Boolean[][] { 
-                { false, false, false }, { false, false, true },
-                { false, true, false }, { false, true, true },
-                { true, false, false }, { true, false, true },
-                { true, true, false }, { true, true, true } });
+    public static Collection<Object[]> data() {
+        return Arrays.asList(new Object[][] { 
+                { false, null, false }, { false, null, true },
+                { false, "TEPHRA", false }, { false, "TEPHRA", true },
+                //{ false, "OMID", false }, { false, "OMID", true },
+                { true, null, false }, { true, null, true },
+                { true, "TEPHRA", false }, { true, "TEPHRA", true },
+                //{ true, "OMID", false }, { true, "OMID", true },
+                });
     }
     
     @Test

http://git-wip-us.apache.org/repos/asf/phoenix/blob/de4c348b/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
index f1344e0..c0ec6b8 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
@@ -32,6 +32,8 @@ import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
+import java.util.Arrays;
+import java.util.Collection;
 import java.util.Properties;
 
 import org.apache.hadoop.hbase.HColumnDescriptor;
@@ -43,6 +45,7 @@ import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
 import org.apache.phoenix.query.QueryConstants;
 import org.apache.phoenix.query.QueryServicesOptions;
+import org.apache.phoenix.schema.PTable;
 import org.apache.phoenix.schema.PTableKey;
 import org.apache.phoenix.transaction.PhoenixTransactionContext;
 import org.apache.phoenix.transaction.TransactionFactory;
@@ -52,16 +55,33 @@ import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.StringUtil;
 import org.apache.phoenix.util.TestUtil;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
 
+@RunWith(Parameterized.class)
 public class TransactionIT  extends ParallelStatsDisabledIT {
+    private final String txProvider;
+    private final String tableDDLOptions;
+    
+    public TransactionIT(String provider) {
+        txProvider = provider;
+        tableDDLOptions = PhoenixDatabaseMetaData.TRANSACTION_PROVIDER + "='" + provider + "'";
+    }
 
+    @Parameters(name="TransactionIT_provider={0}") // name is used by failsafe as file name in reports
+    public static Collection<String[]> data() {
+        return Arrays.asList(new String[][] {     
+                 {"TEPHRA"/*,"OMID"*/}});
+    }
+    
     @Test
     public void testQueryWithSCN() throws Exception {
         String tableName = generateUniqueName();
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         try (Connection conn = DriverManager.getConnection(getUrl(), props);) {
             conn.createStatement().execute(
-                    "CREATE TABLE " + tableName + " (k VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR) TRANSACTIONAL=true");
+                    "CREATE TABLE " + tableName + " (k VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR) TRANSACTIONAL=true," + tableDDLOptions);
         }
         props.put(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(EnvironmentEdgeManager.currentTimeMillis()));
         try (Connection conn = DriverManager.getConnection(getUrl(), props);) {
@@ -85,7 +105,7 @@ public class TransactionIT  extends ParallelStatsDisabledIT {
         Statement stmt = conn.createStatement();
         stmt.execute("CREATE TABLE " + tableName + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR)");
         stmt.execute("DROP TABLE " + tableName);
-        stmt.execute("CREATE TABLE " + tableName + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) TRANSACTIONAL=true");
+        stmt.execute("CREATE TABLE " + tableName + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) TRANSACTIONAL=true," + tableDDLOptions);
         stmt.execute("CREATE INDEX " + tableName + "_IDX ON " + tableName + " (v1) INCLUDE(v2)");
         assertTrue(conn.unwrap(PhoenixConnection.class).getTable(new PTableKey(null, tableName)).isTransactional());
         assertTrue(conn.unwrap(PhoenixConnection.class).getTable(new PTableKey(null,  tableName + "_IDX")).isTransactional());
@@ -99,7 +119,7 @@ public class TransactionIT  extends ParallelStatsDisabledIT {
             conn.setAutoCommit(false);
             Statement stmt = conn.createStatement();
             try {
-                stmt.execute("CREATE TABLE " + tableName + "(k VARCHAR, v VARCHAR, d DATE NOT NULL, CONSTRAINT PK PRIMARY KEY(k,d ROW_TIMESTAMP)) TRANSACTIONAL=true");
+                stmt.execute("CREATE TABLE " + tableName + "(k VARCHAR, v VARCHAR, d DATE NOT NULL, CONSTRAINT PK PRIMARY KEY(k,d ROW_TIMESTAMP)) TRANSACTIONAL=true," + tableDDLOptions);
                 fail();
             }
             catch(SQLException e) {
@@ -123,7 +143,7 @@ public class TransactionIT  extends ParallelStatsDisabledIT {
             String transactTableName = generateUniqueName();
             Statement stmt = conn.createStatement();
             stmt.execute("CREATE TABLE " + transactTableName + " (k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) " +
-                "TRANSACTIONAL=true");
+                "TRANSACTIONAL=true," + tableDDLOptions);
             conn.commit();
 
             DatabaseMetaData dbmd = conn.getMetaData();
@@ -131,7 +151,11 @@ public class TransactionIT  extends ParallelStatsDisabledIT {
             assertTrue(rs.next());
             assertEquals("Transactional table was not marked as transactional in JDBC API.",
                 "true", rs.getString(PhoenixDatabaseMetaData.TRANSACTIONAL));
-            assertEquals(TransactionFactory.Provider.TEPHRA.name(), rs.getString(PhoenixDatabaseMetaData.TRANSACTION_PROVIDER));
+            assertEquals(txProvider, rs.getString(PhoenixDatabaseMetaData.TRANSACTION_PROVIDER));
+            
+            // Ensure round-trip-ability of TRANSACTION_PROVIDER
+            PTable table = PhoenixRuntime.getTableNoCache(conn, transactTableName);
+            assertEquals(txProvider, table.getTransactionProvider().name());
 
             String nonTransactTableName = generateUniqueName();
             Statement stmt2 = conn.createStatement();
@@ -159,7 +183,7 @@ public class TransactionIT  extends ParallelStatsDisabledIT {
         // TODO: we should support having a transactional table defined for a connectionless connection
         try (Connection conn = DriverManager.getConnection(getUrl())) {
             String transactTableName = generateUniqueName();
-            conn.createStatement().execute("CREATE TABLE " + transactTableName + " (k integer not null primary key, v bigint) TRANSACTIONAL=true");
+            conn.createStatement().execute("CREATE TABLE " + transactTableName + " (k integer not null primary key, v bigint) TRANSACTIONAL=true," + tableDDLOptions);
             conn.createStatement().execute("UPSERT INTO " + transactTableName + " VALUES(0,0) ON DUPLICATE KEY UPDATE v = v + 1");
             fail();
         } catch (SQLException e) {
@@ -170,13 +194,28 @@ public class TransactionIT  extends ParallelStatsDisabledIT {
     @Test
     public void testProperties() throws Exception {
         String nonTxTableName = generateUniqueName();
+        String txTableName = generateUniqueName();
+        String idx1 = generateUniqueName();
+        String idx2 = generateUniqueName();
 
         Connection conn = DriverManager.getConnection(getUrl());
         conn.createStatement().execute("CREATE TABLE " + nonTxTableName + "1(k INTEGER PRIMARY KEY, a.v VARCHAR, b.v VARCHAR, c.v VARCHAR) TTL=1000");
-        conn.createStatement().execute("CREATE INDEX idx1 ON " + nonTxTableName + "1(a.v, b.v) TTL=1000");
-        conn.createStatement().execute("CREATE INDEX idx2 ON " + nonTxTableName + "1(c.v) INCLUDE (a.v, b.v) TTL=1000");
+        conn.createStatement().execute("CREATE INDEX " + idx1 + " ON " + nonTxTableName + "1(a.v, b.v) TTL=1000");
+        conn.createStatement().execute("CREATE INDEX " + idx2 + " ON " + nonTxTableName + "1(c.v) INCLUDE (a.v, b.v) TTL=1000");
 
-        conn.createStatement().execute("ALTER TABLE " + nonTxTableName + "1 SET TRANSACTIONAL=true");
+        try {
+            conn.createStatement().execute("ALTER TABLE " + nonTxTableName + "1 SET TRANSACTIONAL=true," + tableDDLOptions);
+            if (TransactionFactory.Provider.OMID.name().equals(txProvider)) {
+                fail("Omid shouldn't allow converting a non transactional table to be transactional");
+            }
+        } catch (SQLException e) { // Should fail for Omid, but not Tephra
+            if (TransactionFactory.Provider.TEPHRA.name().equals(txProvider)) {
+                throw e;
+            }
+            assertEquals(SQLExceptionCode.CANNOT_ALTER_TABLE_FROM_NON_TXN_TO_TXNL.getErrorCode(), e.getErrorCode());
+            // FIXME: should verify Omid table properties too, but the checks below won't be valid for Omid
+            return;
+        }
 
         HTableDescriptor desc = conn.unwrap(PhoenixConnection.class).getQueryServices().getTableDescriptor(Bytes.toBytes(nonTxTableName + "1"));
         for (HColumnDescriptor colDesc : desc.getFamilies()) {
@@ -186,7 +225,7 @@ public class TransactionIT  extends ParallelStatsDisabledIT {
             assertEquals(1000, Integer.parseInt(propertyTTL));
         }
 
-        desc = conn.unwrap(PhoenixConnection.class).getQueryServices().getTableDescriptor(Bytes.toBytes("IDX1"));
+        desc = conn.unwrap(PhoenixConnection.class).getQueryServices().getTableDescriptor(Bytes.toBytes(idx1));
         for (HColumnDescriptor colDesc : desc.getFamilies()) {
             assertEquals(QueryServicesOptions.DEFAULT_MAX_VERSIONS_TRANSACTIONAL, colDesc.getMaxVersions());
             assertEquals(1000, colDesc.getTimeToLive());
@@ -194,7 +233,7 @@ public class TransactionIT  extends ParallelStatsDisabledIT {
             assertEquals(1000, Integer.parseInt(propertyTTL));
         }
         
-        desc = conn.unwrap(PhoenixConnection.class).getQueryServices().getTableDescriptor(Bytes.toBytes("IDX2"));
+        desc = conn.unwrap(PhoenixConnection.class).getQueryServices().getTableDescriptor(Bytes.toBytes(idx2));
         for (HColumnDescriptor colDesc : desc.getFamilies()) {
             assertEquals(QueryServicesOptions.DEFAULT_MAX_VERSIONS_TRANSACTIONAL, colDesc.getMaxVersions());
             assertEquals(1000, colDesc.getTimeToLive());
@@ -220,7 +259,7 @@ public class TransactionIT  extends ParallelStatsDisabledIT {
         }
 
         conn.createStatement().execute("CREATE TABLE " + nonTxTableName + "3(k INTEGER PRIMARY KEY, a.v VARCHAR, b.v VARCHAR, c.v VARCHAR)");
-        conn.createStatement().execute("ALTER TABLE " + nonTxTableName + "3 SET TRANSACTIONAL=true, b.VERSIONS=10, c.VERSIONS=20");
+        conn.createStatement().execute("ALTER TABLE " + nonTxTableName + "3 SET TRANSACTIONAL=true, b.VERSIONS=10, c.VERSIONS=20," + tableDDLOptions);
         desc = conn.unwrap(PhoenixConnection.class).getQueryServices().getTableDescriptor(Bytes.toBytes( nonTxTableName + "3"));
         assertEquals(QueryServicesOptions.DEFAULT_MAX_VERSIONS_TRANSACTIONAL, desc.getFamily(Bytes.toBytes("A")).getMaxVersions());
         assertEquals(10, desc.getFamily(Bytes.toBytes("B")).getMaxVersions());
@@ -228,21 +267,21 @@ public class TransactionIT  extends ParallelStatsDisabledIT {
 
         conn.createStatement().execute("CREATE TABLE " + nonTxTableName + "4(k INTEGER PRIMARY KEY, a.v VARCHAR, b.v VARCHAR, c.v VARCHAR)");
         try {
-            conn.createStatement().execute("ALTER TABLE " + nonTxTableName + "4 SET TRANSACTIONAL=true, VERSIONS=1");
+            conn.createStatement().execute("ALTER TABLE " + nonTxTableName + "4 SET TRANSACTIONAL=true, VERSIONS=1," + tableDDLOptions);
             fail();
         } catch (SQLException e) {
             assertEquals(SQLExceptionCode.TX_MAX_VERSIONS_MUST_BE_GREATER_THAN_ONE.getErrorCode(), e.getErrorCode());
         }
 
         try {
-            conn.createStatement().execute("ALTER TABLE " + nonTxTableName + "4 SET TRANSACTIONAL=true, b.VERSIONS=1");
+            conn.createStatement().execute("ALTER TABLE " + nonTxTableName + "4 SET TRANSACTIONAL=true, b.VERSIONS=1," + tableDDLOptions);
             fail();
         } catch (SQLException e) {
             assertEquals(SQLExceptionCode.TX_MAX_VERSIONS_MUST_BE_GREATER_THAN_ONE.getErrorCode(), e.getErrorCode());
         }
         
-        conn.createStatement().execute("CREATE TABLE TX_TABLE1(k INTEGER PRIMARY KEY, v VARCHAR) TTL=1000, TRANSACTIONAL=true");
-        desc = conn.unwrap(PhoenixConnection.class).getQueryServices().getTableDescriptor(Bytes.toBytes("TX_TABLE1"));
+        conn.createStatement().execute("CREATE TABLE " + txTableName + "(k INTEGER PRIMARY KEY, v VARCHAR) TTL=1000, TRANSACTIONAL=true," + tableDDLOptions);
+        desc = conn.unwrap(PhoenixConnection.class).getQueryServices().getTableDescriptor(Bytes.toBytes(txTableName));
         for (HColumnDescriptor colDesc : desc.getFamilies()) {
             assertEquals(QueryServicesOptions.DEFAULT_MAX_VERSIONS_TRANSACTIONAL, colDesc.getMaxVersions());
             assertEquals(HColumnDescriptor.DEFAULT_TTL, colDesc.getTimeToLive());
@@ -257,7 +296,7 @@ public class TransactionIT  extends ParallelStatsDisabledIT {
         String fullTableName = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + transTableName;
         try (Connection conn1 = DriverManager.getConnection(getUrl()); 
                 Connection conn2 = DriverManager.getConnection(getUrl())) {
-            TestUtil.createTransactionalTable(conn1, fullTableName);
+            TestUtil.createTransactionalTable(conn1, fullTableName, tableDDLOptions);
             conn1.setAutoCommit(false);
             conn2.setAutoCommit(false);
             String selectSql = "SELECT * FROM "+fullTableName;
@@ -296,7 +335,7 @@ public class TransactionIT  extends ParallelStatsDisabledIT {
         conn.setAutoCommit(false);
         try {
             Statement stmt = conn.createStatement();
-            stmt.execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) TRANSACTIONAL=true");
+            stmt.execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) TRANSACTIONAL=true," + tableDDLOptions);
             stmt.executeUpdate("upsert into " + fullTableName + " values('x', 'a', 'a')");
             conn.commit();
             

http://git-wip-us.apache.org/repos/asf/phoenix/blob/de4c348b/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 341fbec..6920772 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
@@ -830,7 +830,11 @@ public class TestUtil {
     }
 
     public static void createTransactionalTable(Connection conn, String tableName) throws SQLException {
-        conn.createStatement().execute("create table " + tableName + TestUtil.TEST_TABLE_SCHEMA + "TRANSACTIONAL=true");
+        createTransactionalTable(conn, tableName, "");
+    }
+
+    public static void createTransactionalTable(Connection conn, String tableName, String extraProps) throws SQLException {
+        conn.createStatement().execute("create table " + tableName + TestUtil.TEST_TABLE_SCHEMA + "TRANSACTIONAL=true" + (extraProps.length() == 0 ? "" : ("," + extraProps)));
     }
 
     public static void dumpTable(HTableInterface table) throws IOException {


[06/10] phoenix git commit: PHOENIX-4623 Inconsistent physical view index name

Posted by ja...@apache.org.
PHOENIX-4623 Inconsistent physical view index name


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

Branch: refs/heads/4.x-cdh5.11
Commit: 034d9867ad0a2dd1c94b26d9108f39aba1dbc024
Parents: de4c348
Author: James Taylor <jt...@salesforce.com>
Authored: Tue May 8 16:29:41 2018 -0700
Committer: James Taylor <jt...@salesforce.com>
Committed: Wed May 9 13:29:40 2018 -0700

----------------------------------------------------------------------
 .../org/apache/phoenix/end2end/BaseViewIT.java    |  7 +++----
 .../java/org/apache/phoenix/end2end/ViewIT.java   |  2 +-
 .../phoenix/schema/stats/StatsCollectorIT.java    |  3 +--
 .../org/apache/phoenix/util/MetaDataUtil.java     | 18 +++++-------------
 .../java/org/apache/phoenix/util/UpgradeUtil.java |  2 +-
 5 files changed, 11 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/034d9867/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseViewIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseViewIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseViewIT.java
index 478b234..5728a20 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseViewIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseViewIT.java
@@ -46,7 +46,6 @@ import org.apache.phoenix.util.MetaDataUtil;
 import org.apache.phoenix.util.QueryUtil;
 import org.apache.phoenix.util.ScanUtil;
 import org.apache.phoenix.util.SchemaUtil;
-import org.apache.phoenix.util.TestUtil;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 import org.junit.runners.Parameterized.Parameters;
@@ -66,7 +65,7 @@ public abstract class BaseViewIT extends ParallelStatsEnabledIT {
 		if (transactional) {
 			optionBuilder.append(" TRANSACTIONAL=true ");
 		}
-		this.schemaName = TestUtil.DEFAULT_SCHEMA_NAME;
+		this.schemaName = "S_" + generateUniqueName();
 		this.tableDDLOptions = optionBuilder.toString();
 		this.tableName = "T_" + generateUniqueName();
         this.fullTableName = SchemaUtil.getTableName(schemaName, tableName);
@@ -166,7 +165,7 @@ public abstract class BaseViewIT extends ParallelStatsEnabledIT {
         ResultSet rs;
         Connection conn = DriverManager.getConnection(getUrl());
         String viewIndexName1 = "I_" + generateUniqueName();
-        String viewIndexPhysicalName = MetaDataUtil.getViewIndexName(schemaName, tableName);
+        String viewIndexPhysicalName = MetaDataUtil.getViewIndexPhysicalName(fullTableName);
         if (localIndex) {
             conn.createStatement().execute("CREATE LOCAL INDEX " + viewIndexName1 + " on " + viewName + "(k3)");
         } else {
@@ -231,7 +230,7 @@ public abstract class BaseViewIT extends ParallelStatsEnabledIT {
         rs = conn.createStatement().executeQuery("EXPLAIN " + query);
         String physicalTableName;
         if (localIndex) {
-            physicalTableName = tableName;
+            physicalTableName = fullTableName;
             assertEquals("CLIENT PARALLEL "+ (saltBuckets == null ? 1 : saltBuckets)  +"-WAY RANGE SCAN OVER " + fullTableName +" [" + (2) + ",'foo']\n"
                     + "    SERVER FILTER BY FIRST KEY ONLY\n"
                     + "CLIENT MERGE SORT",QueryUtil.getExplainPlan(rs));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/034d9867/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java
index 279bbd7..34292ba 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java
@@ -69,7 +69,7 @@ public class ViewIT extends BaseViewIT {
         String ddl = "CREATE TABLE " + fullTableName + " (k INTEGER NOT NULL PRIMARY KEY, v1 DATE) "+ tableDDLOptions;
         conn.createStatement().execute(ddl);
         String fullParentViewName = "V_" + generateUniqueName();
-        ddl = "CREATE VIEW " + fullParentViewName + " (v2 VARCHAR) AS SELECT * FROM " + tableName + " WHERE k > 5";
+        ddl = "CREATE VIEW " + fullParentViewName + " (v2 VARCHAR) AS SELECT * FROM " + fullTableName + " WHERE k > 5";
         conn.createStatement().execute(ddl);
         try {
             conn.createStatement().execute("UPSERT INTO " + fullParentViewName + " VALUES(1)");

http://git-wip-us.apache.org/repos/asf/phoenix/blob/034d9867/phoenix-core/src/it/java/org/apache/phoenix/schema/stats/StatsCollectorIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/schema/stats/StatsCollectorIT.java b/phoenix-core/src/it/java/org/apache/phoenix/schema/stats/StatsCollectorIT.java
index c424f45..09d28f8 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/schema/stats/StatsCollectorIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/schema/stats/StatsCollectorIT.java
@@ -48,7 +48,6 @@ import org.apache.hadoop.hbase.client.ResultScanner;
 import org.apache.hadoop.hbase.client.Scan;
 import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
 import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.phoenix.coprocessor.MetaDataRegionObserver;
 import org.apache.phoenix.coprocessor.UngroupedAggregateRegionObserver;
 import org.apache.phoenix.end2end.BaseUniqueNamesOwnClusterIT;
 import org.apache.phoenix.jdbc.PhoenixConnection;
@@ -785,7 +784,7 @@ public abstract class StatsCollectorIT extends BaseUniqueNamesOwnClusterIT {
             String viewIndex = "VI_" + generateUniqueName();
             ddl = "CREATE INDEX " + viewIndex + " ON " + view + " (b)";
             conn.createStatement().execute(ddl);
-            String viewIndexTableName = MetaDataUtil.getViewIndexTableName(baseTable);
+            String viewIndexTableName = MetaDataUtil.getViewIndexPhysicalName(baseTable);
             statsCollector = getDefaultStatsCollectorForTable(viewIndexTableName);
             statsCollector.init();
             assertEquals(defaultGuidePostWidth, statsCollector.getGuidePostDepth());

http://git-wip-us.apache.org/repos/asf/phoenix/blob/034d9867/phoenix-core/src/main/java/org/apache/phoenix/util/MetaDataUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/MetaDataUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/MetaDataUtil.java
index 2a0c8f0..1dda818 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/MetaDataUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/MetaDataUtil.java
@@ -356,23 +356,15 @@ public class MetaDataUtil {
         return getIndexPhysicalName(physicalTableName, VIEW_INDEX_TABLE_PREFIX);
     }
 
-    public static String getViewIndexTableName(String tableName) {
-        return VIEW_INDEX_TABLE_PREFIX + tableName;
-    }
-
-    public static String getViewIndexSchemaName(String schemaName) {
-        return schemaName;
-    }
-    
-    public static String getViewIndexName(String schemaName, String tableName) {
-        return SchemaUtil.getTableName(getViewIndexSchemaName(schemaName), getViewIndexTableName(tableName));
+    public static String getViewIndexPhysicalName(String physicalTableName) {
+        return getIndexPhysicalName(physicalTableName, VIEW_INDEX_TABLE_PREFIX);
     }
 
-    public static byte[] getIndexPhysicalName(byte[] physicalTableName, String indexPrefix) {
-        return getIndexPhysicalName(Bytes.toString(physicalTableName), indexPrefix).getBytes();
+    private static byte[] getIndexPhysicalName(byte[] physicalTableName, String indexPrefix) {
+        return Bytes.toBytes(getIndexPhysicalName(Bytes.toString(physicalTableName), indexPrefix));
     }
 
-    public static String getIndexPhysicalName(String physicalTableName, String indexPrefix) {
+    private static String getIndexPhysicalName(String physicalTableName, String indexPrefix) {
         if (physicalTableName.contains(QueryConstants.NAMESPACE_SEPARATOR)) {
             String schemaName = SchemaUtil.getSchemaNameFromFullName(physicalTableName,
                     QueryConstants.NAMESPACE_SEPARATOR);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/034d9867/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java
index 63f2183..b127408 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java
@@ -600,7 +600,7 @@ public class UpgradeUtil {
                             viewPTable = PhoenixRuntime.getTable(globalConnection, fullViewName);
                             globalConnection.createStatement().execute(String.format(disableIndexDDL, indexName, fullViewName));
                         }
-                        String indexPhysicalTableName = MetaDataUtil.getViewIndexTableName(viewPTable.getPhysicalName().getString());
+                        String indexPhysicalTableName = MetaDataUtil.getViewIndexPhysicalName(viewPTable.getPhysicalName().getString());
                         if (physicalTables.add(indexPhysicalTableName)) {
                             final TableName tableName = TableName.valueOf(indexPhysicalTableName);
                             if(admin.tableExists(tableName)) {


[07/10] phoenix git commit: PHOENIX-4646 The data exceeds the max capacity for the data type error for valid scenarios (Sergey Soldatov)

Posted by ja...@apache.org.
PHOENIX-4646 The data exceeds the max capacity for the data type error for valid scenarios (Sergey Soldatov)


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

Branch: refs/heads/4.x-cdh5.11
Commit: 810ed4e37a24cc281c46ece4ed958e45ab458ba2
Parents: f1230c0
Author: James Taylor <jt...@salesforce.com>
Authored: Wed May 9 13:12:26 2018 -0700
Committer: James Taylor <jt...@salesforce.com>
Committed: Wed May 9 13:29:40 2018 -0700

----------------------------------------------------------------------
 .../apache/phoenix/end2end/UpsertSelectIT.java   | 19 +++++++++++++++++++
 .../apache/phoenix/schema/types/PVarchar.java    | 10 ++++++----
 2 files changed, 25 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/810ed4e3/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectIT.java
index 99cbe47..5db1fdd 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectIT.java
@@ -1488,6 +1488,25 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
         }
     }
 
+    @Test // See https://issues.apache.org/jira/browse/PHOENIX-4646
+    public void testLengthLimitedVarchar() throws Exception {
+        String tableName1 = generateUniqueName();
+        String tableName2 = generateUniqueName();
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            conn.setAutoCommit(true);
+            conn.createStatement().execute("create table " + tableName1 + "(name varchar(160) primary key, id varchar(120), address varchar(160))"); 
+            conn.createStatement().execute("create table " + tableName2 + "(name varchar(160) primary key, id varchar(10), address  varchar(10))");
+            conn.createStatement().execute("upsert into " + tableName1 + " values('test','test','test')");
+            conn.createStatement().execute("upsert into " + tableName2 + " select * from " + tableName1);
+            ResultSet rs = conn.createStatement().executeQuery("select * from " + tableName2);
+            assertTrue(rs.next());
+            assertEquals("test", rs.getString(1));
+            assertEquals("test", rs.getString(2));
+            assertEquals("test", rs.getString(2));
+            assertFalse(rs.next());
+        }
+    }
+    
     private static Connection getTenantConnection(String tenantId) throws Exception {
         Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
         props.setProperty(TENANT_ID_ATTRIB, tenantId);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/810ed4e3/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PVarchar.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PVarchar.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PVarchar.java
index fb5a045..a99925c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PVarchar.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PVarchar.java
@@ -102,15 +102,17 @@ public class PVarchar extends PDataType<String> {
             SortOrder sortOrder, Integer maxLength, Integer scale,
             Integer desiredMaxLength, Integer desiredScale) {
         if (ptr.getLength() != 0 && desiredMaxLength != null) {
-            if (maxLength == null) {
+            if (maxLength == null || maxLength > desiredMaxLength) {
                 if (value != null) { // Use value if provided
                     maxLength = value.toString().length();
                 } else {
-                    coerceBytes(ptr, value, srcType, maxLength, scale, sortOrder, desiredMaxLength, desiredScale, sortOrder, true);
-                    maxLength = StringUtil.calculateUTF8Length(ptr.get(), ptr.getOffset(), ptr.getLength(), sortOrder);
+                    coerceBytes(ptr, value, srcType, maxLength, scale, sortOrder, desiredMaxLength,
+                        desiredScale, sortOrder, true);
+                    maxLength = StringUtil
+                        .calculateUTF8Length(ptr.get(), ptr.getOffset(), ptr.getLength(), sortOrder);
                 }
+                return maxLength <= desiredMaxLength;
             }
-            return maxLength <= desiredMaxLength;
         }
         return true;
     }


[08/10] phoenix git commit: PHOENIX-4678 ndexScrutinyTool generates malformed query due to incorrect table name(s) (Josh Elser)

Posted by ja...@apache.org.
PHOENIX-4678 ndexScrutinyTool generates malformed query due to incorrect table name(s) (Josh Elser)


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

Branch: refs/heads/4.x-cdh5.11
Commit: f1230c0a04e215230ec0312fe62a34841eec6eaa
Parents: 034d986
Author: James Taylor <jt...@salesforce.com>
Authored: Wed May 9 12:50:22 2018 -0700
Committer: James Taylor <jt...@salesforce.com>
Committed: Wed May 9 13:29:40 2018 -0700

----------------------------------------------------------------------
 phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/f1230c0a/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java
index b43f54e..92a2cde 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java
@@ -1132,7 +1132,7 @@ public class SchemaUtil {
      * @return the byte representation of the HTable
      */
     public static String getQualifiedTableName(String schemaName, String tableName) {
-        if (schemaName != null) {
+        if (schemaName != null && !schemaName.isEmpty()) {
             return String.format("%s.%s", normalizeIdentifier(schemaName),
                     normalizeIdentifier(tableName));
         } else {