Skip to content

Commit 6484ad3

Browse files
authored
HIVE-27224: Enhance drop table/partition command (#5851)
1 parent 9e7f289 commit 6484ad3

File tree

49 files changed

+8432
-4769
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+8432
-4769
lines changed

itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/DummyRawStoreFailEvent.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,16 @@ public boolean dropPartition(String catName, String dbName, String tableName, St
114114
}
115115
}
116116

117+
@Override
118+
public void dropPartitions(String catName, String dbName, String tblName, List<String> partNames)
119+
throws MetaException, NoSuchObjectException {
120+
if (shouldEventSucceed) {
121+
super.dropPartitions(catName, dbName, tblName, partNames);
122+
} else {
123+
throw new RuntimeException("Event failed.");
124+
}
125+
}
126+
117127
@Override
118128
public Table alterTable(String catName, String dbName, String name, Table newTable, String queryValidWriteIds)
119129
throws InvalidObjectException, MetaException {

itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreMetrics.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,15 @@ public void testMetaDataCounts() throws Exception {
118118

119119
Assert.assertEquals(1, Metrics.getRegistry().getCounters().get(MetricsConstants.DELETE_TOTAL_DATABASES).getCount());
120120
Assert.assertEquals(3, Metrics.getRegistry().getCounters().get(MetricsConstants.DELETE_TOTAL_TABLES).getCount());
121-
Assert.assertEquals(3, Metrics.getRegistry().getCounters().get(MetricsConstants.DELETE_TOTAL_PARTITIONS).getCount());
121+
//skip counting the dropped partitions while dropping the database tempdb
122+
Assert.assertEquals(1, Metrics.getRegistry().getCounters().get(MetricsConstants.DELETE_TOTAL_PARTITIONS).getCount());
122123

123124
//to test initial metadata count metrics.
124125
Assert.assertEquals(initDbCount + 1,
125126
Metrics.getRegistry().getGauges().get(MetricsConstants.TOTAL_DATABASES).getValue());
126127
Assert.assertEquals(initTblCount + 4,
127128
Metrics.getRegistry().getGauges().get(MetricsConstants.TOTAL_TABLES).getValue());
128-
Assert.assertEquals(initPartCount + 6,
129+
Assert.assertEquals(initPartCount + 8,
129130
Metrics.getRegistry().getGauges().get(MetricsConstants.TOTAL_PARTITIONS).getValue());
130131

131132
}

ql/src/java/org/apache/hadoop/hive/ql/log/LogDivertAppender.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import org.apache.hadoop.hive.common.LogUtils;
2424
import org.apache.hadoop.hive.conf.HiveConf;
25+
import org.apache.hadoop.hive.metastore.client.ThriftHiveMetaStoreClient;
2526
import org.apache.hadoop.hive.ql.Driver;
2627
import org.apache.hadoop.hive.ql.exec.Task;
2728
import org.apache.hadoop.hive.ql.exec.tez.TezTask;
@@ -86,7 +87,8 @@ private static class NameFilter extends AbstractFilter {
8687
private static final Pattern executionIncludeNamePattern = Pattern.compile(Joiner.on("|").
8788
join(new String[]{"org.apache.hadoop.mapreduce.JobSubmitter",
8889
"org.apache.hadoop.mapreduce.Job", "SessionState", "ReplState", Task.class.getName(),
89-
TezTask.class.getName(), Driver.class.getName(), BasicStatsTask.class.getName()}));
90+
TezTask.class.getName(), Driver.class.getName(), BasicStatsTask.class.getName(),
91+
ThriftHiveMetaStoreClient.class.getName()}));
9092

