phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rajeshb...@apache.org
Subject phoenix git commit: PHOENIX-4360 Prevent System.Catalog from splitting(Lars Hofhansl)
Date Thu, 01 Mar 2018 09:11:41 GMT
Repository: phoenix
Updated Branches:
  refs/heads/5.x-HBase-2.0 6dcc24fa4 -> ba518fb05


PHOENIX-4360 Prevent System.Catalog from splitting(Lars Hofhansl)


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

Branch: refs/heads/5.x-HBase-2.0
Commit: ba518fb05fcdd3c7c3253c010aad29d6231327aa
Parents: 6dcc24f
Author: Rajeshbabu Chintaguntla <rajeshbabu@apache.org>
Authored: Thu Mar 1 14:41:24 2018 +0530
Committer: Rajeshbabu Chintaguntla <rajeshbabu@apache.org>
Committed: Thu Mar 1 14:41:24 2018 +0530

----------------------------------------------------------------------
 .../apache/phoenix/end2end/SystemCatalogIT.java | 97 ++++++++++++++++++++
 .../phoenix/schema/MetaDataSplitPolicy.java     | 23 +----
 2 files changed, 100 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/ba518fb0/phoenix-core/src/it/java/org/apache/phoenix/end2end/SystemCatalogIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SystemCatalogIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SystemCatalogIT.java
new file mode 100644
index 0000000..9c66b9a
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SystemCatalogIT.java
@@ -0,0 +1,97 @@
+/*
+ * 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.junit.Assert.assertEquals;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Properties;
+
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.RegionLocator;
+import org.apache.phoenix.util.PhoenixRuntime;
+import org.junit.After;
+import org.junit.Ignore;
+import org.junit.Test;
+
+@Ignore
+public class SystemCatalogIT {
+    private HBaseTestingUtility testUtil = null;
+
+    @After
+    public void cleanup() throws Exception {
+        if (null != testUtil) {
+          testUtil.shutdownMiniCluster();
+          testUtil = null;
+        }
+    }
+
+    /**
+     * Make sure that SYSTEM.CATALOG cannot be split, even with schemas and multi-tenant
views
+     */
+    @Test
+    public void testSystemTableSplit() throws Exception {
+        testUtil = new HBaseTestingUtility();
+        testUtil.startMiniCluster(1);
+        for (int i=0; i<10; i++) {
+            createTable("schema"+i+".table_"+i);
+        }
+        TableName systemCatalog = TableName.valueOf("SYSTEM.CATALOG");
+        RegionLocator rl = testUtil.getConnection().getRegionLocator(systemCatalog);
+        assertEquals(rl.getAllRegionLocations().size(), 1);
+
+        // now attempt to split SYSTEM.CATALOG
+        testUtil.getAdmin().split(systemCatalog);
+
+        // make sure the split finishes (there's no synchronous splitting before HBase 2.x)
+        testUtil.getAdmin().disableTable(systemCatalog);
+        testUtil.getAdmin().enableTable(systemCatalog);
+
+        // test again... Must still be exactly one region.
+        rl = testUtil.getConnection().getRegionLocator(systemCatalog);
+        assertEquals(1, rl.getAllRegionLocations().size());
+    }
+
+    private void createTable(String tableName) throws Exception {
+        try (Connection conn = DriverManager.getConnection(getJdbcUrl());
+            Statement stmt = conn.createStatement();) {
+            stmt.execute("DROP TABLE IF EXISTS " + tableName);
+            stmt.execute("CREATE TABLE " + tableName
+                + " (TENANT_ID VARCHAR NOT NULL, PK1 VARCHAR NOT NULL, V1 VARCHAR CONSTRAINT
PK PRIMARY KEY(TENANT_ID, PK1)) MULTI_TENANT=true");
+            try (Connection tenant1Conn = getTenantConnection("tenant1")) {
+                String view1DDL = "CREATE VIEW " + tableName + "_view AS SELECT * FROM "
+ tableName;
+                tenant1Conn.createStatement().execute(view1DDL);
+            }
+            conn.commit();
+        }
+    }
+
+    private String getJdbcUrl() {
+        return "jdbc:phoenix:localhost:" + testUtil.getZkCluster().getClientPort() + ":/hbase";
+    }
+
+    private Connection getTenantConnection(String tenantId) throws SQLException {
+        Properties tenantProps = new Properties();
+        tenantProps.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId);
+        return DriverManager.getConnection(getJdbcUrl(), tenantProps);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/phoenix/blob/ba518fb0/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataSplitPolicy.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataSplitPolicy.java
b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataSplitPolicy.java
index 90fb8fb..154a9c2 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataSplitPolicy.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataSplitPolicy.java
@@ -25,25 +25,8 @@ import org.apache.phoenix.util.SchemaUtil;
 public class MetaDataSplitPolicy extends ConstantSizeRegionSplitPolicy {
 
     @Override
-    protected byte[] getSplitPoint() {
-        byte[] splitPoint = super.getSplitPoint();
-        int offset = SchemaUtil.getVarCharLength(splitPoint, 0, splitPoint.length);
-        // Split only on Phoenix schema name, so this is ok b/c we won't be splitting
-        // in the middle of a Phoenix table.
-        if (offset == splitPoint.length) {
-            return splitPoint;
-        }
-//        offset = SchemaUtil.getVarCharLength(splitPoint, offset+1, splitPoint.length-offset-1);
-//        // Split only on Phoenix schema and table name, so this is ok b/c we won't be splitting
-//        // in the middle of a Phoenix table.
-//        if (offset == splitPoint.length) {
-//            return splitPoint;
-//        }
-        // Otherwise, an attempt is being made to split in the middle of a table.
-        // Just return a split point at the schema boundary instead
-        byte[] newSplitPoint = new byte[offset + 1];
-        System.arraycopy(splitPoint, 0, newSplitPoint, 0, offset+1);
-        return newSplitPoint;
+    protected boolean shouldSplit() {
+        // never split SYSTEM.CATALOG
+        return false;
     }
-
 }


Mime
View raw message