From dev-return-50833-archive-asf-public=cust-asf.ponee.io@phoenix.apache.org Thu Apr 12 03:52:07 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 3D21618064A for ; Thu, 12 Apr 2018 03:52:06 +0200 (CEST) Received: (qmail 20770 invoked by uid 500); 12 Apr 2018 01:52:05 -0000 Mailing-List: contact dev-help@phoenix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@phoenix.apache.org Delivered-To: mailing list dev@phoenix.apache.org Received: (qmail 20759 invoked by uid 99); 12 Apr 2018 01:52:05 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Apr 2018 01:52:05 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id AD41218061D for ; Thu, 12 Apr 2018 01:52:04 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -109.511 X-Spam-Level: X-Spam-Status: No, score=-109.511 tagged_above=-999 required=6.31 tests=[ENV_AND_HDR_SPF_MATCH=-0.5, KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01, USER_IN_DEF_SPF_WL=-7.5, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id IT2Cgub1OJvy for ; Thu, 12 Apr 2018 01:52:02 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id 23DF75FDB5 for ; Thu, 12 Apr 2018 01:52:02 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 57FA7E0BE1 for ; Thu, 12 Apr 2018 01:52:01 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id B1C05241C8 for ; Thu, 12 Apr 2018 01:52:00 +0000 (UTC) Date: Thu, 12 Apr 2018 01:52:00 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: dev@phoenix.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (PHOENIX-4579) Add a config to conditionally create Phoenix meta tables on first client connection MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/PHOENIX-4579?page=3Dcom.atlassi= an.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D16= 434819#comment-16434819 ]=20 ASF GitHub Bot commented on PHOENIX-4579: ----------------------------------------- Github user JamesRTaylor commented on a diff in the pull request: https://github.com/apache/phoenix/pull/295#discussion_r180945785 =20 --- Diff: phoenix-core/src/it/java/org/apache/phoenix/end2end/SystemCat= alogCreationOnConnectionIT.java --- @@ -0,0 +1,577 @@ +/* + * 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 imp= lied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.phoenix.end2end; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.TableName; +import org.apache.phoenix.coprocessor.MetaDataProtocol; +import org.apache.phoenix.exception.SQLExceptionCode; +import org.apache.phoenix.exception.UpgradeRequiredException; +import org.apache.phoenix.jdbc.PhoenixConnection; +import org.apache.phoenix.jdbc.PhoenixEmbeddedDriver; +import org.apache.phoenix.jdbc.PhoenixTestDriver; +import org.apache.phoenix.query.*; +import org.apache.phoenix.util.ReadOnlyProps; +import org.apache.phoenix.util.UpgradeUtil; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import java.io.IOException; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.*; +import java.util.concurrent.TimeoutException; + +import static org.junit.Assert.*; + +@Category(NeedsOwnMiniClusterTest.class) +public class SystemCatalogCreationOnConnectionIT { + private HBaseTestingUtility testUtil =3D null; + private Set hbaseTables; + private static boolean setOldTimestampToInduceUpgrade =3D false; + private static int countUpgradeAttempts; + // This flag is used to figure out if the SYSCAT schema was actual= ly upgraded or not, based on the timestamp of SYSCAT + // (different from an upgrade attempt) + private static int actualSysCatUpgrades; + private static final String PHOENIX_NAMESPACE_MAPPED_SYSTEM_CATALO= G =3D "SYSTEM:CATALOG"; + private static final String PHOENIX_SYSTEM_CATALOG =3D "SYSTEM.CAT= ALOG"; + private static final String EXECUTE_UPGRADE_COMMAND =3D "EXECUTE U= PGRADE"; + + private static final Set PHOENIX_SYSTEM_TABLES =3D new Has= hSet<>(Arrays.asList( + "SYSTEM.CATALOG", "SYSTEM.SEQUENCE", "SYSTEM.STATS", "SYSTEM.FUN= CTION", + "SYSTEM.MUTEX")); + + private static final Set PHOENIX_NAMESPACE_MAPPED_SYSTEM_T= ABLES =3D new HashSet<>( + Arrays.asList("SYSTEM:CATALOG", "SYSTEM:SEQUENCE", "SYSTEM:STATS= ", "SYSTEM:FUNCTION", + "SYSTEM:MUTEX")); + + private static class PhoenixSysCatCreationServices extends Connect= ionQueryServicesImpl { + + public PhoenixSysCatCreationServices(QueryServices services, P= hoenixEmbeddedDriver.ConnectionInfo connectionInfo, Properties info) { + super(services, connectionInfo, info); + } + + @Override + protected void setUpgradeRequired() { + super.setUpgradeRequired(); + countUpgradeAttempts++; + } + + @Override + protected long getSystemTableVersion() { + if (setOldTimestampToInduceUpgrade) { + // Return the next lower version where an upgrade was = performed to induce setting the upgradeRequired flag + return MetaDataProtocol.getPriorUpgradeVersion(); + } + return MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP; + } + + @Override + protected PhoenixConnection upgradeSystemCatalogIfRequired(Pho= enixConnection metaConnection, + long currentServerSideTableTimeStamp) throws InterruptedExce= ption, SQLException, TimeoutException, IOException { + PhoenixConnection newMetaConnection =3D super.upgradeSyste= mCatalogIfRequired(metaConnection, currentServerSideTableTimeStamp); + if (currentServerSideTableTimeStamp < MetaDataProtocol.MIN= _SYSTEM_TABLE_TIMESTAMP) { + actualSysCatUpgrades++; + } + return newMetaConnection; + } + } + =20 + public static class PhoenixSysCatCreationTestingDriver extends Pho= enixTestDriver { + private ConnectionQueryServices cqs; + private final ReadOnlyProps overrideProps; + =20 + public PhoenixSysCatCreationTestingDriver(ReadOnlyProps props)= { + overrideProps =3D props; + } + =20 + @Override // public for testing + public synchronized ConnectionQueryServices getConnectionQuery= Services(String url, Properties info) throws SQLException { + if (cqs =3D=3D null) { + cqs =3D new PhoenixSysCatCreationServices(new QuerySer= vicesTestImpl(getDefaultProps(), overrideProps), ConnectionInfo.create(url)= , info); + cqs.init(url, info); + } + return cqs; + } + =20 + // NOTE: Do not use this if you want to try re-establishing a = connection from the client using a previously + // used ConnectionQueryServices instance. This is used only in= cases where we need to test server-side + // changes and don't care about client-side properties set fro= m the init method. + // Reset the Connection Query Services instance so we can crea= te a new connection to the cluster + public void resetCQS() { + cqs =3D null; + } + } + + + @Before + public void resetVariables() { + setOldTimestampToInduceUpgrade =3D false; + countUpgradeAttempts =3D 0; + actualSysCatUpgrades =3D 0; + } + + @After + public void tearDownMiniCluster() { + try { + if (testUtil !=3D null) { + testUtil.shutdownMiniCluster(); + testUtil =3D null; + } + } catch (Exception e) { + // ignore + } + } + + + // Conditions: isDoNotUpgradePropSet is true + // Expected: We do not create SYSTEM.CATALOG even if this is the = first connection to the server + @Test + public void firstConnectionDoNotUpgradePropSet() throws Exception = { + startMiniClusterWithToggleNamespaceMapping(Boolean.FALSE.toStr= ing()); + Properties propsDoNotUpgradePropSet =3D new Properties(); + // Set doNotUpgradeProperty to true + UpgradeUtil.doNotUpgradeOnFirstConnection(propsDoNotUpgradePro= pSet); + SystemCatalogCreationOnConnectionIT.PhoenixSysCatCreationTesti= ngDriver driver =3D + new SystemCatalogCreationOnConnectionIT.PhoenixSysCatCreatio= nTestingDriver(ReadOnlyProps.EMPTY_PROPS); + try { + driver.getConnectionQueryServices(getJdbcUrl(), propsDoNot= UpgradePropSet); + fail("Client should not be able to create SYSTEM.CATALOG s= ince we set the doNotUpgrade property"); + } catch (Exception e) { + assertTrue(e instanceof UpgradeRequiredException); + } + hbaseTables =3D getHBaseTables(); + assertFalse(hbaseTables.contains(PHOENIX_SYSTEM_CATALOG) || hb= aseTables.contains(PHOENIX_NAMESPACE_MAPPED_SYSTEM_CATALOG)); + assertTrue(hbaseTables.size() =3D=3D 0); + assertEquals(1, countUpgradeAttempts); + } + + // Conditions: isAutoUpgradeEnabled is false + // Expected: We do not create SYSTEM.CATALOG even if this is the f= irst connection to the server. Later, when we manually + // run "EXECUTE UPGRADE", we create SYSTEM tables (except SYSTEM.M= UTEX) + @Test + public void firstConnectionAutoUpgradeDisabled() throws Exception = { + startMiniClusterWithToggleNamespaceMapping(Boolean.FALSE.toStr= ing()); + Map props =3D new HashMap<>(); + // Note that the isAutoUpgradeEnabled property is set when ins= tantiating connection query services, not during init + // Here we disable isAutoUpgradeEnabled + props.put(QueryServices.AUTO_UPGRADE_ENABLED, Boolean.FALSE.to= String()); + ReadOnlyProps readOnlyProps =3D new ReadOnlyProps(props); + SystemCatalogCreationOnConnectionIT.PhoenixSysCatCreationTesti= ngDriver driver =3D + new SystemCatalogCreationOnConnectionIT.PhoenixSysCatCreatio= nTestingDriver(readOnlyProps); + try { + driver.getConnectionQueryServices(getJdbcUrl(), new Proper= ties()); + fail("Client should not be able to create SYSTEM.CATALOG s= ince we set the isAutoUpgradeEnabled property to false"); + } catch (Exception e) { + assertTrue(e instanceof UpgradeRequiredException); + } + hbaseTables =3D getHBaseTables(); + assertFalse(hbaseTables.contains(PHOENIX_SYSTEM_CATALOG) || hb= aseTables.contains(PHOENIX_NAMESPACE_MAPPED_SYSTEM_CATALOG)); + assertTrue(hbaseTables.size() =3D=3D 0); + assertEquals(1, countUpgradeAttempts); + + // We use the same ConnectionQueryServices instance to run "EX= ECUTE UPGRADE" + Connection conn =3D driver.getConnectionQueryServices(getJdbcU= rl(), new Properties()).connect(getJdbcUrl(), new Properties()); + try { + conn.createStatement().execute(EXECUTE_UPGRADE_COMMAND); + } catch (Exception e) { + fail("EXECUTE UPGRADE should not fail"); + } finally { + conn.close(); + } + hbaseTables =3D getHBaseTables(); + assertTrue(PHOENIX_SYSTEM_TABLES.containsAll(hbaseTables)); + // SYSTEM.MUTEX table is not created + assertTrue(hbaseTables.size() =3D=3D 4); + } + + + /********************* Testing SYSTEM.CATALOG/SYSTEM:CATALOG creat= ion/upgrade behavior for subsequent connections *********************/ + + + // Conditions: server-side namespace mapping is enabled, the first= connection to the server will create unmapped + // SYSTEM tables i.e. SYSTEM\..*, the second connection has client= -side namespace mapping enabled and + // system table to system namespace mapping enabled + // Expected: We will migrate all SYSTEM\..* tables to the SYSTEM n= amespace + @Test + public void testMigrateToSystemNamespace() throws Exception { + SystemCatalogCreationOnConnectionIT.PhoenixSysCatCreationTesti= ngDriver driver =3D + firstConnectionNSMappingServerEnabledClientEnabledMappingDis= abled(); + driver.resetCQS(); + // Setting this to true to effect migration of SYSTEM tables t= o the SYSTEM namespace + Properties clientProps =3D getClientProperties(true, true); + driver.getConnectionQueryServices(getJdbcUrl(), clientProps); + hbaseTables =3D getHBaseTables(); + assertEquals(PHOENIX_NAMESPACE_MAPPED_SYSTEM_TABLES, hbaseTabl= es); + assertEquals(1, countUpgradeAttempts); + } + + // Conditions: server-side namespace mapping is enabled, the first= connection to the server will create all namespace + // mapped SYSTEM tables i.e. SYSTEM:.*, the SYSTEM:CATALOG timesta= mp at creation is purposefully set to be < + // MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP. The subsequent con= nection has client-side namespace mapping enabled + // Expected: An upgrade is attempted when the second client connec= ts to the server + @Test + public void testUpgradeAttempted() throws Exception { + setOldTimestampToInduceUpgrade =3D true; + SystemCatalogCreationOnConnectionIT.PhoenixSysCatCreationTesti= ngDriver driver =3D + firstConnectionNSMappingServerEnabledClientEnabled(); + driver.resetCQS(); + Properties clientProps =3D getClientProperties(true, true); + setOldTimestampToInduceUpgrade =3D false; + driver.getConnectionQueryServices(getJdbcUrl(), clientProps); + // There should be no new tables + assertEquals(hbaseTables, getHBaseTables()); + // Since we set an old timestamp on purpose when creating SYST= EM:CATALOG, the second connection attempts to upgrade it + assertEquals(1, countUpgradeAttempts); + assertEquals(1, actualSysCatUpgrades); + } + + // Conditions: server-side namespace mapping is enabled, the first= connection to the server will create all namespace + // mapped SYSTEM tables i.e. SYSTEM:.*, the SYSTEM:CATALOG timesta= mp at creation is purposefully set to be < + // MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP. The subsequent con= nection has client-side namespace mapping enabled + // Expected: An upgrade is attempted when the second client connec= ts to the server, but this fails since the + // isDoNotUpgradePropSet is set to true. We later run EXECUTE UPGR= ADE manually + @Test + public void testUpgradeNotAllowed() throws Exception { + setOldTimestampToInduceUpgrade =3D true; + SystemCatalogCreationOnConnectionIT.PhoenixSysCatCreationTesti= ngDriver driver =3D + firstConnectionNSMappingServerEnabledClientEnabled(); + driver.resetCQS(); + Properties clientProps =3D getClientProperties(true, true); + UpgradeUtil.doNotUpgradeOnFirstConnection(clientProps); + setOldTimestampToInduceUpgrade =3D false; + try { + driver.getConnectionQueryServices(getJdbcUrl(), clientProp= s); + } catch (Exception e) { + assertTrue(e instanceof UpgradeRequiredException); + } + // There should be no new tables + assertEquals(hbaseTables, getHBaseTables()); + // Since we set an old timestamp on purpose when creating SYST= EM:CATALOG, the second connection attempts to upgrade it + assertEquals(1, countUpgradeAttempts); + // This connection is unable to actually upgrade SYSTEM:CATALO= G due to isDoNotUpgradePropSet + assertEquals(0, actualSysCatUpgrades); + Connection conn =3D driver.getConnectionQueryServices(getJdbcU= rl(), new Properties()).connect(getJdbcUrl(), new Properties()); + try { + conn.createStatement().execute(EXECUTE_UPGRADE_COMMAND); + // Actually upgraded SYSTEM:CATALOG + assertEquals(1, actualSysCatUpgrades); + } catch (Exception e) { --- End diff -- =20 Same here - remove the catch block. > Add a config to conditionally create Phoenix meta tables on first client = connection > -------------------------------------------------------------------------= ---------- > > Key: PHOENIX-4579 > URL: https://issues.apache.org/jira/browse/PHOENIX-4579 > Project: Phoenix > Issue Type: New Feature > Reporter: Mujtaba Chohan > Assignee: Chinmay Kulkarni > Priority: Major > Attachments: PHOENIX-4579.patch > > > Currently we create/modify Phoenix meta tables on first client connection= . Adding a property to make it configurable (with default true as=C2=A0it i= s currently implemented). > With this property set to false, it will avoid lockstep upgrade requireme= nt for all clients when changing meta properties using=C2=A0PHOENIX-4575 as= this property can be flipped back on once all the clients are upgraded. -- This message was sent by Atlassian JIRA (v7.6.3#76005)