This is an automated email from the ASF dual-hosted git repository. jisaac 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 d381c878ad PHOENIX-7573 (ADDENDUM) Handles upgrade for tables with alternate default column family (#2179) d381c878ad is described below commit d381c878adcc4f5fe3835d5234adf9b02ae0c3d2 Author: Jacob Isaac <jacobpisaa...@gmail.com> AuthorDate: Fri Jun 6 07:15:54 2025 -0700 PHOENIX-7573 (ADDENDUM) Handles upgrade for tables with alternate default column family (#2179) --- .../java/org/apache/phoenix/util/UpgradeUtil.java | 20 ++++++++++++++++++-- .../phoenix/end2end/MoveTTLDuringUpgradeIT.java | 22 +++++++++++++++++++++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/phoenix-core-client/src/main/java/org/apache/phoenix/util/UpgradeUtil.java b/phoenix-core-client/src/main/java/org/apache/phoenix/util/UpgradeUtil.java index 121aad1afa..86d4494ef5 100644 --- a/phoenix-core-client/src/main/java/org/apache/phoenix/util/UpgradeUtil.java +++ b/phoenix-core-client/src/main/java/org/apache/phoenix/util/UpgradeUtil.java @@ -1514,6 +1514,7 @@ public class UpgradeUtil { scan.withStartRow(lastRowKey, false); } // Collect the row keys to process them in batch + String currentTableName = ""; try (ResultScanner scanner = sysCatalogTable.getScanner(scan)) { int count = 0; List<byte[]> rowKeys = new ArrayList<>(); @@ -1530,15 +1531,23 @@ public class UpgradeUtil { byte[] tableName = rowKeyMetaData[PhoenixDatabaseMetaData.TABLE_NAME_INDEX]; String fullTableName = SchemaUtil.getTableName(schemaName, tableName); + currentTableName = fullTableName; if (SchemaUtil.isSystemTable(SchemaUtil.getTableNameAsBytes(schemaName, tableName))) { //We do not support system table ttl through phoenix ttl, and it will be moved to a //constant value in future commit. continue; } + PTable pTable = oldMetaConnection.getTable(null, fullTableName); + byte[] emptyCF = SchemaUtil.getEmptyColumnFamily(pTable); TableDescriptor tableDesc = admin.getDescriptor(SchemaUtil.getPhysicalTableName( fullTableName, readOnlyProps)); - int ttl = tableDesc.getColumnFamily(DEFAULT_COLUMN_FAMILY_BYTES). - getTimeToLive(); + ColumnFamilyDescriptor cfd = tableDesc.getColumnFamily(emptyCF); + if (cfd == null) { + LOGGER.warn("No emptyCF found. Not upgrading HBase level TTL definition for table {}", fullTableName); + continue; + } + LOGGER.info("Upgrading HBase level TTL definition for table {}", fullTableName); + int ttl = cfd.getTimeToLive(); // As we have ttl defined for this table create a Put to set TTL with // backward compatibility in mind. long rowTS = EnvironmentEdgeManager.currentTimeMillis(); @@ -1571,6 +1580,7 @@ public class UpgradeUtil { "Failed moving ttl value batch from ColumnDescriptor to TTL" + " column on %s with Exception :", SYSTEM_CATALOG_NAME), e); + throw new IOException(e); } } @@ -1579,6 +1589,12 @@ public class UpgradeUtil { "in progress => numOfTableHasTTLMoved: %d", numOfTableThatHasTTLMoved)); + } catch (Exception e) { + LOGGER.error(String.format( + "Failed moving ttl value to TTL column for %s with Exception :", + currentTableName), e); + throw new IOException(e); + } } while (pageMore); } catch (IOException ioe) { diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/MoveTTLDuringUpgradeIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/MoveTTLDuringUpgradeIT.java index 45ace8d26a..f182fa0c42 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/MoveTTLDuringUpgradeIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/MoveTTLDuringUpgradeIT.java @@ -105,7 +105,7 @@ public class MoveTTLDuringUpgradeIT extends ParallelStatsDisabledIT { while (rs.next()) { count++; String table = rs.getString(1); - LOGGER.info("found table: {} ", table); + LOGGER.info("found table {} : {} ", count, table); int ttl = tableTTLMap.get(table); int ttlInSyscat = Integer.valueOf(rs.getString(2)).intValue(); //Check if TTL is moved to SYSCAT. @@ -160,6 +160,26 @@ public class MoveTTLDuringUpgradeIT extends ParallelStatsDisabledIT { admin.modifyTable(builder.build()); admin.enableTable(tableName); } + + // Create table with non default column family + for (int i = numOfTable; i < numOfTable+2; i++ ) { + table = "T_" + generateUniqueName(); + randomTTL = i%2 == 0 ? HConstants.FOREVER : 100 + (int)(Math.random() * 1000); + tableTTLMap.put(table, randomTTL); + String ddl = "CREATE TABLE " + schema + "." + table + + " (a_string varchar not null, b_string varbinary not null, col1 integer" + + " CONSTRAINT pk PRIMARY KEY (a_string, b_string)) DEFAULT_COLUMN_FAMILY='Z'"; + + BaseTest.createTestTable(getUrl(), ddl); + TableName tableName = TableName.valueOf(SchemaUtil.getTableName(schema, table)); + TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName); + builder.setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder( + Bytes.toBytes("Z")).setTimeToLive(randomTTL).build()); + admin.disableTable(tableName); + admin.modifyTable(builder.build()); + admin.enableTable(tableName); + } + return tableTTLMap; }