You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by pb...@apache.org on 2018/06/28 00:02:59 UTC
[04/11] phoenix git commit: PHOENIX-4772 phoenix.sequence.saltBuckets
is not honoured
PHOENIX-4772 phoenix.sequence.saltBuckets is not honoured
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/91ffc048
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/91ffc048
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/91ffc048
Branch: refs/heads/4.x-cdh5.12
Commit: 91ffc048cda58cd986ea0ae74d857568801d15a2
Parents: 6916b8d
Author: Ankit Singhal <an...@gmail.com>
Authored: Thu Jun 7 19:23:44 2018 +0100
Committer: Pedro Boado <pb...@apache.org>
Committed: Sat Jun 9 19:42:27 2018 +0100
----------------------------------------------------------------------
.../org/apache/phoenix/end2end/SequenceIT.java | 57 +---------
.../phoenix/end2end/SequencePointInTimeIT.java | 112 +++++++++++++++++++
.../query/ConnectionQueryServicesImpl.java | 13 ++-
.../query/ConnectionlessQueryServicesImpl.java | 7 +-
.../apache/phoenix/query/QueryConstants.java | 2 +
.../org/apache/phoenix/schema/Sequence.java | 6 +-
6 files changed, 139 insertions(+), 58 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/91ffc048/phoenix-core/src/it/java/org/apache/phoenix/end2end/SequenceIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SequenceIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SequenceIT.java
index 4cc9628..b76cc4e 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SequenceIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SequenceIT.java
@@ -18,6 +18,8 @@
package org.apache.phoenix.end2end;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SYSTEM_CATALOG_SCHEMA;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TYPE_SEQUENCE;
import static org.apache.phoenix.query.QueryServicesTestImpl.DEFAULT_SEQUENCE_CACHE_SIZE;
import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
import static org.junit.Assert.assertEquals;
@@ -38,6 +40,7 @@ import org.apache.phoenix.exception.SQLExceptionCode;
import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
import org.apache.phoenix.jdbc.PhoenixStatement;
import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.query.QueryServicesTestImpl;
import org.apache.phoenix.schema.SchemaNotFoundException;
import org.apache.phoenix.schema.SequenceAlreadyExistsException;
import org.apache.phoenix.schema.SequenceNotFoundException;
@@ -202,6 +205,8 @@ public class SequenceIT extends ParallelStatsDisabledIT {
String schemaName = getSchemaName(sequenceName);
conn.createStatement().execute("CREATE SEQUENCE " + sequenceName + " START WITH 2 INCREMENT BY 4");
+ int bucketNum = PhoenixRuntime.getTableNoCache(conn, SYSTEM_CATALOG_SCHEMA + "." + TYPE_SEQUENCE).getBucketNum();
+ assertEquals("Salt bucket for SYSTEM.SEQUENCE should be test default",bucketNum , QueryServicesTestImpl.DEFAULT_SEQUENCE_TABLE_SALT_BUCKETS);
String query = "SELECT sequence_schema, sequence_name, current_value, increment_by FROM \"SYSTEM\".\"SEQUENCE\" WHERE sequence_name='" + sequenceNameWithoutSchema + "'";
ResultSet rs = conn.prepareStatement(query).executeQuery();
assertTrue(rs.next());
@@ -1406,56 +1411,4 @@ public class SequenceIT extends ParallelStatsDisabledIT {
return tableName.substring(tableName.indexOf(".") + 1, tableName.length());
}
- @Test
- public void testPointInTimeSequence() throws Exception {
- String seqName = generateSequenceNameWithSchema();
- Properties scnProps = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- scnProps.put(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(EnvironmentEdgeManager.currentTimeMillis()));
- Connection beforeSeqConn = DriverManager.getConnection(getUrl(), scnProps);
-
- ResultSet rs;
- Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- Connection conn = DriverManager.getConnection(getUrl(), props);
- conn.createStatement().execute("CREATE SEQUENCE " + seqName + "");
-
- try {
- beforeSeqConn.createStatement().executeQuery("SELECT next value for " + seqName);
- fail();
- } catch (SequenceNotFoundException e) {
- beforeSeqConn.close();
- }
-
- scnProps.put(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(EnvironmentEdgeManager.currentTimeMillis()));
- Connection afterSeqConn = DriverManager.getConnection(getUrl(), scnProps);
-
- rs = conn.createStatement().executeQuery("SELECT next value for " + seqName);
- assertTrue(rs.next());
- assertEquals(1, rs.getInt(1));
- rs = conn.createStatement().executeQuery("SELECT next value for " + seqName);
- assertTrue(rs.next());
- assertEquals(2, rs.getInt(1));
-
- conn.createStatement().execute("DROP SEQUENCE " + seqName + "");
-
- rs = afterSeqConn.createStatement().executeQuery("SELECT next value for " + seqName);
- assertTrue(rs.next());
- assertEquals(3, rs.getInt(1));
-
- try {
- rs = conn.createStatement().executeQuery("SELECT next value for " + seqName);
- fail();
- } catch (SequenceNotFoundException e) { // expected
- }
-
- conn.createStatement().execute("CREATE SEQUENCE " + seqName);
- rs = conn.createStatement().executeQuery("SELECT next value for " + seqName);
- assertTrue(rs.next());
- assertEquals(1, rs.getInt(1));
-
- rs = afterSeqConn.createStatement().executeQuery("SELECT next value for " + seqName);
- assertTrue(rs.next());
- assertEquals(4, rs.getInt(1));
- afterSeqConn.close();
- }
-
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/phoenix/blob/91ffc048/phoenix-core/src/it/java/org/apache/phoenix/end2end/SequencePointInTimeIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SequencePointInTimeIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SequencePointInTimeIT.java
new file mode 100644
index 0000000..3608901
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SequencePointInTimeIT.java
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.phoenix.end2end;
+
+import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.schema.SequenceNotFoundException;
+import org.apache.phoenix.util.EnvironmentEdgeManager;
+import org.apache.phoenix.util.PhoenixRuntime;
+import org.apache.phoenix.util.PropertiesUtil;
+import org.apache.phoenix.util.ReadOnlyProps;
+import org.apache.phoenix.util.SchemaUtil;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.google.common.collect.Maps;
+
+
+public class SequencePointInTimeIT extends BaseUniqueNamesOwnClusterIT {
+ private static final String SCHEMA_NAME = "S";
+
+ private static String generateSequenceNameWithSchema() {
+ return SchemaUtil.getTableName(SCHEMA_NAME, generateUniqueSequenceName());
+ }
+ @BeforeClass
+ public static void doSetup() throws Exception {
+ Map<String,String> props = Maps.newHashMapWithExpectedSize(5);
+ // Must update config before starting server
+ props.put(QueryServices.DEFAULT_SYSTEM_KEEP_DELETED_CELLS_ATTRIB, Boolean.TRUE.toString());
+ props.put(QueryServices.DEFAULT_SYSTEM_MAX_VERSIONS_ATTRIB, "5");
+ setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
+ }
+
+ @Test
+ public void testPointInTimeSequence() throws Exception {
+ String seqName = generateSequenceNameWithSchema();
+ Properties scnProps = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ scnProps.put(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(EnvironmentEdgeManager.currentTimeMillis()));
+ Connection beforeSeqConn = DriverManager.getConnection(getUrl(), scnProps);
+
+ ResultSet rs;
+ Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ Connection conn = DriverManager.getConnection(getUrl(), props);
+ conn.createStatement().execute("CREATE SEQUENCE " + seqName + "");
+
+ try {
+ beforeSeqConn.createStatement().executeQuery("SELECT next value for " + seqName);
+ fail();
+ } catch (SequenceNotFoundException e) {
+ beforeSeqConn.close();
+ }
+
+ scnProps.put(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(EnvironmentEdgeManager.currentTimeMillis()));
+ Connection afterSeqConn = DriverManager.getConnection(getUrl(), scnProps);
+
+ rs = conn.createStatement().executeQuery("SELECT next value for " + seqName);
+ assertTrue(rs.next());
+ assertEquals(1, rs.getInt(1));
+ rs = conn.createStatement().executeQuery("SELECT next value for " + seqName);
+ assertTrue(rs.next());
+ assertEquals(2, rs.getInt(1));
+
+ conn.createStatement().execute("DROP SEQUENCE " + seqName + "");
+
+ rs = afterSeqConn.createStatement().executeQuery("SELECT next value for " + seqName);
+ assertTrue(rs.next());
+ assertEquals(3, rs.getInt(1));
+
+ try {
+ rs = conn.createStatement().executeQuery("SELECT next value for " + seqName);
+ fail();
+ } catch (SequenceNotFoundException e) { // expected
+ }
+
+ conn.createStatement().execute("CREATE SEQUENCE " + seqName);
+ rs = conn.createStatement().executeQuery("SELECT next value for " + seqName);
+ assertTrue(rs.next());
+ assertEquals(1, rs.getInt(1));
+
+ rs = afterSeqConn.createStatement().executeQuery("SELECT next value for " + seqName);
+ assertTrue(rs.next());
+ assertEquals(4, rs.getInt(1));
+ afterSeqConn.close();
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/phoenix/blob/91ffc048/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 4290d23..bfaffbd 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
@@ -2464,6 +2464,11 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
return setSystemDDLProperties(QueryConstants.CREATE_TABLE_METADATA);
}
+ protected String getSystemSequenceTableDDL(int nSaltBuckets) {
+ String schema = String.format(setSystemDDLProperties(QueryConstants.CREATE_SEQUENCE_METADATA));
+ return Sequence.getCreateTableStatement(schema, nSaltBuckets);
+ }
+
// Available for testing
protected String getFunctionTableDDL() {
return setSystemDDLProperties(QueryConstants.CREATE_FUNCTION_METADATA);
@@ -2679,7 +2684,11 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
private void createOtherSystemTables(PhoenixConnection metaConnection, HBaseAdmin hbaseAdmin) throws SQLException, IOException {
try {
- metaConnection.createStatement().execute(QueryConstants.CREATE_SEQUENCE_METADATA);
+
+ nSequenceSaltBuckets = ConnectionQueryServicesImpl.this.props.getInt(
+ QueryServices.SEQUENCE_SALT_BUCKETS_ATTRIB,
+ QueryServicesOptions.DEFAULT_SEQUENCE_TABLE_SALT_BUCKETS);
+ metaConnection.createStatement().execute(getSystemSequenceTableDDL(nSequenceSaltBuckets));
} catch (TableAlreadyExistsException e) {
nSequenceSaltBuckets = getSaltBuckets(e);
}
@@ -3054,7 +3063,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
QueryServices.SEQUENCE_SALT_BUCKETS_ATTRIB,
QueryServicesOptions.DEFAULT_SEQUENCE_TABLE_SALT_BUCKETS);
try {
- String createSequenceTable = Sequence.getCreateTableStatement(nSaltBuckets);
+ String createSequenceTable = getSystemSequenceTableDDL(nSaltBuckets);
metaConnection.createStatement().executeUpdate(createSequenceTable);
nSequenceSaltBuckets = nSaltBuckets;
} catch (NewerTableAlreadyExistsException e) {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/91ffc048/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 cbc73ba..caec670 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
@@ -159,6 +159,11 @@ public class ConnectionlessQueryServicesImpl extends DelegateQueryServices imple
return setSystemDDLProperties(QueryConstants.CREATE_TABLE_METADATA);
}
+ protected String getSystemSequenceTableDDL(int nSaltBuckets) {
+ String schema = String.format(setSystemDDLProperties(QueryConstants.CREATE_SEQUENCE_METADATA));
+ return Sequence.getCreateTableStatement(schema, nSaltBuckets);
+ }
+
protected String getFunctionTableDDL() {
return setSystemDDLProperties(QueryConstants.CREATE_FUNCTION_METADATA);
}
@@ -343,7 +348,7 @@ public class ConnectionlessQueryServicesImpl extends DelegateQueryServices imple
}
try {
int nSaltBuckets = getSequenceSaltBuckets();
- String createTableStatement = Sequence.getCreateTableStatement(nSaltBuckets);
+ String createTableStatement = getSystemSequenceTableDDL(nSaltBuckets);
metaConnection.createStatement().executeUpdate(createTableStatement);
} catch (NewerTableAlreadyExistsException ignore) {
// Ignore, as this will happen if the SYSTEM.SEQUENCE already exists at this fixed timestamp.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/91ffc048/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java
index 52abed0..b31175a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java
@@ -279,6 +279,8 @@ public interface QueryConstants {
CYCLE_FLAG + " BOOLEAN, \n" +
LIMIT_REACHED_FLAG + " BOOLEAN \n" +
" CONSTRAINT " + SYSTEM_TABLE_PK_NAME + " PRIMARY KEY (" + TENANT_ID + "," + SEQUENCE_SCHEMA + "," + SEQUENCE_NAME + "))\n" +
+ HConstants.VERSIONS + "=%s,\n" +
+ HColumnDescriptor.KEEP_DELETED_CELLS + "=%s,\n"+
PhoenixDatabaseMetaData.TRANSACTIONAL + "=" + Boolean.FALSE;
public static final String CREATE_SYSTEM_SCHEMA = "CREATE SCHEMA " + SYSTEM_CATALOG_SCHEMA;
public static final String UPGRADE_TABLE_SNAPSHOT_PREFIX = "_UPGRADING_TABLE_";
http://git-wip-us.apache.org/repos/asf/phoenix/blob/91ffc048/phoenix-core/src/main/java/org/apache/phoenix/schema/Sequence.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/Sequence.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/Sequence.java
index 9598ace..e3704dc 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/Sequence.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/Sequence.java
@@ -626,10 +626,10 @@ public class Sequence {
.build().buildException();
}
- public static String getCreateTableStatement(int nSaltBuckets) {
+ public static String getCreateTableStatement(String schema, int nSaltBuckets) {
if (nSaltBuckets <= 0) {
- return QueryConstants.CREATE_SEQUENCE_METADATA;
+ return schema;
}
- return QueryConstants.CREATE_SEQUENCE_METADATA + "," + PhoenixDatabaseMetaData.SALT_BUCKETS + "=" + nSaltBuckets;
+ return schema + "," + PhoenixDatabaseMetaData.SALT_BUCKETS + "=" + nSaltBuckets;
}
}