[
https://issues.apache.org/jira/browse/PHOENIX-6191?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17232200#comment-17232200
]
ASF GitHub Bot commented on PHOENIX-6191:
-----------------------------------------
virajjasani commented on a change in pull request #966:
URL: https://github.com/apache/phoenix/pull/966#discussion_r523713916
##########
File path:
phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewConcurrencyAndFailureIT.java
##########
@@ -0,0 +1,793 @@
+/*
+ * 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.coprocessor.PhoenixMetaDataCoprocessorHost
+ .PHOENIX_META_DATA_COPROCESSOR_CONF_KEY;
+import static
org.apache.phoenix.exception.SQLExceptionCode.CANNOT_MUTATE_TABLE;
+import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.concurrent.Callable;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.hadoop.hbase.DoNotRetryIOException;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.coprocessor.ObserverContext;
+import org.apache.phoenix.coprocessor.BaseMetaDataEndpointObserver;
+import org.apache.phoenix.coprocessor.PhoenixMetaDataCoprocessorHost
+ .PhoenixMetaDataControllerEnvironment;
+import org.apache.phoenix.exception.PhoenixIOException;
+import org.apache.phoenix.exception.SQLExceptionCode;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.schema.ConcurrentTableMutationException;
+import org.apache.phoenix.schema.PTable;
+import org.apache.phoenix.schema.PTableType;
+import org.apache.phoenix.schema.TableNotFoundException;
+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.apache.phoenix.util.TestUtil;
+import org.junit.After;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import com.google.common.collect.Maps;
+
+/**
+ * Tests for views dealing with other ongoing concurrent operations and
+ * failure scenarios
+ */
+@RunWith(Parameterized.class)
+public class ViewConcurrencyAndFailureIT extends SplitSystemCatalogIT {
+
+ protected String tableDDLOptions;
+ protected String transactionProvider;
+ protected boolean columnEncoded;
+
+ private static final String FAILED_VIEWNAME = SchemaUtil.getTableName(
+ SCHEMA2, "FAILED_VIEW_" + generateUniqueName());
+ private static final String SLOW_VIEWNAME_PREFIX =
+ SchemaUtil.getTableName(SCHEMA2, "SLOW_VIEW");
+
+ private static volatile CountDownLatch latch1 = null;
+ private static volatile CountDownLatch latch2 = null;
+ private static volatile boolean throwExceptionInChildLinkPreHook = false;
+ private static volatile boolean slowDownAddingChildLink = false;
+
+ public ViewConcurrencyAndFailureIT(String transactionProvider,
+ boolean columnEncoded) {
+ StringBuilder optionBuilder = new StringBuilder();
+ this.transactionProvider = transactionProvider;
+ this.columnEncoded = columnEncoded;
+ if (transactionProvider != null) {
+ optionBuilder.append(" TRANSACTION_PROVIDER='")
+ .append(transactionProvider)
+ .append("'");
+ }
+ if (!columnEncoded) {
+ if (optionBuilder.length()!=0)
+ optionBuilder.append(",");
+ optionBuilder.append("COLUMN_ENCODED_BYTES=0");
+ }
+ this.tableDDLOptions = optionBuilder.toString();
+ }
+
+ // name is used by failsafe as file name in reports
+ @Parameters(name="ViewIT_transactionProvider={0}, columnEncoded={1}")
+ public static synchronized Collection<Object[]> data() {
+ return TestUtil.filterTxParamData(Arrays.asList(new Object[][] {
+ { "TEPHRA", false }, { "TEPHRA", true },
+ { "OMID", false },
+ { null, false }, { null, true }}),0);
+ }
+
+ @BeforeClass
+ public static synchronized void doSetup() throws Exception {
+ NUM_SLAVES_BASE = 6;
+ boolean splitSystemCatalog = (driver == null);
+ Map<String, String> serverProps = Maps.newHashMapWithExpectedSize(1);
+ serverProps.put(QueryServices.PHOENIX_ACLS_ENABLED, "true");
+ serverProps.put(PHOENIX_META_DATA_COPROCESSOR_CONF_KEY,
+ TestMetaDataRegionObserver.class.getName());
+ serverProps.put("hbase.coprocessor.abortonerror", "false");
+ setUpTestDriver(new ReadOnlyProps(serverProps.entrySet().iterator()),
+ ReadOnlyProps.EMPTY_PROPS);
+ // Split SYSTEM.CATALOG once after the mini-cluster is started
+ if (splitSystemCatalog) {
+ // splitSystemCatalog is incompatible with the balancer chore
+ getUtility().getHBaseCluster().getMaster().balanceSwitch(false);
+ splitSystemCatalog();
+ }
+ }
+
+ @After
+ public void cleanup() {
+ latch1 = null;
+ latch2 = null;
+ throwExceptionInChildLinkPreHook = false;
+ slowDownAddingChildLink = false;
+ }
+
+ @Test
+ public void testChildViewCreationFails() throws Exception {
+ try (Connection conn = DriverManager.getConnection(getUrl());
+ Statement stmt = conn.createStatement()) {
+
+ String fullTableName = SchemaUtil.getTableName(SCHEMA1,
+ generateUniqueName());
+ String failingViewName = FAILED_VIEWNAME;
+ String succeedingViewName = SchemaUtil.getTableName(SCHEMA3,
+ generateUniqueName());
+
+ String createTableDdl = "CREATE TABLE " + fullTableName
+ + " (k INTEGER NOT NULL PRIMARY KEY, v1 DATE)"
+ + tableDDLOptions;
+ stmt.execute(createTableDdl);
+
+ String createViewDdl = "CREATE VIEW " + failingViewName
+ + " (v2 VARCHAR) AS SELECT * FROM "
+ + fullTableName + " WHERE k > 5";
+ try {
+ stmt.execute(createViewDdl);
+ fail();
+ } catch (PhoenixIOException ignored) {
+ }
+ createViewDdl = "CREATE VIEW " + succeedingViewName
+ + "(v2 VARCHAR) AS SELECT * FROM " + fullTableName
+ + " WHERE k > 10";
+ stmt.execute(createViewDdl);
+
+ // the first child view should not exist
+ try {
+ PhoenixRuntime.getTableNoCache(conn, failingViewName);
+ fail();
+ } catch (TableNotFoundException ignored) {
+ }
+
+ // we should be able to load the table
+ PhoenixRuntime.getTableNoCache(conn, fullTableName);
+ // we should be able to load the second view
+ PhoenixRuntime.getTableNoCache(conn, succeedingViewName);
+ }
+ }
+
+ @Test
+ public void testConcurrentViewCreationAndTableDrop() throws Exception {
+ try (Connection conn = DriverManager.getConnection(getUrl());
+ Statement stmt = conn.createStatement()) {
+ String fullTableName = SchemaUtil.getTableName(SCHEMA1,
+ generateUniqueName());
+ String fullViewName1 = SLOW_VIEWNAME_PREFIX + "_"
+ + generateUniqueName();
+ latch1 = new CountDownLatch(1);
+ latch2 = new CountDownLatch(1);
+ String tableDdl = "CREATE TABLE " + fullTableName +
+ " (k INTEGER NOT NULL PRIMARY KEY, v1 INTEGER, v2
INTEGER)"
+ + tableDDLOptions;
+ stmt.execute(tableDdl);
+
+ ExecutorService executorService = Executors.newFixedThreadPool(
+ 1, new ThreadFactory() {
Review comment:
nit: maybe use `newSingleThreadExecutor()` instead? (for all similar
places in this file)
----------------------------------------------------------------
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:
[email protected]
> Creating a view which has its own new columns should also do checkAndPut
> checks on SYSTEM.MUTEX
> -----------------------------------------------------------------------------------------------
>
> Key: PHOENIX-6191
> URL: https://issues.apache.org/jira/browse/PHOENIX-6191
> Project: Phoenix
> Issue Type: Bug
> Affects Versions: 5.0.0, 4.15.0
> Reporter: Chinmay Kulkarni
> Assignee: Chinmay Kulkarni
> Priority: Critical
> Fix For: 5.1.0, 4.16.0
>
>
> Currently, when creating a view we do conditional writes with a checkAndPut
> to SYSTEM.MUTEX for the keys:
> (<physical parent's schema name>, <physical parent's table name>, <column
> name>)
> for each column in the view WHERE clause. Similarly, when issuing an ALTER
> TABLE/VIEW, we do a conditional write with a checkAndPut to SYSTEM.MUTEX for
> the key:
> (<physical parent's schema name>, <physical parent's table name>, <name of
> the column to add/drop>)
> to prevent conflicting modifications between a base table/view and its child
> views. However, if we create a view with its own new columns, for ex:
> {code:sql}
> CREATE VIEW V1 (NEW_COL1 INTEGER, NEW_COL2 INTEGER) AS SELECT * FROM T1 WHERE
> B = 10;
> {code}
> we will not do a checkAndPut with the new columns being added to the view
> (NEW_COL1 and NEW_COL2) thus conflicting concurrent mutations may occur to a
> parent in this case, for ex: a simultaneous ALTER TABLE/VIEW of the parent
> which adds NEW_COL1 as a VARCHAR. This will lead to data being unable to be
> read properly.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)