From 7a226553de9a9441d4a64ae977ec807b98805c78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=BE=E6=96=B0=E4=BA=AE?= Date: Mon, 28 Jul 2025 19:16:58 +0800 Subject: [PATCH 01/14] HIVE-29106: When drop a table, there is no need to verify the directory permission --- .../TestHiveMetaStoreAuthorizer.java | 20 ++++++++----- .../hadoop/hive/metastore/HMSHandler.java | 30 ++++++++----------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java b/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java index 8975c605c17e..e60926097c15 100644 --- a/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java +++ b/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java @@ -23,6 +23,7 @@ import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hive.common.FileUtils; import org.apache.hadoop.hive.conf.HiveConf; @@ -69,6 +70,7 @@ import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -846,16 +848,20 @@ public void testDropTableNoTablePathWritePermissionShouldFail() throws Exception .build(conf); hmsHandler.create_table(table); - Path tablePath = new Path(table.getSd().getLocation()); - when(wh.isWritable(Mockito.eq(tablePath.getParent()))).thenReturn(true); - when(wh.isWritable(Mockito.eq(tablePath))).thenReturn(false); + FileStatus fileStatus = Mockito.mock(FileStatus.class); + when(fileStatus.isDirectory()).thenReturn(true); + when(fileStatus.getPath()).thenReturn(new Path(tblName)); + when(wh.getFs().listStatus(new Path(tblName))).thenReturn(new FileStatus[] { fileStatus }); + + doThrow(new FileNotFoundException("Failed to delete director:")) + .when(wh.getFs()).delete(any(Path.class), anyBoolean()); try { - hmsHandler.drop_table("default", tblName, true); + hmsHandler.drop_table(default_db, tblName, true); + fail("Expected exception to be thrown due to lack of write permission"); } catch (MetaException e) { - String expected = "%s metadata not deleted since %s is not writable by %s" - .formatted("Table", tablePath.toString(), authorizedUser); - assertEquals(expected, e.getMessage()); + String expected = "Failed to delete director:"; + assertTrue(e.getMessage().contains(expected)); } } } diff --git a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java index e4bcb21d6a4b..de63d74a2c80 100644 --- a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java +++ b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java @@ -3050,18 +3050,6 @@ private boolean drop_table_core(final RawStore ms, final String catName, final S firePreEvent(new PreDropTableEvent(tbl, deleteData, this)); tableDataShouldBeDeleted = checkTableDataShouldBeDeleted(tbl, deleteData); - if (tableDataShouldBeDeleted && tbl.getSd().getLocation() != null) { - tblPath = new Path(tbl.getSd().getLocation()); - String target = indexName == null ? "Table" : "Index table"; - // HIVE-28804 drop table user should have table path and parent path permission - if (!wh.isWritable(tblPath.getParent())) { - throw new MetaException("%s metadata not deleted since %s is not writable by %s" - .formatted(target, tblPath.getParent(), SecurityUtils.getUser())); - } else if (!wh.isWritable(tblPath)) { - throw new MetaException("%s metadata not deleted since %s is not writable by %s" - .formatted(target, tblPath, SecurityUtils.getUser())); - } - } // Drop the partitions and get a list of locations which need to be deleted // In case of drop database cascade we need not to drop the partitions, they are already dropped. @@ -3090,11 +3078,16 @@ private boolean drop_table_core(final RawStore ms, final String catName, final S if (!success) { ms.rollbackTransaction(); } else if (tableDataShouldBeDeleted) { - // Data needs deletion. Check if trash may be skipped. - // Delete the data in the partitions which have other locations - deletePartitionData(partPaths, ifPurge, ReplChangeManager.shouldEnableCm(db, tbl)); - // Delete the data in the table - deleteTableData(tblPath, ifPurge, ReplChangeManager.shouldEnableCm(db, tbl)); + try { + // Data needs deletion. Check if trash may be skipped. + // Delete the data in the partitions which have other locations + deletePartitionData(partPaths, ifPurge, ReplChangeManager.shouldEnableCm(db, tbl)); + // Delete the data in the table + deleteTableData(tblPath, ifPurge, ReplChangeManager.shouldEnableCm(db, tbl)); + } catch (Exception e) { + ms.rollbackTransaction(); + throw new MetaException(org.apache.hadoop.util.StringUtils.stringifyException(e)); + } } if (!listeners.isEmpty()) { @@ -3216,7 +3209,8 @@ private void deleteDataExcludeCmroot(Path path, boolean ifPurge, boolean shouldE wh.deleteDir(path, true, ifPurge, shouldEnableCm); } } catch (Exception e) { - LOG.error("Failed to delete directory: {}", path, e); + throw new MetaException("Failed to delete directory: %s . Exception detail : %s") + .formatted(path, org.apache.hadoop.util.StringUtils.stringifyException(e)); } } From 478f7e8998e53fad6b9a5ebe7bb21532d058f9da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=BE=E6=96=B0=E4=BA=AE?= Date: Mon, 28 Jul 2025 20:01:02 +0800 Subject: [PATCH 02/14] path to string --- .../main/java/org/apache/hadoop/hive/metastore/HMSHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java index de63d74a2c80..2687008ebdbf 100644 --- a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java +++ b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java @@ -3210,7 +3210,7 @@ private void deleteDataExcludeCmroot(Path path, boolean ifPurge, boolean shouldE } } catch (Exception e) { throw new MetaException("Failed to delete directory: %s . Exception detail : %s") - .formatted(path, org.apache.hadoop.util.StringUtils.stringifyException(e)); + .formatted(path.toString(), org.apache.hadoop.util.StringUtils.stringifyException(e)); } } From 1026bf71f1f7dacd6256df68f989ee6ae559c0e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=BE=E6=96=B0=E4=BA=AE?= Date: Mon, 28 Jul 2025 20:23:52 +0800 Subject: [PATCH 03/14] formatted --- .../java/org/apache/hadoop/hive/metastore/HMSHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java index 2687008ebdbf..f913b29f4b1a 100644 --- a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java +++ b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java @@ -3209,8 +3209,8 @@ private void deleteDataExcludeCmroot(Path path, boolean ifPurge, boolean shouldE wh.deleteDir(path, true, ifPurge, shouldEnableCm); } } catch (Exception e) { - throw new MetaException("Failed to delete directory: %s . Exception detail : %s") - .formatted(path.toString(), org.apache.hadoop.util.StringUtils.stringifyException(e)); + throw new MetaException("Failed to delete directory: %s . Exception detail : %s" + .formatted(path.toString(), org.apache.hadoop.util.StringUtils.stringifyException(e))); } } From c96481cd7d198e5a69ee990314fa4d2a97dc1fd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=BE=E6=96=B0=E4=BA=AE?= Date: Tue, 29 Jul 2025 08:58:52 +0800 Subject: [PATCH 04/14] change formatted --- .../java/org/apache/hadoop/hive/metastore/HMSHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java index f913b29f4b1a..72071cbf186c 100644 --- a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java +++ b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java @@ -3209,8 +3209,8 @@ private void deleteDataExcludeCmroot(Path path, boolean ifPurge, boolean shouldE wh.deleteDir(path, true, ifPurge, shouldEnableCm); } } catch (Exception e) { - throw new MetaException("Failed to delete directory: %s . Exception detail : %s" - .formatted(path.toString(), org.apache.hadoop.util.StringUtils.stringifyException(e))); + throw new MetaException("Failed to delete directory: " + path.toString() + " . Exception detail : " + + org.apache.hadoop.util.StringUtils.stringifyException(e)); } } From 73ff00418dd8c52c2590fcba8fd380df310087a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=BE=E6=96=B0=E4=BA=AE?= Date: Tue, 29 Jul 2025 09:29:37 +0800 Subject: [PATCH 05/14] throw exception --- .../java/org/apache/hadoop/hive/metastore/HMSHandler.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java index 72071cbf186c..64199ccd749b 100644 --- a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java +++ b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java @@ -3117,7 +3117,7 @@ private boolean checkTableDataShouldBeDeleted(Table tbl, boolean deleteData) { * data from warehouse * @param shouldEnableCm If cm should be enabled */ - private void deleteTableData(Path tablePath, boolean ifPurge, boolean shouldEnableCm) { + private void deleteTableData(Path tablePath, boolean ifPurge, boolean shouldEnableCm) throws MetaException { if (tablePath != null) { deleteDataExcludeCmroot(tablePath, ifPurge, shouldEnableCm); } @@ -3151,7 +3151,7 @@ private void deleteTableData(Path tablePath, boolean ifPurge, Database db) { * removing data from warehouse * @param shouldEnableCm If cm should be enabled */ - private void deletePartitionData(List partPaths, boolean ifPurge, boolean shouldEnableCm) { + private void deletePartitionData(List partPaths, boolean ifPurge, boolean shouldEnableCm) throws MetaException { if (partPaths != null && !partPaths.isEmpty()) { for (Path partPath : partPaths) { deleteDataExcludeCmroot(partPath, ifPurge, shouldEnableCm); @@ -3190,7 +3190,7 @@ private void deletePartitionData(List partPaths, boolean ifPurge, Database * removing data from warehouse * @param shouldEnableCm If cm should be enabled */ - private void deleteDataExcludeCmroot(Path path, boolean ifPurge, boolean shouldEnableCm) { + private void deleteDataExcludeCmroot(Path path, boolean ifPurge, boolean shouldEnableCm) throws MetaException { try { if (shouldEnableCm) { //Don't delete cmdir if its inside the partition path From f49a5b4a484a54a734d0963af32c4b46039a34b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=BE=E6=96=B0=E4=BA=AE?= Date: Tue, 29 Jul 2025 10:12:39 +0800 Subject: [PATCH 06/14] modify test --- .../plugin/metastore/TestHiveMetaStoreAuthorizer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java b/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java index e60926097c15..b3f7baf64cdb 100644 --- a/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java +++ b/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java @@ -851,10 +851,10 @@ public void testDropTableNoTablePathWritePermissionShouldFail() throws Exception FileStatus fileStatus = Mockito.mock(FileStatus.class); when(fileStatus.isDirectory()).thenReturn(true); when(fileStatus.getPath()).thenReturn(new Path(tblName)); - when(wh.getFs().listStatus(new Path(tblName))).thenReturn(new FileStatus[] { fileStatus }); + when(wh.getFs(new Path(tblName)).listStatus(new Path(tblName))).thenReturn(new FileStatus[] { fileStatus }); doThrow(new FileNotFoundException("Failed to delete director:")) - .when(wh.getFs()).delete(any(Path.class), anyBoolean()); + .when(wh.getFs(new Path(tblName))).delete(any(Path.class), anyBoolean()); try { hmsHandler.drop_table(default_db, tblName, true); From caa4e90bf8fb9f7da22c95a5dc98be5bb454530a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=BE=E6=96=B0=E4=BA=AE?= Date: Tue, 29 Jul 2025 10:52:42 +0800 Subject: [PATCH 07/14] modify test --- .../plugin/metastore/TestHiveMetaStoreAuthorizer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java b/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java index b3f7baf64cdb..8144626c483e 100644 --- a/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java +++ b/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java @@ -68,7 +68,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; -import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.eq; @@ -853,7 +853,7 @@ public void testDropTableNoTablePathWritePermissionShouldFail() throws Exception when(fileStatus.getPath()).thenReturn(new Path(tblName)); when(wh.getFs(new Path(tblName)).listStatus(new Path(tblName))).thenReturn(new FileStatus[] { fileStatus }); - doThrow(new FileNotFoundException("Failed to delete director:")) + doThrow(new MetaException("Failed to delete director:")) .when(wh.getFs(new Path(tblName))).delete(any(Path.class), anyBoolean()); try { From 7e49d102ee6f0088defa84536e630267441212a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=BE=E6=96=B0=E4=BA=AE?= Date: Tue, 29 Jul 2025 11:08:53 +0800 Subject: [PATCH 08/14] modify test --- .../plugin/metastore/TestHiveMetaStoreAuthorizer.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java b/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java index 8144626c483e..ffa72d424151 100644 --- a/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java +++ b/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java @@ -68,7 +68,8 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; -import static org.mockito.ArgumentMatchers; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.eq; From e7455a3f490e4b30683588af996c1b22acfe3e76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=BE=E6=96=B0=E4=BA=AE?= Date: Sun, 17 Aug 2025 20:25:00 +0800 Subject: [PATCH 09/14] Ensure the rollback of failed transactions is deleted --- .../hadoop/hive/metastore/HMSHandler.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java index 64199ccd749b..e5b3c54a673f 100644 --- a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java +++ b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java @@ -3072,22 +3072,26 @@ private boolean drop_table_core(final RawStore ms, final String catName, final S this, isReplicated), envContext); } - success = ms.commitTransaction(); - } - } finally { - if (!success) { - ms.rollbackTransaction(); - } else if (tableDataShouldBeDeleted) { - try { + if (tableDataShouldBeDeleted) { // Data needs deletion. Check if trash may be skipped. // Delete the data in the partitions which have other locations deletePartitionData(partPaths, ifPurge, ReplChangeManager.shouldEnableCm(db, tbl)); // Delete the data in the table deleteTableData(tblPath, ifPurge, ReplChangeManager.shouldEnableCm(db, tbl)); - } catch (Exception e) { - ms.rollbackTransaction(); - throw new MetaException(org.apache.hadoop.util.StringUtils.stringifyException(e)); } + success = ms.commitTransaction(); + } + } catch (Exception e) { + ms.rollbackTransaction(); + LOG.error("Failed to drop table " + name + ", rolling back transaction", e); + if (e instanceof MetaException) { + throw (MetaException) e; + } else { + throw new MetaException(org.apache.hadoop.util.StringUtils.stringifyException(e)); + } + } finally { + if (!success) { + ms.rollbackTransaction(); } if (!listeners.isEmpty()) { From 83ca188d866468b0712499df3c90a750abf69026 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=BE=E6=96=B0=E4=BA=AE?= Date: Thu, 21 Aug 2025 10:09:14 +0800 Subject: [PATCH 10/14] get tbl path --- .../java/org/apache/hadoop/hive/metastore/HMSHandler.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java index e5b3c54a673f..e4113328aea5 100644 --- a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java +++ b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java @@ -3051,6 +3051,10 @@ private boolean drop_table_core(final RawStore ms, final String catName, final S tableDataShouldBeDeleted = checkTableDataShouldBeDeleted(tbl, deleteData); + if (tableDataShouldBeDeleted && tbl.getSd().getLocation() != null) { + tblPath = new Path(tbl.getSd().getLocation()); + } + // Drop the partitions and get a list of locations which need to be deleted // In case of drop database cascade we need not to drop the partitions, they are already dropped. if (dropPartitions) { From 07ac244557160b4c98617cd20f55d9e715949744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=BE=E6=96=B0=E4=BA=AE?= Date: Mon, 8 Sep 2025 11:49:17 +0800 Subject: [PATCH 11/14] modify throw exception --- .../metastore/TestHiveMetaStoreAuthorizer.java | 4 ++-- .../apache/hadoop/hive/metastore/HMSHandler.java | 15 ++++++--------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java b/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java index ffa72d424151..caf865afbfe1 100644 --- a/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java +++ b/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java @@ -854,13 +854,13 @@ public void testDropTableNoTablePathWritePermissionShouldFail() throws Exception when(fileStatus.getPath()).thenReturn(new Path(tblName)); when(wh.getFs(new Path(tblName)).listStatus(new Path(tblName))).thenReturn(new FileStatus[] { fileStatus }); - doThrow(new MetaException("Failed to delete director:")) + doThrow(new IOException("Failed to delete director:")) .when(wh.getFs(new Path(tblName))).delete(any(Path.class), anyBoolean()); try { hmsHandler.drop_table(default_db, tblName, true); fail("Expected exception to be thrown due to lack of write permission"); - } catch (MetaException e) { + } catch (IOException e) { String expected = "Failed to delete director:"; assertTrue(e.getMessage().contains(expected)); } diff --git a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java index e4113328aea5..e8476783d9ed 100644 --- a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java +++ b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java @@ -3088,11 +3088,7 @@ private boolean drop_table_core(final RawStore ms, final String catName, final S } catch (Exception e) { ms.rollbackTransaction(); LOG.error("Failed to drop table " + name + ", rolling back transaction", e); - if (e instanceof MetaException) { - throw (MetaException) e; - } else { - throw new MetaException(org.apache.hadoop.util.StringUtils.stringifyException(e)); - } + throw new IOException(org.apache.hadoop.util.StringUtils.stringifyException(e)); } finally { if (!success) { ms.rollbackTransaction(); @@ -3125,7 +3121,7 @@ private boolean checkTableDataShouldBeDeleted(Table tbl, boolean deleteData) { * data from warehouse * @param shouldEnableCm If cm should be enabled */ - private void deleteTableData(Path tablePath, boolean ifPurge, boolean shouldEnableCm) throws MetaException { + private void deleteTableData(Path tablePath, boolean ifPurge, boolean shouldEnableCm) throws IOException { if (tablePath != null) { deleteDataExcludeCmroot(tablePath, ifPurge, shouldEnableCm); } @@ -3159,7 +3155,7 @@ private void deleteTableData(Path tablePath, boolean ifPurge, Database db) { * removing data from warehouse * @param shouldEnableCm If cm should be enabled */ - private void deletePartitionData(List partPaths, boolean ifPurge, boolean shouldEnableCm) throws MetaException { + private void deletePartitionData(List partPaths, boolean ifPurge, boolean shouldEnableCm) throws IOException { if (partPaths != null && !partPaths.isEmpty()) { for (Path partPath : partPaths) { deleteDataExcludeCmroot(partPath, ifPurge, shouldEnableCm); @@ -3198,7 +3194,7 @@ private void deletePartitionData(List partPaths, boolean ifPurge, Database * removing data from warehouse * @param shouldEnableCm If cm should be enabled */ - private void deleteDataExcludeCmroot(Path path, boolean ifPurge, boolean shouldEnableCm) throws MetaException { + private void deleteDataExcludeCmroot(Path path, boolean ifPurge, boolean shouldEnableCm) throws IOException { try { if (shouldEnableCm) { //Don't delete cmdir if its inside the partition path @@ -3217,7 +3213,8 @@ private void deleteDataExcludeCmroot(Path path, boolean ifPurge, boolean shouldE wh.deleteDir(path, true, ifPurge, shouldEnableCm); } } catch (Exception e) { - throw new MetaException("Failed to delete directory: " + path.toString() + " . Exception detail : " + LOG.error("Failed to delete directory: {}", path, e); + throw new IOException("Failed to delete directory: " + path.toString() + " . Exception detail : " + org.apache.hadoop.util.StringUtils.stringifyException(e)); } } From a5a78ac990e5e466d820080c5d8f1178c29e1f1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=BE=E6=96=B0=E4=BA=AE?= Date: Mon, 8 Sep 2025 17:37:14 +0800 Subject: [PATCH 12/14] import ioexception --- .../plugin/metastore/TestHiveMetaStoreAuthorizer.java | 1 + 1 file changed, 1 insertion(+) diff --git a/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java b/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java index caf865afbfe1..8475feace11f 100644 --- a/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java +++ b/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java @@ -60,6 +60,7 @@ import java.util.List; import java.util.Map; import java.io.File; +import java.io.IOException; import java.util.stream.Collectors; import java.util.Arrays; From 4b7d5d1480d0f1c734f5b56b3bd1febb84710db7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=BE=E6=96=B0=E4=BA=AE?= Date: Wed, 10 Sep 2025 18:38:19 +0800 Subject: [PATCH 13/14] modify test --- .../plugin/metastore/TestHiveMetaStoreAuthorizer.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java b/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java index 8475feace11f..f6819aa99134 100644 --- a/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java +++ b/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java @@ -60,7 +60,6 @@ import java.util.List; import java.util.Map; import java.io.File; -import java.io.IOException; import java.util.stream.Collectors; import java.util.Arrays; @@ -861,7 +860,7 @@ public void testDropTableNoTablePathWritePermissionShouldFail() throws Exception try { hmsHandler.drop_table(default_db, tblName, true); fail("Expected exception to be thrown due to lack of write permission"); - } catch (IOException e) { + } catch (MetaException e) { String expected = "Failed to delete director:"; assertTrue(e.getMessage().contains(expected)); } From 1c3380c34eed573d23bffd2d6d15b8b4d4e5dfc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=BE=E6=96=B0=E4=BA=AE?= Date: Thu, 11 Sep 2025 18:54:06 +0800 Subject: [PATCH 14/14] modify test --- .../plugin/metastore/TestHiveMetaStoreAuthorizer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java b/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java index f6819aa99134..ffa72d424151 100644 --- a/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java +++ b/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java @@ -854,7 +854,7 @@ public void testDropTableNoTablePathWritePermissionShouldFail() throws Exception when(fileStatus.getPath()).thenReturn(new Path(tblName)); when(wh.getFs(new Path(tblName)).listStatus(new Path(tblName))).thenReturn(new FileStatus[] { fileStatus }); - doThrow(new IOException("Failed to delete director:")) + doThrow(new MetaException("Failed to delete director:")) .when(wh.getFs(new Path(tblName))).delete(any(Path.class), anyBoolean()); try {