9193
/* Patterns that are included in performance logging level.
9294
* In performance mode, show execution and performance logger messages.

ql/src/java/org/apache/hadoop/hive/ql/metadata/SessionHiveMetaStoreClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,14 +2157,14 @@ private boolean validatePartitions(List<Partition> partitions, String dbName, St
21572157
}
21582158

21592159
// check that all new partitions are belonging to tables located in the same database
2160-
if (dbName != null && !dbName.equals(p.getDbName())) {
2160+
if (dbName != null && !dbName.equalsIgnoreCase(p.getDbName())) {
21612161
throw new MetaException("Partition tables doesn't belong to the same database "
21622162
+ Arrays.toString(partitions.toArray()));
21632163
} else {
21642164
dbName = p.getDbName();
21652165
}
21662166
// check if all new partitions are part of the same table
2167-
if (tableName != null && !tableName.equals(p.getTableName())) {
2167+
if (tableName != null && !tableName.equalsIgnoreCase(p.getTableName())) {
21682168
throw new MetaException("New partitions doesn't belong to the same table "
21692169
+ Arrays.toString(partitions.toArray()));
21702170
} else {

standalone-metastore/metastore-client/src/main/java/org/apache/hadoop/hive/metastore/client/ThriftHiveMetaStoreClient.java

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.google.common.annotations.VisibleForTesting;
2222
import com.google.common.base.Preconditions;
2323
import com.google.common.collect.Lists;
24-
import org.apache.commons.lang3.tuple.Pair;
2524
import org.apache.hadoop.classification.InterfaceAudience;
2625
import org.apache.hadoop.conf.Configuration;
2726
import org.apache.hadoop.hive.common.StatsSetupConst;
@@ -1028,8 +1027,12 @@ public Partition add_partition(Partition new_part, EnvironmentContext envContext
10281027
new ArrayList<>(Arrays.asList(new_part)), false);
10291028
addPartitionsReq.setCatName(new_part.getCatName());
10301029
addPartitionsReq.setEnvironmentContext(envContext);
1031-
Partition p = client.add_partitions_req(addPartitionsReq).getPartitions().get(0);
1032-
return HiveMetaStoreClientUtils.deepCopy(p);
1030+
1031+
List<Partition> new_parts = client.add_partitions_req(addPartitionsReq).getPartitions();
1032+
if (new_parts != null && !new_parts.isEmpty()) {
1033+
return HiveMetaStoreClientUtils.deepCopy(new_parts.getFirst());
1034+
}
1035+
return null;
10331036
}
10341037

10351038
@Override
@@ -1076,10 +1079,13 @@ public List<Partition> add_partitions(
10761079
AddPartitionsResult result = client.add_partitions_req(req);
10771080
if (needResults) {
10781081
List<Partition> new_parts = HiveMetaStoreClientUtils.deepCopyPartitions(result.getPartitions());
1079-
if (skipColumnSchemaForPartition) {
1080-
new_parts.forEach(partition -> partition.getSd().setCols(result.getPartitionColSchema()));
1082+
if (new_parts != null && !new_parts.isEmpty()) {
1083+
if (skipColumnSchemaForPartition) {
1084+
new_parts.forEach(partition -> partition.getSd().setCols(result.getPartitionColSchema()));
1085+
}
1086+
return FilterUtils.filterPartitionsIfEnabled(isClientFilterEnabled, filterHook, new_parts);
10811087
}
1082-
return FilterUtils.filterPartitionsIfEnabled(isClientFilterEnabled, filterHook, new_parts);
1088+
return new ArrayList<>();
10831089
}
10841090
return null;
10851091
}
@@ -1518,7 +1524,22 @@ public boolean createType(Type type) throws AlreadyExistsException,
15181524

15191525
@Override
15201526
public void dropDatabase(DropDatabaseRequest req) throws TException {
1521-
client.drop_database_req(req);
1527+
req.setAsyncDrop(!isLocalMetaStore());
1528+
AsyncOperationResp resp = client.drop_database_req(req);
1529+
req.setId(resp.getId());
1530+
try {
1531+
while (!resp.isFinished() && !Thread.currentThread().isInterrupted()) {
1532+
resp = client.drop_database_req(req);
1533+
if (resp.getMessage() != null) {
1534+
LOG.info(resp.getMessage());
1535+
}
1536+
}
1537+
} finally {
1538+
if (!resp.isFinished()) {
1539+
req.setCancel(true);
1540+
client.drop_database_req(req);
1541+
}
1542+
}
15221543
}
15231544

15241545
@Override
@@ -1679,7 +1700,22 @@ public void dropTable(String catName, String dbname, String name, boolean delete
16791700
dropTableReq.setCatalogName(catName);
16801701
dropTableReq.setDropPartitions(true);
16811702
dropTableReq.setEnvContext(envContext);
1682-
client.drop_table_req(dropTableReq);
1703+
dropTableReq.setAsyncDrop(!isLocalMetaStore());
1704+
AsyncOperationResp resp = client.drop_table_req(dropTableReq);
1705+
dropTableReq.setId(resp.getId());
1706+
try {
1707+
while (!resp.isFinished() && !Thread.currentThread().isInterrupted()) {
1708+
resp = client.drop_table_req(dropTableReq);
1709+
if (resp.getMessage() != null) {
1710+
LOG.info(resp.getMessage());
1711+
}
1712+
}
1713+
} finally {
1714+
if (!resp.isFinished()) {
1715+
dropTableReq.setCancel(true);
1716+
client.drop_table_req(dropTableReq);
1717+
}
1718+
}
16831719
}
16841720

16851721
@Override

0 commit comments

Comments
 (0)