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/10/16 07:11:46 UTC
git commit: PHOENIX-1214 SYSTEM.CATALOG cannot be created when first
connection to cluster is tenant-specific (Jan Van Besien)
Repository: phoenix
Updated Branches:
refs/heads/4.0 6f2758c40 -> 6333e70af
PHOENIX-1214 SYSTEM.CATALOG cannot be created when first connection to cluster is tenant-specific (Jan Van Besien)
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/6333e70a
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/6333e70a
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/6333e70a
Branch: refs/heads/4.0
Commit: 6333e70afbcb49efb680b5ab1d062655b32dbfd2
Parents: 6f2758c
Author: James Taylor <jt...@salesforce.com>
Authored: Wed Oct 15 22:17:28 2014 -0700
Committer: James Taylor <jt...@salesforce.com>
Committed: Wed Oct 15 22:17:28 2014 -0700
----------------------------------------------------------------------
.../phoenix/end2end/CSVCommonsLoaderIT.java | 4 ++-
.../query/ConnectionQueryServicesImpl.java | 4 ++-
.../query/ConnectionlessQueryServicesImpl.java | 4 ++-
.../java/org/apache/phoenix/util/JDBCUtil.java | 18 +++++++++++-
.../apache/phoenix/jdbc/PhoenixDriverTest.java | 31 ++++++++++----------
.../org/apache/phoenix/util/JDBCUtilTest.java | 9 ++++++
6 files changed, 51 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/6333e70a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CSVCommonsLoaderIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CSVCommonsLoaderIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CSVCommonsLoaderIT.java
index 9f36b93..f51f908 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CSVCommonsLoaderIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CSVCommonsLoaderIT.java
@@ -30,10 +30,12 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Collections;
+import java.util.Properties;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;
import org.apache.phoenix.jdbc.PhoenixConnection;
+import org.apache.phoenix.jdbc.PhoenixTestDriver;
import org.apache.phoenix.schema.PArrayDataType;
import org.apache.phoenix.schema.PDataType;
import org.apache.phoenix.util.CSVCommonsLoader;
@@ -156,7 +158,7 @@ public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeIT {
new StringReader(statements), null);
globalConn.close();
- tenantConn = DriverManager.getConnection(getUrl() + ";TenantId=acme").unwrap(
+ tenantConn = new PhoenixTestDriver().connect(getUrl() + ";TenantId=acme", new Properties()).unwrap(
PhoenixConnection.class);
// Upsert CSV file
http://git-wip-us.apache.org/repos/asf/phoenix/blob/6333e70a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
index 1b76900..232a284 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
@@ -126,6 +126,7 @@ import org.apache.phoenix.schema.stats.PTableStats;
import org.apache.phoenix.util.ByteUtil;
import org.apache.phoenix.util.Closeables;
import org.apache.phoenix.util.ConfigUtil;
+import org.apache.phoenix.util.JDBCUtil;
import org.apache.phoenix.util.MetaDataUtil;
import org.apache.phoenix.util.PhoenixContextExecutor;
import org.apache.phoenix.util.PhoenixRuntime;
@@ -1502,8 +1503,9 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
PhoenixRuntime.CURRENT_SCN_ATTRIB,
Long.toString(MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP));
scnProps.remove(PhoenixRuntime.TENANT_ID_ATTRIB);
+ String globalUrl = JDBCUtil.removeProperty(url, PhoenixRuntime.TENANT_ID_ATTRIB);
metaConnection = new PhoenixConnection(
- ConnectionQueryServicesImpl.this, url, scnProps, newEmptyMetaData());
+ ConnectionQueryServicesImpl.this, globalUrl, scnProps, newEmptyMetaData());
try {
metaConnection.createStatement().executeUpdate(QueryConstants.CREATE_TABLE_METADATA);
} catch (NewerTableAlreadyExistsException ignore) {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/6333e70a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionlessQueryServicesImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionlessQueryServicesImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionlessQueryServicesImpl.java
index 5b92439..4700d44 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionlessQueryServicesImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionlessQueryServicesImpl.java
@@ -69,6 +69,7 @@ import org.apache.phoenix.schema.SequenceNotFoundException;
import org.apache.phoenix.schema.TableAlreadyExistsException;
import org.apache.phoenix.schema.TableNotFoundException;
import org.apache.phoenix.schema.stats.PTableStats;
+import org.apache.phoenix.util.JDBCUtil;
import org.apache.phoenix.util.MetaDataUtil;
import org.apache.phoenix.util.PhoenixRuntime;
import org.apache.phoenix.util.PropertiesUtil;
@@ -215,7 +216,8 @@ public class ConnectionlessQueryServicesImpl extends DelegateQueryServices imple
Properties scnProps = PropertiesUtil.deepCopy(props);
scnProps.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP));
scnProps.remove(PhoenixRuntime.TENANT_ID_ATTRIB);
- metaConnection = new PhoenixConnection(this, url, scnProps, newEmptyMetaData());
+ String globalUrl = JDBCUtil.removeProperty(url, PhoenixRuntime.TENANT_ID_ATTRIB);
+ metaConnection = new PhoenixConnection(this, globalUrl, scnProps, newEmptyMetaData());
try {
metaConnection.createStatement().executeUpdate(QueryConstants.CREATE_TABLE_METADATA);
} catch (TableAlreadyExistsException ignore) {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/6333e70a/phoenix-core/src/main/java/org/apache/phoenix/util/JDBCUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/JDBCUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/JDBCUtil.java
index 4e9f01b..df1f949 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/JDBCUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/JDBCUtil.java
@@ -68,7 +68,23 @@ public class JDBCUtil {
}
return propValue;
}
-
+
+ public static String removeProperty(String url, String propName) {
+ String urlPropName = ";" + propName + "=";
+ int begIndex = url.indexOf(urlPropName);
+ if (begIndex >= 0) {
+ int endIndex = url.indexOf(';', begIndex + urlPropName.length());
+ if (endIndex < 0) {
+ endIndex = url.length();
+ }
+ String prefix = url.substring(0, begIndex);
+ String suffix = url.substring(endIndex, url.length());
+ return prefix + suffix;
+ } else {
+ return url;
+ }
+ }
+
/**
* Returns a map that contains connection properties from both <code>info</code> and <code>url</code>.
*/
http://git-wip-us.apache.org/repos/asf/phoenix/blob/6333e70a/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixDriverTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixDriverTest.java b/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixDriverTest.java
index bcb4f51..be40702 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixDriverTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixDriverTest.java
@@ -24,7 +24,6 @@ import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
-import java.sql.SQLException;
import java.util.Properties;
import org.apache.phoenix.query.BaseConnectionlessQueryTest;
@@ -37,10 +36,23 @@ public class PhoenixDriverTest extends BaseConnectionlessQueryTest {
@Test
public void testFirstConnectionWhenPropsHasTenantId() throws Exception {
- final String url = getUrl();
- verifyConnectionValid(url);
+ Properties props = new Properties();
+ final String tenantId = "00Dxx0000001234";
+ props.put(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId);
+
+ Connection connection = new PhoenixTestDriver().connect(getUrl(), props);
+ assertEquals(tenantId, connection.getClientInfo(PhoenixRuntime.TENANT_ID_ATTRIB));
}
-
+
+ @Test
+ public void testFirstConnectionWhenUrlHasTenantId() throws Exception {
+ final String tenantId = "00Dxx0000001234";
+ String url = getUrl() + ";" + PhoenixRuntime.TENANT_ID_ATTRIB + "=" + tenantId;
+ Driver driver = new PhoenixTestDriver();
+
+ driver.connect(url, new Properties());
+ }
+
@Test
public void testMaxMutationSizeSetCorrectly() throws Exception {
Properties connectionProperties = new Properties();
@@ -59,15 +71,4 @@ public class PhoenixDriverTest extends BaseConnectionlessQueryTest {
fail("Upsert should have failed since the number of upserts (200) is greater than the MAX_MUTATION_SIZE_ATTRIB (100)");
} catch (IllegalArgumentException expected) {}
}
-
- private void verifyConnectionValid(String url) throws SQLException {
- Driver driver = DriverManager.getDriver(url);
-
- Properties props = new Properties();
- final String tenantId = "00Dxx0000001234";
- props.put(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId);
-
- Connection connection = driver.connect(url, props);
- assertEquals(tenantId, connection.getClientInfo(PhoenixRuntime.TENANT_ID_ATTRIB));
- }
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/6333e70a/phoenix-core/src/test/java/org/apache/phoenix/util/JDBCUtilTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/util/JDBCUtilTest.java b/phoenix-core/src/test/java/org/apache/phoenix/util/JDBCUtilTest.java
index e138806..71bd6df 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/util/JDBCUtilTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/util/JDBCUtilTest.java
@@ -18,6 +18,7 @@
package org.apache.phoenix.util;
import static org.apache.phoenix.util.PhoenixRuntime.ANNOTATION_ATTRIB_PREFIX;
+import static org.apache.phoenix.util.PhoenixRuntime.TENANT_ID_ATTRIB;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -56,4 +57,12 @@ public class JDBCUtilTest {
assertEquals(annotVal2, customAnnotations.get(annotKey2));
assertEquals(annotVal3, customAnnotations.get(annotKey3));
}
+
+ @Test
+ public void testRemoveProperty() {
+ assertEquals("localhost;", JDBCUtil.removeProperty("localhost;TenantId=abc;", TENANT_ID_ATTRIB));
+ assertEquals("localhost;foo=bar", JDBCUtil.removeProperty("localhost;TenantId=abc;foo=bar", TENANT_ID_ATTRIB));
+ assertEquals("localhost;TenantId=abc", JDBCUtil.removeProperty("localhost;TenantId=abc;foo=bar", "foo"));
+ assertEquals("localhost;TenantId=abc;foo=bar", JDBCUtil.removeProperty("localhost;TenantId=abc;foo=bar", "bar"));
+ }
}