PHOENIX-1559 Add auto-commit config property Allow specifying the initial connection auto-commit property via the phoenix.connection.autoCommit configuration property.
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/abb5c24f Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/abb5c24f Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/abb5c24f Branch: refs/heads/3.0 Commit: abb5c24f4d43b47c434239d4d0f369167fe33411 Parents: 745425f Author: Gabriel Reid <gr...@apache.org> Authored: Wed Dec 31 10:58:52 2014 +0100 Committer: Gabriel Reid <gr...@apache.org> Committed: Thu Jan 1 12:06:38 2015 +0100 ---------------------------------------------------------------------- .../apache/phoenix/jdbc/PhoenixConnection.java | 6 +++++- .../org/apache/phoenix/query/QueryServices.java | 1 + .../phoenix/query/QueryServicesOptions.java | 3 +++ .../java/org/apache/phoenix/util/JDBCUtil.java | 12 ++++++++---- .../org/apache/phoenix/util/JDBCUtilTest.java | 19 ++++++++++++------- 5 files changed, 29 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/abb5c24f/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java index 7353ffd..25287c3 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java @@ -173,7 +173,11 @@ public class PhoenixConnection implements Connection, org.apache.phoenix.jdbc.Jd }; } this.scn = JDBCUtil.getCurrentSCN(url, this.info); - this.isAutoCommit = JDBCUtil.getAutoCommit(url, this.info); + this.isAutoCommit = JDBCUtil.getAutoCommit( + url, this.info, + this.services.getProps().getBoolean( + QueryServices.AUTO_COMMIT_ATTRIB, + QueryServicesOptions.DEFAULT_AUTO_COMMIT)); this.tenantId = tenantId; this.mutateBatchSize = JDBCUtil.getMutateBatchSize(url, this.info, this.services.getProps()); datePattern = this.services.getProps().get(QueryServices.DATE_FORMAT_ATTRIB, DateUtil.DEFAULT_DATE_FORMAT); http://git-wip-us.apache.org/repos/asf/phoenix/blob/abb5c24f/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java index f444df9..1ebc4c6 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java @@ -47,6 +47,7 @@ public interface QueryServices extends SQLCloseable { public static final String HBASE_CLIENT_KEYTAB = "hbase.myclient.keytab"; public static final String HBASE_CLIENT_PRINCIPAL = "hbase.myclient.principal"; public static final String SPOOL_DIRECTORY = "phoenix.spool.directory"; + public static final String AUTO_COMMIT_ATTRIB = "phoenix.connection.autoCommit"; /** * max size to spool the the result into http://git-wip-us.apache.org/repos/asf/phoenix/blob/abb5c24f/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java index ff7d1dd..1b65098 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java @@ -155,6 +155,9 @@ public class QueryServicesOptions { public static final int DEFAULT_COPROCESSOR_PRIORITY = Coprocessor.PRIORITY_SYSTEM/2 + Coprocessor.PRIORITY_USER/2; // Divide individually to prevent any overflow public static final boolean DEFAULT_EXPLAIN_CHUNK_COUNT = true; + // TODO Change this to true as part of PHOENIX-1543 + public static final boolean DEFAULT_AUTO_COMMIT = false; + private final Configuration config; private QueryServicesOptions(Configuration config) { http://git-wip-us.apache.org/repos/asf/phoenix/blob/abb5c24f/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 e2efe79..60d9a51 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 @@ -95,18 +95,22 @@ public class JDBCUtil { return (tenantId == null ? null : PNameFactory.newName(tenantId)); } - // TODO Make true the default return value once PHOENIX-1543 is in place /** * Retrieve the value of the optional auto-commit setting from JDBC url or connection * properties. * * @param url JDBC url used for connecting to Phoenix * @param info connection properties - * @return <tt>true</tt> if AutoCommit=true was specified in the connection URL or properties, - * otherwise false + * @param defaultValue default to return if the auto-commit property is not set in the url + * or connection properties + * @return the boolean value supplied for the AutoCommit in the connection URL or properties, + * or the supplied default value if no AutoCommit attribute was provided */ - public static boolean getAutoCommit(String url, Properties info) { + public static boolean getAutoCommit(String url, Properties info, boolean defaultValue) { String autoCommit = findProperty(url, info, PhoenixRuntime.AUTO_COMMIT_ATTRIB); + if (autoCommit == null) { + return defaultValue; + } return Boolean.valueOf(autoCommit); } } http://git-wip-us.apache.org/repos/asf/phoenix/blob/abb5c24f/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 b41ce5b..8201cf2 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 @@ -38,32 +38,37 @@ public class JDBCUtilTest { } @Test - public void testGetAutoCommit_NotSpecified() { - // TODO Make true the default return value once PHOENIX-1543 is in place - assertFalse(JDBCUtil.getAutoCommit("localhost", new Properties())); + public void testGetAutoCommit_NotSpecified_DefaultTrue() { + assertTrue(JDBCUtil.getAutoCommit("localhost", new Properties(), true)); + } + + + @Test + public void testGetAutoCommit_NotSpecified_DefaultFalse() { + assertFalse(JDBCUtil.getAutoCommit("localhost", new Properties(), false)); } @Test public void testGetAutoCommit_TrueInUrl() { - assertTrue(JDBCUtil.getAutoCommit("localhost;AutoCommit=TrUe", new Properties())); + assertTrue(JDBCUtil.getAutoCommit("localhost;AutoCommit=TrUe", new Properties(), false)); } @Test public void testGetAutoCommit_FalseInUrl() { - assertFalse(JDBCUtil.getAutoCommit("localhost;AutoCommit=FaLse", new Properties())); + assertFalse(JDBCUtil.getAutoCommit("localhost;AutoCommit=FaLse", new Properties(), false)); } @Test public void testGetAutoCommit_TrueInProperties() { Properties props = new Properties(); props.setProperty("AutoCommit", "true"); - assertTrue(JDBCUtil.getAutoCommit("localhost", props)); + assertTrue(JDBCUtil.getAutoCommit("localhost", props, false)); } @Test public void testGetAutoCommit_FalseInProperties() { Properties props = new Properties(); props.setProperty("AutoCommit", "false"); - assertFalse(JDBCUtil.getAutoCommit("localhost", props)); + assertFalse(JDBCUtil.getAutoCommit("localhost", props, false)); } }