You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by la...@apache.org on 2017/11/20 22:09:05 UTC

phoenix git commit: PHOENIX-4360 Prevent System.Catalog from splitting.

Repository: phoenix
Updated Branches:
  refs/heads/master ca1e17b75 -> c216b667a


PHOENIX-4360 Prevent System.Catalog from splitting.


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

Branch: refs/heads/master
Commit: c216b667a8da568f768c0d26f46fa1a9c0994a04
Parents: ca1e17b
Author: Lars Hofhansl <la...@apache.org>
Authored: Mon Nov 20 14:08:44 2017 -0800
Committer: Lars Hofhansl <la...@apache.org>
Committed: Mon Nov 20 14:08:44 2017 -0800

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


http://git-wip-us.apache.org/repos/asf/phoenix/blob/c216b667/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..8a9bca2
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SystemCatalogIT.java
@@ -0,0 +1,79 @@
+package org.apache.phoenix.end2end;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+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.Test;
+
+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.getHBaseAdmin().split(systemCatalog);
+
+        // make sure the split finishes (there's no synchronous splitting before HBase 2.x)
+        testUtil.getHBaseAdmin().disableTable(systemCatalog);
+        testUtil.getHBaseAdmin().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);
+    }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/c216b667/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;
     }
-
 }