You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@phoenix.apache.org by GitBox <gi...@apache.org> on 2020/11/03 13:49:37 UTC

[GitHub] [phoenix] ChinmaySKulkarni commented on a change in pull request #949: PHOENIX-6032: When phoenix.allow.system.catalog.rollback=true, a view still sees data from a column that was dropped

ChinmaySKulkarni commented on a change in pull request #949:
URL: https://github.com/apache/phoenix/pull/949#discussion_r516230051



##########
File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/SystemCatalogRollbackEnabledIT.java
##########
@@ -0,0 +1,273 @@
+/*
+ * 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 static org.junit.Assert.assertFalse;
+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.sql.SQLException;
+import java.sql.Statement;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.hadoop.hbase.DoNotRetryIOException;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.RegionLocator;
+import org.apache.phoenix.exception.SQLExceptionCode;
+import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
+import org.apache.phoenix.query.BaseTest;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.schema.ColumnNotFoundException;
+import org.apache.phoenix.util.PhoenixRuntime;
+import org.apache.phoenix.util.ReadOnlyProps;
+import org.apache.phoenix.util.SchemaUtil;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+/**
+ * Tests various scenarios when {@link QueryServices#ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK}
+ * is set to true and SYSTEM.CATALOG should not be allowed to split. Note that this config must
+ * be set on both the client and server
+ */
+@Category(NeedsOwnMiniClusterTest.class)
+public class SystemCatalogRollbackEnabledIT extends BaseTest {
+
+    @BeforeClass
+    public static synchronized void doSetup() throws Exception {
+        Map<String, String> serverProps = new HashMap<>(2);
+        Map<String, String> clientProps = new HashMap<>(1);
+        serverProps.put(QueryServices.SYSTEM_CATALOG_SPLITTABLE, "false");
+        serverProps.put(QueryServices.ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK,
+                "true");
+        clientProps.put(QueryServices.ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK,
+                "true");
+        setUpTestDriver(new ReadOnlyProps(serverProps.entrySet().iterator()),
+                new ReadOnlyProps(clientProps.entrySet().iterator()));
+    }
+
+    private void createTable(String tableName) throws Exception {
+        try (Connection conn = DriverManager.getConnection(getUrl());
+                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 + "_view1 AS SELECT * FROM " +
+                        tableName;
+                tenant1Conn.createStatement().execute(view1DDL);
+            }
+            try (Connection tenant1Conn = getTenantConnection("tenant2")) {
+                String view1DDL = "CREATE VIEW " + tableName + "_view2 AS SELECT * FROM " +
+                        tableName;
+                tenant1Conn.createStatement().execute(view1DDL);
+            }
+            conn.commit();
+        }
+    }
+
+    private Connection getTenantConnection(String tenantId) throws SQLException {
+        Properties tenantProps = new Properties();
+        tenantProps.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId);
+        return DriverManager.getConnection(getUrl(), tenantProps);
+    }
+
+
+    /**
+     * Make sure that SYSTEM.CATALOG cannot be split if
+     * {@link QueryServices#SYSTEM_CATALOG_SPLITTABLE} is false
+     */
+    @Test
+    public void testSystemTableDoesNotSplit() throws Exception {
+        HBaseTestingUtility testUtil = getUtility();
+        for (int i=0; i<10; i++) {
+            createTable("schema"+i+".table_"+i);
+        }
+        TableName systemCatalog = TableName.valueOf(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME);
+        RegionLocator rl = testUtil.getConnection().getRegionLocator(systemCatalog);
+        assertEquals(1, rl.getAllRegionLocations().size());
+        try {
+            // 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);
+        } catch (DoNotRetryIOException e) {
+            // table is not splittable
+            assert (e.getMessage().contains("NOT splittable"));
+        }
+
+        // test again... Must still be exactly one region.
+        rl = testUtil.getConnection().getRegionLocator(systemCatalog);
+        assertEquals(1, rl.getAllRegionLocations().size());
+    }
+
+    /**
+     * Ensure that we cannot add a column to a parent table or view if
+     * {@link QueryServices#ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK} is true
+     */
+    @Test
+    public void testAddColumnOnParentFails() throws Exception {
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            final String parentTableName = SchemaUtil.getTableName(generateUniqueName(),
+                    generateUniqueName());
+            final String parentViewName = SchemaUtil.getTableName(generateUniqueName(),
+                    generateUniqueName());
+            final String childViewName = SchemaUtil.getTableName(generateUniqueName(),
+                    generateUniqueName());
+            // create parent table
+            String ddl = "CREATE TABLE " + parentTableName + " (col1 INTEGER NOT NULL,"
+                    + " col2 INTEGER " + "CONSTRAINT pk PRIMARY KEY (col1))";
+            conn.createStatement().execute(ddl);
+
+            // create view on table
+            ddl = "CREATE VIEW " + parentViewName + " AS SELECT * FROM " + parentTableName;
+            conn.createStatement().execute(ddl);
+            try {
+                ddl = "ALTER TABLE " + parentTableName + " ADD col4 INTEGER";
+                conn.createStatement().execute(ddl);
+                fail("ALTER TABLE ADD should not be allowed on parent table");
+            } catch (SQLException e) {
+                assertEquals(SQLExceptionCode.CANNOT_MUTATE_TABLE.getErrorCode(), e.getErrorCode());
+            }
+
+            // create child view on above view
+            ddl = "CREATE VIEW " + childViewName + "(col3 INTEGER) AS SELECT * FROM "
+                    + parentViewName;
+            conn.createStatement().execute(ddl);
+            try {
+                ddl = "ALTER VIEW " + parentViewName + " ADD col4 INTEGER";
+                conn.createStatement().execute(ddl);
+                fail("ALTER VIEW ADD should not be allowed on parent view");
+            } catch (SQLException e) {
+                assertEquals(SQLExceptionCode.CANNOT_MUTATE_TABLE.getErrorCode(), e.getErrorCode());
+            }
+
+            // alter child view with add column should be allowed
+            ddl = "ALTER VIEW " + childViewName + " ADD col4 INTEGER";
+            conn.createStatement().execute(ddl);
+        }
+    }
+
+    /**
+     * Ensure that we cannot drop a column from a parent table or view if
+     * {@link QueryServices#ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK} is true
+     */
+    @Test
+    public void testDropColumnOnParentFails() throws Exception {
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            final String parentTableName = SchemaUtil.getTableName(generateUniqueName(),
+                    generateUniqueName());
+            final String parentViewName = SchemaUtil.getTableName(generateUniqueName(),
+                    generateUniqueName());
+            final String childViewName = SchemaUtil.getTableName(generateUniqueName(),
+                    generateUniqueName());
+            // create parent table
+            String ddl = "CREATE TABLE " + parentTableName
+                    + " (col1 INTEGER NOT NULL, col2 INTEGER, col3 VARCHAR "
+                    + "CONSTRAINT pk PRIMARY KEY (col1))";
+            conn.createStatement().execute(ddl);
+
+            // create view on table
+            ddl = "CREATE VIEW " + parentViewName + " AS SELECT * FROM " + parentTableName;
+            conn.createStatement().execute(ddl);
+            try {
+                ddl = "ALTER TABLE " + parentTableName + " DROP COLUMN col2";
+                conn.createStatement().execute(ddl);
+                fail("ALTER TABLE DROP COLUMN should not be allowed on parent table");
+            } catch (SQLException e) {
+                assertEquals(SQLExceptionCode.CANNOT_MUTATE_TABLE.getErrorCode(), e.getErrorCode());
+            }
+
+            // create child view on above view
+            ddl = "CREATE VIEW " + childViewName + "(col5 INTEGER) AS SELECT * FROM "
+                    + parentViewName;
+            conn.createStatement().execute(ddl);
+            try {
+                ddl = "ALTER VIEW " + parentViewName + " DROP COLUMN col2";
+                conn.createStatement().execute(ddl);
+                fail("ALTER VIEW DROP COLUMN should not be allowed on parent view");
+            } catch (SQLException e) {
+                assertEquals(SQLExceptionCode.CANNOT_MUTATE_TABLE.getErrorCode(), e.getErrorCode());
+            }
+
+            // alter child view with drop column should be allowed
+            ddl = "ALTER VIEW " + childViewName + " DROP COLUMN col2";
+            conn.createStatement().execute(ddl);
+        }
+    }
+
+    // Test for PHOENIX-6032
+    @Test
+    public void testViewDoesNotSeeDataForDroppedColumn() throws Exception {
+        final String parentName = "T_"
+                + SchemaUtil.getTableName(generateUniqueName(), generateUniqueName());
+        final String viewName = "V_"
+                + SchemaUtil.getTableName(generateUniqueName(), generateUniqueName());
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            conn.createStatement().execute("CREATE TABLE " + parentName
+                    + " (A INTEGER PRIMARY KEY, B INTEGER, C VARCHAR, D INTEGER)");
+            conn.createStatement().execute("CREATE VIEW " + viewName + " (VA INTEGER, VB INTEGER)"
+                    + " AS SELECT * FROM " + parentName + " WHERE B=200");
+            // Upsert some data via the view
+            conn.createStatement().execute("UPSERT INTO " + viewName + " (A,B,C,D,VA,VB) VALUES"
+                    + " (2, 200, 'def', -20, 91, 101)");
+            conn.commit();
+        }
+
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            // Query from the parent table and assert expected values
+            ResultSet rs = conn.createStatement().executeQuery("SELECT A,B,C,D FROM " + parentName);
+            assertTrue(rs.next());
+            assertEquals(2, rs.getInt(1));
+            assertEquals(200, rs.getInt(2));
+            assertEquals("def", rs.getString(3));
+            assertEquals(-20, rs.getInt(4));
+            assertFalse(rs.next());
+
+            // Query from the view and assert expected values
+            rs = conn.createStatement().executeQuery("SELECT A,B,C,D,VA,VB FROM " + viewName);
+            assertTrue(rs.next());
+            assertEquals(2, rs.getInt(1));
+            assertEquals(200, rs.getInt(2));
+            assertEquals("def", rs.getString(3));
+            assertEquals(-20, rs.getInt(4));
+            assertEquals(91, rs.getInt(5));
+            assertEquals(101, rs.getInt(6));
+            assertFalse(rs.next());
+        }
+
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            // Drop a parent column from the view
+            conn.createStatement().execute("ALTER VIEW " + viewName + " DROP COLUMN C");
+            try {
+                conn.createStatement().executeQuery("SELECT C FROM " + viewName);
+                fail("Expected a ColumnNotFoundException for C since it was dropped");
+            } catch (ColumnNotFoundException ignore) { }

