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/15 06:27:25 UTC

[GitHub] [phoenix] virajjasani commented on a change in pull request #966: PHOENIX-6191: Creating a view which has its own new columns should also do checkAndPut checks on SYSTEM.MUTEX

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:
users@infra.apache.org