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 2014/02/26 01:13:58 UTC
git commit: PHOENIX-67 Lazy initialize QueryServices in PhoenixDriver
(JamesTaylor)
Repository: incubator-phoenix
Updated Branches:
refs/heads/master ff9280e79 -> 1e2df030c
PHOENIX-67 Lazy initialize QueryServices in PhoenixDriver (JamesTaylor)
Project: http://git-wip-us.apache.org/repos/asf/incubator-phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-phoenix/commit/1e2df030
Tree: http://git-wip-us.apache.org/repos/asf/incubator-phoenix/tree/1e2df030
Diff: http://git-wip-us.apache.org/repos/asf/incubator-phoenix/diff/1e2df030
Branch: refs/heads/master
Commit: 1e2df030c597dd8aac4a9cff5acab8fd7be71a71
Parents: ff9280e
Author: James Taylor <ja...@apache.org>
Authored: Tue Feb 25 16:13:48 2014 -0800
Committer: James Taylor <ja...@apache.org>
Committed: Tue Feb 25 16:13:48 2014 -0800
----------------------------------------------------------------------
.../phoenix/coprocessor/MetaDataProtocol.java | 14 +++-------
.../org/apache/phoenix/jdbc/PhoenixDriver.java | 21 +++++++++++++--
.../phoenix/jdbc/PhoenixEmbeddedDriver.java | 27 +++++++++++---------
.../apache/phoenix/jdbc/PhoenixTestDriver.java | 20 ++++++++++++---
.../java/org/apache/phoenix/query/BaseTest.java | 12 ++++-----
5 files changed, 59 insertions(+), 35 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/1e2df030/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataProtocol.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataProtocol.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataProtocol.java
index 419502e..11732c9 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataProtocol.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataProtocol.java
@@ -28,14 +28,14 @@ import org.apache.hadoop.hbase.ipc.CoprocessorProtocol;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableUtils;
-
-import com.google.common.collect.Lists;
import org.apache.phoenix.schema.PColumn;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTableImpl;
import org.apache.phoenix.util.ByteUtil;
import org.apache.phoenix.util.MetaDataUtil;
+import com.google.common.collect.Lists;
+
/**
*
@@ -62,15 +62,7 @@ public interface MetaDataProtocol extends CoprocessorProtocol {
MetaDataUtil.encodeVersion(PHOENIX_MAJOR_VERSION, PHOENIX_MINOR_VERSION, PHOENIX_PATCH_NUMBER);
public static final long MIN_TABLE_TIMESTAMP = 0;
- // Increase MIN_SYSTEM_TABLE_TIMESTAMP by one for each schema change SYSTEM.TABLE schema changes.
- // For 1.0,1.1,1.2,and 1.2.1 we used MetaDataProtocol.MIN_TABLE_TIMESTAMP+1
- // For 2.0 and above, we use MetaDataProtocol.MIN_TABLE_TIMESTAMP+7 so that we can add the five new
- // columns to the existing system table (three new columns in 1.2.1 and two new columns in 1.2)
- // For 3.0 and above, we use MIN_TABLE_TIMESTAMP + 8 so that we can add the tenant_id column
- // as the first column to the existing system table.
- // For 3.1 (SNAPSHOT) and above, we use MIN_TABLE_TIMESTAMP + 9 so that we can add
- // the multi_tenant and multi_type columns for multi tenancy
- public static final long MIN_SYSTEM_TABLE_TIMESTAMP = MIN_TABLE_TIMESTAMP + 9;
+ public static final long MIN_SYSTEM_TABLE_TIMESTAMP = MIN_TABLE_TIMESTAMP + 1;
public static final int DEFAULT_MAX_META_DATA_VERSIONS = 1000;
// TODO: pare this down to minimum, as we don't need duplicates for both table and column errors, nor should we need
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/1e2df030/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDriver.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDriver.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDriver.java
index 99390d9..836590b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDriver.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDriver.java
@@ -23,7 +23,11 @@ import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
-import org.apache.phoenix.query.*;
+import org.apache.phoenix.query.ConnectionQueryServices;
+import org.apache.phoenix.query.ConnectionQueryServicesImpl;
+import org.apache.phoenix.query.ConnectionlessQueryServicesImpl;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.query.QueryServicesImpl;
import org.apache.phoenix.util.SQLCloseables;
@@ -54,7 +58,20 @@ public final class PhoenixDriver extends PhoenixEmbeddedDriver {
public PhoenixDriver() { // for Squirrel
// Use production services implementation
- super(new QueryServicesImpl());
+ super();
+ }
+
+ private QueryServices services;
+
+ @Override
+ public synchronized QueryServices getQueryServices() {
+ // Lazy initialize QueryServices so that we only attempt to create an HBase Configuration
+ // object upon the first attempt to connect to any cluster. Otherwise, an attempt will be
+ // made at driver initialization time which is too early for some systems.
+ if (services == null) {
+ services = new QueryServicesImpl();
+ }
+ return services;
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/1e2df030/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java
index 4fc9e9a..2f28962 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java
@@ -17,17 +17,26 @@
*/
package org.apache.phoenix.jdbc;
-import java.sql.*;
-import java.util.*;
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.DriverPropertyInfo;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.util.Map;
+import java.util.Properties;
+import java.util.StringTokenizer;
import java.util.logging.Logger;
-import com.google.common.collect.Maps;
import org.apache.phoenix.coprocessor.MetaDataProtocol;
import org.apache.phoenix.exception.SQLExceptionCode;
import org.apache.phoenix.exception.SQLExceptionInfo;
import org.apache.phoenix.query.ConnectionQueryServices;
import org.apache.phoenix.query.QueryServices;
-import org.apache.phoenix.util.*;
+import org.apache.phoenix.util.PhoenixRuntime;
+import org.apache.phoenix.util.ReadOnlyProps;
+import org.apache.phoenix.util.SQLCloseable;
+
+import com.google.common.collect.Maps;
@@ -51,20 +60,14 @@ public abstract class PhoenixEmbeddedDriver implements Driver, org.apache.phoeni
public final static String MINOR_VERSION_PROP = "DriverMinorVersion";
public final static String DRIVER_NAME_PROP = "DriverName";
- private final QueryServices services;
-
-
- PhoenixEmbeddedDriver(QueryServices queryServices) {
- services = queryServices;
+ PhoenixEmbeddedDriver() {
}
private String getDriverName() {
return this.getClass().getName();
}
- public QueryServices getQueryServices() {
- return services;
- }
+ abstract public QueryServices getQueryServices();
@Override
public boolean acceptsURL(String url) throws SQLException {
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/1e2df030/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixTestDriver.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixTestDriver.java b/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixTestDriver.java
index b6a4799..afc7143 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixTestDriver.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixTestDriver.java
@@ -25,6 +25,7 @@ import org.apache.phoenix.query.ConnectionQueryServices;
import org.apache.phoenix.query.ConnectionlessQueryServicesImpl;
import org.apache.phoenix.query.QueryServices;
import org.apache.phoenix.query.QueryServicesTestImpl;
+import org.apache.phoenix.util.ReadOnlyProps;
@@ -38,13 +39,24 @@ import org.apache.phoenix.query.QueryServicesTestImpl;
*/
public class PhoenixTestDriver extends PhoenixEmbeddedDriver {
private ConnectionQueryServices queryServices;
-
+ private final ReadOnlyProps overrideProps;
+ private QueryServices services;
+
public PhoenixTestDriver() {
- this(new QueryServicesTestImpl());
+ this.overrideProps = ReadOnlyProps.EMPTY_PROPS;
+ }
+
+ // For tests to override the default configuration
+ public PhoenixTestDriver(ReadOnlyProps overrideProps) {
+ this.overrideProps = overrideProps;
}
- public PhoenixTestDriver(QueryServices services) {
- super(services);
+ @Override
+ public synchronized QueryServices getQueryServices() {
+ if (services == null) {
+ services = new QueryServicesTestImpl(overrideProps);
+ }
+ return services;
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/1e2df030/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java b/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
index 67ba6df..e8a5e48 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
@@ -57,14 +57,14 @@ import java.util.Properties;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
-import org.junit.AfterClass;
-
-import com.google.common.collect.ImmutableMap;
import org.apache.phoenix.jdbc.PhoenixEmbeddedDriver;
import org.apache.phoenix.jdbc.PhoenixTestDriver;
import org.apache.phoenix.schema.TableAlreadyExistsException;
import org.apache.phoenix.util.PhoenixRuntime;
import org.apache.phoenix.util.ReadOnlyProps;
+import org.junit.AfterClass;
+
+import com.google.common.collect.ImmutableMap;
public abstract class BaseTest {
private static final Map<String,String> tableDDLMap;
@@ -366,10 +366,10 @@ public abstract class BaseTest {
protected static PhoenixTestDriver driver;
private static int driverRefCount = 0;
- protected static synchronized PhoenixTestDriver initDriver(QueryServices services) throws Exception {
+ protected static synchronized PhoenixTestDriver initDriver(ReadOnlyProps props) throws Exception {
if (driver == null) {
if (driverRefCount == 0) {
- BaseTest.driver = new PhoenixTestDriver(services);
+ BaseTest.driver = new PhoenixTestDriver(props);
DriverManager.registerDriver(driver);
driverRefCount++;
}
@@ -409,7 +409,7 @@ public abstract class BaseTest {
// only load the test driver if we are testing locally - for integration tests, we want to
// test on a wider scale
if (PhoenixEmbeddedDriver.isTestUrl(url)) {
- PhoenixTestDriver driver = initDriver(new QueryServicesTestImpl(props));
+ PhoenixTestDriver driver = initDriver(props);
assertTrue(DriverManager.getDriver(url) == driver);
}
}