PHOENIX-2713 Backward compatibility fails with CNF exception with 4.7 client and server when upgraded from 4.6
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/1f7b47a5 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/1f7b47a5 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/1f7b47a5 Branch: refs/heads/calcite Commit: 1f7b47a5e75fe5f6014b4dcdeb4637d05fd12a43 Parents: 05e6e2a Author: James Taylor <jtay...@salesforce.com> Authored: Wed Feb 24 11:48:16 2016 -0800 Committer: James Taylor <jtay...@salesforce.com> Committed: Wed Feb 24 12:01:21 2016 -0800 ---------------------------------------------------------------------- .../phoenix/coprocessor/MetaDataProtocol.java | 2 +- .../query/ConnectionQueryServicesImpl.java | 35 ++++++++++++++++---- 2 files changed, 30 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/1f7b47a5/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataProtocol.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataProtocol.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataProtocol.java index a704e22..fb9d228 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataProtocol.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataProtocol.java @@ -73,7 +73,7 @@ public abstract class MetaDataProtocol extends MetaDataService { public static final long MIN_SYSTEM_TABLE_TIMESTAMP_4_3_0 = MIN_TABLE_TIMESTAMP + 7; public static final long MIN_SYSTEM_TABLE_TIMESTAMP_4_5_0 = MIN_TABLE_TIMESTAMP + 8; public static final long MIN_SYSTEM_TABLE_TIMESTAMP_4_6_0 = MIN_TABLE_TIMESTAMP + 9; - public static final long MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0 = MIN_TABLE_TIMESTAMP + 13; + public static final long MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0 = MIN_TABLE_TIMESTAMP + 14; // MIN_SYSTEM_TABLE_TIMESTAMP needs to be set to the max of all the MIN_SYSTEM_TABLE_TIMESTAMP_* constants public static final long MIN_SYSTEM_TABLE_TIMESTAMP = MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0; // TODO: pare this down to minimum, as we don't need duplicates for both table and column errors, nor should we need http://git-wip-us.apache.org/repos/asf/phoenix/blob/1f7b47a5/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java index d55ab30..d27a4bc 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java @@ -2370,17 +2370,20 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement // Add these columns one at a time, each with different timestamps so that if folks have // run the upgrade code already for a snapshot, we'll still enter this block (and do the // parts we haven't yet done). - metaConnection = addColumnsIfNotExists(metaConnection, PhoenixDatabaseMetaData.SYSTEM_CATALOG, MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0 - 2, + metaConnection = addColumnsIfNotExists(metaConnection, PhoenixDatabaseMetaData.SYSTEM_CATALOG, MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0 - 4, PhoenixDatabaseMetaData.TRANSACTIONAL + " " + PBoolean.INSTANCE.getSqlTypeName()); // Drop old stats table so that new stats table is created metaConnection = dropStatsTable(metaConnection, - MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0 - 1); + MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0 - 3); metaConnection = addColumnsIfNotExists(metaConnection, PhoenixDatabaseMetaData.SYSTEM_CATALOG, - MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0, + MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0 - 2, PhoenixDatabaseMetaData.UPDATE_CACHE_FREQUENCY + " " + PLong.INSTANCE.getSqlTypeName()); - setImmutableTableIndexesImmutable(metaConnection); + metaConnection = setImmutableTableIndexesImmutable(metaConnection, MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0 - 1); + Properties props = PropertiesUtil.deepCopy(metaConnection.getClientInfo()); + props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0)); + metaConnection = new PhoenixConnection(metaConnection, ConnectionQueryServicesImpl.this, props); // that already have cached data. clearCache(); } @@ -2490,7 +2493,11 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement * @param metaConnection connection over which to run the upgrade * @throws SQLException */ - private static void setImmutableTableIndexesImmutable(PhoenixConnection metaConnection) throws SQLException { + private PhoenixConnection setImmutableTableIndexesImmutable(PhoenixConnection oldMetaConnection, long timestamp) throws SQLException { + SQLException sqlE = null; + Properties props = PropertiesUtil.deepCopy(oldMetaConnection.getClientInfo()); + props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(timestamp)); + PhoenixConnection metaConnection = new PhoenixConnection(oldMetaConnection, this, props); boolean autoCommit = metaConnection.getAutoCommit(); try { metaConnection.setAutoCommit(true); @@ -2507,9 +2514,25 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement "WHERE A.COLUMN_FAMILY IS NULL AND\n" + " B.COLUMN_FAMILY IS NOT NULL AND\n" + " A.IMMUTABLE_ROWS = TRUE"); + } catch (SQLException e) { + logger.warn("exception during upgrading stats table:" + e); + sqlE = e; } finally { - metaConnection.setAutoCommit(autoCommit); + try { + metaConnection.setAutoCommit(autoCommit); + oldMetaConnection.close(); + } catch (SQLException e) { + if (sqlE != null) { + sqlE.setNextException(e); + } else { + sqlE = e; + } + } + if (sqlE != null) { + throw sqlE; + } } + return metaConnection; } private PhoenixConnection dropStatsTable(PhoenixConnection oldMetaConnection, long timestamp)