This is an automated email from the ASF dual-hosted git repository. chinmayskulkarni pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/master by this push: new 964dd80 PHOENIX-5605: 4.14 Client can't add a column to a table on a 4.15 server 964dd80 is described below commit 964dd80f20ab8649af7672314f4127b73c0280b7 Author: Chinmay Kulkarni <chinmayskulka...@gmail.com> AuthorDate: Fri Dec 6 16:56:02 2019 -0800 PHOENIX-5605: 4.14 Client can't add a column to a table on a 4.15 server --- .../phoenix/coprocessor/MetaDataEndpointImpl.java | 9 +-- .../java/org/apache/phoenix/util/UpgradeUtil.java | 78 ++++++++++++++-------- .../java/org/apache/phoenix/util/ViewUtil.java | 16 ++--- 3 files changed, 62 insertions(+), 41 deletions(-) diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java index c3739d4..86afe8d 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java @@ -2131,12 +2131,12 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements RegionCopr return PTableType.INDEX == tableType && parentTable.getIndexes().size() >= maxIndexesPerTable; } - private List<PTable> findAllChildViews(long clientTimeStamp, byte[] tenantId, byte[] schemaName, byte[] tableName) throws IOException, SQLException { + private List<PTable> findAllChildViews(long clientTimeStamp, int clientVersion, byte[] tenantId, + byte[] schemaName, byte[] tableName) throws IOException, SQLException { TableViewFinderResult result = new TableViewFinderResult(); try (Table hTable = ServerUtil.getHTableForCoprocessorScan(env, - SchemaUtil.getPhysicalTableName(SYSTEM_CHILD_LINK_NAME_BYTES, - env.getConfiguration()))) { + getSystemTableForChildLinks(clientVersion, env.getConfiguration()))) { ViewUtil.findAllRelatives(hTable, tenantId, schemaName, tableName, LinkType.CHILD_TABLE, result); } @@ -2521,7 +2521,8 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements RegionCopr List<RowLock> locks = Lists.newArrayList(); try { if (expectedType == PTableType.TABLE) { - childViews = findAllChildViews(clientTimeStamp, tenantId, schemaName, tableName); + childViews = findAllChildViews(clientTimeStamp, clientVersion, tenantId, + schemaName, tableName); if (!childViews.isEmpty()) { // From 4.15 onwards we allow SYSTEM.CATALOG to split and no longer propagate parent diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java index e1a7608..830d702 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java @@ -42,6 +42,8 @@ import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.START_WITH; import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME; import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SYSTEM_CATALOG_SCHEMA; import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SYSTEM_CATALOG_TABLE; +import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SYSTEM_CATALOG_TABLE_BYTES; +import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SYSTEM_CHILD_LINK_NAME_BYTES; import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_CAT; import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_NAME; import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_SCHEM; @@ -1360,28 +1362,37 @@ public class UpgradeUtil { syncUpdateCacheFreqForIndexesOfTable(table, stmt); TableViewFinderResult childViewsResult = new TableViewFinderResult(); - try (Table childLinkTable = newConn.getQueryServices() - .getTable(SchemaUtil.getPhysicalName( - PhoenixDatabaseMetaData.SYSTEM_CHILD_LINK_NAME_BYTES, - newConn.getQueryServices().getProps()) - .getName())) { - ViewUtil.findAllRelatives(childLinkTable, tenantId, - table.getSchemaName().getBytes(), table.getTableName().getBytes(), - LinkType.CHILD_TABLE, childViewsResult); - - // Iterate over the chain of child views - for (TableInfo tableInfo: childViewsResult.getLinks()) { - PTable view; - String viewName = SchemaUtil.getTableName(tableInfo.getSchemaName(), - tableInfo.getTableName()); - try { - view = PhoenixRuntime.getTable(newConn, viewName); - } catch (TableNotFoundException e) { - // Ignore - LOGGER.warn("Error getting PTable for view: " + viewName); - continue; + for (int i=0; i<2; i++) { + try (Table sysCatOrSysChildLinkTable = newConn.getQueryServices() + .getTable(SchemaUtil.getPhysicalName( + i==0 ? SYSTEM_CHILD_LINK_NAME_BYTES : SYSTEM_CATALOG_TABLE_BYTES, + newConn.getQueryServices().getProps()) + .getName())) { + ViewUtil.findAllRelatives(sysCatOrSysChildLinkTable, tenantId, + table.getSchemaName().getBytes(), table.getTableName().getBytes(), + LinkType.CHILD_TABLE, childViewsResult); + + // Iterate over the chain of child views + for (TableInfo tableInfo: childViewsResult.getLinks()) { + PTable view; + String viewName = SchemaUtil.getTableName(tableInfo.getSchemaName(), + tableInfo.getTableName()); + try { + view = PhoenixRuntime.getTable(newConn, viewName); + } catch (TableNotFoundException e) { + // Ignore + LOGGER.warn("Error getting PTable for view: " + viewName); + continue; + } + syncUpdateCacheFreqForIndexesOfTable(view, stmt); + } + break; + } catch (TableNotFoundException ex) { + // try again with SYSTEM.CATALOG in case the schema is old + if (i == 1) { + // This means even SYSTEM.CATALOG was not found, so this is bad, rethrow + throw ex; } - syncUpdateCacheFreqForIndexesOfTable(view, stmt); } } stmt.executeBatch(); @@ -2123,14 +2134,23 @@ public class UpgradeUtil { LOGGER.info(String.format("teanantId %s..", conn.getTenantId())); TableViewFinderResult childViewsResult = new TableViewFinderResult(); - try (Table childLinkTable = - conn.getQueryServices() - .getTable(SchemaUtil.getPhysicalName( - PhoenixDatabaseMetaData.SYSTEM_CHILD_LINK_NAME_BYTES, readOnlyProps) - .getName())) { - byte[] tenantId = conn.getTenantId() != null ? conn.getTenantId().getBytes() : null; - ViewUtil.findAllRelatives(childLinkTable, tenantId, schemaName.getBytes(), - tableName.getBytes(), LinkType.CHILD_TABLE, childViewsResult); + + for (int i=0; i<2; i++) { + try (Table sysCatOrSysChildLinkTable = conn.getQueryServices() + .getTable(SchemaUtil.getPhysicalName( + i==0 ? SYSTEM_CHILD_LINK_NAME_BYTES : SYSTEM_CATALOG_TABLE_BYTES, + readOnlyProps).getName())) { + byte[] tenantId = conn.getTenantId() != null ? conn.getTenantId().getBytes() : null; + ViewUtil.findAllRelatives(sysCatOrSysChildLinkTable, tenantId, schemaName.getBytes(), + tableName.getBytes(), LinkType.CHILD_TABLE, childViewsResult); + break; + } catch (TableNotFoundException ex) { + // try again with SYSTEM.CATALOG in case the schema is old + if (i == 1) { + // This means even SYSTEM.CATALOG was not found, so this is bad, rethrow + throw ex; + } + } } // Upgrade the data or main table diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/ViewUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/ViewUtil.java index 559fbd5..8382c4b 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/util/ViewUtil.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/util/ViewUtil.java @@ -86,25 +86,25 @@ public class ViewUtil { private static final Logger logger = LoggerFactory.getLogger(ViewUtil.class); - public static void findAllRelatives(Table systemTable, byte[] tenantId, byte[] schema, byte[] table, + public static void findAllRelatives(Table sysCatOrsysChildLink, byte[] tenantId, byte[] schema, byte[] table, PTable.LinkType linkType, TableViewFinderResult result) throws IOException { - findAllRelatives(systemTable, tenantId, schema, table, linkType, HConstants.LATEST_TIMESTAMP, result); + findAllRelatives(sysCatOrsysChildLink, tenantId, schema, table, linkType, HConstants.LATEST_TIMESTAMP, result); } - static void findAllRelatives(Table systemCatalog, byte[] tenantId, byte[] schema, byte[] table, + private static void findAllRelatives(Table sysCatOrsysChildLink, byte[] tenantId, byte[] schema, byte[] table, PTable.LinkType linkType, long timestamp, TableViewFinderResult result) throws IOException { TableViewFinderResult currentResult = - findRelatedViews(systemCatalog, tenantId, schema, table, linkType, timestamp); + findRelatedViews(sysCatOrsysChildLink, tenantId, schema, table, linkType, timestamp); result.addResult(currentResult); for (TableInfo viewInfo : currentResult.getLinks()) { - findAllRelatives(systemCatalog, viewInfo.getTenantId(), viewInfo.getSchemaName(), viewInfo.getTableName(), linkType, timestamp, result); + findAllRelatives(sysCatOrsysChildLink, viewInfo.getTenantId(), viewInfo.getSchemaName(), viewInfo.getTableName(), linkType, timestamp, result); } } /** * Runs a scan on SYSTEM.CATALOG or SYSTEM.CHILD_LINK to get the related tables/views */ - static TableViewFinderResult findRelatedViews(Table systemCatalog, byte[] tenantId, byte[] schema, byte[] table, + private static TableViewFinderResult findRelatedViews(Table sysCatOrsysChildLink, byte[] tenantId, byte[] schema, byte[] table, PTable.LinkType linkType, long timestamp) throws IOException { if (linkType==PTable.LinkType.INDEX_TABLE || linkType==PTable.LinkType.EXCLUDED_COLUMN) { throw new IllegalArgumentException("findAllRelatives does not support link type "+linkType); @@ -122,7 +122,7 @@ public class ViewUtil { if (linkType==PTable.LinkType.PHYSICAL_TABLE) scan.addColumn(TABLE_FAMILY_BYTES, TABLE_TYPE_BYTES); List<TableInfo> tableInfoList = Lists.newArrayList(); - try (ResultScanner scanner = systemCatalog.getScanner(scan)) { + try (ResultScanner scanner = sysCatOrsysChildLink.getScanner(scan)) { for (Result result = scanner.next(); (result != null); result = scanner.next()) { byte[][] rowKeyMetaData = new byte[5][]; byte[] viewTenantId = null; @@ -191,7 +191,7 @@ public class ViewUtil { } catch (Exception e){ } - // if the SYSTEM.CHILD_LINK doesn't exist just return + // if the SYSTEM.CATALOG or SYSTEM.CHILD_LINK doesn't exist just return if (hTable==null) { return; }