diff --git a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java index 83306bf653..6029d11e67 100644 --- a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java +++ b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java @@ -88,8 +88,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import static org.apache.hadoop.hive.metastore.DatabaseProduct.MYSQL; +import static org.apache.hadoop.hive.metastore.utils.MetaStoreUtils.getDefaultCatalog; import static org.apache.hadoop.hive.metastore.utils.StringUtils.normalizeIdentifier; + import com.google.common.annotations.VisibleForTesting; /** @@ -3264,6 +3266,10 @@ public void addDynamicPartitions(AddDynamicPartitions rqst) @RetrySemantics.Idempotent public void cleanupRecords(HiveObjectType type, Database db, Table table, Iterator partitionIterator) throws MetaException { + + // cleanup should be done only for objecdts belonging to default catalog + final String defaultCatalog = getDefaultCatalog(conf); + try { Connection dbConn = null; Statement stmt = null; @@ -3279,6 +3285,11 @@ public void cleanupRecords(HiveObjectType type, Database db, Table table, switch (type) { case DATABASE: { dbName = db.getName(); + if(!defaultCatalog.equals(db.getCatalogName())) { + LOG.debug("Skipping cleanup because db: " + dbName + " belongs to catalog " + + "other than default catalog: " + db.getCatalogName()); + return; + } buff.append("delete from TXN_COMPONENTS where tc_database='"); buff.append(dbName); @@ -3320,6 +3331,11 @@ public void cleanupRecords(HiveObjectType type, Database db, Table table, case TABLE: { dbName = table.getDbName(); tblName = table.getTableName(); + if(!defaultCatalog.equals(table.getCatName())) { + LOG.debug("Skipping cleanup because table: " + tblName + " belongs to catalog " + + "other than default catalog: " + table.getCatName()); + return; + } buff.append("delete from TXN_COMPONENTS where tc_database='"); buff.append(dbName); @@ -3373,6 +3389,12 @@ public void cleanupRecords(HiveObjectType type, Database db, Table table, case PARTITION: { dbName = table.getDbName(); tblName = table.getTableName(); + if(!defaultCatalog.equals(table.getCatName())) { + LOG.debug("Skipping cleanup because partitions belong to catalog " + + "other than default catalog: " + table.getCatName()); + return; + } + List partCols = table.getPartitionKeys(); // partition columns List partVals; // partition values String partName;