[ https://issues.apache.org/jira/browse/PHOENIX-6032?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17223361#comment-17223361 ]
ASF GitHub Bot commented on PHOENIX-6032: ----------------------------------------- yanxinyi commented on a change in pull request #949: URL: https://github.com/apache/phoenix/pull/949#discussion_r514740510 ########## File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/SystemCatalogRollbackEnabledIT.java ########## @@ -0,0 +1,271 @@ +/* + * 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.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.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; + +import com.google.common.collect.Maps; + +/** + * 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 = Maps.newHashMapWithExpectedSize(2); + Map<String, String> clientProps = Maps.newHashMapWithExpectedSize(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("SYSTEM.CATALOG"); Review comment: nit: using PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME ---------------------------------------------------------------- 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: us...@infra.apache.org > When phoenix.allow.system.catalog.rollback=true, a view still sees data from > a column that was dropped > ------------------------------------------------------------------------------------------------------ > > Key: PHOENIX-6032 > URL: https://issues.apache.org/jira/browse/PHOENIX-6032 > Project: Phoenix > Issue Type: Bug > Affects Versions: 5.0.0, 4.15.0 > Reporter: Chinmay Kulkarni > Assignee: Chinmay Kulkarni > Priority: Blocker > Fix For: 5.1.0, 4.16.0 > > Attachments: PHOENIX-6032.master.v1.patch > > > Start a 4.x server with phoenix.allow.system.catalog.rollback=true, > phoenix.system.catalog.splittable=false. Connect to it from a 4.x client with > phoenix.allow.system.catalog.rollback=true. Run the following from the 4.x > client: > {code:sql} > CREATE TABLE IF NOT EXISTS T (A INTEGER PRIMARY KEY, B INTEGER, C VARCHAR, D > INTEGER); > CREATE VIEW IF NOT EXISTS V (VA INTEGER, VB INTEGER) AS SELECT * FROM T WHERE > B=200; > UPSERT INTO V(A,B,C,D,VA,VB) VALUES (2, 200, 'def', -20, 91, 101); > SELECT * FROM T; > +----+------+------+------+ > | A | B | C | D | > +----+------+------+------+ > | 2 | 200 | def | -20 | > +----+------+------+------+ > SELECT * FROM V; > +----+------+------+------+-----+------+ > | A | B | C | D | VA | VB | > +----+------+------+------+-----+------+ > | 2 | 200 | def | -20 | 91 | 101 | > +----+------+------+------+-----+------+ > -- as expected > -- drop a parent column from the view > ALTER VIEW V DROP COLUMN C; > SELECT * FROM V; > +------+----+------+------+-----+------+ > | C | A | B | D | VA | VB | > +------+----+------+------+-----+------+ > | def | 2 | 200 | -20 | 91 | 101 | > +------+----+------+------+-----+------+ > -- Column C can still be seen and its ordering is changed for some reason. If > you run the drop column again, it is actually dropped > ALTER VIEW V DROP COLUMN C; > SELECT * FROM V; > +----+------+------+-----+------+ > | A | B | D | VA | VB | > +----+------+------+-----+------+ > | 2 | 200 | -20 | 91 | 101 | > +----+------+------+-----+------+ > -- Gets dropped when drop column is run a second time. > {code} > When splittable SYSTEM.CATALOG rollback is enabled, we store the parent's > column metadata along with the view as well. After the first drop column > command, metadata for column 'C' of the parent is removed from the view's > metadata rows however it is not marked diverged, nor is an EXCLUDED_COLUMN > entry made for that column in the view metadata rows. > Because of this, when resolving the view we potentially keep combining the > parent table columns and still get column 'C'. When the second drop column > command is issued is when we actually add an EXCLUDED_COLUMN linking row for > 'C' in the view metadata. -- This message was sent by Atlassian Jira (v8.3.4#803005)