Review comment:
       I think it would be a much bigger bug if a view alteration caused the base table's data to be deleted :) This patch doesn't change any of that, so not sure that an extra check is valuable after this.

##########
File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/SystemCatalogRollbackEnabledIT.java
##########
@@ -0,0 +1,273 @@
+/*
+ * 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 static org.junit.Assert.assertFalse;
+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.sql.SQLException;
+import java.sql.Statement;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.hadoop.hbase.DoNotRetryIOException;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.RegionLocator;
+import org.apache.phoenix.exception.SQLExceptionCode;
+import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
+import org.apache.phoenix.query.BaseTest;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.schema.ColumnNotFoundException;
+import org.apache.phoenix.util.PhoenixRuntime;
+import org.apache.phoenix.util.ReadOnlyProps;
+import org.apache.phoenix.util.SchemaUtil;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+/**
+ * Tests various scenarios when {@link QueryServices#ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK}
+ * is set to true and SYSTEM.CATALOG should not be allowed to split. Note that this config must
+ * be set on both the client and server
+ */
+@Category(NeedsOwnMiniClusterTest.class)
+public class SystemCatalogRollbackEnabledIT extends BaseTest {
+
+    @BeforeClass
+    public static synchronized void doSetup() throws Exception {
+        Map<String, String> serverProps = new HashMap<>(2);
+        Map<String, String> clientProps = new HashMap<>(1);
+        serverProps.put(QueryServices.SYSTEM_CATALOG_SPLITTABLE, "false");
+        serverProps.put(QueryServices.ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK,
+                "true");
+        clientProps.put(QueryServices.ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK,
+                "true");
+        setUpTestDriver(new ReadOnlyProps(serverProps.entrySet().iterator()),
+                new ReadOnlyProps(clientProps.entrySet().iterator()));
+    }
+
+    private void createTable(String tableName) throws Exception {
+        try (Connection conn = DriverManager.getConnection(getUrl());
+                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 + "_view1 AS SELECT * FROM " +
+                        tableName;
+                tenant1Conn.createStatement().execute(view1DDL);
+            }
+            try (Connection tenant1Conn = getTenantConnection("tenant2")) {
+                String view1DDL = "CREATE VIEW " + tableName + "_view2 AS SELECT * FROM " +
+                        tableName;
+                tenant1Conn.createStatement().execute(view1DDL);
+            }
+            conn.commit();
+        }
+    }
+
+    private Connection getTenantConnection(String tenantId) throws SQLException {
+        Properties tenantProps = new Properties();
+        tenantProps.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId);
+        return DriverManager.getConnection(getUrl(), tenantProps);
+    }
+
+
+    /**
+     * Make sure that SYSTEM.CATALOG cannot be split if
+     * {@link QueryServices#SYSTEM_CATALOG_SPLITTABLE} is false
+     */
+    @Test
+    public void testSystemTableDoesNotSplit() throws Exception {
+        HBaseTestingUtility testUtil = getUtility();
+        for (int i=0; i<10; i++) {
+            createTable("schema"+i+".table_"+i);
+        }
+        TableName systemCatalog = TableName.valueOf(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME);
+        RegionLocator rl = testUtil.getConnection().getRegionLocator(systemCatalog);
+        assertEquals(1, rl.getAllRegionLocations().size());
+        try {
+            // 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);
+        } catch (DoNotRetryIOException e) {
+            // table is not splittable
+            assert (e.getMessage().contains("NOT splittable"));
+        }
+
+        // test again... Must still be exactly one region.
+        rl = testUtil.getConnection().getRegionLocator(systemCatalog);
+        assertEquals(1, rl.getAllRegionLocations().size());
+    }
+
+    /**
+     * Ensure that we cannot add a column to a parent table or view if
+     * {@link QueryServices#ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK} is true
+     */
+    @Test
+    public void testAddColumnOnParentFails() throws Exception {
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            final String parentTableName = SchemaUtil.getTableName(generateUniqueName(),
+                    generateUniqueName());
+            final String parentViewName = SchemaUtil.getTableName(generateUniqueName(),
+                    generateUniqueName());
+            final String childViewName = SchemaUtil.getTableName(generateUniqueName(),
+                    generateUniqueName());
+            // create parent table
+            String ddl = "CREATE TABLE " + parentTableName + " (col1 INTEGER NOT NULL,"
+                    + " col2 INTEGER " + "CONSTRAINT pk PRIMARY KEY (col1))";
+            conn.createStatement().execute(ddl);
+
+            // create view on table
+            ddl = "CREATE VIEW " + parentViewName + " AS SELECT * FROM " + parentTableName;
+            conn.createStatement().execute(ddl);
+            try {
+                ddl = "ALTER TABLE " + parentTableName + " ADD col4 INTEGER";
+                conn.createStatement().execute(ddl);
+                fail("ALTER TABLE ADD should not be allowed on parent table");
+            } catch (SQLException e) {
+                assertEquals(SQLExceptionCode.CANNOT_MUTATE_TABLE.getErrorCode(), e.getErrorCode());
+            }
+
+            // create child view on above view
+            ddl = "CREATE VIEW " + childViewName + "(col3 INTEGER) AS SELECT * FROM "
+                    + parentViewName;
+            conn.createStatement().execute(ddl);
+            try {
+                ddl = "ALTER VIEW " + parentViewName + " ADD col4 INTEGER";
+                conn.createStatement().execute(ddl);
+                fail("ALTER VIEW ADD should not be allowed on parent view");
+            } catch (SQLException e) {
+                assertEquals(SQLExceptionCode.CANNOT_MUTATE_TABLE.getErrorCode(), e.getErrorCode());
+            }
+
+            // alter child view with add column should be allowed
+            ddl = "ALTER VIEW " + childViewName + " ADD col4 INTEGER";
+            conn.createStatement().execute(ddl);
+        }
+    }
+
+    /**
+     * Ensure that we cannot drop a column from a parent table or view if
+     * {@link QueryServices#ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK} is true
+     */
+    @Test
+    public void testDropColumnOnParentFails() throws Exception {
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            final String parentTableName = SchemaUtil.getTableName(generateUniqueName(),
+                    generateUniqueName());
+            final String parentViewName = SchemaUtil.getTableName(generateUniqueName(),
+                    generateUniqueName());
+            final String childViewName = SchemaUtil.getTableName(generateUniqueName(),
+                    generateUniqueName());
+            // create parent table
+            String ddl = "CREATE TABLE " + parentTableName
+                    + " (col1 INTEGER NOT NULL, col2 INTEGER, col3 VARCHAR "
+                    + "CONSTRAINT pk PRIMARY KEY (col1))";
+            conn.createStatement().execute(ddl);
+
+            // create view on table
+            ddl = "CREATE VIEW " + parentViewName + " AS SELECT * FROM " + parentTableName;
+            conn.createStatement().execute(ddl);
+            try {
+                ddl = "ALTER TABLE " + parentTableName + " DROP COLUMN col2";
+                conn.createStatement().execute(ddl);
+                fail("ALTER TABLE DROP COLUMN should not be allowed on parent table");
+            } catch (SQLException e) {
+                assertEquals(SQLExceptionCode.CANNOT_MUTATE_TABLE.getErrorCode(), e.getErrorCode());
+            }
+
+            // create child view on above view
+            ddl = "CREATE VIEW " + childViewName + "(col5 INTEGER) AS SELECT * FROM "
+                    + parentViewName;
+            conn.createStatement().execute(ddl);
+            try {
+                ddl = "ALTER VIEW " + parentViewName + " DROP COLUMN col2";
+                conn.createStatement().execute(ddl);
+                fail("ALTER VIEW DROP COLUMN should not be allowed on parent view");
+            } catch (SQLException e) {
+                assertEquals(SQLExceptionCode.CANNOT_MUTATE_TABLE.getErrorCode(), e.getErrorCode());
+            }
+
+            // alter child view with drop column should be allowed
+            ddl = "ALTER VIEW " + childViewName + " DROP COLUMN col2";
+            conn.createStatement().execute(ddl);
+        }
+    }
+
+    // Test for PHOENIX-6032
+    @Test
+    public void testViewDoesNotSeeDataForDroppedColumn() throws Exception {
+        final String parentName = "T_"
+                + SchemaUtil.getTableName(generateUniqueName(), generateUniqueName());
+        final String viewName = "V_"
+                + SchemaUtil.getTableName(generateUniqueName(), generateUniqueName());
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            conn.createStatement().execute("CREATE TABLE " + parentName
+                    + " (A INTEGER PRIMARY KEY, B INTEGER, C VARCHAR, D INTEGER)");
+            conn.createStatement().execute("CREATE VIEW " + viewName + " (VA INTEGER, VB INTEGER)"
+                    + " AS SELECT * FROM " + parentName + " WHERE B=200");
+            // Upsert some data via the view
+            conn.createStatement().execute("UPSERT INTO " + viewName + " (A,B,C,D,VA,VB) VALUES"
+                    + " (2, 200, 'def', -20, 91, 101)");
+            conn.commit();
+        }
+
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            // Query from the parent table and assert expected values
+            ResultSet rs = conn.createStatement().executeQuery("SELECT A,B,C,D FROM " + parentName);
+            assertTrue(rs.next());
+            assertEquals(2, rs.getInt(1));
+            assertEquals(200, rs.getInt(2));
+            assertEquals("def", rs.getString(3));
+            assertEquals(-20, rs.getInt(4));
+            assertFalse(rs.next());
+
+            // Query from the view and assert expected values
+            rs = conn.createStatement().executeQuery("SELECT A,B,C,D,VA,VB FROM " + viewName);
+            assertTrue(rs.next());
+            assertEquals(2, rs.getInt(1));
+            assertEquals(200, rs.getInt(2));
+            assertEquals("def", rs.getString(3));
+            assertEquals(-20, rs.getInt(4));
+            assertEquals(91, rs.getInt(5));
+            assertEquals(101, rs.getInt(6));
+            assertFalse(rs.next());
+        }
+
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            // Drop a parent column from the view
+            conn.createStatement().execute("ALTER VIEW " + viewName + " DROP COLUMN C");
+            try {
+                conn.createStatement().executeQuery("SELECT C FROM " + viewName);
+                fail("Expected a ColumnNotFoundException for C since it was dropped");
+            } catch (ColumnNotFoundException ignore) { }

