[GitHub] [hive] sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target.
sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target. URL: https://github.com/apache/hive/pull/578#discussion_r268483462 ## File path: itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenariosExternalTables.java ## @@ -673,6 +674,59 @@ public void retryIncBootstrapExternalTablesFromDifferentDumpWithoutCleanTablesCo ErrorMsg.REPL_BOOTSTRAP_LOAD_PATH_NOT_VALID.getErrorCode()); } + @Test + public void dynamicallyConvertManagedToExternalTable() throws Throwable { +List dumpWithClause = Collections.singletonList( +"'" + HiveConf.ConfVars.REPL_INCLUDE_EXTERNAL_TABLES.varname + "'='true'" +); +List loadWithClause = externalTableBasePathWithClause(); + +WarehouseInstance.Tuple tupleBootstrapManagedTable = primary.run("use " + primaryDbName) +.run("create table t1 (id int)") +.run("insert into table t1 values (1)") +.run("create table t2 (id int) partitioned by (key int)") Review comment: Did you mean, a non-acid table is created as acid table in target (due to migration) and later in source they change to external? I think, this case, need lot of changes to avoid distcp for external table and so on. I will create another ticket for this as there might be other cases too. 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [hive] sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target.
sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target. URL: https://github.com/apache/hive/pull/578#discussion_r268483462 ## File path: itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenariosExternalTables.java ## @@ -673,6 +674,59 @@ public void retryIncBootstrapExternalTablesFromDifferentDumpWithoutCleanTablesCo ErrorMsg.REPL_BOOTSTRAP_LOAD_PATH_NOT_VALID.getErrorCode()); } + @Test + public void dynamicallyConvertManagedToExternalTable() throws Throwable { +List dumpWithClause = Collections.singletonList( +"'" + HiveConf.ConfVars.REPL_INCLUDE_EXTERNAL_TABLES.varname + "'='true'" +); +List loadWithClause = externalTableBasePathWithClause(); + +WarehouseInstance.Tuple tupleBootstrapManagedTable = primary.run("use " + primaryDbName) +.run("create table t1 (id int)") +.run("insert into table t1 values (1)") +.run("create table t2 (id int) partitioned by (key int)") Review comment: Did you mean, a non-acid table is created as acid table in target (due to migration) and later in source they change to external? 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [hive] sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target.
sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target. URL: https://github.com/apache/hive/pull/578#discussion_r268480500 ## File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java ## @@ -400,7 +405,26 @@ public void alterTable(RawStore msdb, Warehouse wh, String catName, String dbnam "Unable to change partition or table. Object " + e.getMessage() + " does not exist." + " Check metastore logs for detailed stack."); } finally { - if (!success) { + if (success) { +// Txn was committed successfully. +// If data location is changed in replication flow, then need to delete the old path. +if (replDataLocationChanged) { + assert(olddb != null); + assert(oldt != null); + Path deleteOldDataLoc = new Path(oldt.getSd().getLocation()); + boolean isAutoPurge = "true".equalsIgnoreCase(oldt.getParameters().get("auto.purge")); + try { +wh.deleteDir(deleteOldDataLoc, true, isAutoPurge, olddb); +LOG.info("Deleted the old data location: {} for the table: {}", +deleteOldDataLoc, dbname + "." + name); + } catch (MetaException ex) { +// Eat the exception as it doesn't affect the state of existing tables. +// Expect, user to manually drop this path when exception and so logging a warning. +LOG.warn("Unable to delete the old data location: {} for the table: {}", Review comment: I think, if old dir is deleted, then metadata update was already successful. In this case, during replay of event in next cycle would not set the flag as the table/partition locations were already pointing to new location under base dir. 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [hive] sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target.
sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target. URL: https://github.com/apache/hive/pull/578#discussion_r268480500 ## File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java ## @@ -400,7 +405,26 @@ public void alterTable(RawStore msdb, Warehouse wh, String catName, String dbnam "Unable to change partition or table. Object " + e.getMessage() + " does not exist." + " Check metastore logs for detailed stack."); } finally { - if (!success) { + if (success) { +// Txn was committed successfully. +// If data location is changed in replication flow, then need to delete the old path. +if (replDataLocationChanged) { + assert(olddb != null); + assert(oldt != null); + Path deleteOldDataLoc = new Path(oldt.getSd().getLocation()); + boolean isAutoPurge = "true".equalsIgnoreCase(oldt.getParameters().get("auto.purge")); + try { +wh.deleteDir(deleteOldDataLoc, true, isAutoPurge, olddb); +LOG.info("Deleted the old data location: {} for the table: {}", +deleteOldDataLoc, dbname + "." + name); + } catch (MetaException ex) { +// Eat the exception as it doesn't affect the state of existing tables. +// Expect, user to manually drop this path when exception and so logging a warning. +LOG.warn("Unable to delete the old data location: {} for the table: {}", Review comment: Doesn't matter, we ignore that exception here. REPL LOAD will succeed. Also, previous run already archived in CM dir. 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [hive] sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target.
sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target. URL: https://github.com/apache/hive/pull/578#discussion_r268480382 ## File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java ## @@ -209,7 +214,13 @@ public void alterTable(RawStore msdb, Warehouse wh, String catName, String dbnam boolean tableInSpecifiedLoc = !oldtRelativePath.equalsIgnoreCase(name) && !oldtRelativePath.equalsIgnoreCase(name + Path.SEPARATOR); -if (!tableInSpecifiedLoc) { +if (replDataLocationChanged) { + // If data location is changed in replication flow, then new path was already set in + // the newt. Also, it is as good as the data is moved and set dataWasMoved=true so that + // location in partitions are also updated accordingly. + destPath = new Path(newt.getSd().getLocation()); Review comment: Yes. it is already like that. 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [hive] sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target.
sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target. URL: https://github.com/apache/hive/pull/578#discussion_r268480328 ## File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java ## @@ -192,12 +197,12 @@ public void alterTable(RawStore msdb, Warehouse wh, String catName, String dbnam // 2) the table is not an external table, and // 3) the user didn't change the default location (or new location is empty), and // 4) the table was not initially created with a specified location - if (rename - && !oldt.getTableType().equals(TableType.VIRTUAL_VIEW.toString()) - && (oldt.getSd().getLocation().compareTo(newt.getSd().getLocation()) == 0 -|| StringUtils.isEmpty(newt.getSd().getLocation())) - && !MetaStoreUtils.isExternalTable(oldt)) { -Database olddb = msdb.getDatabase(catName, dbname); + if (replDataLocationChanged + || (rename Review comment: It cannot be same because the behaviour is different. If location is set for normal flow, we shouldn't update for partitions. Also, it is risky to modify any of current behaviour. It is not in scope of this ticket. 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [hive] sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target.
sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target. URL: https://github.com/apache/hive/pull/578#discussion_r268480242 ## File path: standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/common/ReplConst.java ## @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hive.common; + +/** + * A class that defines the constant strings used by the replication implementation. + */ + +public class ReplConst { Review comment: I will keep it ReplConst for now. We have ReplUtils for common methods and if needed we can add another class. 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [hive] sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target.
sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target. URL: https://github.com/apache/hive/pull/578#discussion_r268479992 ## File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java ## @@ -99,9 +100,12 @@ public void alterTable(RawStore msdb, Warehouse wh, String catName, String dbnam dbname = dbname.toLowerCase(); final boolean cascade = environmentContext != null -&& environmentContext.isSetProperties() -&& StatsSetupConst.TRUE.equals(environmentContext.getProperties().get( -StatsSetupConst.CASCADE)); +&& environmentContext.isSetProperties() +&& StatsSetupConst.TRUE.equals(environmentContext.getProperties().get(StatsSetupConst.CASCADE)); +final boolean replDataLocationChanged = environmentContext != null Review comment: I think flag is needed as we shouldn't update partition locations if user set location for a table. That is current behaviour and shouldn't be changed. Only for repl flow, this is needed. 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [hive] sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target.
sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target. URL: https://github.com/apache/hive/pull/578#discussion_r268480113 ## File path: itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenariosExternalTables.java ## @@ -673,6 +674,59 @@ public void retryIncBootstrapExternalTablesFromDifferentDumpWithoutCleanTablesCo ErrorMsg.REPL_BOOTSTRAP_LOAD_PATH_NOT_VALID.getErrorCode()); } + @Test + public void dynamicallyConvertManagedToExternalTable() throws Throwable { +List dumpWithClause = Collections.singletonList( +"'" + HiveConf.ConfVars.REPL_INCLUDE_EXTERNAL_TABLES.varname + "'='true'" +); +List loadWithClause = externalTableBasePathWithClause(); + +WarehouseInstance.Tuple tupleBootstrapManagedTable = primary.run("use " + primaryDbName) +.run("create table t1 (id int)") +.run("insert into table t1 values (1)") +.run("create table t2 (id int) partitioned by (key int)") Review comment: It is not acid table. It is non-acid managed table. 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [hive] sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target.
sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target. URL: https://github.com/apache/hive/pull/578#discussion_r268381082 ## File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java ## @@ -99,9 +100,12 @@ public void alterTable(RawStore msdb, Warehouse wh, String catName, String dbnam dbname = dbname.toLowerCase(); final boolean cascade = environmentContext != null -&& environmentContext.isSetProperties() -&& StatsSetupConst.TRUE.equals(environmentContext.getProperties().get( -StatsSetupConst.CASCADE)); +&& environmentContext.isSetProperties() +&& StatsSetupConst.TRUE.equals(environmentContext.getProperties().get(StatsSetupConst.CASCADE)); +final boolean replDataLocationChanged = environmentContext != null Review comment: It is not possible in normal flow to have table type changed from managed to external and location set in same ALTER query. 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [hive] sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target.
sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target. URL: https://github.com/apache/hive/pull/578#discussion_r268381343 ## File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java ## @@ -357,6 +368,13 @@ public void alterTable(RawStore msdb, Warehouse wh, String catName, String dbnam } } + // If data location is changed in replication flow, then need to delete the old path. + if (replDataLocationChanged) { +Path deleteOldDataLoc = new Path(oldt.getSd().getLocation()); +boolean isAutoPurge = "true".equalsIgnoreCase(oldt.getParameters().get("auto.purge")); +wh.deleteDir(deleteOldDataLoc, true, isAutoPurge, olddb); Review comment: Good catch. Will move it to finally block only when success=true and eat any exception by DeleteDir and just log a warn instead. 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [hive] sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target.
sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target. URL: https://github.com/apache/hive/pull/578#discussion_r268381321 ## File path: standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/common/ReplConst.java ## @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hive.common; + +/** + * A class that defines the constant strings used by the replication implementation. + */ + +public class ReplConst { Review comment: ReplUtils was already taken. I used similar naming as StatsSetupConst. I think ReplConst is good enough for now. Will change if any utility methods comes up for metastore common. 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [hive] sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target.
sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target. URL: https://github.com/apache/hive/pull/578#discussion_r268381295 ## File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java ## @@ -192,12 +197,12 @@ public void alterTable(RawStore msdb, Warehouse wh, String catName, String dbnam // 2) the table is not an external table, and // 3) the user didn't change the default location (or new location is empty), and // 4) the table was not initially created with a specified location - if (rename - && !oldt.getTableType().equals(TableType.VIRTUAL_VIEW.toString()) - && (oldt.getSd().getLocation().compareTo(newt.getSd().getLocation()) == 0 -|| StringUtils.isEmpty(newt.getSd().getLocation())) - && !MetaStoreUtils.isExternalTable(oldt)) { -Database olddb = msdb.getDatabase(catName, dbname); + if (replDataLocationChanged + || (rename Review comment: This patch is not dealing with set location at source. It deals with changing table type to external at source via ALTER table EXTERNAL=true in table properties. So, this scenario is not valid and not in scope. 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [hive] sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target.
sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target. URL: https://github.com/apache/hive/pull/578#discussion_r268381269 ## File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java ## @@ -209,7 +214,13 @@ public void alterTable(RawStore msdb, Warehouse wh, String catName, String dbnam boolean tableInSpecifiedLoc = !oldtRelativePath.equalsIgnoreCase(name) Review comment: OK 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [hive] sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target.
sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target. URL: https://github.com/apache/hive/pull/578#discussion_r268381258 ## File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java ## @@ -209,7 +214,13 @@ public void alterTable(RawStore msdb, Warehouse wh, String catName, String dbnam boolean tableInSpecifiedLoc = !oldtRelativePath.equalsIgnoreCase(name) && !oldtRelativePath.equalsIgnoreCase(name + Path.SEPARATOR); -if (!tableInSpecifiedLoc) { +if (replDataLocationChanged) { + // If data location is changed in replication flow, then new path was already set in + // the newt. Also, it is as good as the data is moved and set dataWasMoved=true so that + // location in partitions are also updated accordingly. + destPath = new Path(newt.getSd().getLocation()); Review comment: Already handled. If you notice the line 279, the partition location is changed only if the old location is a sub-dir of old table location. 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [hive] sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target.
sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target. URL: https://github.com/apache/hive/pull/578#discussion_r268381242 ## File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java ## @@ -192,12 +197,12 @@ public void alterTable(RawStore msdb, Warehouse wh, String catName, String dbnam // 2) the table is not an external table, and Review comment: OK 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [hive] sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target.
sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target. URL: https://github.com/apache/hive/pull/578#discussion_r268381212 ## File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java ## @@ -99,9 +100,12 @@ public void alterTable(RawStore msdb, Warehouse wh, String catName, String dbnam dbname = dbname.toLowerCase(); final boolean cascade = environmentContext != null -&& environmentContext.isSetProperties() -&& StatsSetupConst.TRUE.equals(environmentContext.getProperties().get( -StatsSetupConst.CASCADE)); +&& environmentContext.isSetProperties() +&& StatsSetupConst.TRUE.equals(environmentContext.getProperties().get(StatsSetupConst.CASCADE)); +final boolean replDataLocationChanged = environmentContext != null Review comment: OK. 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [hive] sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target.
sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target. URL: https://github.com/apache/hive/pull/578#discussion_r268381204 ## File path: ql/src/java/org/apache/hadoop/hive/ql/ddl/table/CreateTableOperation.java ## @@ -108,6 +116,12 @@ private void createTableReplaceMode(Table tbl) throws HiveException { } } +// If table's data location is moved, then set the corresponding flag in environment context to Review comment: Nope. The scenario is location is changed at target not at source. At source only the table type is changed from managed to external not location. I will update the comment to say that in repl flow. 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [hive] sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target.
sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target. URL: https://github.com/apache/hive/pull/578#discussion_r268381165 ## File path: ql/src/java/org/apache/hadoop/hive/ql/ddl/table/CreateTableOperation.java ## @@ -54,17 +55,24 @@ public int execute() throws HiveException { Table tbl = desc.toTable(context.getConf()); LOG.debug("creating table {} on {}", tbl.getFullyQualifiedName(), tbl.getDataLocation()); -if (desc.getReplicationSpec().isInReplicationScope() && (!desc.getReplaceMode())){ - // if this is a replication spec, then replace-mode semantics might apply. - // if we're already asking for a table replacement, then we can skip this check. - // however, otherwise, if in replication scope, and we've not been explicitly asked - // to replace, we should check if the object we're looking at exists, and if so, +boolean dataLocationChanged = false; +if (desc.getReplicationSpec().isInReplicationScope()) { + // If in replication scope, we should check if the object we're looking at exists, and if so, // trigger replace-mode semantics. Table existingTable = context.getDb().getTable(tbl.getDbName(), tbl.getTableName(), false); - if (existingTable != null){ + if (existingTable != null) { if (desc.getReplicationSpec().allowEventReplacementInto(existingTable.getParameters())) { desc.setReplaceMode(true); // we replace existing table. ReplicationSpec.copyLastReplId(existingTable.getParameters(), tbl.getParameters()); + + // If location of an existing managed table is changed, then need to delete the old location if exists. + // This scenario occurs when a managed table is converted into external table at source. In this case, + // at target, the table data would be moved to different location under base directory for external tables. + if (existingTable.getTableType().equals(TableType.MANAGED_TABLE) + && tbl.getTableType().equals(TableType.EXTERNAL_TABLE) + && (!existingTable.getDataLocation().equals(tbl.getDataLocation( { Review comment: It's not possible in replication flow. But I kept the check explicitly for better readability. There is no harm in keeping it. If you insist, let me change it to assert. 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [hive] sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target.
sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target. URL: https://github.com/apache/hive/pull/578#discussion_r268381147 ## File path: itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenariosExternalTables.java ## @@ -673,6 +674,59 @@ public void retryIncBootstrapExternalTablesFromDifferentDumpWithoutCleanTablesCo ErrorMsg.REPL_BOOTSTRAP_LOAD_PATH_NOT_VALID.getErrorCode()); } + @Test + public void dynamicallyConvertManagedToExternalTable() throws Throwable { +List dumpWithClause = Collections.singletonList( +"'" + HiveConf.ConfVars.REPL_INCLUDE_EXTERNAL_TABLES.varname + "'='true'" +); +List loadWithClause = externalTableBasePathWithClause(); + +WarehouseInstance.Tuple tupleBootstrapManagedTable = primary.run("use " + primaryDbName) +.run("create table t1 (id int)") +.run("insert into table t1 values (1)") +.run("create table t2 (id int) partitioned by (key int)") Review comment: Nope. It is not a case of migration. It is external table replication specific where the table is converted to external at source not at target. So, here location is changed only at target not in source. 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [hive] sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target.
sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target. URL: https://github.com/apache/hive/pull/578#discussion_r26838 ## File path: standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/common/ReplConst.java ## @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hive.common; + +/** + * A class that defines the constant strings used by the replication implementation. + */ + +public class ReplConst { + + /** + * The constant that denotes the table data location is changed to different path. This indicates + * Metastore to update corresponding path in Partitions and also need to delete old path. + */ + public static final String DATA_LOCATION_CHANGED = "DATA_LOCATION_CHANGED"; Review comment: I thought ReplConst is self explanatory that it is Repl specific. Anyways, I will prefix with REPL_ 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [hive] sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target.
sankarh commented on a change in pull request #578: HIVE-21471: Replicating conversion of managed to external table leaks HDFS files at target. URL: https://github.com/apache/hive/pull/578#discussion_r268381082 ## File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java ## @@ -99,9 +100,12 @@ public void alterTable(RawStore msdb, Warehouse wh, String catName, String dbnam dbname = dbname.toLowerCase(); final boolean cascade = environmentContext != null -&& environmentContext.isSetProperties() -&& StatsSetupConst.TRUE.equals(environmentContext.getProperties().get( -StatsSetupConst.CASCADE)); +&& environmentContext.isSetProperties() +&& StatsSetupConst.TRUE.equals(environmentContext.getProperties().get(StatsSetupConst.CASCADE)); +final boolean replDataLocationChanged = environmentContext != null Review comment: It is not possible in normal flow to have table type changed from managed to external and location set in same ALTER query. Also, it won't reach here as it is CreateTableTask flow. Only repl flow reaches here for this scenario. 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: us...@infra.apache.org With regards, Apache Git Services