maheshk114 commented on a change in pull request #613: HIVE-20967
URL: https://github.com/apache/hive/pull/613#discussion_r281906966
##########
File path:
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java
##########
@@ -805,22 +811,89 @@ public Partition alterPartition(RawStore msdb, Warehouse
wh, String catName, Str
return oldParts;
}
- private void checkTableTypeConversion(Database db, Table oldTbl, Table
newTbl)
+ // Validate changes to partition's location to protect against errors on
migration during
+ // replication
+ private void blockPartitionLocationChangesOnReplSource(Database db, Table
tbl,
+ EnvironmentContext ec)
+ throws InvalidOperationException {
+ // If the database is not replication source, nothing to do
+ if (!ReplChangeManager.isSourceOfReplication(db)) {
+ return;
+ }
+
+ // For now validate only the changes when strict managed tables is false.
That's when there's
+ // scope for migration during replication, at least for now.
+ if
(conf.getBoolean(MetastoreConf.ConfVars.STRICT_MANAGED_TABLES.getHiveName(),
false)) {
+ return;
+ }
+
+ // Do not allow changing location of a managed table as as alter event
doesn't capture the
+ // new files list. So, it may cause data inconsistency.
+ boolean isChangingLocation = false;
+ if (ec.isSetProperties()) {
+ String alterType = ec.getProperties().get(ALTER_TABLE_OPERATION_TYPE);
+ if (alterType != null && alterType.equalsIgnoreCase(ALTERLOCATION)) {
+ isChangingLocation = true;
+ }
+ }
+ if (isChangingLocation &&
+
tbl.getTableType().equalsIgnoreCase(TableType.MANAGED_TABLE.name())) {
+ throw new InvalidOperationException("Cannot change location of a managed
table " +
+ TableName.getQualified(tbl.getCatName(),
+ tbl.getDbName(), tbl.getTableName()) + " as it is
enabled for replication.");
+ }
+ }
+
+ // Validate changes to a table to protect against errors on migration during
replication.
+ private void validateTableChangesOnReplSource(Database db, Table oldTbl,
Table newTbl,
+ EnvironmentContext ec)
throws InvalidOperationException {
- // If the given DB is enabled for replication and strict managed is false,
then table type cannot be changed.
- // This is to avoid migration scenarios which causes Managed ACID table to
be converted to external at replica.
- // As ACID tables cannot be converted to external table and vice versa, we
need to restrict this conversion at
- // primary as well.
- // Currently, table type conversion is allowed only between managed and
external table types.
- // But, to be future proof, any table type conversion is restricted on a
replication enabled DB.
- if
(!conf.getBoolean(MetastoreConf.ConfVars.STRICT_MANAGED_TABLES.getHiveName(),
false)
- && !oldTbl.getTableType().equalsIgnoreCase(newTbl.getTableType())
- && ReplChangeManager.isSourceOfReplication(db)) {
+ // If the database is not replication source, nothing to do
+ if (!ReplChangeManager.isSourceOfReplication(db)) {
+ return;
+ }
+
+ // Do not allow changing location of a managed table as as alter event
doesn't capture the
+ // new files list. So, it may cause data inconsistency. We do this whether
or not strict
+ // managed is true on the source cluster.
+ if (ec.isSetProperties()) {
+ String alterType = ec.getProperties().get(ALTER_TABLE_OPERATION_TYPE);
+ if (alterType != null && alterType.equalsIgnoreCase(ALTERLOCATION) &&
+
oldTbl.getTableType().equalsIgnoreCase(TableType.MANAGED_TABLE.name())) {
+ throw new InvalidOperationException("Cannot change location of a
managed table " +
+ TableName.getQualified(oldTbl.getCatName(),
+ oldTbl.getDbName(), oldTbl.getTableName()) + " as it
is enabled for replication.");
+ }
+ }
+
+ // Rest of the changes are need validation only when strict managed tables
is false. That's
Review comment:
"changes are need" to "changes need"
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]