Repository: phoenix Updated Branches: refs/heads/4.x-HBase-0.98 3c804320c -> 377ef938c
PHOENIX-3424 Backward compatibility failure: 4.8 -> 4.9 upgrade Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/377ef938 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/377ef938 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/377ef938 Branch: refs/heads/4.x-HBase-0.98 Commit: 377ef938c52d020837b10ba2a2afef0b03b56c1c Parents: 3c80432 Author: James Taylor <[email protected]> Authored: Sun Oct 30 08:32:14 2016 -0700 Committer: James Taylor <[email protected]> Committed: Sun Oct 30 08:35:22 2016 -0700 ---------------------------------------------------------------------- .../query/ConnectionQueryServicesImpl.java | 68 ++++++++++++-------- 1 file changed, 42 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/377ef938/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 62ee2bf..ff4e404 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 @@ -25,6 +25,7 @@ import static org.apache.phoenix.coprocessor.MetaDataProtocol.PHOENIX_MAJOR_VERS import static org.apache.phoenix.coprocessor.MetaDataProtocol.PHOENIX_MINOR_VERSION; import static org.apache.phoenix.coprocessor.MetaDataProtocol.PHOENIX_PATCH_NUMBER; import static org.apache.phoenix.coprocessor.MetaDataProtocol.getVersion; +import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME; import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES; import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SYSTEM_STATS_NAME; import static org.apache.phoenix.query.QueryServicesOptions.DEFAULT_DROP_METADATA; @@ -37,6 +38,7 @@ import static org.apache.phoenix.util.UpgradeUtil.upgradeTo4_5_0; import java.io.IOException; import java.lang.ref.WeakReference; +import java.sql.PreparedStatement; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.util.ArrayList; @@ -194,7 +196,6 @@ import org.apache.phoenix.util.ByteUtil; import org.apache.phoenix.util.Closeables; import org.apache.phoenix.util.ConfigUtil; import org.apache.phoenix.util.JDBCUtil; -import org.apache.phoenix.util.KeyValueUtil; import org.apache.phoenix.util.MetaDataUtil; import org.apache.phoenix.util.PhoenixContextExecutor; import org.apache.phoenix.util.PhoenixRuntime; @@ -2271,30 +2272,44 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement } - private void removeNotNullConstraint(String schemaName, String tableName, long timestamp, String columnName) throws SQLException { - try (HTableInterface htable = this.getTable(SYSTEM_CATALOG_NAME_BYTES)) { - byte[] tableRowKey = SchemaUtil.getTableKey(null, schemaName, tableName); - Put tableHeader = new Put(tableRowKey); - tableHeader.add(KeyValueUtil.newKeyValue(tableRowKey, - QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, - QueryConstants.EMPTY_COLUMN_BYTES, - timestamp, - QueryConstants.EMPTY_COLUMN_VALUE_BYTES)); - byte[] columnRowKey = SchemaUtil.getColumnKey(null, schemaName, tableName, columnName, null); - Put tableColumn = new Put(columnRowKey); - tableColumn.add(KeyValueUtil.newKeyValue(columnRowKey, - QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, - PhoenixDatabaseMetaData.NULLABLE_BYTES, - timestamp, - PInteger.INSTANCE.toBytes(ResultSetMetaData.columnNullable))); - List<Mutation> mutations = Lists.<Mutation>newArrayList(tableHeader, tableColumn); - htable.batch(mutations, new Object[mutations.size()]); - } catch (IOException e) { - throw new SQLException(e); - } catch (InterruptedException e) { - Thread.currentThread().isInterrupted(); - throw new SQLExceptionInfo.Builder(SQLExceptionCode.INTERRUPTED_EXCEPTION).setRootCause(e).build().buildException(); + private PhoenixConnection removeNotNullConstraint(PhoenixConnection oldMetaConnection, String schemaName, String tableName, long timestamp, String columnName) throws SQLException { + Properties props = PropertiesUtil.deepCopy(oldMetaConnection.getClientInfo()); + props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(timestamp)); + // Cannot go through DriverManager or you end up in an infinite loop because it'll call init again + PhoenixConnection metaConnection = new PhoenixConnection(oldMetaConnection, this, props); + SQLException sqlE = null; + try { + String dml = "UPSERT INTO " + SYSTEM_CATALOG_NAME + " (" + PhoenixDatabaseMetaData.TENANT_ID + "," + + PhoenixDatabaseMetaData.TABLE_SCHEM + "," + PhoenixDatabaseMetaData.TABLE_NAME + "," + + PhoenixDatabaseMetaData.COLUMN_NAME + "," + + PhoenixDatabaseMetaData.NULLABLE + ") VALUES (null, ?, ?, ?, ?)"; + PreparedStatement stmt = metaConnection.prepareStatement(dml); + stmt.setString(1, schemaName); + stmt.setString(2, tableName); + stmt.setString(3, columnName); + stmt.setInt(4, ResultSetMetaData.columnNullable); + stmt.executeUpdate(); + metaConnection.commit(); + } catch (NewerTableAlreadyExistsException e) { + logger.warn("Table already modified at this timestamp, so assuming column already nullable: " + columnName); + } catch (SQLException e) { + logger.warn("Add column failed due to:" + e); + sqlE = e; + } finally { + try { + oldMetaConnection.close(); + } catch (SQLException e) { + if (sqlE != null) { + sqlE.setNextException(e); + } else { + sqlE = e; + } + } + if (sqlE != null) { + throw sqlE; + } } + return metaConnection; } /** * This closes the passed connection. @@ -2748,7 +2763,8 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement if (currentServerSideTableTimeStamp < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_9_0) { // The COLUMN_FAMILY column should be nullable as we create a row in it without // any column family to mark when guideposts were last collected. - removeNotNullConstraint(PhoenixDatabaseMetaData.SYSTEM_SCHEMA_NAME, + metaConnection = removeNotNullConstraint(metaConnection, + PhoenixDatabaseMetaData.SYSTEM_SCHEMA_NAME, PhoenixDatabaseMetaData.SYSTEM_STATS_TABLE, MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_9_0, PhoenixDatabaseMetaData.COLUMN_FAMILY); @@ -4101,4 +4117,4 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement public boolean isUpgradeRequired() { return upgradeRequired.get(); } -} +} \ No newline at end of file