Review comment:
       I think it would be a much bigger bug if a view alteration caused the base table's schema to be changed. This patch doesn't change any of that, so not sure that an extra check is valuable after this.

##########
File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/SystemCatalogRollbackEnabledIT.java
##########
@@ -0,0 +1,273 @@
+/*
+ * 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 static org.junit.Assert.assertFalse;
+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.sql.SQLException;
+import java.sql.Statement;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.hadoop.hbase.DoNotRetryIOException;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.RegionLocator;
+import org.apache.phoenix.exception.SQLExceptionCode;
+import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
+import org.apache.phoenix.query.BaseTest;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.schema.ColumnNotFoundException;
+import org.apache.phoenix.util.PhoenixRuntime;
+import org.apache.phoenix.util.ReadOnlyProps;
+import org.apache.phoenix.util.SchemaUtil;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+/**
+ * Tests various scenarios when {@link QueryServices#ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK}
+ * is set to true and SYSTEM.CATALOG should not be allowed to split. Note that this config must
+ * be set on both the client and server
+ */
+@Category(NeedsOwnMiniClusterTest.class)
+public class SystemCatalogRollbackEnabledIT extends BaseTest {
+
+    @BeforeClass
+    public static synchronized void doSetup() throws Exception {
+        Map<String, String> serverProps = new HashMap<>(2);
+        Map<String, String> clientProps = new HashMap<>(1);
+        serverProps.put(QueryServices.SYSTEM_CATALOG_SPLITTABLE, "false");
+        serverProps.put(QueryServices.ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK,
+                "true");
+        clientProps.put(QueryServices.ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK,
+                "true");
+        setUpTestDriver(new ReadOnlyProps(serverProps.entrySet().iterator()),
+                new ReadOnlyProps(clientProps.entrySet().iterator()));
+    }
+
+    private void createTable(String tableName) throws Exception {

Review comment:
       This is copied over from an existing class to consolidate tests, but sure I will rename it.

##########
File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/SystemCatalogRollbackEnabledIT.java
##########
@@ -0,0 +1,273 @@
+/*
+ * 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 static org.junit.Assert.assertFalse;
+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.sql.SQLException;
+import java.sql.Statement;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.hadoop.hbase.DoNotRetryIOException;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.RegionLocator;
+import org.apache.phoenix.exception.SQLExceptionCode;
+import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
+import org.apache.phoenix.query.BaseTest;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.schema.ColumnNotFoundException;
+import org.apache.phoenix.util.PhoenixRuntime;
+import org.apache.phoenix.util.ReadOnlyProps;
+import org.apache.phoenix.util.SchemaUtil;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+/**
+ * Tests various scenarios when {@link QueryServices#ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK}
+ * is set to true and SYSTEM.CATALOG should not be allowed to split. Note that this config must
+ * be set on both the client and server
+ */
+@Category(NeedsOwnMiniClusterTest.class)
+public class SystemCatalogRollbackEnabledIT extends BaseTest {
+
+    @BeforeClass
+    public static synchronized void doSetup() throws Exception {
+        Map<String, String> serverProps = new HashMap<>(2);
+        Map<String, String> clientProps = new HashMap<>(1);
+        serverProps.put(QueryServices.SYSTEM_CATALOG_SPLITTABLE, "false");
+        serverProps.put(QueryServices.ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK,
+                "true");
+        clientProps.put(QueryServices.ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK,
+                "true");
+        setUpTestDriver(new ReadOnlyProps(serverProps.entrySet().iterator()),
+                new ReadOnlyProps(clientProps.entrySet().iterator()));
+    }
+
+    private void createTable(String tableName) throws Exception {
+        try (Connection conn = DriverManager.getConnection(getUrl());
+                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 + "_view1 AS SELECT * FROM " +
+                        tableName;
+                tenant1Conn.createStatement().execute(view1DDL);
+            }
+            try (Connection tenant1Conn = getTenantConnection("tenant2")) {

Review comment:
       Similarly, this is just copied over but I will change it. Thanks

##########
File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/SystemCatalogRollbackEnabledIT.java
##########
@@ -0,0 +1,298 @@
+/*
+ * 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 static org.junit.Assert.assertFalse;
+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.sql.SQLException;
+import java.sql.Statement;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.hadoop.hbase.DoNotRetryIOException;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.RegionLocator;
+import org.apache.phoenix.exception.SQLExceptionCode;
+import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
+import org.apache.phoenix.query.BaseTest;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.schema.ColumnNotFoundException;
+import org.apache.phoenix.util.PhoenixRuntime;
+import org.apache.phoenix.util.ReadOnlyProps;
+import org.apache.phoenix.util.SchemaUtil;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+/**
+ * Tests various scenarios when
+ * {@link QueryServices#ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK}
+ * is set to true and SYSTEM.CATALOG should not be allowed to split.
+ * Note that this config must
+ * be set on both the client and server
+ */
+@Category(NeedsOwnMiniClusterTest.class)
+public class SystemCatalogRollbackEnabledIT extends BaseTest {
+
+    @BeforeClass
+    public static synchronized void doSetup() throws Exception {
+        Map<String, String> serverProps = new HashMap<>(2);
+        Map<String, String> clientProps = new HashMap<>(1);
+        serverProps.put(QueryServices.SYSTEM_CATALOG_SPLITTABLE, "false");
+        serverProps.put(QueryServices.ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK,
+                "true");
+        clientProps.put(QueryServices.ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK,
+                "true");
+        setUpTestDriver(new ReadOnlyProps(serverProps.entrySet().iterator()),
+                new ReadOnlyProps(clientProps.entrySet().iterator()));
+    }
+
+    private void createTableAndTenantViews(String tableName) throws Exception {
+        try (Connection conn = DriverManager.getConnection(getUrl());
+                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 +
+                        "_view1 AS SELECT * FROM " +
+                        tableName;
+                tenant1Conn.createStatement().execute(view1DDL);
+            }
+            try (Connection tenant2Conn = getTenantConnection("tenant2")) {
+                String view1DDL = "CREATE VIEW " + tableName +
+                        "_view2 AS SELECT * FROM " + tableName;
+                tenant2Conn.createStatement().execute(view1DDL);
+            }
+            conn.commit();
+        }
+    }
+
+    private Connection getTenantConnection(String tenantId)
+            throws SQLException {
+        Properties tenantProps = new Properties();
+        tenantProps.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId);
+        return DriverManager.getConnection(getUrl(), tenantProps);
+    }
+
+
+    /**
+     * Make sure that SYSTEM.CATALOG cannot be split if
+     * {@link QueryServices#SYSTEM_CATALOG_SPLITTABLE} is false
+     */
+    @Test
+    public void testSystemTableDoesNotSplit() throws Exception {
+        HBaseTestingUtility testUtil = getUtility();
+        for (int i=0; i<10; i++) {
+            createTableAndTenantViews("schema"+i+".table_"+i);
+        }
+        TableName systemCatalog = TableName.valueOf(
+                PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME);
+        RegionLocator rl = testUtil.getConnection()
+                .getRegionLocator(systemCatalog);
+        assertEquals(1, rl.getAllRegionLocations().size());
+        try {
+            // 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);
+        } catch (DoNotRetryIOException e) {
+            // table is not splittable
+            assert (e.getMessage().contains("NOT splittable"));

Review comment:
       hmm I'm not sure. This diff is just a result of copy pasting from the original test `SystemCatalogIT` Let me try to find out. Will change to using JUnit assert.

##########
File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/SystemCatalogRollbackEnabledIT.java
##########
@@ -0,0 +1,298 @@
+/*
+ * 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 static org.junit.Assert.assertFalse;
+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.sql.SQLException;
+import java.sql.Statement;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.hadoop.hbase.DoNotRetryIOException;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.RegionLocator;
+import org.apache.phoenix.exception.SQLExceptionCode;
+import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
+import org.apache.phoenix.query.BaseTest;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.schema.ColumnNotFoundException;
+import org.apache.phoenix.util.PhoenixRuntime;
+import org.apache.phoenix.util.ReadOnlyProps;
+import org.apache.phoenix.util.SchemaUtil;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+/**
+ * Tests various scenarios when
+ * {@link QueryServices#ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK}
+ * is set to true and SYSTEM.CATALOG should not be allowed to split.
+ * Note that this config must
+ * be set on both the client and server
+ */
+@Category(NeedsOwnMiniClusterTest.class)
+public class SystemCatalogRollbackEnabledIT extends BaseTest {
+
+    @BeforeClass
+    public static synchronized void doSetup() throws Exception {
+        Map<String, String> serverProps = new HashMap<>(2);
+        Map<String, String> clientProps = new HashMap<>(1);
+        serverProps.put(QueryServices.SYSTEM_CATALOG_SPLITTABLE, "false");
+        serverProps.put(QueryServices.ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK,
+                "true");
+        clientProps.put(QueryServices.ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK,
+                "true");
+        setUpTestDriver(new ReadOnlyProps(serverProps.entrySet().iterator()),
+                new ReadOnlyProps(clientProps.entrySet().iterator()));
+    }
+
+    private void createTableAndTenantViews(String tableName) throws Exception {
+        try (Connection conn = DriverManager.getConnection(getUrl());
+                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 +
+                        "_view1 AS SELECT * FROM " +
+                        tableName;
+                tenant1Conn.createStatement().execute(view1DDL);
+            }
+            try (Connection tenant2Conn = getTenantConnection("tenant2")) {
+                String view1DDL = "CREATE VIEW " + tableName +
+                        "_view2 AS SELECT * FROM " + tableName;
+                tenant2Conn.createStatement().execute(view1DDL);
+            }
+            conn.commit();
+        }
+    }
+
+    private Connection getTenantConnection(String tenantId)
+            throws SQLException {
+        Properties tenantProps = new Properties();
+        tenantProps.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId);
+        return DriverManager.getConnection(getUrl(), tenantProps);
+    }
+
+
+    /**
+     * Make sure that SYSTEM.CATALOG cannot be split if
+     * {@link QueryServices#SYSTEM_CATALOG_SPLITTABLE} is false
+     */
+    @Test
+    public void testSystemTableDoesNotSplit() throws Exception {
+        HBaseTestingUtility testUtil = getUtility();
+        for (int i=0; i<10; i++) {
+            createTableAndTenantViews("schema"+i+".table_"+i);
+        }
+        TableName systemCatalog = TableName.valueOf(
+                PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME);
+        RegionLocator rl = testUtil.getConnection()
+                .getRegionLocator(systemCatalog);
+        assertEquals(1, rl.getAllRegionLocations().size());
+        try {
+            // 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);
+        } catch (DoNotRetryIOException e) {
+            // table is not splittable
+            assert (e.getMessage().contains("NOT splittable"));
+        }
+
+        // test again... Must still be exactly one region.
+        rl = testUtil.getConnection().getRegionLocator(systemCatalog);
+        assertEquals(1, rl.getAllRegionLocations().size());
+    }
+
+    /**
+     * Ensure that we cannot add a column to a parent table or view if
+     * {@link QueryServices#ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK} is true
+     */
+    @Test
+    public void testAddColumnOnParentFails() throws Exception {
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            final String parentTableName = SchemaUtil.getTableName(
+                    generateUniqueName(), generateUniqueName());
+            final String parentViewName = SchemaUtil.getTableName(
+                    generateUniqueName(), generateUniqueName());
+            final String childViewName = SchemaUtil.getTableName(
+                    generateUniqueName(), generateUniqueName());
+            // create parent table
+            String ddl = "CREATE TABLE " + parentTableName
+                    + " (col1 INTEGER NOT NULL,"
+                    + " col2 INTEGER " + "CONSTRAINT pk PRIMARY KEY (col1))";
+            conn.createStatement().execute(ddl);
+
+            // create view on table
+            ddl = "CREATE VIEW " + parentViewName + " AS SELECT * FROM "
+                    + parentTableName;
+            conn.createStatement().execute(ddl);
+            try {
+                ddl = "ALTER TABLE " + parentTableName + " ADD col4 INTEGER";
+                conn.createStatement().execute(ddl);
+                fail("ALTER TABLE ADD should not be allowed on parent table");
+            } catch (SQLException e) {
+                assertEquals(SQLExceptionCode.CANNOT_MUTATE_TABLE
+                        .getErrorCode(), e.getErrorCode());
+            }
+
+            // create child view on above view
+            ddl = "CREATE VIEW " + childViewName
+                    + "(col3 INTEGER) AS SELECT * FROM " + parentViewName;
+            conn.createStatement().execute(ddl);
+            try {
+                ddl = "ALTER VIEW " + parentViewName + " ADD col4 INTEGER";
+                conn.createStatement().execute(ddl);
+                fail("ALTER VIEW ADD should not be allowed on parent view");
+            } catch (SQLException e) {
+                assertEquals(SQLExceptionCode.CANNOT_MUTATE_TABLE
+                        .getErrorCode(), e.getErrorCode());
+            }
+
+            // alter child view with add column should be allowed
+            ddl = "ALTER VIEW " + childViewName + " ADD col4 INTEGER";
+            conn.createStatement().execute(ddl);
+        }
+    }
+
+    /**
+     * Ensure that we cannot drop a column from a parent table or view if
+     * {@link QueryServices#ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK} is true
+     */
+    @Test
+    public void testDropColumnOnParentFails() throws Exception {
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            final String parentTableName = SchemaUtil.getTableName(
+                    generateUniqueName(), generateUniqueName());
+            final String parentViewName = SchemaUtil.getTableName(
+                    generateUniqueName(), generateUniqueName());
+            final String childViewName = SchemaUtil.getTableName(
+                    generateUniqueName(), generateUniqueName());
+            // create parent table
+            String ddl = "CREATE TABLE " + parentTableName
+                    + " (col1 INTEGER NOT NULL, col2 INTEGER, col3 VARCHAR "
+                    + "CONSTRAINT pk PRIMARY KEY (col1))";
+            conn.createStatement().execute(ddl);
+
+            // create view on table
+            ddl = "CREATE VIEW " + parentViewName + " AS SELECT * FROM "
+                    + parentTableName;
+            conn.createStatement().execute(ddl);
+            try {
+                ddl = "ALTER TABLE " + parentTableName + " DROP COLUMN col2";
+                conn.createStatement().execute(ddl);
+                fail("ALTER TABLE DROP COLUMN should not be allowed on "
+                        + "parent table");
+            } catch (SQLException e) {
+                assertEquals(SQLExceptionCode.CANNOT_MUTATE_TABLE
+                        .getErrorCode(), e.getErrorCode());
+            }
+
+            // create child view on above view
+            ddl = "CREATE VIEW " + childViewName
+                    + "(col5 INTEGER) AS SELECT * FROM " + parentViewName;
+            conn.createStatement().execute(ddl);
+            try {
+                ddl = "ALTER VIEW " + parentViewName + " DROP COLUMN col2";
+                conn.createStatement().execute(ddl);
+                fail("ALTER VIEW DROP COLUMN should not be allowed on "
+                        + "parent view");
+            } catch (SQLException e) {
+                assertEquals(SQLExceptionCode.CANNOT_MUTATE_TABLE
+                        .getErrorCode(), e.getErrorCode());
+            }
+
+            // alter child view with drop column should be allowed
+            ddl = "ALTER VIEW " + childViewName + " DROP COLUMN col2";
+            conn.createStatement().execute(ddl);
+        }
+    }
+
+    // Test for PHOENIX-6032
+    @Test
+    public void testViewDoesNotSeeDataForDroppedColumn() throws Exception {
+        final String parentName = "T_" + SchemaUtil.getTableName(
+                generateUniqueName(), generateUniqueName());
+        final String viewName = "V_" + SchemaUtil.getTableName(
+                generateUniqueName(), generateUniqueName());
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            conn.createStatement().execute("CREATE TABLE " + parentName
+                    + " (A INTEGER PRIMARY KEY, B INTEGER, C"
+                    + " VARCHAR, D INTEGER)");
+            conn.createStatement().execute("CREATE VIEW " + viewName
+                    + " (VA INTEGER, VB INTEGER)"
+                    + " AS SELECT * FROM " + parentName + " WHERE B=200");
+            // Upsert some data via the view
+            conn.createStatement().execute("UPSERT INTO " + viewName
+                    + " (A,B,C,D,VA,VB) VALUES"
+                    + " (2, 200, 'def', -20, 91, 101)");
+            conn.commit();
+        }
+
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            // Query from the parent table and assert expected values
+            ResultSet rs = conn.createStatement().executeQuery(
+                    "SELECT A,B,C,D FROM " + parentName);
+            assertTrue(rs.next());
+            assertEquals(2, rs.getInt(1));
+            assertEquals(200, rs.getInt(2));
+            assertEquals("def", rs.getString(3));
+            assertEquals(-20, rs.getInt(4));
+            assertFalse(rs.next());
+
+            // Query from the view and assert expected values
+            rs = conn.createStatement().executeQuery(
+                    "SELECT A,B,C,D,VA,VB FROM " + viewName);
+            assertTrue(rs.next());
+            assertEquals(2, rs.getInt(1));
+            assertEquals(200, rs.getInt(2));
+            assertEquals("def", rs.getString(3));
+            assertEquals(-20, rs.getInt(4));
+            assertEquals(91, rs.getInt(5));
+            assertEquals(101, rs.getInt(6));
+            assertFalse(rs.next());
+        }
+
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            // Drop a parent column from the view
+            conn.createStatement().execute("ALTER VIEW " + viewName
+                    + " DROP COLUMN C");
+            try {
+                conn.createStatement().executeQuery("SELECT C FROM "
+                        + viewName);
+                fail("Expected a ColumnNotFoundException for C since it "
+                        + "was dropped");
+            } catch (ColumnNotFoundException ignore) { }
+        }

Review comment:
       If any other exception apart from CNFE gets thrown here the test will fail anyways.

##########
File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/SystemCatalogRollbackEnabledIT.java
##########
@@ -0,0 +1,298 @@
+/*
+ * 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 static org.junit.Assert.assertFalse;
+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.sql.SQLException;
+import java.sql.Statement;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.hadoop.hbase.DoNotRetryIOException;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.RegionLocator;
+import org.apache.phoenix.exception.SQLExceptionCode;
+import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
+import org.apache.phoenix.query.BaseTest;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.schema.ColumnNotFoundException;
+import org.apache.phoenix.util.PhoenixRuntime;
+import org.apache.phoenix.util.ReadOnlyProps;
+import org.apache.phoenix.util.SchemaUtil;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+/**
+ * Tests various scenarios when
+ * {@link QueryServices#ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK}
+ * is set to true and SYSTEM.CATALOG should not be allowed to split.
+ * Note that this config must
+ * be set on both the client and server
+ */
+@Category(NeedsOwnMiniClusterTest.class)
+public class SystemCatalogRollbackEnabledIT extends BaseTest {
+
+    @BeforeClass
+    public static synchronized void doSetup() throws Exception {
+        Map<String, String> serverProps = new HashMap<>(2);
+        Map<String, String> clientProps = new HashMap<>(1);
+        serverProps.put(QueryServices.SYSTEM_CATALOG_SPLITTABLE, "false");
+        serverProps.put(QueryServices.ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK,
+                "true");
+        clientProps.put(QueryServices.ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK,
+                "true");
+        setUpTestDriver(new ReadOnlyProps(serverProps.entrySet().iterator()),
+                new ReadOnlyProps(clientProps.entrySet().iterator()));
+    }
+
+    private void createTableAndTenantViews(String tableName) throws Exception {
+        try (Connection conn = DriverManager.getConnection(getUrl());
+                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 +
+                        "_view1 AS SELECT * FROM " +
+                        tableName;
+                tenant1Conn.createStatement().execute(view1DDL);
+            }
+            try (Connection tenant2Conn = getTenantConnection("tenant2")) {
+                String view1DDL = "CREATE VIEW " + tableName +
+                        "_view2 AS SELECT * FROM " + tableName;
+                tenant2Conn.createStatement().execute(view1DDL);
+            }
+            conn.commit();
+        }
+    }
+
+    private Connection getTenantConnection(String tenantId)
+            throws SQLException {
+        Properties tenantProps = new Properties();
+        tenantProps.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId);
+        return DriverManager.getConnection(getUrl(), tenantProps);
+    }
+
+
+    /**
+     * Make sure that SYSTEM.CATALOG cannot be split if
+     * {@link QueryServices#SYSTEM_CATALOG_SPLITTABLE} is false
+     */
+    @Test
+    public void testSystemTableDoesNotSplit() throws Exception {
+        HBaseTestingUtility testUtil = getUtility();
+        for (int i=0; i<10; i++) {
+            createTableAndTenantViews("schema"+i+".table_"+i);
+        }
+        TableName systemCatalog = TableName.valueOf(
+                PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME);
+        RegionLocator rl = testUtil.getConnection()
+                .getRegionLocator(systemCatalog);
+        assertEquals(1, rl.getAllRegionLocations().size());
+        try {
+            // 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);
+        } catch (DoNotRetryIOException e) {
+            // table is not splittable
+            assert (e.getMessage().contains("NOT splittable"));

Review comment:
       Looks like that test wasn't reliably trying to split SYSCAT at all. I will open a follow-up Jira to fix this since it is unrelated to 6032.

##########
File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/SystemCatalogRollbackEnabledIT.java
##########
@@ -0,0 +1,298 @@
+/*
+ * 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 static org.junit.Assert.assertFalse;
+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.sql.SQLException;
+import java.sql.Statement;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.hadoop.hbase.DoNotRetryIOException;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.RegionLocator;
+import org.apache.phoenix.exception.SQLExceptionCode;
+import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
+import org.apache.phoenix.query.BaseTest;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.schema.ColumnNotFoundException;
+import org.apache.phoenix.util.PhoenixRuntime;
+import org.apache.phoenix.util.ReadOnlyProps;
+import org.apache.phoenix.util.SchemaUtil;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+/**
+ * Tests various scenarios when
+ * {@link QueryServices#ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK}
+ * is set to true and SYSTEM.CATALOG should not be allowed to split.
+ * Note that this config must
+ * be set on both the client and server
+ */
+@Category(NeedsOwnMiniClusterTest.class)
+public class SystemCatalogRollbackEnabledIT extends BaseTest {
+
+    @BeforeClass
+    public static synchronized void doSetup() throws Exception {
+        Map<String, String> serverProps = new HashMap<>(2);
+        Map<String, String> clientProps = new HashMap<>(1);
+        serverProps.put(QueryServices.SYSTEM_CATALOG_SPLITTABLE, "false");
+        serverProps.put(QueryServices.ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK,
+                "true");
+        clientProps.put(QueryServices.ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK,
+                "true");
+        setUpTestDriver(new ReadOnlyProps(serverProps.entrySet().iterator()),
+                new ReadOnlyProps(clientProps.entrySet().iterator()));
+    }
+
+    private void createTableAndTenantViews(String tableName) throws Exception {
+        try (Connection conn = DriverManager.getConnection(getUrl());
+                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 +
+                        "_view1 AS SELECT * FROM " +
+                        tableName;
+                tenant1Conn.createStatement().execute(view1DDL);
+            }
+            try (Connection tenant2Conn = getTenantConnection("tenant2")) {
+                String view1DDL = "CREATE VIEW " + tableName +
+                        "_view2 AS SELECT * FROM " + tableName;
+                tenant2Conn.createStatement().execute(view1DDL);
+            }
+            conn.commit();
+        }
+    }
+
+    private Connection getTenantConnection(String tenantId)
+            throws SQLException {
+        Properties tenantProps = new Properties();
+        tenantProps.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId);
+        return DriverManager.getConnection(getUrl(), tenantProps);
+    }
+
+
+    /**
+     * Make sure that SYSTEM.CATALOG cannot be split if
+     * {@link QueryServices#SYSTEM_CATALOG_SPLITTABLE} is false
+     */
+    @Test
+    public void testSystemTableDoesNotSplit() throws Exception {
+        HBaseTestingUtility testUtil = getUtility();
+        for (int i=0; i<10; i++) {
+            createTableAndTenantViews("schema"+i+".table_"+i);
+        }
+        TableName systemCatalog = TableName.valueOf(
+                PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME);
+        RegionLocator rl = testUtil.getConnection()
+                .getRegionLocator(systemCatalog);
+        assertEquals(1, rl.getAllRegionLocations().size());
+        try {
+            // 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);
+        } catch (DoNotRetryIOException e) {
+            // table is not splittable
+            assert (e.getMessage().contains("NOT splittable"));

Review comment:
       Created https://issues.apache.org/jira/browse/PHOENIX-6212




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org